@vaadin/radio-group 24.2.3 → 24.3.0-alpha10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/radio-group",
3
- "version": "24.2.3",
3
+ "version": "24.3.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,6 +21,10 @@
21
21
  "type": "module",
22
22
  "files": [
23
23
  "src",
24
+ "!src/vaadin-lit-radio-button.d.ts",
25
+ "!src/vaadin-lit-radio-button.js",
26
+ "!src/vaadin-lit-radio-group.d.ts",
27
+ "!src/vaadin-lit-radio-group.js",
24
28
  "theme",
25
29
  "vaadin-*.d.ts",
26
30
  "vaadin-*.js",
@@ -37,22 +41,23 @@
37
41
  "polymer"
38
42
  ],
39
43
  "dependencies": {
44
+ "@open-wc/dedupe-mixin": "^1.3.0",
40
45
  "@polymer/polymer": "^3.0.0",
41
- "@vaadin/a11y-base": "~24.2.3",
42
- "@vaadin/component-base": "~24.2.3",
43
- "@vaadin/field-base": "~24.2.3",
44
- "@vaadin/vaadin-lumo-styles": "~24.2.3",
45
- "@vaadin/vaadin-material-styles": "~24.2.3",
46
- "@vaadin/vaadin-themable-mixin": "~24.2.3"
46
+ "@vaadin/a11y-base": "24.3.0-alpha10",
47
+ "@vaadin/component-base": "24.3.0-alpha10",
48
+ "@vaadin/field-base": "24.3.0-alpha10",
49
+ "@vaadin/vaadin-lumo-styles": "24.3.0-alpha10",
50
+ "@vaadin/vaadin-material-styles": "24.3.0-alpha10",
51
+ "@vaadin/vaadin-themable-mixin": "24.3.0-alpha10"
47
52
  },
48
53
  "devDependencies": {
49
54
  "@esm-bundle/chai": "^4.3.4",
50
- "@vaadin/testing-helpers": "^0.5.0",
55
+ "@vaadin/testing-helpers": "^0.6.0",
51
56
  "sinon": "^13.0.2"
52
57
  },
53
58
  "web-types": [
54
59
  "web-types.json",
55
60
  "web-types.lit.json"
56
61
  ],
57
- "gitHead": "72e557e765e72559e9c6a525e257d185ad186dc5"
62
+ "gitHead": "0271523d93fe5df0425ff64206886614f3c6f401"
58
63
  }
