Skip to content

Commit b8956eb

Browse files
authored
refactor: extract radio button and group styles literals (#6676)
1 parent eb3ee80 commit b8956eb

6 files changed

Lines changed: 139 additions & 101 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const radioButtonStyles: CSSResult;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7+
8+
export const radioButtonStyles = css`
9+
:host {
10+
display: inline-block;
11+
}
12+
13+
:host([hidden]) {
14+
display: none !important;
15+
}
16+
17+
:host([disabled]) {
18+
-webkit-tap-highlight-color: transparent;
19+
}
20+
21+
.vaadin-radio-button-container {
22+
display: grid;
23+
grid-template-columns: auto 1fr;
24+
align-items: baseline;
25+
}
26+
27+
[part='radio'],
28+
::slotted(input),
29+
::slotted(label) {
30+
grid-row: 1;
31+
}
32+
33+
[part='radio'],
34+
::slotted(input) {
35+
grid-column: 1;
36+
}
37+
38+
[part='radio'] {
39+
width: var(--vaadin-radio-button-size, 1em);
40+
height: var(--vaadin-radio-button-size, 1em);
41+
--_input-border-width: var(--vaadin-input-field-border-width, 0);
42+
--_input-border-color: var(--vaadin-input-field-border-color, transparent);
43+
box-shadow: inset 0 0 0 var(--_input-border-width, 0) var(--_input-border-color);
44+
}
45+
46+
[part='radio']::before {
47+
display: block;
48+
content: '\\202F';
49+
line-height: var(--vaadin-radio-button-size, 1em);
50+
contain: paint;
51+
}
52+
53+
/* visually hidden */
54+
::slotted(input) {
55+
opacity: 0;
56+
cursor: inherit;
57+
margin: 0;
58+
align-self: stretch;
59+
-webkit-appearance: none;
60+
width: initial;
61+
height: initial;
62+
}
63+
64+
@media (forced-colors: active) {
65+
[part='radio'] {
66+
outline: 1px solid;
67+
outline-offset: -1px;
68+
}
69+
70+
:host([focused]) [part='radio'] {
71+
outline-width: 2px;
72+
}
73+
74+
:host([disabled]) [part='radio'] {
75+
outline-color: GrayText;
76+
}
77+
}
78+
`;

‎packages/radio-group/src/vaadin-radio-button.js‎

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
1313
import { InputController } from '@vaadin/field-base/src/input-controller.js';
1414
import { LabelMixin } from '@vaadin/field-base/src/label-mixin.js';
1515
import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
16-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
16+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
17+
import { radioButtonStyles } from './vaadin-radio-button-styles.js';
18+
19+
registerStyles('vaadin-radio-button', radioButtonStyles, { moduleId: 'vaadin-radio-button-styles' });
1720

1821
/**
1922
* `<vaadin-radio-button>` is a web component representing a choice in a radio group.
@@ -68,75 +71,6 @@ class RadioButton extends LabelMixin(
6871

6972
static get template() {
7073
return html`
71-
<style>
72-
:host {
73-
display: inline-block;
74-
}
75-
76-
:host([hidden]) {
77-
display: none !important;
78-
}
79-
80-
:host([disabled]) {
81-
-webkit-tap-highlight-color: transparent;
82-
}
83-
84-
.vaadin-radio-button-container {
85-
display: grid;
86-
grid-template-columns: auto 1fr;
87-
align-items: baseline;
88-
}
89-
90-
[part='radio'],
91-
::slotted(input),
92-
::slotted(label) {
93-
grid-row: 1;
94-
}
95-
96-
[part='radio'],
97-
::slotted(input) {
98-
grid-column: 1;
99-
}
100-
101-
[part='radio'] {
102-
width: var(--vaadin-radio-button-size, 1em);
103-
height: var(--vaadin-radio-button-size, 1em);
104-
--_input-border-width: var(--vaadin-input-field-border-width, 0);
105-
--_input-border-color: var(--vaadin-input-field-border-color, transparent);
106-
box-shadow: inset 0 0 0 var(--_input-border-width, 0) var(--_input-border-color);
107-
}
108-
109-
[part='radio']::before {
110-
display: block;
111-
content: '\\202F';
112-
line-height: var(--vaadin-radio-button-size, 1em);
113-
contain: paint;
114-
}
115-
116-
/* visually hidden */
117-
::slotted(input) {
118-
opacity: 0;
119-
cursor: inherit;
120-
margin: 0;
121-
align-self: stretch;
122-
-webkit-appearance: none;
123-
width: initial;
124-
height: initial;
125-
}
126-
127-
@media (forced-colors: active) {
128-
[part='radio'] {
129-
outline: 1px solid;
130-
outline-offset: -1px;
131-
}
132-
:host([focused]) [part='radio'] {
133-
outline-width: 2px;
134-
}
135-
:host([disabled]) [part='radio'] {
136-
outline-color: GrayText;
137-
}
138-
}
139-
</style>
14074
<div class="vaadin-radio-button-container">
14175
<div part="radio" aria-hidden="true"></div>
14276
<slot name="input"></slot>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const radioGroupStyles: CSSResult;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7+
8+
export const radioGroupStyles = css`
9+
:host {
10+
display: inline-flex;
11+
}
12+
13+
:host::before {
14+
content: '\\2003';
15+
width: 0;
16+
display: inline-block;
17+
}
18+
19+
:host([hidden]) {
20+
display: none !important;
21+
}
22+
23+
.vaadin-group-field-container {
24+
display: flex;
25+
flex-direction: column;
26+
width: 100%;
27+
}
28+
29+
[part='group-field'] {
30+
display: flex;
31+
flex-wrap: wrap;
32+
}
33+
34+
:host(:not([has-label])) [part='label'] {
35+
display: none;
36+
}
37+
`;

‎packages/radio-group/src/vaadin-radio-group.js‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
1313
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
1414
import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
1515
import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
16-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
16+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
1717
import { RadioButton } from './vaadin-radio-button.js';
18+
import { radioGroupStyles } from './vaadin-radio-group-styles.js';
19+
20+
registerStyles('vaadin-radio-group', radioGroupStyles, { moduleId: 'vaadin-radio-group-styles' });
1821

1922
/**
2023
* `<vaadin-radio-group>` is a web component that allows the user to choose one item from a group of choices.
@@ -76,36 +79,6 @@ class RadioGroup extends FieldMixin(
7679

7780
static get template() {
7881
return html`
79-
<style>
80-
:host {
81-
display: inline-flex;
82-
}
83-
84-
:host::before {
85-
content: '\\2003';
86-
width: 0;
87-
display: inline-block;
88-
}
89-
90-
:host([hidden]) {
91-
display: none !important;
92-
}
93-
94-
.vaadin-group-field-container {
95-
display: flex;
96-
flex-direction: column;
97-
width: 100%;
98-
}
99-
100-
[part='group-field'] {
101-
display: flex;
102-
flex-wrap: wrap;
103-
}
104-
105-
:host(:not([has-label])) [part='label'] {
106-
display: none;
107-
}
108-
</style>
10982
<div class="vaadin-group-field-container">
11083
<div part="label">
11184
<slot name="label"></slot>

0 commit comments

Comments
 (0)