@justeattakeaway/pie-switch 2.0.7 → 2.2.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 +9 -4
- package/dist/index.d.ts +7 -2
- package/dist/index.js +138 -136
- package/dist/react.d.ts +7 -2
- package/package.json +5 -5
- package/src/index.ts +16 -5
- package/src/switch.scss +6 -11
package/custom-elements.json
CHANGED
|
@@ -148,6 +148,15 @@
|
|
|
148
148
|
"privacy": "private",
|
|
149
149
|
"default": "false"
|
|
150
150
|
},
|
|
151
|
+
{
|
|
152
|
+
"kind": "field",
|
|
153
|
+
"name": "shadowRootOptions",
|
|
154
|
+
"type": {
|
|
155
|
+
"text": "object"
|
|
156
|
+
},
|
|
157
|
+
"static": true,
|
|
158
|
+
"default": "{ ...LitElement.shadowRootOptions, delegatesFocus: true }"
|
|
159
|
+
},
|
|
151
160
|
{
|
|
152
161
|
"kind": "method",
|
|
153
162
|
"name": "handleFormAssociation",
|
|
@@ -274,10 +283,6 @@
|
|
|
274
283
|
{
|
|
275
284
|
"name": "FormControlMixin",
|
|
276
285
|
"package": "@justeattakeaway/pie-webc-core"
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
"name": "RtlMixin",
|
|
280
|
-
"package": "@justeattakeaway/pie-webc-core"
|
|
281
286
|
}
|
|
282
287
|
],
|
|
283
288
|
"superclass": {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
|
4
4
|
import { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
5
5
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
6
6
|
import { PIEInputElement } from '@justeattakeaway/pie-webc-core';
|
|
7
|
-
import { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
8
7
|
import { TemplateResult } from 'lit-html';
|
|
9
8
|
|
|
10
9
|
declare type AriaProps = {
|
|
@@ -41,6 +40,12 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
41
40
|
private input;
|
|
42
41
|
focusTarget: HTMLElement;
|
|
43
42
|
private _isAnimationAllowed;
|
|
43
|
+
static shadowRootOptions: {
|
|
44
|
+
delegatesFocus: boolean;
|
|
45
|
+
mode: ShadowRootMode;
|
|
46
|
+
serializable?: boolean;
|
|
47
|
+
slotAssignment?: SlotAssignmentMode;
|
|
48
|
+
};
|
|
44
49
|
protected firstUpdated(): void;
|
|
45
50
|
protected updated(): void;
|
|
46
51
|
static styles: CSSResult;
|
|
@@ -92,7 +97,7 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
92
97
|
render(): TemplateResult<1>;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
declare const PieSwitch_base: GenericConstructor<FormControlInterface> &
|
|
100
|
+
declare const PieSwitch_base: GenericConstructor<FormControlInterface> & typeof PieElement;
|
|
96
101
|
|
|
97
102
|
export declare interface SwitchProps {
|
|
98
103
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as E, query as
|
|
1
|
+
import { LitElement as dt, nothing as L, html as N, unsafeCSS as It } from "lit";
|
|
2
|
+
import { property as E, query as ht, state as St } from "lit/decorators.js";
|
|
3
3
|
import { classMap as Vt } from "lit/directives/class-map.js";
|
|
4
4
|
import { ifDefined as Tt } from "lit/directives/if-defined.js";
|
|
5
|
-
import { FormControlMixin as Lt,
|
|
5
|
+
import { FormControlMixin as Lt, wrapNativeEvent as Nt, validPropertyValues as Ot, safeCustomElement as Pt } from "@justeattakeaway/pie-webc-core";
|
|
6
6
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
7
|
-
const O = class O extends
|
|
7
|
+
const O = class O extends dt {
|
|
8
8
|
willUpdate() {
|
|
9
9
|
this.getAttribute("v") || this.setAttribute("v", O.v);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
O.v = "2.0
|
|
12
|
+
O.v = "2.2.0";
|
|
13
13
|
let q = O;
|
|
14
14
|
(function() {
|
|
15
|
-
(function(
|
|
16
|
-
const
|
|
15
|
+
(function(l) {
|
|
16
|
+
const n = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), F = {
|
|
17
17
|
ariaAtomic: "aria-atomic",
|
|
18
18
|
ariaAutoComplete: "aria-autocomplete",
|
|
19
19
|
ariaBusy: "aria-busy",
|
|
@@ -56,7 +56,7 @@ let q = O;
|
|
|
56
56
|
ariaValueNow: "aria-valuenow",
|
|
57
57
|
ariaValueText: "aria-valuetext",
|
|
58
58
|
role: "role"
|
|
59
|
-
},
|
|
59
|
+
}, ut = (e, t) => {
|
|
60
60
|
for (let i in F) {
|
|
61
61
|
t[i] = null;
|
|
62
62
|
let a = null;
|
|
@@ -65,8 +65,8 @@ let q = O;
|
|
|
65
65
|
get() {
|
|
66
66
|
return a;
|
|
67
67
|
},
|
|
68
|
-
set(
|
|
69
|
-
a =
|
|
68
|
+
set(o) {
|
|
69
|
+
a = o, e.isConnected ? e.setAttribute(r, o) : A.set(e, t);
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -77,8 +77,8 @@ let q = O;
|
|
|
77
77
|
}
|
|
78
78
|
const J = (e, t = !1) => {
|
|
79
79
|
const i = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, {
|
|
80
|
-
acceptNode(
|
|
81
|
-
return c.has(
|
|
80
|
+
acceptNode(o) {
|
|
81
|
+
return c.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
let a = i.nextNode();
|
|
@@ -96,37 +96,37 @@ let q = O;
|
|
|
96
96
|
}) : {};
|
|
97
97
|
function _(e) {
|
|
98
98
|
e.forEach((t) => {
|
|
99
|
-
const { addedNodes: i, removedNodes: a } = t, r = Array.from(i),
|
|
100
|
-
r.forEach((
|
|
99
|
+
const { addedNodes: i, removedNodes: a } = t, r = Array.from(i), o = Array.from(a);
|
|
100
|
+
r.forEach((s) => {
|
|
101
101
|
var u;
|
|
102
|
-
if (c.has(
|
|
103
|
-
const d = A.get(
|
|
102
|
+
if (c.has(s) && s.constructor.formAssociated && Y(s), A.has(s)) {
|
|
103
|
+
const d = A.get(s);
|
|
104
104
|
Object.keys(F).filter((b) => d[b] !== null).forEach((b) => {
|
|
105
|
-
|
|
106
|
-
}), A.delete(
|
|
105
|
+
s.setAttribute(F[b], d[b]);
|
|
106
|
+
}), A.delete(s);
|
|
107
107
|
}
|
|
108
|
-
if (C.has(
|
|
109
|
-
const d = C.get(
|
|
110
|
-
|
|
108
|
+
if (C.has(s)) {
|
|
109
|
+
const d = C.get(s);
|
|
110
|
+
s.setAttribute("internals-valid", d.validity.valid.toString()), s.setAttribute("internals-invalid", (!d.validity.valid).toString()), s.setAttribute("aria-invalid", (!d.validity.valid).toString()), C.delete(s);
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
113
|
-
const d = y.get(
|
|
112
|
+
if (s.localName === "form") {
|
|
113
|
+
const d = y.get(s), w = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
|
|
114
114
|
acceptNode(z) {
|
|
115
115
|
return c.has(z) && z.constructor.formAssociated && !(d && d.has(z)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
|
-
let b =
|
|
118
|
+
let b = w.nextNode();
|
|
119
119
|
for (; b; )
|
|
120
|
-
Y(b), b =
|
|
120
|
+
Y(b), b = w.nextNode();
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
}),
|
|
124
|
-
const u = c.get(
|
|
125
|
-
u && m.get(u) && X(u), P.has(
|
|
122
|
+
s.localName === "fieldset" && ((u = I.observe) === null || u === void 0 || u.call(I, s, Q), J(s, !0));
|
|
123
|
+
}), o.forEach((s) => {
|
|
124
|
+
const u = c.get(s);
|
|
125
|
+
u && m.get(u) && X(u), P.has(s) && P.get(s).disconnect();
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function pt(e) {
|
|
130
130
|
e.forEach((t) => {
|
|
131
131
|
const { removedNodes: i } = t;
|
|
132
132
|
i.forEach((a) => {
|
|
@@ -135,9 +135,9 @@ let q = O;
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
const
|
|
138
|
+
const mt = (e) => {
|
|
139
139
|
var t, i;
|
|
140
|
-
const a = new MutationObserver(
|
|
140
|
+
const a = new MutationObserver(pt);
|
|
141
141
|
!((t = window == null ? void 0 : window.ShadyDOM) === null || t === void 0) && t.inUse && e.mode && e.host && (e = e.host), (i = a.observe) === null || i === void 0 || i.call(a, e, { childList: !0 }), K.set(e, a);
|
|
142
142
|
};
|
|
143
143
|
T() && new MutationObserver(_);
|
|
@@ -153,7 +153,7 @@ let q = O;
|
|
|
153
153
|
}, Z = (e, t) => {
|
|
154
154
|
const i = document.createElement("input");
|
|
155
155
|
return i.type = "hidden", i.name = e.getAttribute("name"), e.after(i), m.get(t).push(i), i;
|
|
156
|
-
},
|
|
156
|
+
}, ft = (e, t) => {
|
|
157
157
|
var i;
|
|
158
158
|
m.set(t, []), (i = I.observe) === null || i === void 0 || i.call(I, e, Q);
|
|
159
159
|
}, tt = (e, t) => {
|
|
@@ -163,12 +163,12 @@ let q = O;
|
|
|
163
163
|
t[0].id || (i = `${t[0].htmlFor}_Label`, t[0].id = i), e.setAttribute("aria-labelledby", i);
|
|
164
164
|
}
|
|
165
165
|
}, S = (e) => {
|
|
166
|
-
const t = Array.from(e.elements).filter((
|
|
166
|
+
const t = Array.from(e.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = y.get(e) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => c.get(o).validity.valid), r = [...t, ...a].includes(!1);
|
|
167
167
|
e.toggleAttribute("internals-invalid", r), e.toggleAttribute("internals-valid", !r);
|
|
168
|
-
}, ft = (e) => {
|
|
169
|
-
S(V(e.target));
|
|
170
168
|
}, bt = (e) => {
|
|
171
169
|
S(V(e.target));
|
|
170
|
+
}, vt = (e) => {
|
|
171
|
+
S(V(e.target));
|
|
172
172
|
}, wt = (e) => {
|
|
173
173
|
const t = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${e.id ? `,${i}[form='${e.id}']` : ""}`).join(",");
|
|
174
174
|
e.addEventListener("click", (i) => {
|
|
@@ -179,7 +179,7 @@ let q = O;
|
|
|
179
179
|
r.size && Array.from(r).reverse().map((u) => c.get(u).reportValidity()).includes(!1) && i.preventDefault();
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
|
-
},
|
|
182
|
+
}, gt = (e) => {
|
|
183
183
|
const t = y.get(e.target);
|
|
184
184
|
t && t.size && t.forEach((i) => {
|
|
185
185
|
i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
|
|
@@ -191,7 +191,7 @@ let q = O;
|
|
|
191
191
|
a.add(e);
|
|
192
192
|
else {
|
|
193
193
|
const r = /* @__PURE__ */ new Set();
|
|
194
|
-
r.add(e), y.set(t, r), wt(t), t.addEventListener("reset",
|
|
194
|
+
r.add(e), y.set(t, r), wt(t), t.addEventListener("reset", gt), t.addEventListener("input", bt), t.addEventListener("change", vt);
|
|
195
195
|
}
|
|
196
196
|
k.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
|
|
197
197
|
e.formAssociatedCallback.apply(e, [t]);
|
|
@@ -200,7 +200,7 @@ let q = O;
|
|
|
200
200
|
}, V = (e) => {
|
|
201
201
|
let t = e.parentNode;
|
|
202
202
|
return t && t.tagName !== "FORM" && (t = V(t)), t;
|
|
203
|
-
},
|
|
203
|
+
}, v = (e, t, i = DOMException) => {
|
|
204
204
|
if (!e.constructor.formAssociated)
|
|
205
205
|
throw new i(t);
|
|
206
206
|
}, it = (e, t, i) => {
|
|
@@ -217,12 +217,12 @@ let q = O;
|
|
|
217
217
|
function T() {
|
|
218
218
|
return typeof MutationObserver < "u";
|
|
219
219
|
}
|
|
220
|
-
class
|
|
220
|
+
class yt {
|
|
221
221
|
constructor() {
|
|
222
222
|
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);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
const
|
|
225
|
+
const Et = (e) => (e.badInput = !1, e.customError = !1, e.patternMismatch = !1, e.rangeOverflow = !1, e.rangeUnderflow = !1, e.stepMismatch = !1, e.tooLong = !1, e.tooShort = !1, e.typeMismatch = !1, e.valid = !0, e.valueMissing = !1, e), kt = (e, t, i) => (e.valid = Mt(t), Object.keys(t).forEach((a) => e[a] = t[a]), i && S(i), e), Mt = (e) => {
|
|
226
226
|
let t = !0;
|
|
227
227
|
for (let i in e)
|
|
228
228
|
i !== "valid" && e[i] !== !1 && (t = !1);
|
|
@@ -260,18 +260,18 @@ let q = O;
|
|
|
260
260
|
}), i;
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
function
|
|
263
|
+
function ot(e, t, i, a) {
|
|
264
264
|
if (typeof t == "function" ? e !== t || !a : !t.has(e)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
265
265
|
return i === "m" ? a : i === "a" ? a.call(e) : a ? a.value : t.get(e);
|
|
266
266
|
}
|
|
267
|
-
function
|
|
267
|
+
function xt(e, t, i, a, r) {
|
|
268
268
|
if (typeof t == "function" ? e !== t || !0 : !t.has(e)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
269
269
|
return t.set(e, i), i;
|
|
270
270
|
}
|
|
271
271
|
var x;
|
|
272
|
-
class
|
|
272
|
+
class At {
|
|
273
273
|
constructor(t) {
|
|
274
|
-
x.set(this, void 0),
|
|
274
|
+
x.set(this, void 0), xt(this, x, t);
|
|
275
275
|
for (let i = 0; i < t.length; i++) {
|
|
276
276
|
let a = t[i];
|
|
277
277
|
this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
|
|
@@ -279,10 +279,10 @@ let q = O;
|
|
|
279
279
|
Object.freeze(this);
|
|
280
280
|
}
|
|
281
281
|
get length() {
|
|
282
|
-
return
|
|
282
|
+
return ot(this, x, "f").length;
|
|
283
283
|
}
|
|
284
284
|
[(x = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
285
|
-
return
|
|
285
|
+
return ot(this, x, "f")[Symbol.iterator]();
|
|
286
286
|
}
|
|
287
287
|
item(t) {
|
|
288
288
|
return this[t] == null ? null : this[t];
|
|
@@ -291,43 +291,43 @@ let q = O;
|
|
|
291
291
|
return this[t] == null ? null : this[t];
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
function
|
|
294
|
+
function Ct() {
|
|
295
295
|
const e = HTMLFormElement.prototype.checkValidity;
|
|
296
296
|
HTMLFormElement.prototype.checkValidity = i;
|
|
297
297
|
const t = HTMLFormElement.prototype.reportValidity;
|
|
298
298
|
HTMLFormElement.prototype.reportValidity = a;
|
|
299
|
-
function i(...
|
|
300
|
-
let
|
|
301
|
-
return it(this,
|
|
299
|
+
function i(...o) {
|
|
300
|
+
let s = e.apply(this, o);
|
|
301
|
+
return it(this, s, "checkValidity");
|
|
302
302
|
}
|
|
303
|
-
function a(...
|
|
304
|
-
let
|
|
305
|
-
return it(this,
|
|
303
|
+
function a(...o) {
|
|
304
|
+
let s = t.apply(this, o);
|
|
305
|
+
return it(this, s, "reportValidity");
|
|
306
306
|
}
|
|
307
307
|
const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
308
308
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
309
|
-
get(...
|
|
310
|
-
const
|
|
309
|
+
get(...o) {
|
|
310
|
+
const s = r.call(this, ...o), u = Array.from(y.get(this) || []);
|
|
311
311
|
if (u.length === 0)
|
|
312
|
-
return
|
|
313
|
-
const d = Array.from(
|
|
314
|
-
return new
|
|
312
|
+
return s;
|
|
313
|
+
const d = Array.from(s).concat(u).sort((w, b) => w.compareDocumentPosition ? w.compareDocumentPosition(b) & 2 ? 1 : -1 : 0);
|
|
314
|
+
return new At(d);
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
class
|
|
318
|
+
class st {
|
|
319
319
|
static get isPolyfilled() {
|
|
320
320
|
return !0;
|
|
321
321
|
}
|
|
322
322
|
constructor(t) {
|
|
323
323
|
if (!t || !t.tagName || t.tagName.indexOf("-") === -1)
|
|
324
324
|
throw new TypeError("Illegal constructor");
|
|
325
|
-
const i = t.getRootNode(), a = new
|
|
326
|
-
this.states = new H(t),
|
|
325
|
+
const i = t.getRootNode(), a = new yt();
|
|
326
|
+
this.states = new H(t), n.set(this, t), h.set(this, a), c.set(t, this), ut(t, this), ft(t, this), Object.seal(this), i instanceof DocumentFragment && mt(i);
|
|
327
327
|
}
|
|
328
328
|
checkValidity() {
|
|
329
|
-
const t =
|
|
330
|
-
if (
|
|
329
|
+
const t = n.get(this);
|
|
330
|
+
if (v(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
331
331
|
return !0;
|
|
332
332
|
const i = h.get(this);
|
|
333
333
|
if (!i.valid) {
|
|
@@ -341,20 +341,20 @@ let q = O;
|
|
|
341
341
|
return i.valid;
|
|
342
342
|
}
|
|
343
343
|
get form() {
|
|
344
|
-
const t =
|
|
345
|
-
|
|
344
|
+
const t = n.get(this);
|
|
345
|
+
v(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
346
346
|
let i;
|
|
347
347
|
return t.constructor.formAssociated === !0 && (i = V(t)), i;
|
|
348
348
|
}
|
|
349
349
|
get labels() {
|
|
350
|
-
const t =
|
|
351
|
-
|
|
350
|
+
const t = n.get(this);
|
|
351
|
+
v(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
352
352
|
const i = t.getAttribute("id"), a = t.getRootNode();
|
|
353
353
|
return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
|
|
354
354
|
}
|
|
355
355
|
reportValidity() {
|
|
356
|
-
const t =
|
|
357
|
-
if (
|
|
356
|
+
const t = n.get(this);
|
|
357
|
+
if (v(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
358
358
|
return !0;
|
|
359
359
|
const i = this.checkValidity(), a = j.get(this);
|
|
360
360
|
if (a && !t.constructor.formAssociated)
|
|
@@ -362,54 +362,54 @@ let q = O;
|
|
|
362
362
|
return !i && a && (t.focus(), a.focus()), i;
|
|
363
363
|
}
|
|
364
364
|
setFormValue(t) {
|
|
365
|
-
const i =
|
|
366
|
-
if (
|
|
365
|
+
const i = n.get(this);
|
|
366
|
+
if (v(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), X(this), t != null && !(t instanceof FormData)) {
|
|
367
367
|
if (i.getAttribute("name")) {
|
|
368
368
|
const a = Z(i, this);
|
|
369
369
|
a.value = t;
|
|
370
370
|
}
|
|
371
371
|
} else t != null && t instanceof FormData && Array.from(t).reverse().forEach(([a, r]) => {
|
|
372
372
|
if (typeof r == "string") {
|
|
373
|
-
const
|
|
374
|
-
|
|
373
|
+
const o = Z(i, this);
|
|
374
|
+
o.name = a, o.value = r;
|
|
375
375
|
}
|
|
376
376
|
});
|
|
377
377
|
B.set(i, t);
|
|
378
378
|
}
|
|
379
379
|
setValidity(t, i, a) {
|
|
380
|
-
const r =
|
|
381
|
-
if (
|
|
380
|
+
const r = n.get(this);
|
|
381
|
+
if (v(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
|
|
382
382
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
383
383
|
j.set(this, a);
|
|
384
|
-
const
|
|
385
|
-
for (const
|
|
386
|
-
|
|
387
|
-
Object.keys(
|
|
388
|
-
const u = Object.assign(Object.assign({},
|
|
384
|
+
const o = h.get(this), s = {};
|
|
385
|
+
for (const w in t)
|
|
386
|
+
s[w] = t[w];
|
|
387
|
+
Object.keys(s).length === 0 && Et(o);
|
|
388
|
+
const u = Object.assign(Object.assign({}, o), s);
|
|
389
389
|
delete u.valid;
|
|
390
|
-
const { valid: d } =
|
|
390
|
+
const { valid: d } = kt(o, u, this.form);
|
|
391
391
|
if (!d && !i)
|
|
392
392
|
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.");
|
|
393
393
|
g.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : C.set(r, this);
|
|
394
394
|
}
|
|
395
395
|
get shadowRoot() {
|
|
396
|
-
const t =
|
|
396
|
+
const t = n.get(this), i = U.get(t);
|
|
397
397
|
return i || null;
|
|
398
398
|
}
|
|
399
399
|
get validationMessage() {
|
|
400
|
-
const t =
|
|
401
|
-
return
|
|
400
|
+
const t = n.get(this);
|
|
401
|
+
return v(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), g.get(this);
|
|
402
402
|
}
|
|
403
403
|
get validity() {
|
|
404
|
-
const t =
|
|
405
|
-
return
|
|
404
|
+
const t = n.get(this);
|
|
405
|
+
return v(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), h.get(this);
|
|
406
406
|
}
|
|
407
407
|
get willValidate() {
|
|
408
|
-
const t =
|
|
409
|
-
return
|
|
408
|
+
const t = n.get(this);
|
|
409
|
+
return v(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
function
|
|
412
|
+
function Ft() {
|
|
413
413
|
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
|
|
414
414
|
return !1;
|
|
415
415
|
class e extends HTMLElement {
|
|
@@ -442,13 +442,13 @@ let q = O;
|
|
|
442
442
|
}
|
|
443
443
|
function ct(e = !0) {
|
|
444
444
|
if (!nt) {
|
|
445
|
-
if (nt = !0, typeof window < "u" && (window.ElementInternals =
|
|
445
|
+
if (nt = !0, typeof window < "u" && (window.ElementInternals = st), typeof CustomElementRegistry < "u") {
|
|
446
446
|
const t = CustomElementRegistry.prototype.define;
|
|
447
447
|
CustomElementRegistry.prototype.define = function(i, a, r) {
|
|
448
448
|
if (a.formAssociated) {
|
|
449
|
-
const
|
|
449
|
+
const o = a.prototype.connectedCallback;
|
|
450
450
|
a.prototype.connectedCallback = function() {
|
|
451
|
-
G.has(this) || (G.set(this, !0), this.hasAttribute("disabled") && R(this, !0)),
|
|
451
|
+
G.has(this) || (G.set(this, !0), this.hasAttribute("disabled") && R(this, !0)), o != null && o.apply(this), at(this);
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
454
|
t.call(this, i, a, r);
|
|
@@ -461,45 +461,45 @@ let q = O;
|
|
|
461
461
|
} else return {};
|
|
462
462
|
if (c.has(this))
|
|
463
463
|
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
|
|
464
|
-
return new
|
|
464
|
+
return new st(this);
|
|
465
465
|
}), typeof Element < "u") {
|
|
466
466
|
let t = function(...a) {
|
|
467
467
|
const r = i.apply(this, a);
|
|
468
468
|
if (U.set(this, r), T()) {
|
|
469
|
-
const
|
|
470
|
-
window.ShadyDOM ?
|
|
469
|
+
const o = new MutationObserver(_);
|
|
470
|
+
window.ShadyDOM ? o.observe(this, $) : o.observe(r, $), P.set(this, o);
|
|
471
471
|
}
|
|
472
472
|
return r;
|
|
473
473
|
};
|
|
474
474
|
const i = Element.prototype.attachShadow;
|
|
475
475
|
Element.prototype.attachShadow = t;
|
|
476
476
|
}
|
|
477
|
-
T() && typeof document < "u" && new MutationObserver(_).observe(document.documentElement, $), typeof HTMLFormElement < "u" &&
|
|
477
|
+
T() && typeof document < "u" && new MutationObserver(_).observe(document.documentElement, $), typeof HTMLFormElement < "u" && Ct(), (e || typeof window < "u" && !window.CustomStateSet) && W();
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
|
-
return !!customElements.polyfillWrapFlushCallback || (
|
|
480
|
+
return !!customElements.polyfillWrapFlushCallback || (Ft() ? typeof window < "u" && !window.CustomStateSet && W(HTMLElement.prototype.attachInternals) : ct(!1)), l.forceCustomStateSetPolyfill = W, l.forceElementInternalsPolyfill = ct, Object.defineProperty(l, "__esModule", { value: !0 }), l;
|
|
481
481
|
})({});
|
|
482
482
|
})();
|
|
483
|
-
const
|
|
483
|
+
const _t = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);vertical-align:top;font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--int-states-mixin-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(--int-states-mixin-bg-color)}.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--hover-modifier)))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-form))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-form))}}.c-switch[checked]{--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--hover-modifier)))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-brand))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-brand))}}[disabled] .c-switch{--int-states-mixin-bg-color: var(--switch-bg-color--disabled);pointer-events:none}.c-switch:has(.c-switch-input:focus-visible){box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline: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)}.c-switch-wrapper:dir(rtl) .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-control .c-pieIcon--check{vertical-align:top}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--dt-color-interactive-brand)}.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)}.c-switch-label{color:var(--dt-color-content-default)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation .c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation .c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-wrapper:dir(rtl) .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}", $t = ["leading", "trailing"], Gt = "change", M = {
|
|
484
484
|
checked: !1,
|
|
485
485
|
disabled: !1,
|
|
486
486
|
labelPlacement: "leading",
|
|
487
487
|
required: !1,
|
|
488
488
|
value: "on"
|
|
489
489
|
};
|
|
490
|
-
var
|
|
491
|
-
for (var c = m > 1 ? void 0 : m ?
|
|
492
|
-
(k =
|
|
493
|
-
return m && c &&
|
|
490
|
+
var Rt = Object.defineProperty, Dt = Object.getOwnPropertyDescriptor, f = (l, n, h, m) => {
|
|
491
|
+
for (var c = m > 1 ? void 0 : m ? Dt(n, h) : n, g = l.length - 1, k; g >= 0; g--)
|
|
492
|
+
(k = l[g]) && (c = (m ? k(n, h, c) : k(c)) || c);
|
|
493
|
+
return m && c && Rt(n, h, c), c;
|
|
494
494
|
};
|
|
495
|
-
const
|
|
496
|
-
let p = class extends Lt(
|
|
495
|
+
const Ht = "pie-switch";
|
|
496
|
+
let p = class extends Lt(q) {
|
|
497
497
|
constructor() {
|
|
498
498
|
super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.required = M.required, this.value = M.value, this.disabled = M.disabled, this._isAnimationAllowed = !1;
|
|
499
499
|
}
|
|
500
500
|
firstUpdated() {
|
|
501
|
-
this.handleFormAssociation(), this.input.addEventListener("invalid", (
|
|
502
|
-
this.dispatchEvent(new Event("invalid",
|
|
501
|
+
this.handleFormAssociation(), this.input.addEventListener("invalid", (l) => {
|
|
502
|
+
this.dispatchEvent(new Event("invalid", l));
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
505
|
updated() {
|
|
@@ -515,10 +515,10 @@ let p = class extends Lt(Nt(q)) {
|
|
|
515
515
|
* The handleChange function updates the checkbox state and emits an event for consumers.
|
|
516
516
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
517
517
|
*/
|
|
518
|
-
handleChange(
|
|
519
|
-
const { checked:
|
|
520
|
-
this.checked =
|
|
521
|
-
const h =
|
|
518
|
+
handleChange(l) {
|
|
519
|
+
const { checked: n } = l == null ? void 0 : l.currentTarget;
|
|
520
|
+
this.checked = n;
|
|
521
|
+
const h = Nt(l);
|
|
522
522
|
this._isAnimationAllowed || (this._isAnimationAllowed = !0), this.dispatchEvent(h), this.handleFormAssociation();
|
|
523
523
|
}
|
|
524
524
|
/**
|
|
@@ -541,8 +541,8 @@ let p = class extends Lt(Nt(q)) {
|
|
|
541
541
|
* Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
|
|
542
542
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
|
|
543
543
|
*/
|
|
544
|
-
setCustomValidity(
|
|
545
|
-
this.input.setCustomValidity(
|
|
544
|
+
setCustomValidity(l) {
|
|
545
|
+
this.input.setCustomValidity(l), this._internals.setValidity(this.validity, this.validationMessage, this.input);
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
548
548
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -565,19 +565,21 @@ let p = class extends Lt(Nt(q)) {
|
|
|
565
565
|
*
|
|
566
566
|
* @private
|
|
567
567
|
*/
|
|
568
|
-
renderSwitchLabel(
|
|
569
|
-
const { label:
|
|
570
|
-
return !
|
|
568
|
+
renderSwitchLabel(l) {
|
|
569
|
+
const { label: n, labelPlacement: h } = this;
|
|
570
|
+
return !n || h !== l ? L : N`
|
|
571
571
|
<span
|
|
572
|
+
aria-hidden="true"
|
|
572
573
|
data-test-id="switch-label-${h}"
|
|
573
574
|
class="c-switch-label">
|
|
574
|
-
${
|
|
575
|
+
${n}
|
|
575
576
|
</span>`;
|
|
576
577
|
}
|
|
577
578
|
renderAriaDescription() {
|
|
578
|
-
var
|
|
579
|
-
return (
|
|
579
|
+
var l;
|
|
580
|
+
return (l = this.aria) != null && l.describedBy ? N`
|
|
580
581
|
<div
|
|
582
|
+
aria-hidden="true"
|
|
581
583
|
id="switch-description"
|
|
582
584
|
data-test-id="switch-description"
|
|
583
585
|
class="c-switch-description">
|
|
@@ -586,10 +588,10 @@ let p = class extends Lt(Nt(q)) {
|
|
|
586
588
|
}
|
|
587
589
|
render() {
|
|
588
590
|
const {
|
|
591
|
+
label: l,
|
|
589
592
|
aria: n,
|
|
590
|
-
checked:
|
|
591
|
-
disabled:
|
|
592
|
-
isRTL: m,
|
|
593
|
+
checked: h,
|
|
594
|
+
disabled: m,
|
|
593
595
|
required: c,
|
|
594
596
|
_isAnimationAllowed: g
|
|
595
597
|
} = this;
|
|
@@ -597,28 +599,27 @@ let p = class extends Lt(Nt(q)) {
|
|
|
597
599
|
<label
|
|
598
600
|
class="${Vt({
|
|
599
601
|
"c-switch-wrapper": !0,
|
|
600
|
-
"c-switch-wrapper--rtl": m,
|
|
601
602
|
"c-switch-wrapper--allow-animation": g
|
|
602
603
|
})}"
|
|
603
|
-
?disabled=${
|
|
604
|
+
?disabled=${m}>
|
|
604
605
|
${this.renderSwitchLabel("leading")}
|
|
605
606
|
<div
|
|
606
607
|
data-test-id="switch-component"
|
|
607
608
|
class="c-switch"
|
|
608
|
-
?checked=${
|
|
609
|
+
?checked=${h}>
|
|
609
610
|
<input
|
|
610
611
|
data-test-id="switch-input"
|
|
611
612
|
role="switch"
|
|
612
613
|
type="checkbox"
|
|
613
614
|
class="c-switch-input"
|
|
614
615
|
.required=${c}
|
|
615
|
-
.checked="${
|
|
616
|
-
.disabled="${
|
|
616
|
+
.checked="${h}"
|
|
617
|
+
.disabled="${m}"
|
|
617
618
|
@change="${this.handleChange}"
|
|
618
|
-
aria-label="${Tt(n == null ? void 0 : n.label)}"
|
|
619
|
+
aria-label="${Tt((n == null ? void 0 : n.label) || l)}"
|
|
619
620
|
aria-describedby="${n != null && n.describedBy ? "switch-description" : L}">
|
|
620
621
|
<div class="c-switch-control">
|
|
621
|
-
${
|
|
622
|
+
${h ? N`<icon-check></icon-check>` : L}
|
|
622
623
|
</div>
|
|
623
624
|
</div>
|
|
624
625
|
${this.renderSwitchLabel("trailing")}
|
|
@@ -626,13 +627,14 @@ let p = class extends Lt(Nt(q)) {
|
|
|
626
627
|
</label>`;
|
|
627
628
|
}
|
|
628
629
|
};
|
|
629
|
-
p.
|
|
630
|
+
p.shadowRootOptions = { ...dt.shadowRootOptions, delegatesFocus: !0 };
|
|
631
|
+
p.styles = It(_t);
|
|
630
632
|
f([
|
|
631
633
|
E({ type: String })
|
|
632
634
|
], p.prototype, "label", 2);
|
|
633
635
|
f([
|
|
634
636
|
E({ type: String }),
|
|
635
|
-
|
|
637
|
+
Ot(Ht, $t, M.labelPlacement)
|
|
636
638
|
], p.prototype, "labelPlacement", 2);
|
|
637
639
|
f([
|
|
638
640
|
E({ type: Object })
|
|
@@ -653,20 +655,20 @@ f([
|
|
|
653
655
|
E({ type: Boolean, reflect: !0 })
|
|
654
656
|
], p.prototype, "disabled", 2);
|
|
655
657
|
f([
|
|
656
|
-
|
|
658
|
+
ht('input[type="checkbox"]')
|
|
657
659
|
], p.prototype, "input", 2);
|
|
658
660
|
f([
|
|
659
|
-
|
|
661
|
+
ht("label")
|
|
660
662
|
], p.prototype, "focusTarget", 2);
|
|
661
663
|
f([
|
|
662
664
|
St()
|
|
663
665
|
], p.prototype, "_isAnimationAllowed", 2);
|
|
664
666
|
p = f([
|
|
665
|
-
|
|
667
|
+
Pt("pie-switch")
|
|
666
668
|
], p);
|
|
667
669
|
export {
|
|
668
|
-
|
|
670
|
+
Gt as ON_SWITCH_CHANGED_EVENT,
|
|
669
671
|
p as PieSwitch,
|
|
670
672
|
M as defaultProps,
|
|
671
|
-
|
|
673
|
+
$t as labelPlacements
|
|
672
674
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
|
5
5
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
6
6
|
import { PIEInputElement } from '@justeattakeaway/pie-webc-core';
|
|
7
7
|
import * as React_2 from 'react';
|
|
8
|
-
import { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
9
8
|
import { TemplateResult } from 'lit-html';
|
|
10
9
|
|
|
11
10
|
declare type AriaProps = {
|
|
@@ -44,6 +43,12 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInpu
|
|
|
44
43
|
private input;
|
|
45
44
|
focusTarget: HTMLElement;
|
|
46
45
|
private _isAnimationAllowed;
|
|
46
|
+
static shadowRootOptions: {
|
|
47
|
+
delegatesFocus: boolean;
|
|
48
|
+
mode: ShadowRootMode;
|
|
49
|
+
serializable?: boolean;
|
|
50
|
+
slotAssignment?: SlotAssignmentMode;
|
|
51
|
+
};
|
|
47
52
|
protected firstUpdated(): void;
|
|
48
53
|
protected updated(): void;
|
|
49
54
|
static styles: CSSResult;
|
|
@@ -95,7 +100,7 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInpu
|
|
|
95
100
|
render(): TemplateResult<1>;
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
declare const PieSwitch_base: GenericConstructor<FormControlInterface> &
|
|
103
|
+
declare const PieSwitch_base: GenericConstructor<FormControlInterface> & typeof PieElement;
|
|
99
104
|
|
|
100
105
|
declare type PieSwitchEvents = {
|
|
101
106
|
onInvalid?: (event: Event) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-switch",
|
|
3
3
|
"description": "PIE Design System Switch built using Web Components",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/justeattakeaway/pie",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
42
42
|
"@justeattakeaway/pie-components-config": "0.21.0",
|
|
43
|
-
"@justeattakeaway/pie-css": "0.
|
|
44
|
-
"@justeattakeaway/pie-monorepo-utils": "0.
|
|
43
|
+
"@justeattakeaway/pie-css": "0.20.0",
|
|
44
|
+
"@justeattakeaway/pie-monorepo-utils": "0.7.0",
|
|
45
45
|
"@justeattakeaway/pie-wrapper-react": "0.14.3",
|
|
46
46
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@justeattakeaway/pie-icons-webc": "1.14.
|
|
50
|
-
"@justeattakeaway/pie-webc-core": "1.
|
|
49
|
+
"@justeattakeaway/pie-icons-webc": "1.14.2",
|
|
50
|
+
"@justeattakeaway/pie-webc-core": "1.1.0",
|
|
51
51
|
"element-internals-polyfill": "1.3.11"
|
|
52
52
|
},
|
|
53
53
|
"volta": {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
html, unsafeCSS, nothing,
|
|
3
|
+
LitElement,
|
|
3
4
|
} from 'lit';
|
|
4
5
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
5
6
|
import { property, query, state } from 'lit/decorators.js';
|
|
@@ -8,8 +9,11 @@ import { ifDefined } from 'lit/directives/if-defined.js';
|
|
|
8
9
|
import 'element-internals-polyfill';
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
+
validPropertyValues,
|
|
13
|
+
FormControlMixin,
|
|
14
|
+
wrapNativeEvent,
|
|
12
15
|
safeCustomElement,
|
|
16
|
+
type PIEInputElement,
|
|
13
17
|
} from '@justeattakeaway/pie-webc-core';
|
|
14
18
|
import '@justeattakeaway/pie-icons-webc/dist/IconCheck.js';
|
|
15
19
|
|
|
@@ -26,7 +30,7 @@ const componentSelector = 'pie-switch';
|
|
|
26
30
|
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
27
31
|
*/
|
|
28
32
|
@safeCustomElement('pie-switch')
|
|
29
|
-
export class PieSwitch extends FormControlMixin(
|
|
33
|
+
export class PieSwitch extends FormControlMixin(PieElement) implements SwitchProps, PIEInputElement {
|
|
30
34
|
@property({ type: String })
|
|
31
35
|
public label: SwitchProps['label'];
|
|
32
36
|
|
|
@@ -61,6 +65,8 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
|
|
|
61
65
|
@state()
|
|
62
66
|
private _isAnimationAllowed = false;
|
|
63
67
|
|
|
68
|
+
static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
69
|
+
|
|
64
70
|
protected firstUpdated (): void {
|
|
65
71
|
this.handleFormAssociation();
|
|
66
72
|
// This ensures that invalid events triggered by checkValidity() are propagated to the custom element
|
|
@@ -169,8 +175,11 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
|
|
|
169
175
|
return nothing;
|
|
170
176
|
}
|
|
171
177
|
|
|
178
|
+
// Using aria-hidden here to prevent the label from potentially being narrated twice by screen readers such as Apple VoiceOver.
|
|
179
|
+
// Instead, we apply the label as an aria-label attribute on the input (if no aria.label prop is provided).
|
|
172
180
|
return html`
|
|
173
181
|
<span
|
|
182
|
+
aria-hidden="true"
|
|
174
183
|
data-test-id="switch-label-${labelPlacement}"
|
|
175
184
|
class="c-switch-label">
|
|
176
185
|
${label}
|
|
@@ -182,8 +191,11 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
|
|
|
182
191
|
return nothing;
|
|
183
192
|
}
|
|
184
193
|
|
|
194
|
+
// we apply aria-hidden to the element containing the description because it prevent some screen readers such as Apple VoiceOver from announcing the description once
|
|
195
|
+
// on the input and again separately. The description is still announced once, when the input is focused/selected.
|
|
185
196
|
return html`
|
|
186
197
|
<div
|
|
198
|
+
aria-hidden="true"
|
|
187
199
|
id="switch-description"
|
|
188
200
|
data-test-id="switch-description"
|
|
189
201
|
class="c-switch-description">
|
|
@@ -193,17 +205,16 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
|
|
|
193
205
|
|
|
194
206
|
render () {
|
|
195
207
|
const {
|
|
208
|
+
label,
|
|
196
209
|
aria,
|
|
197
210
|
checked,
|
|
198
211
|
disabled,
|
|
199
|
-
isRTL,
|
|
200
212
|
required,
|
|
201
213
|
_isAnimationAllowed,
|
|
202
214
|
} = this;
|
|
203
215
|
|
|
204
216
|
const classes = {
|
|
205
217
|
'c-switch-wrapper': true,
|
|
206
|
-
'c-switch-wrapper--rtl': isRTL,
|
|
207
218
|
'c-switch-wrapper--allow-animation': _isAnimationAllowed,
|
|
208
219
|
};
|
|
209
220
|
|
|
@@ -225,7 +236,7 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
|
|
|
225
236
|
.checked="${checked}"
|
|
226
237
|
.disabled="${disabled}"
|
|
227
238
|
@change="${this.handleChange}"
|
|
228
|
-
aria-label="${ifDefined(aria?.label)}"
|
|
239
|
+
aria-label="${ifDefined(aria?.label || label)}"
|
|
229
240
|
aria-describedby="${aria?.describedBy ? 'switch-description' : nothing}">
|
|
230
241
|
<div class="c-switch-control">
|
|
231
242
|
${checked ? html`<icon-check></icon-check>` : nothing}
|
package/src/switch.scss
CHANGED
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
background-color: var(--dt-color-interactive-light);
|
|
96
96
|
padding: var(--switch-padding);
|
|
97
97
|
|
|
98
|
-
.c-switch-wrapper
|
|
98
|
+
.c-switch-wrapper:dir(rtl) & {
|
|
99
99
|
position: absolute;
|
|
100
100
|
left: initial;
|
|
101
101
|
right: 2px;
|
|
@@ -131,11 +131,6 @@
|
|
|
131
131
|
@include p.visually-hidden;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
.c-switch-wrapper--rtl {
|
|
135
|
-
.c-switch-input:checked + .c-switch-control {
|
|
136
|
-
transform: translateX(calc(-1 * var(--switch-translation)));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
134
|
|
|
140
135
|
.c-switch-wrapper--allow-animation {
|
|
141
136
|
/* stylelint-disable-next-line no-descending-specificity */
|
|
@@ -165,10 +160,10 @@
|
|
|
165
160
|
}
|
|
166
161
|
}
|
|
167
162
|
}
|
|
163
|
+
}
|
|
168
164
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
165
|
+
.c-switch-wrapper:dir(rtl) {
|
|
166
|
+
.c-switch-input:checked + .c-switch-control {
|
|
167
|
+
transform: translateX(calc(-1 * var(--switch-translation)));
|
|
173
168
|
}
|
|
174
|
-
}
|
|
169
|
+
}
|