@justeattakeaway/pie-switch 0.30.1 → 0.30.2
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/dist/index.js +161 -171
- package/dist/react.js +10 -16
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import { classMap as
|
|
4
|
-
import { ifDefined as
|
|
5
|
-
import { FormControlMixin as
|
|
1
|
+
import { LitElement as Fe, unsafeCSS as Ie, nothing as L, html as N } from "lit";
|
|
2
|
+
import { property as y, query as ce } from "lit/decorators.js";
|
|
3
|
+
import { classMap as Ve } from "lit/directives/class-map.js";
|
|
4
|
+
import { ifDefined as Se } from "lit/directives/if-defined.js";
|
|
5
|
+
import { FormControlMixin as Te, RtlMixin as Le, wrapNativeEvent as Ne, validPropertyValues as Oe, defineCustomElement as Pe } from "@justeattakeaway/pie-webc-core";
|
|
6
6
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
7
7
|
(function() {
|
|
8
|
-
(function(
|
|
9
|
-
const o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(),
|
|
8
|
+
(function(E) {
|
|
9
|
+
const o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), F = {
|
|
10
10
|
ariaAtomic: "aria-atomic",
|
|
11
11
|
ariaAutoComplete: "aria-autocomplete",
|
|
12
12
|
ariaBusy: "aria-busy",
|
|
@@ -49,7 +49,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
49
49
|
ariaValueNow: "aria-valuenow",
|
|
50
50
|
ariaValueText: "aria-valuetext",
|
|
51
51
|
role: "role"
|
|
52
|
-
},
|
|
52
|
+
}, he = (t, e) => {
|
|
53
53
|
for (let i in F) {
|
|
54
54
|
e[i] = null;
|
|
55
55
|
let a = null;
|
|
@@ -64,11 +64,11 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
function
|
|
67
|
+
function G(t) {
|
|
68
68
|
const e = l.get(t), { form: i } = e;
|
|
69
|
-
|
|
69
|
+
ee(t, i, e), Z(t, e.labels);
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const Y = (t, e = !1) => {
|
|
72
72
|
const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
|
|
73
73
|
acceptNode(s) {
|
|
74
74
|
return l.has(s) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
@@ -78,21 +78,21 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
78
78
|
const r = !e || t.disabled;
|
|
79
79
|
for (; a; )
|
|
80
80
|
a.formDisabledCallback && r && $(a, t.disabled), a = i.nextNode();
|
|
81
|
-
},
|
|
81
|
+
}, J = { attributes: !0, attributeFilter: ["disabled", "name"] }, I = T() ? new MutationObserver((t) => {
|
|
82
82
|
for (const e of t) {
|
|
83
83
|
const i = e.target;
|
|
84
|
-
if (e.attributeName === "disabled" && (i.constructor.formAssociated ? $(i, i.hasAttribute("disabled")) : i.localName === "fieldset" &&
|
|
85
|
-
const a = l.get(i), r =
|
|
84
|
+
if (e.attributeName === "disabled" && (i.constructor.formAssociated ? $(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && Y(i)), e.attributeName === "name" && i.constructor.formAssociated) {
|
|
85
|
+
const a = l.get(i), r = q.get(i);
|
|
86
86
|
a.setFormValue(r);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}) : {};
|
|
90
|
-
function
|
|
90
|
+
function P(t) {
|
|
91
91
|
t.forEach((e) => {
|
|
92
92
|
const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), s = Array.from(a);
|
|
93
93
|
r.forEach((n) => {
|
|
94
|
-
var
|
|
95
|
-
if (l.has(n) && n.constructor.formAssociated &&
|
|
94
|
+
var h;
|
|
95
|
+
if (l.has(n) && n.constructor.formAssociated && G(n), A.has(n)) {
|
|
96
96
|
const d = A.get(n);
|
|
97
97
|
Object.keys(F).filter((f) => d[f] !== null).forEach((f) => {
|
|
98
98
|
n.setAttribute(F[f], d[f]);
|
|
@@ -103,125 +103,125 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
103
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);
|
|
104
104
|
}
|
|
105
105
|
if (n.localName === "form") {
|
|
106
|
-
const d =
|
|
106
|
+
const d = g.get(n), b = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
|
|
107
107
|
acceptNode(W) {
|
|
108
108
|
return l.has(W) && W.constructor.formAssociated && !(d && d.has(W)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
let f = b.nextNode();
|
|
112
112
|
for (; f; )
|
|
113
|
-
|
|
113
|
+
G(f), f = b.nextNode();
|
|
114
114
|
}
|
|
115
|
-
n.localName === "fieldset" && ((
|
|
115
|
+
n.localName === "fieldset" && ((h = I.observe) === null || h === void 0 || h.call(I, n, J), Y(n, !0));
|
|
116
116
|
}), s.forEach((n) => {
|
|
117
|
-
const
|
|
118
|
-
|
|
117
|
+
const h = l.get(n);
|
|
118
|
+
h && u.get(h) && Q(h), O.has(n) && O.get(n).disconnect();
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function ue(t) {
|
|
123
123
|
t.forEach((e) => {
|
|
124
124
|
const { removedNodes: i } = e;
|
|
125
125
|
i.forEach((a) => {
|
|
126
|
-
const r =
|
|
127
|
-
l.has(a) &&
|
|
126
|
+
const r = j.get(e.target);
|
|
127
|
+
l.has(a) && ie(a), r.disconnect();
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
const
|
|
131
|
+
const pe = (t) => {
|
|
132
132
|
var e, i;
|
|
133
|
-
const a = new MutationObserver(
|
|
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 }),
|
|
133
|
+
const a = new MutationObserver(ue);
|
|
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 }), j.set(t, a);
|
|
135
135
|
};
|
|
136
|
-
T() && new MutationObserver(
|
|
136
|
+
T() && new MutationObserver(P);
|
|
137
137
|
const _ = {
|
|
138
138
|
childList: !0,
|
|
139
139
|
subtree: !0
|
|
140
140
|
}, $ = (t, e) => {
|
|
141
141
|
t.toggleAttribute("internals-disabled", e), e ? t.setAttribute("aria-disabled", "true") : t.removeAttribute("aria-disabled"), t.formDisabledCallback && t.formDisabledCallback.apply(t, [e]);
|
|
142
|
-
},
|
|
143
|
-
|
|
142
|
+
}, Q = (t) => {
|
|
143
|
+
u.get(t).forEach((i) => {
|
|
144
144
|
i.remove();
|
|
145
|
-
}),
|
|
146
|
-
},
|
|
145
|
+
}), u.set(t, []);
|
|
146
|
+
}, X = (t, e) => {
|
|
147
147
|
const i = document.createElement("input");
|
|
148
|
-
return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i),
|
|
149
|
-
},
|
|
148
|
+
return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i), u.get(e).push(i), i;
|
|
149
|
+
}, fe = (t, e) => {
|
|
150
150
|
var i;
|
|
151
|
-
|
|
152
|
-
},
|
|
151
|
+
u.set(e, []), (i = I.observe) === null || i === void 0 || i.call(I, t, J);
|
|
152
|
+
}, Z = (t, e) => {
|
|
153
153
|
if (e.length) {
|
|
154
154
|
Array.from(e).forEach((a) => a.addEventListener("click", t.click.bind(t)));
|
|
155
155
|
let i = e[0].id;
|
|
156
156
|
e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), t.setAttribute("aria-labelledby", i);
|
|
157
157
|
}
|
|
158
|
-
},
|
|
159
|
-
const e = Array.from(t.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i =
|
|
158
|
+
}, V = (t) => {
|
|
159
|
+
const e = Array.from(t.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i = g.get(t) || [], a = Array.from(i).filter((s) => s.isConnected).map((s) => l.get(s).validity.valid), r = [...e, ...a].includes(!1);
|
|
160
160
|
t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
|
|
161
|
-
}, fe = (t) => {
|
|
162
|
-
I(V(t.target));
|
|
163
161
|
}, me = (t) => {
|
|
164
|
-
|
|
162
|
+
V(S(t.target));
|
|
165
163
|
}, we = (t) => {
|
|
164
|
+
V(S(t.target));
|
|
165
|
+
}, be = (t) => {
|
|
166
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(",");
|
|
167
167
|
t.addEventListener("click", (i) => {
|
|
168
168
|
if (i.target.closest(e)) {
|
|
169
|
-
const r =
|
|
169
|
+
const r = g.get(t);
|
|
170
170
|
if (t.noValidate)
|
|
171
171
|
return;
|
|
172
|
-
r.size && Array.from(r).reverse().map((
|
|
172
|
+
r.size && Array.from(r).reverse().map((h) => l.get(h).reportValidity()).includes(!1) && i.preventDefault();
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
|
-
},
|
|
176
|
-
const e =
|
|
175
|
+
}, ve = (t) => {
|
|
176
|
+
const e = g.get(t.target);
|
|
177
177
|
e && e.size && e.forEach((i) => {
|
|
178
178
|
i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
|
|
179
179
|
});
|
|
180
|
-
},
|
|
180
|
+
}, ee = (t, e, i) => {
|
|
181
181
|
if (e) {
|
|
182
|
-
const a =
|
|
182
|
+
const a = g.get(e);
|
|
183
183
|
if (a)
|
|
184
184
|
a.add(t);
|
|
185
185
|
else {
|
|
186
186
|
const r = /* @__PURE__ */ new Set();
|
|
187
|
-
r.add(t),
|
|
187
|
+
r.add(t), g.set(e, r), be(e), e.addEventListener("reset", ve), e.addEventListener("input", me), e.addEventListener("change", we);
|
|
188
188
|
}
|
|
189
|
-
|
|
189
|
+
M.set(e, { ref: t, internals: i }), t.constructor.formAssociated && t.formAssociatedCallback && setTimeout(() => {
|
|
190
190
|
t.formAssociatedCallback.apply(t, [e]);
|
|
191
|
-
}, 0),
|
|
191
|
+
}, 0), V(e);
|
|
192
192
|
}
|
|
193
|
-
},
|
|
193
|
+
}, S = (t) => {
|
|
194
194
|
let e = t.parentNode;
|
|
195
|
-
return e && e.tagName !== "FORM" && (e =
|
|
195
|
+
return e && e.tagName !== "FORM" && (e = S(e)), e;
|
|
196
196
|
}, w = (t, e, i = DOMException) => {
|
|
197
197
|
if (!t.constructor.formAssociated)
|
|
198
198
|
throw new i(e);
|
|
199
|
-
},
|
|
200
|
-
const a =
|
|
199
|
+
}, te = (t, e, i) => {
|
|
200
|
+
const a = g.get(t);
|
|
201
201
|
return a && a.size && a.forEach((r) => {
|
|
202
202
|
l.get(r)[i]() || (e = !1);
|
|
203
203
|
}), e;
|
|
204
|
-
},
|
|
204
|
+
}, ie = (t) => {
|
|
205
205
|
if (t.constructor.formAssociated) {
|
|
206
206
|
const e = l.get(t), { labels: i, form: a } = e;
|
|
207
|
-
|
|
207
|
+
Z(t, i), ee(t, a, e);
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
function T() {
|
|
211
211
|
return typeof MutationObserver < "u";
|
|
212
212
|
}
|
|
213
|
-
class
|
|
213
|
+
class ge {
|
|
214
214
|
constructor() {
|
|
215
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);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
const
|
|
218
|
+
const ye = (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), Ee = (t, e, i) => (t.valid = ke(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && V(i), t), ke = (t) => {
|
|
219
219
|
let e = !0;
|
|
220
220
|
for (let i in t)
|
|
221
221
|
i !== "valid" && t[i] !== !1 && (e = !1);
|
|
222
222
|
return e;
|
|
223
223
|
}, R = /* @__PURE__ */ new WeakMap();
|
|
224
|
-
function
|
|
224
|
+
function ae(t, e) {
|
|
225
225
|
t.toggleAttribute(e, !0), t.part && t.part.add(e);
|
|
226
226
|
}
|
|
227
227
|
class D extends Set {
|
|
@@ -237,8 +237,8 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
237
237
|
if (!/^--/.test(e) || typeof e != "string")
|
|
238
238
|
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${e} must start with '--'.`);
|
|
239
239
|
const i = super.add(e), a = R.get(this), r = `state${e}`;
|
|
240
|
-
return a.isConnected ?
|
|
241
|
-
|
|
240
|
+
return a.isConnected ? ae(a, r) : setTimeout(() => {
|
|
241
|
+
ae(a, r);
|
|
242
242
|
}), i;
|
|
243
243
|
}
|
|
244
244
|
clear() {
|
|
@@ -253,26 +253,19 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
253
253
|
}), i;
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
function
|
|
257
|
-
if (i === "a" && !a)
|
|
258
|
-
|
|
259
|
-
if (typeof e == "function" ? t !== e || !a : !e.has(t))
|
|
260
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
256
|
+
function re(t, e, i, a) {
|
|
257
|
+
if (i === "a" && !a) throw new TypeError("Private accessor was defined without a getter");
|
|
258
|
+
if (typeof e == "function" ? t !== e || !a : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
261
259
|
return i === "m" ? a : i === "a" ? a.call(t) : a ? a.value : e.get(t);
|
|
262
260
|
}
|
|
263
|
-
function
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
if (a === "a" && !r)
|
|
267
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
268
|
-
if (typeof e == "function" ? t !== e || !r : !e.has(t))
|
|
269
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
270
|
-
return a === "a" ? r.call(t, i) : r ? r.value = i : e.set(t, i), i;
|
|
261
|
+
function Me(t, e, i, a, r) {
|
|
262
|
+
if (typeof e == "function" ? t !== e || !r : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
263
|
+
return e.set(t, i), i;
|
|
271
264
|
}
|
|
272
265
|
var C;
|
|
273
|
-
class
|
|
266
|
+
class Ce {
|
|
274
267
|
constructor(e) {
|
|
275
|
-
C.set(this, void 0),
|
|
268
|
+
C.set(this, void 0), Me(this, C, e);
|
|
276
269
|
for (let i = 0; i < e.length; i++) {
|
|
277
270
|
let a = e[i];
|
|
278
271
|
this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
|
|
@@ -280,10 +273,10 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
280
273
|
Object.freeze(this);
|
|
281
274
|
}
|
|
282
275
|
get length() {
|
|
283
|
-
return
|
|
276
|
+
return re(this, C, "f").length;
|
|
284
277
|
}
|
|
285
278
|
[(C = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
286
|
-
return
|
|
279
|
+
return re(this, C, "f")[Symbol.iterator]();
|
|
287
280
|
}
|
|
288
281
|
item(e) {
|
|
289
282
|
return this[e] == null ? null : this[e];
|
|
@@ -292,39 +285,39 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
292
285
|
return this[e] == null ? null : this[e];
|
|
293
286
|
}
|
|
294
287
|
}
|
|
295
|
-
function
|
|
288
|
+
function Ae() {
|
|
296
289
|
const t = HTMLFormElement.prototype.checkValidity;
|
|
297
290
|
HTMLFormElement.prototype.checkValidity = i;
|
|
298
291
|
const e = HTMLFormElement.prototype.reportValidity;
|
|
299
292
|
HTMLFormElement.prototype.reportValidity = a;
|
|
300
293
|
function i(...s) {
|
|
301
294
|
let n = t.apply(this, s);
|
|
302
|
-
return
|
|
295
|
+
return te(this, n, "checkValidity");
|
|
303
296
|
}
|
|
304
297
|
function a(...s) {
|
|
305
298
|
let n = e.apply(this, s);
|
|
306
|
-
return
|
|
299
|
+
return te(this, n, "reportValidity");
|
|
307
300
|
}
|
|
308
301
|
const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
309
302
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
310
303
|
get(...s) {
|
|
311
|
-
const n = r.call(this, ...s),
|
|
312
|
-
if (
|
|
304
|
+
const n = r.call(this, ...s), h = Array.from(g.get(this) || []);
|
|
305
|
+
if (h.length === 0)
|
|
313
306
|
return n;
|
|
314
|
-
const d = Array.from(n).concat(
|
|
315
|
-
return new
|
|
307
|
+
const d = Array.from(n).concat(h).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
|
|
308
|
+
return new Ce(d);
|
|
316
309
|
}
|
|
317
310
|
});
|
|
318
311
|
}
|
|
319
|
-
class
|
|
312
|
+
class oe {
|
|
320
313
|
static get isPolyfilled() {
|
|
321
314
|
return !0;
|
|
322
315
|
}
|
|
323
316
|
constructor(e) {
|
|
324
317
|
if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
|
|
325
318
|
throw new TypeError("Illegal constructor");
|
|
326
|
-
const i = e.getRootNode(), a = new
|
|
327
|
-
this.states = new D(e), o.set(this, e), c.set(this, a), l.set(e, this),
|
|
319
|
+
const i = e.getRootNode(), a = new ge();
|
|
320
|
+
this.states = new D(e), o.set(this, e), c.set(this, a), l.set(e, this), he(e, this), fe(e, this), Object.seal(this), i instanceof DocumentFragment && pe(i);
|
|
328
321
|
}
|
|
329
322
|
checkValidity() {
|
|
330
323
|
const e = o.get(this);
|
|
@@ -345,7 +338,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
345
338
|
const e = o.get(this);
|
|
346
339
|
w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
347
340
|
let i;
|
|
348
|
-
return e.constructor.formAssociated === !0 && (i =
|
|
341
|
+
return e.constructor.formAssociated === !0 && (i = S(e)), i;
|
|
349
342
|
}
|
|
350
343
|
get labels() {
|
|
351
344
|
const e = o.get(this);
|
|
@@ -357,50 +350,49 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
357
350
|
const e = o.get(this);
|
|
358
351
|
if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
359
352
|
return !0;
|
|
360
|
-
const i = this.checkValidity(), a =
|
|
353
|
+
const i = this.checkValidity(), a = U.get(this);
|
|
361
354
|
if (a && !e.constructor.formAssociated)
|
|
362
355
|
throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
|
|
363
356
|
return !i && a && (e.focus(), a.focus()), i;
|
|
364
357
|
}
|
|
365
358
|
setFormValue(e) {
|
|
366
359
|
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."),
|
|
360
|
+
if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Q(this), e != null && !(e instanceof FormData)) {
|
|
368
361
|
if (i.getAttribute("name")) {
|
|
369
|
-
const a =
|
|
362
|
+
const a = X(i, this);
|
|
370
363
|
a.value = e;
|
|
371
364
|
}
|
|
372
|
-
} else
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
z.set(i, e);
|
|
365
|
+
} else e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
|
|
366
|
+
if (typeof r == "string") {
|
|
367
|
+
const s = X(i, this);
|
|
368
|
+
s.name = a, s.value = r;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
q.set(i, e);
|
|
380
372
|
}
|
|
381
373
|
setValidity(e, i, a) {
|
|
382
374
|
const r = o.get(this);
|
|
383
375
|
if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
|
|
384
376
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
385
|
-
|
|
377
|
+
U.set(this, a);
|
|
386
378
|
const s = c.get(this), n = {};
|
|
387
379
|
for (const b in e)
|
|
388
380
|
n[b] = e[b];
|
|
389
|
-
Object.keys(n).length === 0 &&
|
|
390
|
-
const
|
|
391
|
-
delete
|
|
392
|
-
const { valid: d } =
|
|
381
|
+
Object.keys(n).length === 0 && ye(s);
|
|
382
|
+
const h = Object.assign(Object.assign({}, s), n);
|
|
383
|
+
delete h.valid;
|
|
384
|
+
const { valid: d } = Ee(s, h, this.form);
|
|
393
385
|
if (!d && !i)
|
|
394
386
|
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.");
|
|
395
|
-
|
|
387
|
+
v.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);
|
|
396
388
|
}
|
|
397
389
|
get shadowRoot() {
|
|
398
|
-
const e = o.get(this), i =
|
|
390
|
+
const e = o.get(this), i = B.get(e);
|
|
399
391
|
return i || null;
|
|
400
392
|
}
|
|
401
393
|
get validationMessage() {
|
|
402
394
|
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."),
|
|
395
|
+
return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), v.get(this);
|
|
404
396
|
}
|
|
405
397
|
get validity() {
|
|
406
398
|
const e = o.get(this);
|
|
@@ -411,7 +403,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
411
403
|
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"));
|
|
412
404
|
}
|
|
413
405
|
}
|
|
414
|
-
function
|
|
406
|
+
function xe() {
|
|
415
407
|
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
|
|
416
408
|
return !1;
|
|
417
409
|
class t extends HTMLElement {
|
|
@@ -435,22 +427,22 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
435
427
|
"reportValidity"
|
|
436
428
|
].every((a) => a in i.internals);
|
|
437
429
|
}
|
|
438
|
-
let
|
|
430
|
+
let se = !1, ne = !1;
|
|
439
431
|
function H(t) {
|
|
440
|
-
|
|
432
|
+
ne || (ne = !0, window.CustomStateSet = D, t && (HTMLElement.prototype.attachInternals = function(...e) {
|
|
441
433
|
const i = t.call(this, e);
|
|
442
434
|
return i.states = new D(this), i;
|
|
443
435
|
}));
|
|
444
436
|
}
|
|
445
|
-
function
|
|
446
|
-
if (!
|
|
447
|
-
if (
|
|
437
|
+
function le(t = !0) {
|
|
438
|
+
if (!se) {
|
|
439
|
+
if (se = !0, typeof window < "u" && (window.ElementInternals = oe), typeof CustomElementRegistry < "u") {
|
|
448
440
|
const e = CustomElementRegistry.prototype.define;
|
|
449
441
|
CustomElementRegistry.prototype.define = function(i, a, r) {
|
|
450
442
|
if (a.formAssociated) {
|
|
451
443
|
const s = a.prototype.connectedCallback;
|
|
452
444
|
a.prototype.connectedCallback = function() {
|
|
453
|
-
|
|
445
|
+
K.has(this) || (K.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), s != null && s.apply(this), ie(this);
|
|
454
446
|
};
|
|
455
447
|
}
|
|
456
448
|
e.call(this, i, a, r);
|
|
@@ -460,46 +452,43 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
|
460
452
|
if (this.tagName) {
|
|
461
453
|
if (this.tagName.indexOf("-") === -1)
|
|
462
454
|
throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
|
|
463
|
-
} else
|
|
464
|
-
return {};
|
|
455
|
+
} else return {};
|
|
465
456
|
if (l.has(this))
|
|
466
457
|
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
|
|
467
|
-
return new
|
|
458
|
+
return new oe(this);
|
|
468
459
|
}), typeof Element < "u") {
|
|
469
460
|
let e = function(...a) {
|
|
470
461
|
const r = i.apply(this, a);
|
|
471
|
-
if (
|
|
472
|
-
const s = new MutationObserver(
|
|
473
|
-
window.ShadyDOM ? s.observe(this, _) : s.observe(r, _),
|
|
462
|
+
if (B.set(this, r), T()) {
|
|
463
|
+
const s = new MutationObserver(P);
|
|
464
|
+
window.ShadyDOM ? s.observe(this, _) : s.observe(r, _), O.set(this, s);
|
|
474
465
|
}
|
|
475
466
|
return r;
|
|
476
467
|
};
|
|
477
468
|
const i = Element.prototype.attachShadow;
|
|
478
469
|
Element.prototype.attachShadow = e;
|
|
479
470
|
}
|
|
480
|
-
T() && typeof document < "u" && new MutationObserver(
|
|
471
|
+
T() && typeof document < "u" && new MutationObserver(P).observe(document.documentElement, _), typeof HTMLFormElement < "u" && Ae(), (t || typeof window < "u" && !window.CustomStateSet) && H();
|
|
481
472
|
}
|
|
482
473
|
}
|
|
483
|
-
return !!customElements.polyfillWrapFlushCallback || (
|
|
474
|
+
return !!customElements.polyfillWrapFlushCallback || (xe() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : le(!1)), E.forceCustomStateSetPolyfill = H, E.forceElementInternalsPolyfill = le, Object.defineProperty(E, "__esModule", { value: !0 }), E;
|
|
484
475
|
})({});
|
|
485
476
|
})();
|
|
486
|
-
const
|
|
487
|
-
`, _e = ["leading", "trailing"], je = "change", M = {
|
|
477
|
+
const _e = "*,*: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}}", $e = ["leading", "trailing"], je = "change", k = {
|
|
488
478
|
checked: !1,
|
|
489
479
|
disabled: !1,
|
|
490
480
|
labelPlacement: "leading",
|
|
491
481
|
required: !1,
|
|
492
482
|
value: "on"
|
|
493
483
|
};
|
|
494
|
-
var
|
|
495
|
-
for (var l =
|
|
496
|
-
(
|
|
497
|
-
return
|
|
484
|
+
var Re = Object.defineProperty, m = (E, o, c, u) => {
|
|
485
|
+
for (var l = void 0, v = E.length - 1, M; v >= 0; v--)
|
|
486
|
+
(M = E[v]) && (l = M(o, c, l) || l);
|
|
487
|
+
return l && Re(o, c, l), l;
|
|
498
488
|
};
|
|
499
|
-
const
|
|
500
|
-
class p extends Ve(Te(xe)) {
|
|
489
|
+
const de = "pie-switch", z = class z extends Te(Le(Fe)) {
|
|
501
490
|
constructor() {
|
|
502
|
-
super(...arguments), this.labelPlacement =
|
|
491
|
+
super(...arguments), this.labelPlacement = k.labelPlacement, this.checked = k.checked, this.required = k.required, this.value = k.value, this.disabled = k.disabled;
|
|
503
492
|
}
|
|
504
493
|
firstUpdated() {
|
|
505
494
|
var o;
|
|
@@ -523,8 +512,8 @@ class p extends Ve(Te(xe)) {
|
|
|
523
512
|
handleChange(o) {
|
|
524
513
|
const { checked: c } = o == null ? void 0 : o.currentTarget;
|
|
525
514
|
this.checked = c;
|
|
526
|
-
const
|
|
527
|
-
this.dispatchEvent(
|
|
515
|
+
const u = Ne(o);
|
|
516
|
+
this.dispatchEvent(u), this.handleFormAssociation();
|
|
528
517
|
}
|
|
529
518
|
/**
|
|
530
519
|
* 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.
|
|
@@ -572,9 +561,9 @@ class p extends Ve(Te(xe)) {
|
|
|
572
561
|
* @private
|
|
573
562
|
*/
|
|
574
563
|
renderSwitchLabel(o) {
|
|
575
|
-
const { label: c, labelPlacement:
|
|
576
|
-
return !c ||
|
|
577
|
-
<span data-test-id="switch-label-${
|
|
564
|
+
const { label: c, labelPlacement: u } = this;
|
|
565
|
+
return !c || u !== o ? L : N`
|
|
566
|
+
<span data-test-id="switch-label-${u}">
|
|
578
567
|
${c}
|
|
579
568
|
</span>`;
|
|
580
569
|
}
|
|
@@ -592,17 +581,17 @@ class p extends Ve(Te(xe)) {
|
|
|
592
581
|
const {
|
|
593
582
|
aria: o,
|
|
594
583
|
checked: c,
|
|
595
|
-
disabled:
|
|
584
|
+
disabled: u,
|
|
596
585
|
isRTL: l,
|
|
597
|
-
required:
|
|
586
|
+
required: v
|
|
598
587
|
} = this;
|
|
599
588
|
return N`
|
|
600
589
|
<label
|
|
601
|
-
class="${
|
|
590
|
+
class="${Ve({
|
|
602
591
|
"c-switch-wrapper": !0,
|
|
603
592
|
"c-switch-wrapper--rtl": l
|
|
604
593
|
})}"
|
|
605
|
-
?disabled=${
|
|
594
|
+
?disabled=${u}>
|
|
606
595
|
${this.renderSwitchLabel("leading")}
|
|
607
596
|
<div
|
|
608
597
|
data-test-id="switch-component"
|
|
@@ -613,11 +602,11 @@ class p extends Ve(Te(xe)) {
|
|
|
613
602
|
role="switch"
|
|
614
603
|
type="checkbox"
|
|
615
604
|
class="c-switch-input"
|
|
616
|
-
.required=${
|
|
605
|
+
.required=${v}
|
|
617
606
|
.checked="${c}"
|
|
618
|
-
.disabled="${
|
|
607
|
+
.disabled="${u}"
|
|
619
608
|
@change="${this.handleChange}"
|
|
620
|
-
aria-label="${
|
|
609
|
+
aria-label="${Se(o == null ? void 0 : o.label)}"
|
|
621
610
|
aria-describedby="${o != null && o.describedBy ? "switch-description" : L}">
|
|
622
611
|
<div class="c-switch-control">
|
|
623
612
|
${c ? N`<icon-check></icon-check>` : L}
|
|
@@ -627,43 +616,44 @@ class p extends Ve(Te(xe)) {
|
|
|
627
616
|
${this.renderAriaDescription()}
|
|
628
617
|
</label>`;
|
|
629
618
|
}
|
|
630
|
-
}
|
|
631
|
-
|
|
619
|
+
};
|
|
620
|
+
z.styles = Ie(_e);
|
|
621
|
+
let p = z;
|
|
632
622
|
m([
|
|
633
|
-
|
|
634
|
-
], p.prototype, "label"
|
|
623
|
+
y({ type: String })
|
|
624
|
+
], p.prototype, "label");
|
|
635
625
|
m([
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
], p.prototype, "labelPlacement"
|
|
626
|
+
y({ type: String }),
|
|
627
|
+
Oe(de, $e, k.labelPlacement)
|
|
628
|
+
], p.prototype, "labelPlacement");
|
|
639
629
|
m([
|
|
640
|
-
|
|
641
|
-
], p.prototype, "aria"
|
|
630
|
+
y({ type: Object })
|
|
631
|
+
], p.prototype, "aria");
|
|
642
632
|
m([
|
|
643
|
-
|
|
644
|
-
], p.prototype, "checked"
|
|
633
|
+
y({ type: Boolean, reflect: !0 })
|
|
634
|
+
], p.prototype, "checked");
|
|
645
635
|
m([
|
|
646
|
-
|
|
647
|
-
], p.prototype, "required"
|
|
636
|
+
y({ type: Boolean, reflect: !0 })
|
|
637
|
+
], p.prototype, "required");
|
|
648
638
|
m([
|
|
649
|
-
|
|
650
|
-
], p.prototype, "value"
|
|
639
|
+
y({ type: String })
|
|
640
|
+
], p.prototype, "value");
|
|
651
641
|
m([
|
|
652
|
-
|
|
653
|
-
], p.prototype, "name"
|
|
642
|
+
y({ type: String })
|
|
643
|
+
], p.prototype, "name");
|
|
654
644
|
m([
|
|
655
|
-
|
|
656
|
-
], p.prototype, "disabled"
|
|
645
|
+
y({ type: Boolean, reflect: !0 })
|
|
646
|
+
], p.prototype, "disabled");
|
|
657
647
|
m([
|
|
658
|
-
|
|
659
|
-
], p.prototype, "input"
|
|
648
|
+
ce('input[type="checkbox"]')
|
|
649
|
+
], p.prototype, "input");
|
|
660
650
|
m([
|
|
661
|
-
|
|
662
|
-
], p.prototype, "focusTarget"
|
|
663
|
-
Pe(
|
|
651
|
+
ce("label")
|
|
652
|
+
], p.prototype, "focusTarget");
|
|
653
|
+
Pe(de, p);
|
|
664
654
|
export {
|
|
665
655
|
je as ON_SWITCH_CHANGED_EVENT,
|
|
666
656
|
p as PieSwitch,
|
|
667
|
-
|
|
668
|
-
|
|
657
|
+
k as defaultProps,
|
|
658
|
+
$e as labelPlacements
|
|
669
659
|
};
|
package/dist/react.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
1
|
+
import * as e from "react";
|
|
2
|
+
import { createComponent as t } from "@lit/react";
|
|
3
3
|
import { PieSwitch as i } from "./index.js";
|
|
4
|
-
import { ON_SWITCH_CHANGED_EVENT as
|
|
5
|
-
|
|
6
|
-
import "lit/decorators.js";
|
|
7
|
-
import "lit/directives/class-map.js";
|
|
8
|
-
import "lit/directives/if-defined.js";
|
|
9
|
-
import "@justeattakeaway/pie-webc-core";
|
|
10
|
-
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
11
|
-
const o = e({
|
|
4
|
+
import { ON_SWITCH_CHANGED_EVENT as s, defaultProps as l, labelPlacements as p } from "./index.js";
|
|
5
|
+
const a = t({
|
|
12
6
|
displayName: "PieSwitch",
|
|
13
7
|
elementClass: i,
|
|
14
|
-
react:
|
|
8
|
+
react: e,
|
|
15
9
|
tagName: "pie-switch",
|
|
16
10
|
events: {
|
|
17
11
|
onInvalid: "invalid",
|
|
18
12
|
onChange: "change"
|
|
19
13
|
// when the switch checked state is changed.
|
|
20
14
|
}
|
|
21
|
-
}),
|
|
15
|
+
}), n = a;
|
|
22
16
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
s as ON_SWITCH_CHANGED_EVENT,
|
|
18
|
+
n as PieSwitch,
|
|
19
|
+
l as defaultProps,
|
|
20
|
+
p as labelPlacements
|
|
27
21
|
};
|
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": "0.30.
|
|
4
|
+
"version": "0.30.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
39
39
|
"@justeattakeaway/pie-components-config": "0.18.0",
|
|
40
|
-
"@justeattakeaway/pie-css": "0.
|
|
40
|
+
"@justeattakeaway/pie-css": "0.13.0",
|
|
41
41
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@justeattakeaway/pie-icons-webc": "0.25.
|
|
45
|
-
"@justeattakeaway/pie-webc-core": "0.24.
|
|
44
|
+
"@justeattakeaway/pie-icons-webc": "0.25.2",
|
|
45
|
+
"@justeattakeaway/pie-webc-core": "0.24.1",
|
|
46
46
|
"@justeattakeaway/pie-wrapper-react": "0.14.1",
|
|
47
47
|
"element-internals-polyfill": "1.3.11"
|
|
48
48
|
},
|