@justeattakeaway/pie-switch 0.29.12 → 0.30.0
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/custom-elements.json +33 -31
- package/dist/index.d.ts +13 -15
- package/dist/index.js +183 -171
- package/dist/react.d.ts +13 -15
- package/dist/react.js +12 -10
- package/package.json +1 -1
- package/src/defs-react.ts +1 -1
- package/src/defs.ts +4 -6
- package/src/index.ts +64 -51
- package/src/switch.scss +7 -7
package/custom-elements.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"type": {
|
|
36
36
|
"text": "DefaultProps"
|
|
37
37
|
},
|
|
38
|
-
"default": "{\n checked: false,\n
|
|
38
|
+
"default": "{\r\n checked: false,\r\n disabled: false,\r\n labelPlacement: 'leading',\r\n required: false,\r\n value: 'on',\r\n}"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
41
|
"exports": [
|
|
@@ -74,19 +74,11 @@
|
|
|
74
74
|
"description": "",
|
|
75
75
|
"name": "PieSwitch",
|
|
76
76
|
"members": [
|
|
77
|
-
{
|
|
78
|
-
"kind": "field",
|
|
79
|
-
"name": "input",
|
|
80
|
-
"type": {
|
|
81
|
-
"text": "HTMLInputElement | undefined"
|
|
82
|
-
},
|
|
83
|
-
"privacy": "private"
|
|
84
|
-
},
|
|
85
77
|
{
|
|
86
78
|
"kind": "field",
|
|
87
79
|
"name": "label",
|
|
88
80
|
"type": {
|
|
89
|
-
"text": "
|
|
81
|
+
"text": "SwitchProps['label']"
|
|
90
82
|
},
|
|
91
83
|
"privacy": "public",
|
|
92
84
|
"attribute": "label"
|
|
@@ -94,9 +86,6 @@
|
|
|
94
86
|
{
|
|
95
87
|
"kind": "field",
|
|
96
88
|
"name": "labelPlacement",
|
|
97
|
-
"type": {
|
|
98
|
-
"text": "SwitchProps['labelPlacement']"
|
|
99
|
-
},
|
|
100
89
|
"privacy": "public",
|
|
101
90
|
"attribute": "labelPlacement"
|
|
102
91
|
},
|
|
@@ -104,7 +93,7 @@
|
|
|
104
93
|
"kind": "field",
|
|
105
94
|
"name": "aria",
|
|
106
95
|
"type": {
|
|
107
|
-
"text": "
|
|
96
|
+
"text": "SwitchProps['aria']"
|
|
108
97
|
},
|
|
109
98
|
"privacy": "public",
|
|
110
99
|
"attribute": "aria"
|
|
@@ -133,7 +122,7 @@
|
|
|
133
122
|
"kind": "field",
|
|
134
123
|
"name": "name",
|
|
135
124
|
"type": {
|
|
136
|
-
"text": "
|
|
125
|
+
"text": "SwitchProps['name']"
|
|
137
126
|
},
|
|
138
127
|
"privacy": "public",
|
|
139
128
|
"attribute": "name"
|
|
@@ -145,6 +134,14 @@
|
|
|
145
134
|
"attribute": "disabled",
|
|
146
135
|
"reflects": true
|
|
147
136
|
},
|
|
137
|
+
{
|
|
138
|
+
"kind": "field",
|
|
139
|
+
"name": "input",
|
|
140
|
+
"type": {
|
|
141
|
+
"text": "HTMLInputElement | undefined"
|
|
142
|
+
},
|
|
143
|
+
"privacy": "private"
|
|
144
|
+
},
|
|
148
145
|
{
|
|
149
146
|
"kind": "field",
|
|
150
147
|
"name": "focusTarget",
|
|
@@ -188,7 +185,7 @@
|
|
|
188
185
|
"text": ""
|
|
189
186
|
}
|
|
190
187
|
},
|
|
191
|
-
"description": "Returns a boolean value which indicates validity of the value of the component. If the value is invalid, this method also fires the invalid event on the component.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity"
|
|
188
|
+
"description": "Returns a boolean value which indicates validity of the value of the component. If the value is invalid, this method also fires the invalid event on the component.\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity"
|
|
192
189
|
},
|
|
193
190
|
{
|
|
194
191
|
"kind": "method",
|
|
@@ -199,7 +196,7 @@
|
|
|
199
196
|
"text": ""
|
|
200
197
|
}
|
|
201
198
|
},
|
|
202
|
-
"description": "If the value is invalid, this method also fires the invalid event on the element, and (if the event isn't canceled) reports the problem to the user.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity"
|
|
199
|
+
"description": "If the value is invalid, this method also fires the invalid event on the element, and (if the event isn't canceled) reports the problem to the user.\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity"
|
|
203
200
|
},
|
|
204
201
|
{
|
|
205
202
|
"kind": "method",
|
|
@@ -218,7 +215,7 @@
|
|
|
218
215
|
}
|
|
219
216
|
}
|
|
220
217
|
],
|
|
221
|
-
"description": "Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity"
|
|
218
|
+
"description": "Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity"
|
|
222
219
|
},
|
|
223
220
|
{
|
|
224
221
|
"kind": "field",
|
|
@@ -227,7 +224,7 @@
|
|
|
227
224
|
"text": "ValidityState"
|
|
228
225
|
},
|
|
229
226
|
"privacy": "public",
|
|
230
|
-
"description": "(Read-only) returns a ValidityState with the validity states that this element is in.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity",
|
|
227
|
+
"description": "(Read-only) returns a ValidityState with the validity states that this element is in.\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity",
|
|
231
228
|
"readonly": true
|
|
232
229
|
},
|
|
233
230
|
{
|
|
@@ -237,19 +234,27 @@
|
|
|
237
234
|
"text": "string"
|
|
238
235
|
},
|
|
239
236
|
"privacy": "public",
|
|
240
|
-
"description": "(Read-only) Returns a string representing a localized message that describes the validation constraints that the control does not satisfy (if any).\nThis string is empty if the component is valid.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage",
|
|
237
|
+
"description": "(Read-only) Returns a string representing a localized message that describes the validation constraints that the control does not satisfy (if any).\r\nThis string is empty if the component is valid.\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage",
|
|
241
238
|
"readonly": true
|
|
242
239
|
},
|
|
243
240
|
{
|
|
244
241
|
"kind": "method",
|
|
245
242
|
"name": "renderSwitchLabel",
|
|
246
243
|
"privacy": "private",
|
|
247
|
-
"
|
|
248
|
-
|
|
249
|
-
"
|
|
244
|
+
"parameters": [
|
|
245
|
+
{
|
|
246
|
+
"name": "placement",
|
|
247
|
+
"type": {
|
|
248
|
+
"text": "SwitchProps['labelPlacement']"
|
|
249
|
+
}
|
|
250
250
|
}
|
|
251
|
-
|
|
252
|
-
"description": "
|
|
251
|
+
],
|
|
252
|
+
"description": "If a label is provided, renders it if `labelPlacement` matches the given position.\r\nIf no label is provided, or `labelPlacement` does not match the given position, nothing is rendered."
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"kind": "method",
|
|
256
|
+
"name": "renderAriaDescription",
|
|
257
|
+
"privacy": "private"
|
|
253
258
|
}
|
|
254
259
|
],
|
|
255
260
|
"events": [
|
|
@@ -271,21 +276,18 @@
|
|
|
271
276
|
{
|
|
272
277
|
"name": "label",
|
|
273
278
|
"type": {
|
|
274
|
-
"text": "
|
|
279
|
+
"text": "SwitchProps['label']"
|
|
275
280
|
},
|
|
276
281
|
"fieldName": "label"
|
|
277
282
|
},
|
|
278
283
|
{
|
|
279
284
|
"name": "labelPlacement",
|
|
280
|
-
"type": {
|
|
281
|
-
"text": "SwitchProps['labelPlacement']"
|
|
282
|
-
},
|
|
283
285
|
"fieldName": "labelPlacement"
|
|
284
286
|
},
|
|
285
287
|
{
|
|
286
288
|
"name": "aria",
|
|
287
289
|
"type": {
|
|
288
|
-
"text": "
|
|
290
|
+
"text": "SwitchProps['aria']"
|
|
289
291
|
},
|
|
290
292
|
"fieldName": "aria"
|
|
291
293
|
},
|
|
@@ -304,7 +306,7 @@
|
|
|
304
306
|
{
|
|
305
307
|
"name": "name",
|
|
306
308
|
"type": {
|
|
307
|
-
"text": "
|
|
309
|
+
"text": "SwitchProps['name']"
|
|
308
310
|
},
|
|
309
311
|
"fieldName": "name"
|
|
310
312
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,10 @@ import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
|
4
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
5
5
|
import type { LitElement } from 'lit';
|
|
6
6
|
import type { PIEInputElement } from '@justeattakeaway/pie-webc-core';
|
|
7
|
-
import type { PropertyValues } from 'lit';
|
|
8
7
|
import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
9
|
-
import type { TemplateResult } from 'lit';
|
|
8
|
+
import type { TemplateResult } from 'lit-html';
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
declare type AriaProps = {
|
|
12
11
|
label?: string;
|
|
13
12
|
describedBy?: string;
|
|
14
13
|
};
|
|
@@ -17,8 +16,6 @@ export declare type DefaultProps = ComponentDefaultProps<SwitchProps, keyof Omit
|
|
|
17
16
|
|
|
18
17
|
export declare const defaultProps: DefaultProps;
|
|
19
18
|
|
|
20
|
-
export declare type LabelPlacement = typeof labelPlacements[number];
|
|
21
|
-
|
|
22
19
|
export declare const labelPlacements: readonly ["leading", "trailing"];
|
|
23
20
|
|
|
24
21
|
/**
|
|
@@ -33,18 +30,18 @@ export declare const ON_SWITCH_CHANGED_EVENT = "change";
|
|
|
33
30
|
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
34
31
|
*/
|
|
35
32
|
export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PIEInputElement {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
label?: string;
|
|
40
|
-
labelPlacement: SwitchProps['labelPlacement'];
|
|
41
|
-
aria: AriaProps;
|
|
33
|
+
label: SwitchProps['label'];
|
|
34
|
+
labelPlacement: "leading" | "trailing";
|
|
35
|
+
aria: SwitchProps['aria'];
|
|
42
36
|
checked: boolean;
|
|
43
37
|
required: boolean;
|
|
44
38
|
value: string;
|
|
45
|
-
name
|
|
39
|
+
name: SwitchProps['name'];
|
|
46
40
|
disabled: boolean;
|
|
41
|
+
private input?;
|
|
47
42
|
focusTarget: HTMLElement;
|
|
43
|
+
protected firstUpdated(): void;
|
|
44
|
+
protected updated(): void;
|
|
48
45
|
static styles: CSSResult;
|
|
49
46
|
/**
|
|
50
47
|
* Ensures that the form value and validation state are in sync with the component.
|
|
@@ -84,12 +81,13 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
84
81
|
*/
|
|
85
82
|
get validationMessage(): string;
|
|
86
83
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
84
|
+
* If a label is provided, renders it if `labelPlacement` matches the given position.
|
|
85
|
+
* If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
|
|
89
86
|
*
|
|
90
87
|
* @private
|
|
91
88
|
*/
|
|
92
89
|
private renderSwitchLabel;
|
|
90
|
+
private renderAriaDescription;
|
|
93
91
|
render(): TemplateResult<1>;
|
|
94
92
|
}
|
|
95
93
|
|
|
@@ -119,7 +117,7 @@ export declare interface SwitchProps {
|
|
|
119
117
|
/**
|
|
120
118
|
* The placement of the label such as leading or trailing
|
|
121
119
|
*/
|
|
122
|
-
labelPlacement?:
|
|
120
|
+
labelPlacement?: typeof labelPlacements[number];
|
|
123
121
|
/**
|
|
124
122
|
* Same as the HTML name attribute - indicates the name of the switch (for use with forms)
|
|
125
123
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { LitElement as xe, nothing as L, html as N, unsafeCSS as Fe } from "lit";
|
|
2
|
+
import { property as E, query as le } from "lit/decorators.js";
|
|
3
|
+
import { classMap as Se } from "lit/directives/class-map.js";
|
|
4
|
+
import { ifDefined as Ie } from "lit/directives/if-defined.js";
|
|
5
|
+
import { FormControlMixin as Ve, RtlMixin as Te, wrapNativeEvent as Le, validPropertyValues as Ne, defineCustomElement as Pe } from "@justeattakeaway/pie-webc-core";
|
|
4
6
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
5
|
-
const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--switch-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--switch-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-hover-01)))}.c-switch:focus,.c-switch:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch:active{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-active-01)))}.c-switch[checked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.c-switch[checked]:focus,.c-switch[checked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[checked]:active{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}[disabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}@media (prefers-reduced-motion: no-preference){.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:disabled~.c-switch-control{color:var(--switch-bg-color--disabled)}.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--disabled)}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-switch-wrapper[data-is-rtl] .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-wrapper[data-is-rtl] .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper[data-is-rtl] .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
|
|
6
|
-
`, Pe = ["leading", "trailing"], ze = "change", x = {
|
|
7
|
-
checked: !1,
|
|
8
|
-
required: !1,
|
|
9
|
-
disabled: !1,
|
|
10
|
-
value: "on",
|
|
11
|
-
labelPlacement: "leading"
|
|
12
|
-
};
|
|
13
7
|
(function() {
|
|
14
|
-
(function(
|
|
15
|
-
const
|
|
8
|
+
(function(v) {
|
|
9
|
+
const o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), F = {
|
|
16
10
|
ariaAtomic: "aria-atomic",
|
|
17
11
|
ariaAutoComplete: "aria-autocomplete",
|
|
18
12
|
ariaBusy: "aria-busy",
|
|
@@ -56,72 +50,72 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
56
50
|
ariaValueText: "aria-valuetext",
|
|
57
51
|
role: "role"
|
|
58
52
|
}, de = (t, e) => {
|
|
59
|
-
for (let i in
|
|
53
|
+
for (let i in F) {
|
|
60
54
|
e[i] = null;
|
|
61
55
|
let a = null;
|
|
62
|
-
const r =
|
|
56
|
+
const r = F[i];
|
|
63
57
|
Object.defineProperty(e, i, {
|
|
64
58
|
get() {
|
|
65
59
|
return a;
|
|
66
60
|
},
|
|
67
|
-
set(
|
|
68
|
-
a =
|
|
61
|
+
set(s) {
|
|
62
|
+
a = s, t.isConnected ? t.setAttribute(r, s) : A.set(t, e);
|
|
69
63
|
}
|
|
70
64
|
});
|
|
71
65
|
}
|
|
72
66
|
};
|
|
73
67
|
function K(t) {
|
|
74
|
-
const e =
|
|
68
|
+
const e = l.get(t), { form: i } = e;
|
|
75
69
|
Z(t, i, e), X(t, e.labels);
|
|
76
70
|
}
|
|
77
71
|
const G = (t, e = !1) => {
|
|
78
72
|
const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
|
|
79
|
-
acceptNode(
|
|
80
|
-
return
|
|
73
|
+
acceptNode(s) {
|
|
74
|
+
return l.has(s) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
81
75
|
}
|
|
82
76
|
});
|
|
83
77
|
let a = i.nextNode();
|
|
84
78
|
const r = !e || t.disabled;
|
|
85
79
|
for (; a; )
|
|
86
80
|
a.formDisabledCallback && r && $(a, t.disabled), a = i.nextNode();
|
|
87
|
-
}, Y = { attributes: !0, attributeFilter: ["disabled", "name"] },
|
|
81
|
+
}, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, S = T() ? new MutationObserver((t) => {
|
|
88
82
|
for (const e of t) {
|
|
89
83
|
const i = e.target;
|
|
90
84
|
if (e.attributeName === "disabled" && (i.constructor.formAssociated ? $(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && G(i)), e.attributeName === "name" && i.constructor.formAssociated) {
|
|
91
|
-
const a =
|
|
85
|
+
const a = l.get(i), r = z.get(i);
|
|
92
86
|
a.setFormValue(r);
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
}) : {};
|
|
96
90
|
function O(t) {
|
|
97
91
|
t.forEach((e) => {
|
|
98
|
-
const { addedNodes: i, removedNodes: a } = e, r = Array.from(i),
|
|
99
|
-
r.forEach((
|
|
92
|
+
const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), s = Array.from(a);
|
|
93
|
+
r.forEach((n) => {
|
|
100
94
|
var u;
|
|
101
|
-
if (
|
|
102
|
-
const d =
|
|
103
|
-
Object.keys(
|
|
104
|
-
|
|
105
|
-
}),
|
|
95
|
+
if (l.has(n) && n.constructor.formAssociated && K(n), A.has(n)) {
|
|
96
|
+
const d = A.get(n);
|
|
97
|
+
Object.keys(F).filter((f) => d[f] !== null).forEach((f) => {
|
|
98
|
+
n.setAttribute(F[f], d[f]);
|
|
99
|
+
}), A.delete(n);
|
|
106
100
|
}
|
|
107
|
-
if (
|
|
108
|
-
const d =
|
|
109
|
-
|
|
101
|
+
if (x.has(n)) {
|
|
102
|
+
const d = x.get(n);
|
|
103
|
+
n.setAttribute("internals-valid", d.validity.valid.toString()), n.setAttribute("internals-invalid", (!d.validity.valid).toString()), n.setAttribute("aria-invalid", (!d.validity.valid).toString()), x.delete(n);
|
|
110
104
|
}
|
|
111
|
-
if (
|
|
112
|
-
const d = y.get(
|
|
105
|
+
if (n.localName === "form") {
|
|
106
|
+
const d = y.get(n), b = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
|
|
113
107
|
acceptNode(W) {
|
|
114
|
-
return
|
|
108
|
+
return l.has(W) && W.constructor.formAssociated && !(d && d.has(W)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
115
109
|
}
|
|
116
110
|
});
|
|
117
|
-
let f =
|
|
111
|
+
let f = b.nextNode();
|
|
118
112
|
for (; f; )
|
|
119
|
-
K(f), f =
|
|
113
|
+
K(f), f = b.nextNode();
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
}),
|
|
123
|
-
const u =
|
|
124
|
-
u && h.get(u) && J(u),
|
|
115
|
+
n.localName === "fieldset" && ((u = S.observe) === null || u === void 0 || u.call(S, n, Y), G(n, !0));
|
|
116
|
+
}), s.forEach((n) => {
|
|
117
|
+
const u = l.get(n);
|
|
118
|
+
u && h.get(u) && J(u), P.has(n) && P.get(n).disconnect();
|
|
125
119
|
});
|
|
126
120
|
});
|
|
127
121
|
}
|
|
@@ -130,7 +124,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
130
124
|
const { removedNodes: i } = e;
|
|
131
125
|
i.forEach((a) => {
|
|
132
126
|
const r = U.get(e.target);
|
|
133
|
-
|
|
127
|
+
l.has(a) && te(a), r.disconnect();
|
|
134
128
|
});
|
|
135
129
|
});
|
|
136
130
|
}
|
|
@@ -139,7 +133,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
139
133
|
const a = new MutationObserver(he);
|
|
140
134
|
!((e = window == null ? void 0 : window.ShadyDOM) === null || e === void 0) && e.inUse && t.mode && t.host && (t = t.host), (i = a.observe) === null || i === void 0 || i.call(a, t, { childList: !0 }), U.set(t, a);
|
|
141
135
|
};
|
|
142
|
-
|
|
136
|
+
T() && new MutationObserver(O);
|
|
143
137
|
const _ = {
|
|
144
138
|
childList: !0,
|
|
145
139
|
subtree: !0
|
|
@@ -154,20 +148,20 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
154
148
|
return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i), h.get(e).push(i), i;
|
|
155
149
|
}, pe = (t, e) => {
|
|
156
150
|
var i;
|
|
157
|
-
h.set(e, []), (i =
|
|
151
|
+
h.set(e, []), (i = S.observe) === null || i === void 0 || i.call(S, t, Y);
|
|
158
152
|
}, X = (t, e) => {
|
|
159
153
|
if (e.length) {
|
|
160
154
|
Array.from(e).forEach((a) => a.addEventListener("click", t.click.bind(t)));
|
|
161
155
|
let i = e[0].id;
|
|
162
156
|
e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), t.setAttribute("aria-labelledby", i);
|
|
163
157
|
}
|
|
164
|
-
},
|
|
165
|
-
const e = Array.from(t.elements).filter((
|
|
158
|
+
}, I = (t) => {
|
|
159
|
+
const e = Array.from(t.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i = y.get(t) || [], a = Array.from(i).filter((s) => s.isConnected).map((s) => l.get(s).validity.valid), r = [...e, ...a].includes(!1);
|
|
166
160
|
t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
|
|
167
161
|
}, fe = (t) => {
|
|
168
|
-
|
|
162
|
+
I(V(t.target));
|
|
169
163
|
}, me = (t) => {
|
|
170
|
-
|
|
164
|
+
I(V(t.target));
|
|
171
165
|
}, we = (t) => {
|
|
172
166
|
const e = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${t.id ? `,${i}[form='${t.id}']` : ""}`).join(",");
|
|
173
167
|
t.addEventListener("click", (i) => {
|
|
@@ -175,7 +169,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
175
169
|
const r = y.get(t);
|
|
176
170
|
if (t.noValidate)
|
|
177
171
|
return;
|
|
178
|
-
r.size && Array.from(r).reverse().map((u) =>
|
|
172
|
+
r.size && Array.from(r).reverse().map((u) => l.get(u).reportValidity()).includes(!1) && i.preventDefault();
|
|
179
173
|
}
|
|
180
174
|
});
|
|
181
175
|
}, be = (t) => {
|
|
@@ -194,26 +188,26 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
194
188
|
}
|
|
195
189
|
k.set(e, { ref: t, internals: i }), t.constructor.formAssociated && t.formAssociatedCallback && setTimeout(() => {
|
|
196
190
|
t.formAssociatedCallback.apply(t, [e]);
|
|
197
|
-
}, 0),
|
|
191
|
+
}, 0), I(e);
|
|
198
192
|
}
|
|
199
|
-
},
|
|
193
|
+
}, V = (t) => {
|
|
200
194
|
let e = t.parentNode;
|
|
201
|
-
return e && e.tagName !== "FORM" && (e =
|
|
202
|
-
},
|
|
195
|
+
return e && e.tagName !== "FORM" && (e = V(e)), e;
|
|
196
|
+
}, w = (t, e, i = DOMException) => {
|
|
203
197
|
if (!t.constructor.formAssociated)
|
|
204
198
|
throw new i(e);
|
|
205
199
|
}, ee = (t, e, i) => {
|
|
206
200
|
const a = y.get(t);
|
|
207
201
|
return a && a.size && a.forEach((r) => {
|
|
208
|
-
|
|
202
|
+
l.get(r)[i]() || (e = !1);
|
|
209
203
|
}), e;
|
|
210
204
|
}, te = (t) => {
|
|
211
205
|
if (t.constructor.formAssociated) {
|
|
212
|
-
const e =
|
|
206
|
+
const e = l.get(t), { labels: i, form: a } = e;
|
|
213
207
|
X(t, i), Z(t, a, e);
|
|
214
208
|
}
|
|
215
209
|
};
|
|
216
|
-
function
|
|
210
|
+
function T() {
|
|
217
211
|
return typeof MutationObserver < "u";
|
|
218
212
|
}
|
|
219
213
|
class ve {
|
|
@@ -221,7 +215,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
221
215
|
this.badInput = !1, this.customError = !1, this.patternMismatch = !1, this.rangeOverflow = !1, this.rangeUnderflow = !1, this.stepMismatch = !1, this.tooLong = !1, this.tooShort = !1, this.typeMismatch = !1, this.valid = !0, this.valueMissing = !1, Object.seal(this);
|
|
222
216
|
}
|
|
223
217
|
}
|
|
224
|
-
const ge = (t) => (t.badInput = !1, t.customError = !1, t.patternMismatch = !1, t.rangeOverflow = !1, t.rangeUnderflow = !1, t.stepMismatch = !1, t.tooLong = !1, t.tooShort = !1, t.typeMismatch = !1, t.valid = !0, t.valueMissing = !1, t), ye = (t, e, i) => (t.valid = Ee(e), Object.keys(e).forEach((a) => t[a] = e[a]), i &&
|
|
218
|
+
const ge = (t) => (t.badInput = !1, t.customError = !1, t.patternMismatch = !1, t.rangeOverflow = !1, t.rangeUnderflow = !1, t.stepMismatch = !1, t.tooLong = !1, t.tooShort = !1, t.typeMismatch = !1, t.valid = !0, t.valueMissing = !1, t), ye = (t, e, i) => (t.valid = Ee(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && I(i), t), Ee = (t) => {
|
|
225
219
|
let e = !0;
|
|
226
220
|
for (let i in t)
|
|
227
221
|
i !== "valid" && t[i] !== !1 && (e = !1);
|
|
@@ -275,10 +269,10 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
275
269
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
276
270
|
return a === "a" ? r.call(t, i) : r ? r.value = i : e.set(t, i), i;
|
|
277
271
|
}
|
|
278
|
-
var
|
|
272
|
+
var C;
|
|
279
273
|
class Me {
|
|
280
274
|
constructor(e) {
|
|
281
|
-
|
|
275
|
+
C.set(this, void 0), ke(this, C, e, "f");
|
|
282
276
|
for (let i = 0; i < e.length; i++) {
|
|
283
277
|
let a = e[i];
|
|
284
278
|
this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
|
|
@@ -286,10 +280,10 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
286
280
|
Object.freeze(this);
|
|
287
281
|
}
|
|
288
282
|
get length() {
|
|
289
|
-
return ae(this,
|
|
283
|
+
return ae(this, C, "f").length;
|
|
290
284
|
}
|
|
291
|
-
[(
|
|
292
|
-
return ae(this,
|
|
285
|
+
[(C = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
286
|
+
return ae(this, C, "f")[Symbol.iterator]();
|
|
293
287
|
}
|
|
294
288
|
item(e) {
|
|
295
289
|
return this[e] == null ? null : this[e];
|
|
@@ -303,21 +297,21 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
303
297
|
HTMLFormElement.prototype.checkValidity = i;
|
|
304
298
|
const e = HTMLFormElement.prototype.reportValidity;
|
|
305
299
|
HTMLFormElement.prototype.reportValidity = a;
|
|
306
|
-
function i(...
|
|
307
|
-
let
|
|
308
|
-
return ee(this,
|
|
300
|
+
function i(...s) {
|
|
301
|
+
let n = t.apply(this, s);
|
|
302
|
+
return ee(this, n, "checkValidity");
|
|
309
303
|
}
|
|
310
|
-
function a(...
|
|
311
|
-
let
|
|
312
|
-
return ee(this,
|
|
304
|
+
function a(...s) {
|
|
305
|
+
let n = e.apply(this, s);
|
|
306
|
+
return ee(this, n, "reportValidity");
|
|
313
307
|
}
|
|
314
308
|
const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
315
309
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
316
|
-
get(...
|
|
317
|
-
const
|
|
310
|
+
get(...s) {
|
|
311
|
+
const n = r.call(this, ...s), u = Array.from(y.get(this) || []);
|
|
318
312
|
if (u.length === 0)
|
|
319
|
-
return
|
|
320
|
-
const d = Array.from(
|
|
313
|
+
return n;
|
|
314
|
+
const d = Array.from(n).concat(u).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
|
|
321
315
|
return new Me(d);
|
|
322
316
|
}
|
|
323
317
|
});
|
|
@@ -330,13 +324,13 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
330
324
|
if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
|
|
331
325
|
throw new TypeError("Illegal constructor");
|
|
332
326
|
const i = e.getRootNode(), a = new ve();
|
|
333
|
-
this.states = new D(e),
|
|
327
|
+
this.states = new D(e), o.set(this, e), c.set(this, a), l.set(e, this), de(e, this), pe(e, this), Object.seal(this), i instanceof DocumentFragment && ue(i);
|
|
334
328
|
}
|
|
335
329
|
checkValidity() {
|
|
336
|
-
const e =
|
|
337
|
-
if (
|
|
330
|
+
const e = o.get(this);
|
|
331
|
+
if (w(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
338
332
|
return !0;
|
|
339
|
-
const i =
|
|
333
|
+
const i = c.get(this);
|
|
340
334
|
if (!i.valid) {
|
|
341
335
|
const a = new Event("invalid", {
|
|
342
336
|
bubbles: !1,
|
|
@@ -348,20 +342,20 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
348
342
|
return i.valid;
|
|
349
343
|
}
|
|
350
344
|
get form() {
|
|
351
|
-
const e =
|
|
352
|
-
|
|
345
|
+
const e = o.get(this);
|
|
346
|
+
w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
353
347
|
let i;
|
|
354
|
-
return e.constructor.formAssociated === !0 && (i =
|
|
348
|
+
return e.constructor.formAssociated === !0 && (i = V(e)), i;
|
|
355
349
|
}
|
|
356
350
|
get labels() {
|
|
357
|
-
const e =
|
|
358
|
-
|
|
351
|
+
const e = o.get(this);
|
|
352
|
+
w(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
359
353
|
const i = e.getAttribute("id"), a = e.getRootNode();
|
|
360
354
|
return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
|
|
361
355
|
}
|
|
362
356
|
reportValidity() {
|
|
363
|
-
const e =
|
|
364
|
-
if (
|
|
357
|
+
const e = o.get(this);
|
|
358
|
+
if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
365
359
|
return !0;
|
|
366
360
|
const i = this.checkValidity(), a = B.get(this);
|
|
367
361
|
if (a && !e.constructor.formAssociated)
|
|
@@ -369,8 +363,8 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
369
363
|
return !i && a && (e.focus(), a.focus()), i;
|
|
370
364
|
}
|
|
371
365
|
setFormValue(e) {
|
|
372
|
-
const i =
|
|
373
|
-
if (
|
|
366
|
+
const i = o.get(this);
|
|
367
|
+
if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), J(this), e != null && !(e instanceof FormData)) {
|
|
374
368
|
if (i.getAttribute("name")) {
|
|
375
369
|
const a = Q(i, this);
|
|
376
370
|
a.value = e;
|
|
@@ -378,46 +372,46 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
378
372
|
} else
|
|
379
373
|
e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
|
|
380
374
|
if (typeof r == "string") {
|
|
381
|
-
const
|
|
382
|
-
|
|
375
|
+
const s = Q(i, this);
|
|
376
|
+
s.name = a, s.value = r;
|
|
383
377
|
}
|
|
384
378
|
});
|
|
385
379
|
z.set(i, e);
|
|
386
380
|
}
|
|
387
381
|
setValidity(e, i, a) {
|
|
388
|
-
const r =
|
|
389
|
-
if (
|
|
382
|
+
const r = o.get(this);
|
|
383
|
+
if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
|
|
390
384
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
391
385
|
B.set(this, a);
|
|
392
|
-
const
|
|
393
|
-
for (const
|
|
394
|
-
|
|
395
|
-
Object.keys(
|
|
396
|
-
const u = Object.assign(Object.assign({},
|
|
386
|
+
const s = c.get(this), n = {};
|
|
387
|
+
for (const b in e)
|
|
388
|
+
n[b] = e[b];
|
|
389
|
+
Object.keys(n).length === 0 && ge(s);
|
|
390
|
+
const u = Object.assign(Object.assign({}, s), n);
|
|
397
391
|
delete u.valid;
|
|
398
|
-
const { valid: d } = ye(
|
|
392
|
+
const { valid: d } = ye(s, u, this.form);
|
|
399
393
|
if (!d && !i)
|
|
400
394
|
throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
|
|
401
|
-
|
|
395
|
+
g.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : x.set(r, this);
|
|
402
396
|
}
|
|
403
397
|
get shadowRoot() {
|
|
404
|
-
const e =
|
|
398
|
+
const e = o.get(this), i = q.get(e);
|
|
405
399
|
return i || null;
|
|
406
400
|
}
|
|
407
401
|
get validationMessage() {
|
|
408
|
-
const e =
|
|
409
|
-
return
|
|
402
|
+
const e = o.get(this);
|
|
403
|
+
return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), g.get(this);
|
|
410
404
|
}
|
|
411
405
|
get validity() {
|
|
412
|
-
const e =
|
|
413
|
-
return
|
|
406
|
+
const e = o.get(this);
|
|
407
|
+
return w(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), c.get(this);
|
|
414
408
|
}
|
|
415
409
|
get willValidate() {
|
|
416
|
-
const e =
|
|
417
|
-
return
|
|
410
|
+
const e = o.get(this);
|
|
411
|
+
return w(e, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(e.disabled || e.hasAttribute("disabled") || e.hasAttribute("readonly"));
|
|
418
412
|
}
|
|
419
413
|
}
|
|
420
|
-
function
|
|
414
|
+
function Ae() {
|
|
421
415
|
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
|
|
422
416
|
return !1;
|
|
423
417
|
class t extends HTMLElement {
|
|
@@ -454,9 +448,9 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
454
448
|
const e = CustomElementRegistry.prototype.define;
|
|
455
449
|
CustomElementRegistry.prototype.define = function(i, a, r) {
|
|
456
450
|
if (a.formAssociated) {
|
|
457
|
-
const
|
|
451
|
+
const s = a.prototype.connectedCallback;
|
|
458
452
|
a.prototype.connectedCallback = function() {
|
|
459
|
-
j.has(this) || (j.set(this, !0), this.hasAttribute("disabled") && $(this, !0)),
|
|
453
|
+
j.has(this) || (j.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), s != null && s.apply(this), te(this);
|
|
460
454
|
};
|
|
461
455
|
}
|
|
462
456
|
e.call(this, i, a, r);
|
|
@@ -468,45 +462,53 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
|
|
|
468
462
|
throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
|
|
469
463
|
} else
|
|
470
464
|
return {};
|
|
471
|
-
if (
|
|
465
|
+
if (l.has(this))
|
|
472
466
|
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
|
|
473
467
|
return new re(this);
|
|
474
468
|
}), typeof Element < "u") {
|
|
475
469
|
let e = function(...a) {
|
|
476
470
|
const r = i.apply(this, a);
|
|
477
|
-
if (q.set(this, r),
|
|
478
|
-
const
|
|
479
|
-
window.ShadyDOM ?
|
|
471
|
+
if (q.set(this, r), T()) {
|
|
472
|
+
const s = new MutationObserver(O);
|
|
473
|
+
window.ShadyDOM ? s.observe(this, _) : s.observe(r, _), P.set(this, s);
|
|
480
474
|
}
|
|
481
475
|
return r;
|
|
482
476
|
};
|
|
483
477
|
const i = Element.prototype.attachShadow;
|
|
484
478
|
Element.prototype.attachShadow = e;
|
|
485
479
|
}
|
|
486
|
-
|
|
480
|
+
T() && typeof document < "u" && new MutationObserver(O).observe(document.documentElement, _), typeof HTMLFormElement < "u" && Ce(), (t || typeof window < "u" && !window.CustomStateSet) && H();
|
|
487
481
|
}
|
|
488
482
|
}
|
|
489
|
-
return !!customElements.polyfillWrapFlushCallback || (
|
|
483
|
+
return !!customElements.polyfillWrapFlushCallback || (Ae() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : ne(!1)), v.forceCustomStateSetPolyfill = H, v.forceElementInternalsPolyfill = ne, Object.defineProperty(v, "__esModule", { value: !0 }), v;
|
|
490
484
|
})({});
|
|
491
485
|
})();
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
486
|
+
const Oe = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--switch-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--switch-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-hover-01)))}.c-switch:focus,.c-switch:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch:active{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-active-01)))}.c-switch[checked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.c-switch[checked]:focus,.c-switch[checked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[checked]:active{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}[disabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}@media (prefers-reduced-motion: no-preference){.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-wrapper--rtl .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:disabled~.c-switch-control{color:var(--switch-bg-color--disabled)}.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--disabled)}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-switch-wrapper--rtl .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--rtl .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
|
|
487
|
+
`, _e = ["leading", "trailing"], je = "change", M = {
|
|
488
|
+
checked: !1,
|
|
489
|
+
disabled: !1,
|
|
490
|
+
labelPlacement: "leading",
|
|
491
|
+
required: !1,
|
|
492
|
+
value: "on"
|
|
493
|
+
};
|
|
494
|
+
var $e = Object.defineProperty, Re = Object.getOwnPropertyDescriptor, m = (v, o, c, h) => {
|
|
495
|
+
for (var l = h > 1 ? void 0 : h ? Re(o, c) : o, g = v.length - 1, k; g >= 0; g--)
|
|
496
|
+
(k = v[g]) && (l = (h ? k(o, c, l) : k(l)) || l);
|
|
497
|
+
return h && l && $e(o, c, l), l;
|
|
496
498
|
};
|
|
497
499
|
const ce = "pie-switch";
|
|
498
|
-
class p extends
|
|
500
|
+
class p extends Ve(Te(xe)) {
|
|
499
501
|
constructor() {
|
|
500
|
-
super(...arguments), this.labelPlacement =
|
|
502
|
+
super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.required = M.required, this.value = M.value, this.disabled = M.disabled;
|
|
501
503
|
}
|
|
502
|
-
firstUpdated(
|
|
503
|
-
var
|
|
504
|
-
|
|
505
|
-
this.dispatchEvent(new Event("invalid",
|
|
504
|
+
firstUpdated() {
|
|
505
|
+
var o;
|
|
506
|
+
this.handleFormAssociation(), (o = this.input) == null || o.addEventListener("invalid", (c) => {
|
|
507
|
+
this.dispatchEvent(new Event("invalid", c));
|
|
506
508
|
});
|
|
507
509
|
}
|
|
508
|
-
updated(
|
|
509
|
-
|
|
510
|
+
updated() {
|
|
511
|
+
this.handleFormAssociation();
|
|
510
512
|
}
|
|
511
513
|
/**
|
|
512
514
|
* Ensures that the form value and validation state are in sync with the component.
|
|
@@ -518,10 +520,10 @@ class p extends Ie(Se(Fe)) {
|
|
|
518
520
|
* The handleChange function updates the checkbox state and emits an event for consumers.
|
|
519
521
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
520
522
|
*/
|
|
521
|
-
handleChange(
|
|
522
|
-
const { checked:
|
|
523
|
-
this.checked =
|
|
524
|
-
const h =
|
|
523
|
+
handleChange(o) {
|
|
524
|
+
const { checked: c } = o == null ? void 0 : o.currentTarget;
|
|
525
|
+
this.checked = c;
|
|
526
|
+
const h = Le(o);
|
|
525
527
|
this.dispatchEvent(h), this.handleFormAssociation();
|
|
526
528
|
}
|
|
527
529
|
/**
|
|
@@ -544,9 +546,9 @@ class p extends Ie(Se(Fe)) {
|
|
|
544
546
|
* Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
|
|
545
547
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
|
|
546
548
|
*/
|
|
547
|
-
setCustomValidity(
|
|
548
|
-
var
|
|
549
|
-
(
|
|
549
|
+
setCustomValidity(o) {
|
|
550
|
+
var c;
|
|
551
|
+
(c = this.input) == null || c.setCustomValidity(o), this._internals.setValidity(this.validity, this.validationMessage, this.input);
|
|
550
552
|
}
|
|
551
553
|
/**
|
|
552
554
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -564,68 +566,75 @@ class p extends Ie(Se(Fe)) {
|
|
|
564
566
|
return this.input.validationMessage;
|
|
565
567
|
}
|
|
566
568
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
+
* If a label is provided, renders it if `labelPlacement` matches the given position.
|
|
570
|
+
* If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
|
|
569
571
|
*
|
|
570
572
|
* @private
|
|
571
573
|
*/
|
|
572
|
-
renderSwitchLabel() {
|
|
573
|
-
const { label:
|
|
574
|
-
return
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
574
|
+
renderSwitchLabel(o) {
|
|
575
|
+
const { label: c, labelPlacement: h } = this;
|
|
576
|
+
return !c || h !== o ? L : N`
|
|
577
|
+
<span data-test-id="switch-label-${h}">
|
|
578
|
+
${c}
|
|
579
|
+
</span>`;
|
|
580
|
+
}
|
|
581
|
+
renderAriaDescription() {
|
|
582
|
+
var o;
|
|
583
|
+
return (o = this.aria) != null && o.describedBy ? N`
|
|
584
|
+
<div
|
|
585
|
+
id="switch-description"
|
|
586
|
+
data-test-id="switch-description"
|
|
587
|
+
class="c-switch-description">
|
|
588
|
+
${this.aria.describedBy}
|
|
589
|
+
</div>` : L;
|
|
578
590
|
}
|
|
579
591
|
render() {
|
|
580
592
|
const {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
return A`
|
|
593
|
+
aria: o,
|
|
594
|
+
checked: c,
|
|
595
|
+
disabled: h,
|
|
596
|
+
isRTL: l,
|
|
597
|
+
required: g
|
|
598
|
+
} = this;
|
|
599
|
+
return N`
|
|
589
600
|
<label
|
|
590
|
-
class="
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
601
|
+
class="${Se({
|
|
602
|
+
"c-switch-wrapper": !0,
|
|
603
|
+
"c-switch-wrapper--rtl": l
|
|
604
|
+
})}"
|
|
605
|
+
?disabled=${h}>
|
|
606
|
+
${this.renderSwitchLabel("leading")}
|
|
594
607
|
<div
|
|
595
608
|
data-test-id="switch-component"
|
|
596
609
|
class="c-switch"
|
|
597
|
-
?checked=${
|
|
610
|
+
?checked=${c}>
|
|
598
611
|
<input
|
|
599
612
|
data-test-id="switch-input"
|
|
600
613
|
role="switch"
|
|
601
614
|
type="checkbox"
|
|
602
615
|
class="c-switch-input"
|
|
603
|
-
.required=${
|
|
604
|
-
.checked="${
|
|
605
|
-
.disabled="${
|
|
616
|
+
.required=${g}
|
|
617
|
+
.checked="${c}"
|
|
618
|
+
.disabled="${h}"
|
|
606
619
|
@change="${this.handleChange}"
|
|
607
|
-
aria-label="${(
|
|
608
|
-
aria-describedby="${
|
|
620
|
+
aria-label="${Ie(o == null ? void 0 : o.label)}"
|
|
621
|
+
aria-describedby="${o != null && o.describedBy ? "switch-description" : L}">
|
|
609
622
|
<div class="c-switch-control">
|
|
610
|
-
${
|
|
623
|
+
${c ? N`<icon-check></icon-check>` : L}
|
|
611
624
|
</div>
|
|
612
625
|
</div>
|
|
613
|
-
${
|
|
614
|
-
${
|
|
615
|
-
</label
|
|
616
|
-
`;
|
|
626
|
+
${this.renderSwitchLabel("trailing")}
|
|
627
|
+
${this.renderAriaDescription()}
|
|
628
|
+
</label>`;
|
|
617
629
|
}
|
|
618
630
|
}
|
|
619
|
-
p.styles =
|
|
620
|
-
m([
|
|
621
|
-
le('input[type="checkbox"]')
|
|
622
|
-
], p.prototype, "input", 2);
|
|
631
|
+
p.styles = Fe(Oe);
|
|
623
632
|
m([
|
|
624
633
|
E({ type: String })
|
|
625
634
|
], p.prototype, "label", 2);
|
|
626
635
|
m([
|
|
627
636
|
E({ type: String }),
|
|
628
|
-
|
|
637
|
+
Ne(ce, _e, M.labelPlacement)
|
|
629
638
|
], p.prototype, "labelPlacement", 2);
|
|
630
639
|
m([
|
|
631
640
|
E({ type: Object })
|
|
@@ -645,13 +654,16 @@ m([
|
|
|
645
654
|
m([
|
|
646
655
|
E({ type: Boolean, reflect: !0 })
|
|
647
656
|
], p.prototype, "disabled", 2);
|
|
657
|
+
m([
|
|
658
|
+
le('input[type="checkbox"]')
|
|
659
|
+
], p.prototype, "input", 2);
|
|
648
660
|
m([
|
|
649
661
|
le("label")
|
|
650
662
|
], p.prototype, "focusTarget", 2);
|
|
651
|
-
|
|
663
|
+
Pe(ce, p);
|
|
652
664
|
export {
|
|
653
|
-
|
|
665
|
+
je as ON_SWITCH_CHANGED_EVENT,
|
|
654
666
|
p as PieSwitch,
|
|
655
|
-
|
|
656
|
-
|
|
667
|
+
M as defaultProps,
|
|
668
|
+
_e as labelPlacements
|
|
657
669
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -4,12 +4,11 @@ import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
|
4
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
5
5
|
import type { LitElement } from 'lit';
|
|
6
6
|
import type { PIEInputElement } from '@justeattakeaway/pie-webc-core';
|
|
7
|
-
import type { PropertyValues } from 'lit';
|
|
8
7
|
import * as React_2 from 'react';
|
|
9
8
|
import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
10
|
-
import type { TemplateResult } from 'lit';
|
|
9
|
+
import type { TemplateResult } from 'lit-html';
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
declare type AriaProps = {
|
|
13
12
|
label?: string;
|
|
14
13
|
describedBy?: string;
|
|
15
14
|
};
|
|
@@ -18,8 +17,6 @@ export declare type DefaultProps = ComponentDefaultProps<SwitchProps, keyof Omit
|
|
|
18
17
|
|
|
19
18
|
export declare const defaultProps: DefaultProps;
|
|
20
19
|
|
|
21
|
-
export declare type LabelPlacement = typeof labelPlacements[number];
|
|
22
|
-
|
|
23
20
|
export declare const labelPlacements: readonly ["leading", "trailing"];
|
|
24
21
|
|
|
25
22
|
/**
|
|
@@ -36,18 +33,18 @@ export declare const PieSwitch: React_2.ForwardRefExoticComponent<SwitchProps &
|
|
|
36
33
|
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
37
34
|
*/
|
|
38
35
|
declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInputElement {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
label?: string;
|
|
43
|
-
labelPlacement: SwitchProps['labelPlacement'];
|
|
44
|
-
aria: AriaProps;
|
|
36
|
+
label: SwitchProps['label'];
|
|
37
|
+
labelPlacement: "leading" | "trailing";
|
|
38
|
+
aria: SwitchProps['aria'];
|
|
45
39
|
checked: boolean;
|
|
46
40
|
required: boolean;
|
|
47
41
|
value: string;
|
|
48
|
-
name
|
|
42
|
+
name: SwitchProps['name'];
|
|
49
43
|
disabled: boolean;
|
|
44
|
+
private input?;
|
|
50
45
|
focusTarget: HTMLElement;
|
|
46
|
+
protected firstUpdated(): void;
|
|
47
|
+
protected updated(): void;
|
|
51
48
|
static styles: CSSResult;
|
|
52
49
|
/**
|
|
53
50
|
* Ensures that the form value and validation state are in sync with the component.
|
|
@@ -87,12 +84,13 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInpu
|
|
|
87
84
|
*/
|
|
88
85
|
get validationMessage(): string;
|
|
89
86
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
87
|
+
* If a label is provided, renders it if `labelPlacement` matches the given position.
|
|
88
|
+
* If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
|
|
92
89
|
*
|
|
93
90
|
* @private
|
|
94
91
|
*/
|
|
95
92
|
private renderSwitchLabel;
|
|
93
|
+
private renderAriaDescription;
|
|
96
94
|
render(): TemplateResult<1>;
|
|
97
95
|
}
|
|
98
96
|
|
|
@@ -129,7 +127,7 @@ export declare interface SwitchProps {
|
|
|
129
127
|
/**
|
|
130
128
|
* The placement of the label such as leading or trailing
|
|
131
129
|
*/
|
|
132
|
-
labelPlacement?:
|
|
130
|
+
labelPlacement?: typeof labelPlacements[number];
|
|
133
131
|
/**
|
|
134
132
|
* Same as the HTML name attribute - indicates the name of the switch (for use with forms)
|
|
135
133
|
*/
|
package/dist/react.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
1
|
+
import * as t from "react";
|
|
2
|
+
import { createComponent as e } from "@lit/react";
|
|
3
3
|
import { PieSwitch as i } from "./index.js";
|
|
4
|
-
import { ON_SWITCH_CHANGED_EVENT as
|
|
4
|
+
import { ON_SWITCH_CHANGED_EVENT as S, defaultProps as f, labelPlacements as C } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
6
|
import "lit/decorators.js";
|
|
7
|
+
import "lit/directives/class-map.js";
|
|
8
|
+
import "lit/directives/if-defined.js";
|
|
7
9
|
import "@justeattakeaway/pie-webc-core";
|
|
8
10
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
9
|
-
const o =
|
|
11
|
+
const o = e({
|
|
10
12
|
displayName: "PieSwitch",
|
|
11
13
|
elementClass: i,
|
|
12
|
-
react:
|
|
14
|
+
react: t,
|
|
13
15
|
tagName: "pie-switch",
|
|
14
16
|
events: {
|
|
15
17
|
onInvalid: "invalid",
|
|
16
18
|
onChange: "change"
|
|
17
19
|
// when the switch checked state is changed.
|
|
18
20
|
}
|
|
19
|
-
}),
|
|
21
|
+
}), h = o;
|
|
20
22
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
S as ON_SWITCH_CHANGED_EVENT,
|
|
24
|
+
h as PieSwitch,
|
|
25
|
+
f as defaultProps,
|
|
26
|
+
C as labelPlacements
|
|
25
27
|
};
|
package/package.json
CHANGED
package/src/defs-react.ts
CHANGED
package/src/defs.ts
CHANGED
|
@@ -2,9 +2,7 @@ import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
|
2
2
|
|
|
3
3
|
export const labelPlacements = ['leading', 'trailing'] as const;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type AriaProps = {
|
|
5
|
+
type AriaProps = {
|
|
8
6
|
label?: string,
|
|
9
7
|
describedBy?: string
|
|
10
8
|
};
|
|
@@ -33,7 +31,7 @@ export interface SwitchProps {
|
|
|
33
31
|
/**
|
|
34
32
|
* The placement of the label such as leading or trailing
|
|
35
33
|
*/
|
|
36
|
-
labelPlacement?:
|
|
34
|
+
labelPlacement?: typeof labelPlacements[number];
|
|
37
35
|
/**
|
|
38
36
|
* Same as the HTML name attribute - indicates the name of the switch (for use with forms)
|
|
39
37
|
*/
|
|
@@ -55,8 +53,8 @@ export type DefaultProps = ComponentDefaultProps<SwitchProps, keyof Omit<SwitchP
|
|
|
55
53
|
|
|
56
54
|
export const defaultProps: DefaultProps = {
|
|
57
55
|
checked: false,
|
|
58
|
-
required: false,
|
|
59
56
|
disabled: false,
|
|
60
|
-
value: 'on',
|
|
61
57
|
labelPlacement: 'leading',
|
|
58
|
+
required: false,
|
|
59
|
+
value: 'on',
|
|
62
60
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LitElement, html, unsafeCSS, nothing,
|
|
2
|
+
LitElement, html, unsafeCSS, nothing,
|
|
3
3
|
} from 'lit';
|
|
4
4
|
import { property, query } from 'lit/decorators.js';
|
|
5
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
6
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
7
|
+
import 'element-internals-polyfill';
|
|
8
|
+
|
|
5
9
|
import {
|
|
6
|
-
RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin, wrapNativeEvent, PIEInputElement,
|
|
10
|
+
RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin, wrapNativeEvent, type PIEInputElement,
|
|
7
11
|
} from '@justeattakeaway/pie-webc-core';
|
|
8
|
-
import styles from './switch.scss?inline';
|
|
9
|
-
import {
|
|
10
|
-
SwitchProps, AriaProps, labelPlacements, defaultProps,
|
|
11
|
-
} from './defs';
|
|
12
|
-
import 'element-internals-polyfill';
|
|
13
12
|
import '@justeattakeaway/pie-icons-webc/dist/IconCheck.js';
|
|
14
13
|
|
|
14
|
+
import styles from './switch.scss?inline';
|
|
15
|
+
import { type SwitchProps, labelPlacements, defaultProps } from './defs';
|
|
16
|
+
|
|
15
17
|
// Valid values available to consumers
|
|
16
18
|
export * from './defs';
|
|
17
19
|
|
|
@@ -22,34 +24,15 @@ const componentSelector = 'pie-switch';
|
|
|
22
24
|
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
23
25
|
*/
|
|
24
26
|
export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements SwitchProps, PIEInputElement {
|
|
25
|
-
@query('input[type="checkbox"]')
|
|
26
|
-
private input?: HTMLInputElement;
|
|
27
|
-
|
|
28
|
-
protected firstUpdated (_changedProperties: PropertyValues<this>): void {
|
|
29
|
-
super.firstUpdated(_changedProperties);
|
|
30
|
-
|
|
31
|
-
this.handleFormAssociation();
|
|
32
|
-
// This ensures that invalid events triggered by checkValidity() are propagated to the custom element
|
|
33
|
-
// for consumers to listen to: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
|
|
34
|
-
this.input?.addEventListener('invalid', (event) => {
|
|
35
|
-
this.dispatchEvent(new Event('invalid', event));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected updated (_changedProperties: PropertyValues<this>): void {
|
|
40
|
-
super.updated(_changedProperties);
|
|
41
|
-
this.handleFormAssociation();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
27
|
@property({ type: String })
|
|
45
|
-
public label
|
|
28
|
+
public label: SwitchProps['label'];
|
|
46
29
|
|
|
47
30
|
@property({ type: String })
|
|
48
31
|
@validPropertyValues(componentSelector, labelPlacements, defaultProps.labelPlacement)
|
|
49
|
-
public labelPlacement
|
|
32
|
+
public labelPlacement = defaultProps.labelPlacement;
|
|
50
33
|
|
|
51
34
|
@property({ type: Object })
|
|
52
|
-
public aria
|
|
35
|
+
public aria: SwitchProps['aria'];
|
|
53
36
|
|
|
54
37
|
@property({ type: Boolean, reflect: true })
|
|
55
38
|
public checked = defaultProps.checked;
|
|
@@ -61,14 +44,30 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
|
|
|
61
44
|
public value = defaultProps.value;
|
|
62
45
|
|
|
63
46
|
@property({ type: String })
|
|
64
|
-
public name
|
|
47
|
+
public name: SwitchProps['name'];
|
|
65
48
|
|
|
66
49
|
@property({ type: Boolean, reflect: true })
|
|
67
50
|
public disabled = defaultProps.disabled;
|
|
68
51
|
|
|
52
|
+
@query('input[type="checkbox"]')
|
|
53
|
+
private input?: HTMLInputElement;
|
|
54
|
+
|
|
69
55
|
@query('label')
|
|
70
56
|
public focusTarget!: HTMLElement;
|
|
71
57
|
|
|
58
|
+
protected firstUpdated (): void {
|
|
59
|
+
this.handleFormAssociation();
|
|
60
|
+
// This ensures that invalid events triggered by checkValidity() are propagated to the custom element
|
|
61
|
+
// for consumers to listen to: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
|
|
62
|
+
this.input?.addEventListener('invalid', (event) => {
|
|
63
|
+
this.dispatchEvent(new Event('invalid', event));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected updated (): void {
|
|
68
|
+
this.handleFormAssociation();
|
|
69
|
+
}
|
|
70
|
+
|
|
72
71
|
static styles = unsafeCSS(styles);
|
|
73
72
|
|
|
74
73
|
/**
|
|
@@ -148,42 +147,57 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
|
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
150
|
+
* If a label is provided, renders it if `labelPlacement` matches the given position.
|
|
151
|
+
* If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
|
|
153
152
|
*
|
|
154
153
|
* @private
|
|
155
154
|
*/
|
|
156
|
-
private renderSwitchLabel (
|
|
155
|
+
private renderSwitchLabel (placement : SwitchProps['labelPlacement']) {
|
|
157
156
|
const { label, labelPlacement } = this;
|
|
158
157
|
|
|
159
|
-
if (label) {
|
|
160
|
-
return
|
|
161
|
-
<span data-test-id="switch-label-${labelPlacement}">
|
|
162
|
-
${label}
|
|
163
|
-
</span>`;
|
|
158
|
+
if (!label || labelPlacement !== placement) {
|
|
159
|
+
return nothing;
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
return html
|
|
162
|
+
return html`
|
|
163
|
+
<span data-test-id="switch-label-${labelPlacement}">
|
|
164
|
+
${label}
|
|
165
|
+
</span>`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private renderAriaDescription () {
|
|
169
|
+
if (!this.aria?.describedBy) {
|
|
170
|
+
return nothing;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return html`
|
|
174
|
+
<div
|
|
175
|
+
id="switch-description"
|
|
176
|
+
data-test-id="switch-description"
|
|
177
|
+
class="c-switch-description">
|
|
178
|
+
${this.aria.describedBy}
|
|
179
|
+
</div>`;
|
|
167
180
|
}
|
|
168
181
|
|
|
169
182
|
render () {
|
|
170
183
|
const {
|
|
171
|
-
labelPlacement,
|
|
172
184
|
aria,
|
|
173
185
|
checked,
|
|
174
|
-
required,
|
|
175
186
|
disabled,
|
|
176
187
|
isRTL,
|
|
188
|
+
required,
|
|
177
189
|
} = this;
|
|
178
190
|
|
|
179
|
-
const
|
|
191
|
+
const classes = {
|
|
192
|
+
'c-switch-wrapper': true,
|
|
193
|
+
'c-switch-wrapper--rtl': isRTL,
|
|
194
|
+
};
|
|
180
195
|
|
|
181
196
|
return html`
|
|
182
197
|
<label
|
|
183
|
-
class="
|
|
184
|
-
?data-is-rtl=${isRTL}
|
|
198
|
+
class="${classMap(classes)}"
|
|
185
199
|
?disabled=${disabled}>
|
|
186
|
-
${
|
|
200
|
+
${this.renderSwitchLabel('leading')}
|
|
187
201
|
<div
|
|
188
202
|
data-test-id="switch-component"
|
|
189
203
|
class="c-switch"
|
|
@@ -197,16 +211,15 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
|
|
|
197
211
|
.checked="${checked}"
|
|
198
212
|
.disabled="${disabled}"
|
|
199
213
|
@change="${this.handleChange}"
|
|
200
|
-
aria-label="${aria?.label
|
|
201
|
-
aria-describedby="${aria?.describedBy ?
|
|
214
|
+
aria-label="${ifDefined(aria?.label)}"
|
|
215
|
+
aria-describedby="${aria?.describedBy ? 'switch-description' : nothing}">
|
|
202
216
|
<div class="c-switch-control">
|
|
203
217
|
${checked ? html`<icon-check></icon-check>` : nothing}
|
|
204
218
|
</div>
|
|
205
219
|
</div>
|
|
206
|
-
${
|
|
207
|
-
${
|
|
208
|
-
</label
|
|
209
|
-
`;
|
|
220
|
+
${this.renderSwitchLabel('trailing')}
|
|
221
|
+
${this.renderAriaDescription()}
|
|
222
|
+
</label>`;
|
|
210
223
|
}
|
|
211
224
|
}
|
|
212
225
|
|
package/src/switch.scss
CHANGED
|
@@ -111,6 +111,12 @@
|
|
|
111
111
|
background-color: var(--dt-color-interactive-light);
|
|
112
112
|
padding: var(--switch-padding);
|
|
113
113
|
|
|
114
|
+
.c-switch-wrapper--rtl & {
|
|
115
|
+
position: absolute;
|
|
116
|
+
left: initial;
|
|
117
|
+
right: 2px;
|
|
118
|
+
}
|
|
119
|
+
|
|
114
120
|
.c-switch-input:checked + & {
|
|
115
121
|
@include switch-transition(transform);
|
|
116
122
|
transform: translateX(var(--switch-translation));
|
|
@@ -136,13 +142,7 @@
|
|
|
136
142
|
@include p.visually-hidden;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
.c-switch-wrapper
|
|
140
|
-
.c-switch-control {
|
|
141
|
-
position: absolute;
|
|
142
|
-
left: initial;
|
|
143
|
-
right: 2px;
|
|
144
|
-
}
|
|
145
|
-
|
|
145
|
+
.c-switch-wrapper--rtl {
|
|
146
146
|
.c-switch-input:checked + .c-switch-control {
|
|
147
147
|
@include switch-transition(transform);
|
|
148
148
|
transform: translateX(calc(-1 * var(--switch-translation)));
|