@@ -0,0 +1,50 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ActiveMixinClass } from '@vaadin/a11y-base/src/active-mixin.js';
8
+ import type { DelegateFocusMixinClass } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
9
+ import type { DisabledMixinClass } from '@vaadin/a11y-base/src/disabled-mixin.js';
10
+ import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
11
+ import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
12
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
13
+ import type { CheckedMixinClass } from '@vaadin/field-base/src/checked-mixin.js';
14
+ import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
15
+ import type { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js';
16
+
17
+ /**
18
+ * Fired when the `checked` property changes.
19
+ */
20
+ export type RadioButtonCheckedChangedEvent = CustomEvent<{ value: boolean }>;
21
+
22
+ export interface RadioButtonCustomEventMap {
23
+ 'checked-changed': RadioButtonCheckedChangedEvent;
24
+ }
25
+
26
+ export interface RadioButtonEventMap extends HTMLElementEventMap, RadioButtonCustomEventMap {}
27
+
28
+ /**
29
+ * A mixin providing common radio-button functionality.
30
+ */
31
+ export declare function RadioButtonMixin<T extends Constructor<HTMLElement>>(
32
+ base: T,
33
+ ): Constructor<ActiveMixinClass> &
34
+ Constructor<CheckedMixinClass> &
35
+ Constructor<DelegateFocusMixinClass> &
36
+ Constructor<DelegateStateMixinClass> &
37
+ Constructor<DisabledMixinClass> &
38
+ Constructor<FocusMixinClass> &
39
+ Constructor<InputMixinClass> &
40
+ Constructor<KeyboardMixinClass> &
41
+ Constructor<LabelMixinClass> &
42
+ Constructor<RadioButtonMixinClass> &
43
+ T;
44
+
45
+ export declare class RadioButtonMixinClass {
46
+ /**
47
+ * The name of the radio button.
48
+ */
49
+ name: string;
50
+ }
@@ -0,0 +1,67 @@
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 { ActiveMixin } from '@vaadin/a11y-base/src/active-mixin.js';
7
+ import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
8
+ import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
9
+ import { InputController } from '@vaadin/field-base/src/input-controller.js';
10
+ import { LabelMixin } from '@vaadin/field-base/src/label-mixin.js';
11
+ import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
12
+
13
+ /**
14
+ * A mixin providing common radio-button functionality.
15
+ *
16
+ * @polymerMixin
17
+ * @mixes ActiveMixin
18
+ * @mixes CheckedMixin
19
+ * @mixes DelegateFocusMixin
20
+ * @mixes LabelMixin
21
+ */
22
+ export const RadioButtonMixin = (superclass) =>
23
+ class RadioButtonMixinClass extends LabelMixin(CheckedMixin(DelegateFocusMixin(ActiveMixin(superclass)))) {
24
+ static get properties() {
25
+ return {
26
+ /**
27
+ * The name of the radio button.
28
+ *
29
+ * @type {string}
30
+ */
31
+ name: {
32
+ type: String,
33
+ value: '',
34
+ },
35
+ };
36
+ }
37
+
38
+ /** @override */
39
+ static get delegateAttrs() {
40
+ return [...super.delegateAttrs, 'name'];
41
+ }
42
+
43
+ constructor() {
44
+ super();
45
+
46
+ this._setType('radio');
47
+
48
+ // Set the string "on" as the default value for the radio button following the HTML specification:
49
+ // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default-on
50
+ this.value = 'on';
51
+ }
52
+
53
+ /** @protected */
54
+ ready() {
55
+ super.ready();
56
+
57
+ this.addController(
58
+ new InputController(this, (input) => {
59
+ this._setInputElement(input);
60
+ this._setFocusElement(input);
61
+ this.stateTarget = input;
62
+ this.ariaTarget = input;
63
+ }),
64
+ );
65
+ this.addController(new LabelledInputController(this.inputElement, this._labelController));
66
+ }
67
+ };
@@ -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;
@@ -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
+ `;
@@ -3,24 +3,12 @@
3
3
  * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ActiveMixin } from '@vaadin/a11y-base/src/active-mixin.js';
7
- import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
8
6
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
9
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
10
- import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
11
- import { LabelMixin } from '@vaadin/field-base/src/label-mixin.js';
12
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+ import { type RadioButtonEventMap, RadioButtonMixin } from './vaadin-radio-button-mixin.js';
13
10
 
14
- /**
15
- * Fired when the `checked` property changes.
16
- */
17
- export type RadioButtonCheckedChangedEvent = CustomEvent<{ value: boolean }>;
18
-
19
- export interface RadioButtonCustomEventMap {
20
- 'checked-changed': RadioButtonCheckedChangedEvent;
21
- }
22
-
23
- export interface RadioButtonEventMap extends HTMLElementEventMap, RadioButtonCustomEventMap {}
11
+ export * from './vaadin-radio-button-mixin.js';
24
12
 
25
13
  /**
26
14
  * `<vaadin-radio-button>` is a web component representing a choice in a radio group.
@@ -57,14 +45,7 @@ export interface RadioButtonEventMap extends HTMLElementEventMap, RadioButtonCus
57
45
  *
58
46
  * @fires {CustomEvent} checked-changed - Fired when the `checked` property changes.
59
47
  */
60
- declare class RadioButton extends LabelMixin(
61
- CheckedMixin(DelegateFocusMixin(ActiveMixin(ElementMixin(ThemableMixin(ControllerMixin(HTMLElement)))))),
62
- ) {
63
- /**
64
- * The name of the radio button.
65
- */
66
- name: string;
67
-
48
+ declare class RadioButton extends RadioButtonMixin(ElementMixin(ThemableMixin(ControllerMixin(HTMLElement)))) {
68
49
  addEventListener<K extends keyof RadioButtonEventMap>(
69
50
  type: K,
70
51
  listener: (this: RadioButton, ev: RadioButtonEventMap[K]) => void,
@@ -4,16 +4,14 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
- import { ActiveMixin } from '@vaadin/a11y-base/src/active-mixin.js';
8
- import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
9
7
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
10
8
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
11
9
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
12
- import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
13
- import { InputController } from '@vaadin/field-base/src/input-controller.js';
14
- import { LabelMixin } from '@vaadin/field-base/src/label-mixin.js';
15
- import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
16
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
+ import { RadioButtonMixin } from './vaadin-radio-button-mixin.js';
12
+ import { radioButtonStyles } from './vaadin-radio-button-styles.js';
13
+
14
+ registerStyles('vaadin-radio-button', radioButtonStyles, { moduleId: 'vaadin-radio-button-styles' });
17
15
 
18
16
  /**
19
17
  * `<vaadin-radio-button>` is a web component representing a choice in a radio group.
@@ -52,91 +50,17 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
52
50
  *
53
51
  * @customElement
54
52
  * @extends HTMLElement
55
- * @mixes ControllerMixin
56
53
  * @mixes ThemableMixin
57
54
  * @mixes ElementMixin
58
- * @mixes ActiveMixin
59
- * @mixes CheckedMixin
60
- * @mixes LabelMixin
55
+ * @mixes RadioButtonMixin
61
56
  */
62
- class RadioButton extends LabelMixin(
63
- CheckedMixin(DelegateFocusMixin(ActiveMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerElement)))))),
64
- ) {
57
+ class RadioButton extends RadioButtonMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerElement)))) {
65
58
  static get is() {
66
59
  return 'vaadin-radio-button';
67
60
  }
68
61
 
69
62
  static get template() {
70
63
  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>
140
64
  <div class="vaadin-radio-button-container">
141
65
  <div part="radio" aria-hidden="true"></div>
142
66
  <slot name="input"></slot>
@@ -144,50 +68,6 @@ class RadioButton extends LabelMixin(
144
68
  </div>
145
69
  `;
146
70
  }
147
-
148
- static get properties() {
149
- return {
150
- /**
151
- * The name of the radio button.
152
- *
153
- * @type {string}
154
- */
155
- name: {
156
- type: String,
157
- value: '',
158
- },
159
- };
160
- }
161
-
162
- /** @override */
163
- static get delegateAttrs() {
164
- return [...super.delegateAttrs, 'name'];
165
- }
166
-
167
- constructor() {
168
- super();
169
-
170
- this._setType('radio');
171
-
172
- // Set the string "on" as the default value for the radio button following the HTML specification:
173
- // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default-on
174
- this.value = 'on';
175
- }
176
-
177
- /** @protected */
178
- ready() {
179
- super.ready();
180
-
181
- this.addController(
182
- new InputController(this, (input) => {
183
- this._setInputElement(input);
184
- this._setFocusElement(input);
185
- this.stateTarget = input;
186
- this.ariaTarget = input;
187
- }),
188
- );
189
- this.addController(new LabelledInputController(this.inputElement, this._labelController));
190
- }
191
71
  }
192
72
 
193
73
  defineCustomElement(RadioButton);
@@ -0,0 +1,68 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/a11y-base/src/disabled-mixin.js';
8
+ import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
9
+ import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
10
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
11
+ import type { FieldMixinClass } from '@vaadin/field-base/src/field-mixin.js';
12
+ import type { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js';
13
+ import type { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
14
+
15
+ /**
16
+ * Fired when the `invalid` property changes.
17
+ */
18
+ export type RadioGroupInvalidChangedEvent = CustomEvent<{ value: boolean }>;
19
+
20
+ /**
21
+ * Fired when the `value` property changes.
22
+ */
23
+ export type RadioGroupValueChangedEvent = CustomEvent<{ value: string }>;
24
+
25
+ /**
26
+ * Fired whenever the field is validated.
27
+ */
28
+ export type RadioGroupValidatedEvent = CustomEvent<{ valid: boolean }>;
29
+
30
+ export interface RadioGroupCustomEventMap {
31
+ 'invalid-changed': RadioGroupInvalidChangedEvent;
32
+
33
+ 'value-changed': RadioGroupValueChangedEvent;
34
+
35
+ validated: RadioGroupValidatedEvent;
36
+ }
37
+
38
+ export interface RadioGroupEventMap extends HTMLElementEventMap, RadioGroupCustomEventMap {}
39
+
40
+ /**
41
+ * A mixin providing common radio-group functionality.
42
+ */
43
+ export declare function RadioGroupMixin<T extends Constructor<HTMLElement>>(
44
+ base: T,
45
+ ): Constructor<ControllerMixinClass> &
46
+ Constructor<DisabledMixinClass> &
47
+ Constructor<FieldMixinClass> &
48
+ Constructor<FocusMixinClass> &
49
+ Constructor<KeyboardMixinClass> &
50
+ Constructor<LabelMixinClass> &
51
+ Constructor<RadioGroupMixinClass> &
52
+ Constructor<ValidateMixinClass> &
53
+ T;
54
+
55
+ export declare class RadioGroupMixinClass {
56
+ /**
57
+ * The value of the radio group.
58
+ */
59
+ value: string | null | undefined;
60
+
61
+ /**
62
+ * When present, the user cannot modify the value of the radio group.
63
+ * The property works similarly to the `disabled` property.
64
+ * While the `disabled` property disables all the radio buttons inside the group,
65
+ * the `readonly` property disables only unchecked ones.
66
+ */
67
+ readonly: boolean;
68
+ }