@justeattakeaway/pie-switch 2.5.6 → 2.6.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.
@@ -142,6 +142,14 @@
142
142
  "attribute": "disabled",
143
143
  "reflects": true
144
144
  },
145
+ {
146
+ "kind": "field",
147
+ "name": "_contextAria",
148
+ "type": {
149
+ "text": "ContextualAria | undefined"
150
+ },
151
+ "privacy": "private"
152
+ },
145
153
  {
146
154
  "kind": "field",
147
155
  "name": "input",
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
40
40
  value: string;
41
41
  name: SwitchProps['name'];
42
42
  disabled: boolean;
43
+ private _contextAria?;
43
44
  private input;
44
45
  private switchBody;
45
46
  focusTarget: HTMLElement;
package/dist/index.js CHANGED
@@ -1,23 +1,76 @@
1
- import { LitElement as Se, nothing as P, html as B, unsafeCSS as Ve } from "lit";
2
- import { unsafeStatic as Te, html as Le } from "lit/static-html.js";
3
- import { property as y, query as U, state as Ne } from "lit/decorators.js";
4
- import { classMap as Pe } from "lit/directives/class-map.js";
5
- import { ifDefined as _e } from "lit/directives/if-defined.js";
6
- import { live as Oe } from "lit/directives/live.js";
7
- import { AssociatedLabelMixin as $e, FormControlMixin as De, DelegatesFocusMixin as Re, wrapNativeEvent as He, validPropertyValues as We, safeCustomElement as ze } from "@justeattakeaway/pie-webc-core";
1
+ import { LitElement as _t, nothing as O, html as U, unsafeCSS as Nt } from "lit";
2
+ import { unsafeStatic as Pt, html as Ot } from "lit/static-html.js";
3
+ import { property as E, state as bt, query as K } from "lit/decorators.js";
4
+ import { classMap as ht } from "lit/directives/class-map.js";
5
+ import { ifDefined as ut } from "lit/directives/if-defined.js";
6
+ import { live as $t } from "lit/directives/live.js";
7
+ import { AssociatedLabelMixin as Dt, FormControlMixin as Rt, DelegatesFocusMixin as Ht, wrapNativeEvent as Wt, validPropertyValues as zt, safeCustomElement as qt, ariaContext as Bt } from "@justeattakeaway/pie-webc-core";
8
8
  import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
9
- const _ = class _ extends Se {
9
+ const $ = class $ extends _t {
10
10
  willUpdate() {
11
- this.getAttribute("v") || this.setAttribute("v", _.v);
11
+ this.getAttribute("v") || this.setAttribute("v", $.v);
12
12
  }
13
13
  };
14
- _.v = "2.5.6";
15
- let q = _;
16
- var he = {}, ue;
17
- function Be() {
18
- return ue || (ue = 1, (function() {
19
- (function(n) {
20
- const l = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), S = {
14
+ $.v = "2.6.0";
15
+ let j = $;
16
+ /**
17
+ * @license
18
+ * Copyright 2021 Google LLC
19
+ * SPDX-License-Identifier: BSD-3-Clause
20
+ */
21
+ let Ut = class extends Event {
22
+ constructor(c, d, h, l) {
23
+ super("context-request", { bubbles: !0, composed: !0 }), this.context = c, this.contextTarget = d, this.callback = h, this.subscribe = l ?? !1;
24
+ }
25
+ };
26
+ /**
27
+ * @license
28
+ * Copyright 2021 Google LLC
29
+ * SPDX-License-Identifier: BSD-3-Clause
30
+ */
31
+ class pt {
32
+ constructor(c, d, h, l) {
33
+ if (this.subscribe = !1, this.provided = !1, this.value = void 0, this.t = (p, v) => {
34
+ this.unsubscribe && (this.unsubscribe !== v && (this.provided = !1, this.unsubscribe()), this.subscribe || this.unsubscribe()), this.value = p, this.host.requestUpdate(), this.provided && !this.subscribe || (this.provided = !0, this.callback && this.callback(p, v)), this.unsubscribe = v;
35
+ }, this.host = c, d.context !== void 0) {
36
+ const p = d;
37
+ this.context = p.context, this.callback = p.callback, this.subscribe = p.subscribe ?? !1;
38
+ } else this.context = d, this.callback = h, this.subscribe = l ?? !1;
39
+ this.host.addController(this);
40
+ }
41
+ hostConnected() {
42
+ this.dispatchRequest();
43
+ }
44
+ hostDisconnected() {
45
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0);
46
+ }
47
+ dispatchRequest() {
48
+ this.host.dispatchEvent(new Ut(this.context, this.host, this.t, this.subscribe));
49
+ }
50
+ }
51
+ /**
52
+ * @license
53
+ * Copyright 2022 Google LLC
54
+ * SPDX-License-Identifier: BSD-3-Clause
55
+ */
56
+ function jt({ context: s, subscribe: c }) {
57
+ return (d, h) => {
58
+ typeof h == "object" ? h.addInitializer((function() {
59
+ new pt(this, { context: s, callback: (l) => {
60
+ d.set.call(this, l);
61
+ }, subscribe: c });
62
+ })) : d.constructor.addInitializer(((l) => {
63
+ new pt(l, { context: s, callback: (p) => {
64
+ l[h] = p;
65
+ }, subscribe: c });
66
+ }));
67
+ };
68
+ }
69
+ var mt = {}, ft;
70
+ function Kt() {
71
+ return ft || (ft = 1, (function() {
72
+ (function(s) {
73
+ const c = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), T = {
21
74
  ariaAtomic: "aria-atomic",
22
75
  ariaAutoComplete: "aria-autocomplete",
23
76
  ariaBusy: "aria-busy",
@@ -60,278 +113,278 @@ function Be() {
60
113
  ariaValueNow: "aria-valuenow",
61
114
  ariaValueText: "aria-valuetext",
62
115
  role: "role"
63
- }, pe = (t, e) => {
64
- for (let i in S) {
65
- e[i] = null;
116
+ }, vt = (e, t) => {
117
+ for (let i in T) {
118
+ t[i] = null;
66
119
  let a = null;
67
- const r = S[i];
68
- Object.defineProperty(e, i, {
120
+ const r = T[i];
121
+ Object.defineProperty(t, i, {
69
122
  get() {
70
123
  return a;
71
124
  },
72
125
  set(o) {
73
- a = o, t.isConnected ? t.setAttribute(r, o) : M.set(t, e);
126
+ a = o, e.isConnected ? e.setAttribute(r, o) : x.set(e, t);
74
127
  }
75
128
  });
76
129
  }
77
130
  };
78
- function Q(t) {
79
- const e = c.get(t), { form: i } = e;
80
- ie(t, i, e), te(t, e.labels);
131
+ function Q(e) {
132
+ const t = l.get(e), { form: i } = t;
133
+ it(e, i, t), et(e, t.labels);
81
134
  }
82
- const X = (t, e = !1) => {
83
- const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
135
+ const X = (e, t = !1) => {
136
+ const i = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, {
84
137
  acceptNode(o) {
85
- return c.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
138
+ return l.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
86
139
  }
87
140
  });
88
141
  let a = i.nextNode();
89
- const r = !e || t.disabled;
142
+ const r = !t || e.disabled;
90
143
  for (; a; )
91
- a.formDisabledCallback && r && D(a, t.disabled), a = i.nextNode();
92
- }, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, V = N() ? new MutationObserver((t) => {
93
- for (const e of t) {
94
- const i = e.target;
95
- if (e.attributeName === "disabled" && (i.constructor.formAssociated ? D(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && X(i)), e.attributeName === "name" && i.constructor.formAssociated) {
96
- const a = c.get(i), r = F.get(i);
144
+ a.formDisabledCallback && r && H(a, e.disabled), a = i.nextNode();
145
+ }, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, L = P() ? new MutationObserver((e) => {
146
+ for (const t of e) {
147
+ const i = t.target;
148
+ if (t.attributeName === "disabled" && (i.constructor.formAssociated ? H(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && X(i)), t.attributeName === "name" && i.constructor.formAssociated) {
149
+ const a = l.get(i), r = S.get(i);
97
150
  a.setFormValue(r);
98
151
  }
99
152
  }
100
153
  }) : {};
101
- function O(t) {
102
- t.forEach((e) => {
103
- const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), o = Array.from(a);
104
- r.forEach((s) => {
105
- var m;
106
- if (c.has(s) && s.constructor.formAssociated && Q(s), M.has(s)) {
107
- const h = M.get(s);
108
- Object.keys(S).filter((v) => h[v] !== null).forEach((v) => {
109
- s.setAttribute(S[v], h[v]);
110
- }), M.delete(s);
154
+ function D(e) {
155
+ e.forEach((t) => {
156
+ const { addedNodes: i, removedNodes: a } = t, r = Array.from(i), o = Array.from(a);
157
+ r.forEach((n) => {
158
+ var f;
159
+ if (l.has(n) && n.constructor.formAssociated && Q(n), x.has(n)) {
160
+ const u = x.get(n);
161
+ Object.keys(T).filter((g) => u[g] !== null).forEach((g) => {
162
+ n.setAttribute(T[g], u[g]);
163
+ }), x.delete(n);
111
164
  }
112
- if (I.has(s)) {
113
- const h = I.get(s);
114
- s.setAttribute("internals-valid", h.validity.valid.toString()), s.setAttribute("internals-invalid", (!h.validity.valid).toString()), s.setAttribute("aria-invalid", (!h.validity.valid).toString()), I.delete(s);
165
+ if (V.has(n)) {
166
+ const u = V.get(n);
167
+ n.setAttribute("internals-valid", u.validity.valid.toString()), n.setAttribute("internals-invalid", (!u.validity.valid).toString()), n.setAttribute("aria-invalid", (!u.validity.valid).toString()), V.delete(n);
115
168
  }
116
- if (s.localName === "form") {
117
- const h = b.get(s), g = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
118
- acceptNode(z) {
119
- return c.has(z) && z.constructor.formAssociated && !(h && h.has(z)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
169
+ if (n.localName === "form") {
170
+ const u = w.get(n), k = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
171
+ acceptNode(B) {
172
+ return l.has(B) && B.constructor.formAssociated && !(u && u.has(B)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
120
173
  }
121
174
  });
122
- let v = g.nextNode();
123
- for (; v; )
124
- Q(v), v = g.nextNode();
175
+ let g = k.nextNode();
176
+ for (; g; )
177
+ Q(g), g = k.nextNode();
125
178
  }
126
- s.localName === "fieldset" && ((m = V.observe) === null || m === void 0 || m.call(V, s, Y), X(s, !0));
127
- }), o.forEach((s) => {
128
- const m = c.get(s);
129
- m && u.get(m) && Z(m), C.has(s) && C.get(s).disconnect();
179
+ n.localName === "fieldset" && ((f = L.observe) === null || f === void 0 || f.call(L, n, Y), X(n, !0));
180
+ }), o.forEach((n) => {
181
+ const f = l.get(n);
182
+ f && h.get(f) && Z(f), C.has(n) && C.get(n).disconnect();
130
183
  });
131
184
  });
132
185
  }
133
- function me(t) {
134
- t.forEach((e) => {
135
- const { removedNodes: i } = e;
186
+ function wt(e) {
187
+ e.forEach((t) => {
188
+ const { removedNodes: i } = t;
136
189
  i.forEach((a) => {
137
- const r = G.get(e.target);
138
- c.has(a) && re(a), r.disconnect();
190
+ const r = G.get(t.target);
191
+ l.has(a) && rt(a), r.disconnect();
139
192
  });
140
193
  });
141
194
  }
142
- const fe = (t) => {
143
- var e, i;
144
- const a = new MutationObserver(me);
145
- !((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 }), G.set(t, a);
195
+ const gt = (e) => {
196
+ var t, i;
197
+ const a = new MutationObserver(wt);
198
+ !((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 }), G.set(e, a);
146
199
  };
147
- N() && new MutationObserver(O);
148
- const $ = {
200
+ P() && new MutationObserver(D);
201
+ const R = {
149
202
  childList: !0,
150
203
  subtree: !0
151
- }, D = (t, e) => {
152
- t.toggleAttribute("internals-disabled", e), e ? t.setAttribute("aria-disabled", "true") : t.removeAttribute("aria-disabled"), t.formDisabledCallback && t.formDisabledCallback.apply(t, [e]);
153
- }, Z = (t) => {
154
- u.get(t).forEach((i) => {
204
+ }, H = (e, t) => {
205
+ e.toggleAttribute("internals-disabled", t), t ? e.setAttribute("aria-disabled", "true") : e.removeAttribute("aria-disabled"), e.formDisabledCallback && e.formDisabledCallback.apply(e, [t]);
206
+ }, Z = (e) => {
207
+ h.get(e).forEach((i) => {
155
208
  i.remove();
156
- }), u.set(t, []);
157
- }, ee = (t, e) => {
209
+ }), h.set(e, []);
210
+ }, tt = (e, t) => {
158
211
  const i = document.createElement("input");
159
- return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i), u.get(e).push(i), i;
160
- }, be = (t, e) => {
212
+ return i.type = "hidden", i.name = e.getAttribute("name"), e.after(i), h.get(t).push(i), i;
213
+ }, yt = (e, t) => {
161
214
  var i;
162
- u.set(e, []), (i = V.observe) === null || i === void 0 || i.call(V, t, Y);
163
- }, te = (t, e) => {
164
- if (e.length) {
165
- Array.from(e).forEach((a) => a.addEventListener("click", t.click.bind(t)));
166
- let i = e[0].id;
167
- e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), t.setAttribute("aria-labelledby", i);
168
- }
169
- }, T = (t) => {
170
- const e = Array.from(t.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = b.get(t) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => c.get(o).validity.valid), r = [...e, ...a].includes(!1);
171
- t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
172
- }, ve = (t) => {
173
- T(L(t.target));
174
- }, we = (t) => {
175
- T(L(t.target));
176
- }, ge = (t) => {
177
- 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(",");
178
- t.addEventListener("click", (i) => {
179
- if (i.target.closest(e)) {
180
- const r = b.get(t);
181
- if (t.noValidate)
215
+ h.set(t, []), (i = L.observe) === null || i === void 0 || i.call(L, e, Y);
216
+ }, et = (e, t) => {
217
+ if (t.length) {
218
+ Array.from(t).forEach((a) => a.addEventListener("click", e.click.bind(e)));
219
+ let i = t[0].id;
220
+ t[0].id || (i = `${t[0].htmlFor}_Label`, t[0].id = i), e.setAttribute("aria-labelledby", i);
221
+ }
222
+ }, _ = (e) => {
223
+ const t = Array.from(e.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = w.get(e) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => l.get(o).validity.valid), r = [...t, ...a].includes(!1);
224
+ e.toggleAttribute("internals-invalid", r), e.toggleAttribute("internals-valid", !r);
225
+ }, kt = (e) => {
226
+ _(N(e.target));
227
+ }, Et = (e) => {
228
+ _(N(e.target));
229
+ }, xt = (e) => {
230
+ 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(",");
231
+ e.addEventListener("click", (i) => {
232
+ if (i.target.closest(t)) {
233
+ const r = w.get(e);
234
+ if (e.noValidate)
182
235
  return;
183
- r.size && Array.from(r).reverse().map((m) => c.get(m).reportValidity()).includes(!1) && i.preventDefault();
236
+ r.size && Array.from(r).reverse().map((f) => l.get(f).reportValidity()).includes(!1) && i.preventDefault();
184
237
  }
185
238
  });
186
- }, ye = (t) => {
187
- const e = b.get(t.target);
188
- e && e.size && e.forEach((i) => {
239
+ }, Mt = (e) => {
240
+ const t = w.get(e.target);
241
+ t && t.size && t.forEach((i) => {
189
242
  i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
190
243
  });
191
- }, ie = (t, e, i) => {
192
- if (e) {
193
- const a = b.get(e);
244
+ }, it = (e, t, i) => {
245
+ if (t) {
246
+ const a = w.get(t);
194
247
  if (a)
195
- a.add(t);
248
+ a.add(e);
196
249
  else {
197
250
  const r = /* @__PURE__ */ new Set();
198
- r.add(t), b.set(e, r), ge(e), e.addEventListener("reset", ye), e.addEventListener("input", ve), e.addEventListener("change", we);
251
+ r.add(e), w.set(t, r), xt(t), t.addEventListener("reset", Mt), t.addEventListener("input", kt), t.addEventListener("change", Et);
199
252
  }
200
- E.set(e, { ref: t, internals: i }), t.constructor.formAssociated && t.formAssociatedCallback && setTimeout(() => {
201
- t.formAssociatedCallback.apply(t, [e]);
202
- }, 0), T(e);
203
- }
204
- }, L = (t) => {
205
- let e = t.parentNode;
206
- return e && e.tagName !== "FORM" && (e = L(e)), e;
207
- }, w = (t, e, i = DOMException) => {
208
- if (!t.constructor.formAssociated)
209
- throw new i(e);
210
- }, ae = (t, e, i) => {
211
- const a = b.get(t);
253
+ v.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
254
+ e.formAssociatedCallback.apply(e, [t]);
255
+ }, 0), _(t);
256
+ }
257
+ }, N = (e) => {
258
+ let t = e.parentNode;
259
+ return t && t.tagName !== "FORM" && (t = N(t)), t;
260
+ }, y = (e, t, i = DOMException) => {
261
+ if (!e.constructor.formAssociated)
262
+ throw new i(t);
263
+ }, at = (e, t, i) => {
264
+ const a = w.get(e);
212
265
  return a && a.size && a.forEach((r) => {
213
- c.get(r)[i]() || (e = !1);
214
- }), e;
215
- }, re = (t) => {
216
- if (t.constructor.formAssociated) {
217
- const e = c.get(t), { labels: i, form: a } = e;
218
- te(t, i), ie(t, a, e);
266
+ l.get(r)[i]() || (t = !1);
267
+ }), t;
268
+ }, rt = (e) => {
269
+ if (e.constructor.formAssociated) {
270
+ const t = l.get(e), { labels: i, form: a } = t;
271
+ et(e, i), it(e, a, t);
219
272
  }
220
273
  };
221
- function N() {
274
+ function P() {
222
275
  return typeof MutationObserver < "u";
223
276
  }
224
- class ke {
277
+ class Ct {
225
278
  constructor() {
226
279
  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);
227
280
  }
228
281
  }
229
- const Ee = (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), Me = (t, e, i) => (t.valid = xe(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && T(i), t), xe = (t) => {
230
- let e = !0;
231
- for (let i in t)
232
- i !== "valid" && t[i] !== !1 && (e = !1);
233
- return e;
234
- }, R = /* @__PURE__ */ new WeakMap();
235
- function oe(t, e) {
236
- t.toggleAttribute(e, !0), t.part && t.part.add(e);
282
+ const At = (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), Ft = (e, t, i) => (e.valid = It(t), Object.keys(t).forEach((a) => e[a] = t[a]), i && _(i), e), It = (e) => {
283
+ let t = !0;
284
+ for (let i in e)
285
+ i !== "valid" && e[i] !== !1 && (t = !1);
286
+ return t;
287
+ }, W = /* @__PURE__ */ new WeakMap();
288
+ function st(e, t) {
289
+ e.toggleAttribute(t, !0), e.part && e.part.add(t);
237
290
  }
238
- class H extends Set {
291
+ class z extends Set {
239
292
  static get isPolyfilled() {
240
293
  return !0;
241
294
  }
242
- constructor(e) {
243
- if (super(), !e || !e.tagName || e.tagName.indexOf("-") === -1)
295
+ constructor(t) {
296
+ if (super(), !t || !t.tagName || t.tagName.indexOf("-") === -1)
244
297
  throw new TypeError("Illegal constructor");
245
- R.set(this, e);
246
- }
247
- add(e) {
248
- if (!/^--/.test(e) || typeof e != "string")
249
- throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${e} must start with '--'.`);
250
- const i = super.add(e), a = R.get(this), r = `state${e}`;
251
- return a.isConnected ? oe(a, r) : setTimeout(() => {
252
- oe(a, r);
298
+ W.set(this, t);
299
+ }
300
+ add(t) {
301
+ if (!/^--/.test(t) || typeof t != "string")
302
+ throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${t} must start with '--'.`);
303
+ const i = super.add(t), a = W.get(this), r = `state${t}`;
304
+ return a.isConnected ? st(a, r) : setTimeout(() => {
305
+ st(a, r);
253
306
  }), i;
254
307
  }
255
308
  clear() {
256
- for (let [e] of this.entries())
257
- this.delete(e);
309
+ for (let [t] of this.entries())
310
+ this.delete(t);
258
311
  super.clear();
259
312
  }
260
- delete(e) {
261
- const i = super.delete(e), a = R.get(this);
262
- return a.isConnected ? (a.toggleAttribute(`state${e}`, !1), a.part && a.part.remove(`state${e}`)) : setTimeout(() => {
263
- a.toggleAttribute(`state${e}`, !1), a.part && a.part.remove(`state${e}`);
313
+ delete(t) {
314
+ const i = super.delete(t), a = W.get(this);
315
+ return a.isConnected ? (a.toggleAttribute(`state${t}`, !1), a.part && a.part.remove(`state${t}`)) : setTimeout(() => {
316
+ a.toggleAttribute(`state${t}`, !1), a.part && a.part.remove(`state${t}`);
264
317
  }), i;
265
318
  }
266
319
  }
267
- function se(t, e, i, a) {
268
- 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");
269
- return i === "m" ? a : i === "a" ? a.call(t) : a ? a.value : e.get(t);
320
+ function ot(e, t, i, a) {
321
+ 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");
322
+ return i === "m" ? a : i === "a" ? a.call(e) : a ? a.value : t.get(e);
270
323
  }
271
- function Ce(t, e, i, a, r) {
272
- if (typeof e == "function" ? t !== e || !0 : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
273
- return e.set(t, i), i;
324
+ function St(e, t, i, a, r) {
325
+ 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");
326
+ return t.set(e, i), i;
274
327
  }
275
- var A;
276
- class Ae {
277
- constructor(e) {
278
- A.set(this, void 0), Ce(this, A, e);
279
- for (let i = 0; i < e.length; i++) {
280
- let a = e[i];
328
+ var I;
329
+ class Vt {
330
+ constructor(t) {
331
+ I.set(this, void 0), St(this, I, t);
332
+ for (let i = 0; i < t.length; i++) {
333
+ let a = t[i];
281
334
  this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
282
335
  }
283
336
  Object.freeze(this);
284
337
  }
285
338
  get length() {
286
- return se(this, A, "f").length;
339
+ return ot(this, I, "f").length;
287
340
  }
288
- [(A = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
289
- return se(this, A, "f")[Symbol.iterator]();
341
+ [(I = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
342
+ return ot(this, I, "f")[Symbol.iterator]();
290
343
  }
291
- item(e) {
292
- return this[e] == null ? null : this[e];
344
+ item(t) {
345
+ return this[t] == null ? null : this[t];
293
346
  }
294
- namedItem(e) {
295
- return this[e] == null ? null : this[e];
347
+ namedItem(t) {
348
+ return this[t] == null ? null : this[t];
296
349
  }
297
350
  }
298
- function Fe() {
299
- const t = HTMLFormElement.prototype.checkValidity;
351
+ function Tt() {
352
+ const e = HTMLFormElement.prototype.checkValidity;
300
353
  HTMLFormElement.prototype.checkValidity = i;
301
- const e = HTMLFormElement.prototype.reportValidity;
354
+ const t = HTMLFormElement.prototype.reportValidity;
302
355
  HTMLFormElement.prototype.reportValidity = a;
303
356
  function i(...o) {
304
- let s = t.apply(this, o);
305
- return ae(this, s, "checkValidity");
357
+ let n = e.apply(this, o);
358
+ return at(this, n, "checkValidity");
306
359
  }
307
360
  function a(...o) {
308
- let s = e.apply(this, o);
309
- return ae(this, s, "reportValidity");
361
+ let n = t.apply(this, o);
362
+ return at(this, n, "reportValidity");
310
363
  }
311
364
  const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
312
365
  Object.defineProperty(HTMLFormElement.prototype, "elements", {
313
366
  get(...o) {
314
- const s = r.call(this, ...o), m = Array.from(b.get(this) || []);
315
- if (m.length === 0)
316
- return s;
317
- const h = Array.from(s).concat(m).sort((g, v) => g.compareDocumentPosition ? g.compareDocumentPosition(v) & 2 ? 1 : -1 : 0);
318
- return new Ae(h);
367
+ const n = r.call(this, ...o), f = Array.from(w.get(this) || []);
368
+ if (f.length === 0)
369
+ return n;
370
+ const u = Array.from(n).concat(f).sort((k, g) => k.compareDocumentPosition ? k.compareDocumentPosition(g) & 2 ? 1 : -1 : 0);
371
+ return new Vt(u);
319
372
  }
320
373
  });
321
374
  }
322
- class ne {
375
+ class nt {
323
376
  static get isPolyfilled() {
324
377
  return !0;
325
378
  }
326
- constructor(e) {
327
- if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
379
+ constructor(t) {
380
+ if (!t || !t.tagName || t.tagName.indexOf("-") === -1)
328
381
  throw new TypeError("Illegal constructor");
329
- const i = e.getRootNode(), a = new ke();
330
- this.states = new H(e), l.set(this, e), d.set(this, a), c.set(e, this), pe(e, this), be(e, this), Object.seal(this), i instanceof DocumentFragment && fe(i);
382
+ const i = t.getRootNode(), a = new Ct();
383
+ this.states = new z(t), c.set(this, t), d.set(this, a), l.set(t, this), vt(t, this), yt(t, this), Object.seal(this), i instanceof DocumentFragment && gt(i);
331
384
  }
332
385
  checkValidity() {
333
- const e = l.get(this);
334
- if (w(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
386
+ const t = c.get(this);
387
+ if (y(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
335
388
  return !0;
336
389
  const i = d.get(this);
337
390
  if (!i.valid) {
@@ -340,90 +393,90 @@ function Be() {
340
393
  cancelable: !0,
341
394
  composed: !1
342
395
  });
343
- e.dispatchEvent(a);
396
+ t.dispatchEvent(a);
344
397
  }
345
398
  return i.valid;
346
399
  }
347
400
  get form() {
348
- const e = l.get(this);
349
- w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
401
+ const t = c.get(this);
402
+ y(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
350
403
  let i;
351
- return e.constructor.formAssociated === !0 && (i = L(e)), i;
404
+ return t.constructor.formAssociated === !0 && (i = N(t)), i;
352
405
  }
353
406
  get labels() {
354
- const e = l.get(this);
355
- w(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
356
- const i = e.getAttribute("id"), a = e.getRootNode();
407
+ const t = c.get(this);
408
+ y(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
409
+ const i = t.getAttribute("id"), a = t.getRootNode();
357
410
  return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
358
411
  }
359
412
  reportValidity() {
360
- const e = l.get(this);
361
- if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
413
+ const t = c.get(this);
414
+ if (y(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
362
415
  return !0;
363
- const i = this.checkValidity(), a = K.get(this);
364
- if (a && !e.constructor.formAssociated)
416
+ const i = this.checkValidity(), a = F.get(this);
417
+ if (a && !t.constructor.formAssociated)
365
418
  throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
366
- return !i && a && (e.focus(), a.focus()), i;
419
+ return !i && a && (t.focus(), a.focus()), i;
367
420
  }
368
- setFormValue(e) {
369
- const i = l.get(this);
370
- if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Z(this), e != null && !(e instanceof FormData)) {
421
+ setFormValue(t) {
422
+ const i = c.get(this);
423
+ if (y(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Z(this), t != null && !(t instanceof FormData)) {
371
424
  if (i.getAttribute("name")) {
372
- const a = ee(i, this);
373
- a.value = e;
425
+ const a = tt(i, this);
426
+ a.value = t;
374
427
  }
375
- } else e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
428
+ } else t != null && t instanceof FormData && Array.from(t).reverse().forEach(([a, r]) => {
376
429
  if (typeof r == "string") {
377
- const o = ee(i, this);
430
+ const o = tt(i, this);
378
431
  o.name = a, o.value = r;
379
432
  }
380
433
  });
381
- F.set(i, e);
434
+ S.set(i, t);
382
435
  }
383
- setValidity(e, i, a) {
384
- const r = l.get(this);
385
- if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
436
+ setValidity(t, i, a) {
437
+ const r = c.get(this);
438
+ if (y(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
386
439
  throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
387
- K.set(this, a);
388
- const o = d.get(this), s = {};
389
- for (const g in e)
390
- s[g] = e[g];
391
- Object.keys(s).length === 0 && Ee(o);
392
- const m = Object.assign(Object.assign({}, o), s);
393
- delete m.valid;
394
- const { valid: h } = Me(o, m, this.form);
395
- if (!h && !i)
440
+ F.set(this, a);
441
+ const o = d.get(this), n = {};
442
+ for (const k in t)
443
+ n[k] = t[k];
444
+ Object.keys(n).length === 0 && At(o);
445
+ const f = Object.assign(Object.assign({}, o), n);
446
+ delete f.valid;
447
+ const { valid: u } = Ft(o, f, this.form);
448
+ if (!u && !i)
396
449
  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.");
397
- k.set(this, h ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !h), r.toggleAttribute("internals-valid", h), r.setAttribute("aria-invalid", `${!h}`)) : I.set(r, this);
450
+ p.set(this, u ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !u), r.toggleAttribute("internals-valid", u), r.setAttribute("aria-invalid", `${!u}`)) : V.set(r, this);
398
451
  }
399
452
  get shadowRoot() {
400
- const e = l.get(this), i = j.get(e);
453
+ const t = c.get(this), i = A.get(t);
401
454
  return i || null;
402
455
  }
403
456
  get validationMessage() {
404
- const e = l.get(this);
405
- return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), k.get(this);
457
+ const t = c.get(this);
458
+ return y(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), p.get(this);
406
459
  }
407
460
  get validity() {
408
- const e = l.get(this);
409
- return w(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), d.get(this);
461
+ const t = c.get(this);
462
+ return y(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), d.get(this);
410
463
  }
411
464
  get willValidate() {
412
- const e = l.get(this);
413
- 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"));
465
+ const t = c.get(this);
466
+ return y(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"));
414
467
  }
415
468
  }
416
- function Ie() {
469
+ function Lt() {
417
470
  if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
418
471
  return !1;
419
- class t extends HTMLElement {
472
+ class e extends HTMLElement {
420
473
  constructor() {
421
474
  super(), this.internals = this.attachInternals();
422
475
  }
423
476
  }
424
- const e = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, "")}`;
425
- customElements.define(e, t);
426
- const i = new t();
477
+ const t = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, "")}`;
478
+ customElements.define(t, e);
479
+ const i = new e();
427
480
  return [
428
481
  "shadowRoot",
429
482
  "form",
@@ -437,25 +490,25 @@ function Be() {
437
490
  "reportValidity"
438
491
  ].every((a) => a in i.internals);
439
492
  }
440
- let le = !1, ce = !1;
441
- function W(t) {
442
- ce || (ce = !0, window.CustomStateSet = H, t && (HTMLElement.prototype.attachInternals = function(...e) {
443
- const i = t.call(this, e);
444
- return i.states = new H(this), i;
493
+ let ct = !1, lt = !1;
494
+ function q(e) {
495
+ lt || (lt = !0, window.CustomStateSet = z, e && (HTMLElement.prototype.attachInternals = function(...t) {
496
+ const i = e.call(this, t);
497
+ return i.states = new z(this), i;
445
498
  }));
446
499
  }
447
- function de(t = !0) {
448
- if (!le) {
449
- if (le = !0, typeof window < "u" && (window.ElementInternals = ne), typeof CustomElementRegistry < "u") {
450
- const e = CustomElementRegistry.prototype.define;
500
+ function dt(e = !0) {
501
+ if (!ct) {
502
+ if (ct = !0, typeof window < "u" && (window.ElementInternals = nt), typeof CustomElementRegistry < "u") {
503
+ const t = CustomElementRegistry.prototype.define;
451
504
  CustomElementRegistry.prototype.define = function(i, a, r) {
452
505
  if (a.formAssociated) {
453
506
  const o = a.prototype.connectedCallback;
454
507
  a.prototype.connectedCallback = function() {
455
- J.has(this) || (J.set(this, !0), this.hasAttribute("disabled") && D(this, !0)), o != null && o.apply(this), re(this);
508
+ J.has(this) || (J.set(this, !0), this.hasAttribute("disabled") && H(this, !0)), o != null && o.apply(this), rt(this);
456
509
  };
457
510
  }
458
- e.call(this, i, a, r);
511
+ t.call(this, i, a, r);
459
512
  };
460
513
  }
461
514
  if (typeof HTMLElement < "u" && (HTMLElement.prototype.attachInternals = function() {
@@ -463,30 +516,30 @@ function Be() {
463
516
  if (this.tagName.indexOf("-") === -1)
464
517
  throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
465
518
  } else return {};
466
- if (c.has(this))
519
+ if (l.has(this))
467
520
  throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
468
- return new ne(this);
521
+ return new nt(this);
469
522
  }), typeof Element < "u") {
470
- let e = function(...a) {
523
+ let t = function(...a) {
471
524
  const r = i.apply(this, a);
472
- if (j.set(this, r), N()) {
473
- const o = new MutationObserver(O);
474
- window.ShadyDOM ? o.observe(this, $) : o.observe(r, $), C.set(this, o);
525
+ if (A.set(this, r), P()) {
526
+ const o = new MutationObserver(D);
527
+ window.ShadyDOM ? o.observe(this, R) : o.observe(r, R), C.set(this, o);
475
528
  }
476
529
  return r;
477
530
  };
478
531
  const i = Element.prototype.attachShadow;
479
- Element.prototype.attachShadow = e;
532
+ Element.prototype.attachShadow = t;
480
533
  }
481
- N() && typeof document < "u" && new MutationObserver(O).observe(document.documentElement, $), typeof HTMLFormElement < "u" && Fe(), (t || typeof window < "u" && !window.CustomStateSet) && W();
534
+ P() && typeof document < "u" && new MutationObserver(D).observe(document.documentElement, R), typeof HTMLFormElement < "u" && Tt(), (e || typeof window < "u" && !window.CustomStateSet) && q();
482
535
  }
483
536
  }
484
- return !!customElements.polyfillWrapFlushCallback || (Ie() ? typeof window < "u" && !window.CustomStateSet && W(HTMLElement.prototype.attachInternals) : de(!1)), n.forceCustomStateSetPolyfill = W, n.forceElementInternalsPolyfill = de, Object.defineProperty(n, "__esModule", { value: !0 }), n;
537
+ return !!customElements.polyfillWrapFlushCallback || (Lt() ? typeof window < "u" && !window.CustomStateSet && q(HTMLElement.prototype.attachInternals) : dt(!1)), s.forceCustomStateSetPolyfill = q, s.forceElementInternalsPolyfill = dt, Object.defineProperty(s, "__esModule", { value: !0 }), s;
485
538
  })({});
486
- })()), he;
539
+ })()), mt;
487
540
  }
488
- Be();
489
- const qe = "*,*: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)}@media(hover:hover){.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)){@media(hover:hover){.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)}@media(hover:hover){.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)){@media(hover:hover){.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;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-input *{overflow:hidden}.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[checked] .c-switch-control{transform:translate(var(--switch-translation))}.c-switch[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-solid)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-description *{overflow:hidden}.c-switch-wrapper--label-leading{flex-direction:row-reverse}.c-switch-wrapper--label-trailing{flex-direction:row}@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[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[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[checked] .c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}", Ue = ["leading", "trailing"], rt = "change", x = {
541
+ Kt();
542
+ const Gt = "*,*: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)}@media(hover:hover){.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)){@media(hover:hover){.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)}@media(hover:hover){.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)){@media(hover:hover){.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--in-interactive-container{background-image:linear-gradient(var(--interactive-container-tint, transparent) 0 0)}.c-switch--in-interactive-container:hover:not(:disabled),.c-switch--in-interactive-container:active:not(:disabled){--int-states-mixin-bg-color: var(--dt-color-interactive-form)}.c-switch--in-interactive-container[checked]:hover:not(:disabled),.c-switch--in-interactive-container[checked]:active:not(:disabled){--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}.c-switch-input{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-input *{overflow:hidden}.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[checked] .c-switch-control{transform:translate(var(--switch-translation))}.c-switch[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-solid)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-description *{overflow:hidden}.c-switch-wrapper--label-leading{flex-direction:row-reverse}.c-switch-wrapper--label-trailing{flex-direction:row}@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[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[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[checked] .c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}", Jt = ["leading", "trailing"], le = "change", M = {
490
543
  checked: !1,
491
544
  defaultChecked: !1,
492
545
  disabled: !1,
@@ -494,37 +547,37 @@ const qe = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before
494
547
  required: !1,
495
548
  value: "on"
496
549
  };
497
- var je = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, f = (n, l, d, u) => {
498
- for (var c = u > 1 ? void 0 : u ? Ke(l, d) : l, k = n.length - 1, E; k >= 0; k--)
499
- (E = n[k]) && (c = (u ? E(l, d, c) : E(c)) || c);
500
- return u && c && je(l, d, c), c;
550
+ var Qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, b = (s, c, d, h) => {
551
+ for (var l = h > 1 ? void 0 : h ? Xt(c, d) : c, p = s.length - 1, v; p >= 0; p--)
552
+ (v = s[p]) && (l = (h ? v(c, d, l) : v(l)) || l);
553
+ return h && l && Qt(c, d, l), l;
501
554
  };
502
- const Ge = "pie-switch";
503
- let p = class extends $e(De(Re(q))) {
555
+ const Yt = "pie-switch";
556
+ let m = class extends Dt(Rt(Ht(j))) {
504
557
  constructor() {
505
- super(...arguments), this.labelPlacement = x.labelPlacement, this.checked = x.checked, this.defaultChecked = x.defaultChecked, this.required = x.required, this.value = x.value, this.disabled = x.disabled, this._isAnimationAllowed = !1;
558
+ super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.defaultChecked = M.defaultChecked, this.required = M.required, this.value = M.value, this.disabled = M.disabled, this._isAnimationAllowed = !1;
506
559
  }
507
- firstUpdated(n) {
508
- super.firstUpdated(n);
509
- const { signal: l } = this._abortController;
560
+ firstUpdated(s) {
561
+ super.firstUpdated(s);
562
+ const { signal: c } = this._abortController;
510
563
  this.handleFormAssociation(), this.input.addEventListener("invalid", (d) => {
511
564
  this.dispatchEvent(new Event("invalid", d));
512
- }, { signal: l });
565
+ }, { signal: c });
513
566
  }
514
567
  connectedCallback() {
515
568
  super.connectedCallback(), this._abortController = new AbortController();
516
- const { signal: n } = this._abortController;
517
- this.addEventListener("click", (l) => {
518
- const [d] = l.composedPath();
569
+ const { signal: s } = this._abortController;
570
+ this.addEventListener("click", (c) => {
571
+ const [d] = c.composedPath();
519
572
  if (this.disabled || d === this.input)
520
573
  return;
521
- const u = !this.label && l.composedPath().includes(this.switchBody);
522
- (d === this || u) && this.input.click();
523
- }, { signal: n });
574
+ const h = !this.label && c.composedPath().includes(this.switchBody);
575
+ (d === this || h) && this.input.click();
576
+ }, { signal: s });
524
577
  }
525
578
  disconnectedCallback() {
526
- var n;
527
- super.disconnectedCallback(), (n = this._abortController) == null || n.abort();
579
+ var s;
580
+ super.disconnectedCallback(), (s = this._abortController) == null || s.abort();
528
581
  }
529
582
  updated() {
530
583
  this.handleFormAssociation();
@@ -539,10 +592,10 @@ let p = class extends $e(De(Re(q))) {
539
592
  * The handleChange function updates the checkbox state and emits an event for consumers.
540
593
  * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
541
594
  */
542
- handleChange(n) {
543
- const { checked: l } = n == null ? void 0 : n.currentTarget;
544
- this.checked = l;
545
- const d = He(n);
595
+ handleChange(s) {
596
+ const { checked: c } = s == null ? void 0 : s.currentTarget;
597
+ this.checked = c;
598
+ const d = Wt(s);
546
599
  this._isAnimationAllowed || (this._isAnimationAllowed = !0), this.dispatchEvent(d), this.handleFormAssociation();
547
600
  }
548
601
  /**
@@ -565,8 +618,8 @@ let p = class extends $e(De(Re(q))) {
565
618
  * Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
566
619
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
567
620
  */
568
- setCustomValidity(n) {
569
- this.input.setCustomValidity(n), this._internals.setValidity(this.validity, this.validationMessage, this.input);
621
+ setCustomValidity(s) {
622
+ this.input.setCustomValidity(s), this._internals.setValidity(this.validity, this.validationMessage, this.input);
570
623
  }
571
624
  /**
572
625
  * Called when the containing form is reset.
@@ -576,8 +629,8 @@ let p = class extends $e(De(Re(q))) {
576
629
  if (this.checked === this.defaultChecked)
577
630
  return;
578
631
  this.checked = this.defaultChecked;
579
- const n = new Event("change", { bubbles: !0, composed: !0 });
580
- this.dispatchEvent(n), this.handleFormAssociation();
632
+ const s = new Event("change", { bubbles: !0, composed: !0 });
633
+ this.dispatchEvent(s), this.handleFormAssociation();
581
634
  }
582
635
  /**
583
636
  * (Read-only) returns a ValidityState with the validity states that this element is in.
@@ -595,116 +648,122 @@ let p = class extends $e(De(Re(q))) {
595
648
  return this.input.validationMessage;
596
649
  }
597
650
  renderAriaDescription() {
598
- var n;
599
- return (n = this.aria) != null && n.describedBy ? B`
651
+ var s;
652
+ return (s = this.aria) != null && s.describedBy ? U`
600
653
  <div
601
654
  aria-hidden="true"
602
655
  id="switch-description"
603
656
  data-test-id="switch-description"
604
657
  class="c-switch-description">
605
658
  ${this.aria.describedBy}
606
- </div>` : P;
659
+ </div>` : O;
607
660
  }
608
661
  renderSwitchLabel() {
609
- const { label: n, labelPlacement: l } = this;
610
- return n ? B`
662
+ const { label: s, labelPlacement: c } = this;
663
+ return s ? U`
611
664
  <span
612
665
  aria-hidden="true"
613
- data-test-id="switch-label-${l}"
666
+ data-test-id="switch-label-${c}"
614
667
  class="c-switch-label">
615
- ${n}
616
- </span>` : P;
668
+ ${s}
669
+ </span>` : O;
617
670
  }
618
671
  render() {
672
+ var A, F;
619
673
  const {
620
- label: n,
621
- labelPlacement: l,
674
+ label: s,
675
+ labelPlacement: c,
622
676
  aria: d,
623
- checked: u,
624
- disabled: c,
625
- required: k,
626
- _isAnimationAllowed: E,
677
+ checked: h,
678
+ disabled: l,
679
+ required: p,
680
+ _isAnimationAllowed: v,
627
681
  associatedLabelText: C
628
- } = this, b = (d == null ? void 0 : d.label) || n || C, F = {
682
+ } = this, w = (d == null ? void 0 : d.label) || s || ((A = this._contextAria) == null ? void 0 : A.label) || C, S = {
629
683
  "c-switch-wrapper": !0,
630
- "c-switch-wrapper--allow-animation": E,
631
- [`c-switch-wrapper--label-${l}`]: !0
632
- }, M = Te(n ? "label" : "div");
633
- return Le`
634
- <${M}
635
- class="${Pe(F)}"
636
- ?disabled=${c}>
684
+ "c-switch-wrapper--allow-animation": v,
685
+ [`c-switch-wrapper--label-${c}`]: !0
686
+ }, x = Pt(s ? "label" : "div");
687
+ return Ot`
688
+ <${x}
689
+ class="${ht(S)}"
690
+ ?disabled=${l}>
637
691
  <div
638
692
  data-test-id="switch-component"
639
- class="c-switch"
640
- ?checked=${u}>
693
+ class="${ht({ "c-switch": !0, "c-switch--in-interactive-container": !!this._contextAria })}"
694
+ ?checked=${h}>
641
695
  <input
642
696
  data-test-id="switch-input"
643
697
  role="switch"
644
698
  type="checkbox"
645
699
  class="c-switch-input"
646
- ?required=${k}
647
- .checked="${Oe(u)}"
648
- ?disabled="${c}"
700
+ ?required=${p}
701
+ .checked="${$t(h)}"
702
+ ?disabled="${l}"
649
703
  @change="${this.handleChange}"
650
- aria-label="${_e(b)}"
651
- aria-describedby="${d != null && d.describedBy ? "switch-description" : P}">
704
+ aria-label="${ut(w)}"
705
+ aria-description="${ut((F = this._contextAria) == null ? void 0 : F.description)}"
706
+ aria-describedby="${d != null && d.describedBy ? "switch-description" : O}">
652
707
  <div class="c-switch-control">
653
- ${u ? B`<icon-check></icon-check>` : P}
708
+ ${h ? U`<icon-check></icon-check>` : O}
654
709
  </div>
655
710
  </div>
656
711
  ${this.renderSwitchLabel()}
657
712
  ${this.renderAriaDescription()}
658
- </${M}>`;
713
+ </${x}>`;
659
714
  }
660
715
  };
661
- p.styles = Ve(qe);
662
- f([
663
- y({ type: String })
664
- ], p.prototype, "label", 2);
665
- f([
666
- y({ type: String }),
667
- We(Ge, Ue, x.labelPlacement)
668
- ], p.prototype, "labelPlacement", 2);
669
- f([
670
- y({ type: Object })
671
- ], p.prototype, "aria", 2);
672
- f([
673
- y({ type: Boolean, reflect: !0 })
674
- ], p.prototype, "checked", 2);
675
- f([
676
- y({ type: Boolean, reflect: !0 })
677
- ], p.prototype, "defaultChecked", 2);
678
- f([
679
- y({ type: Boolean, reflect: !0 })
680
- ], p.prototype, "required", 2);
681
- f([
682
- y({ type: String })
683
- ], p.prototype, "value", 2);
684
- f([
685
- y({ type: String, reflect: !0 })
686
- ], p.prototype, "name", 2);
687
- f([
688
- y({ type: Boolean, reflect: !0 })
689
- ], p.prototype, "disabled", 2);
690
- f([
691
- U('input[type="checkbox"]')
692
- ], p.prototype, "input", 2);
693
- f([
694
- U(".c-switch")
695
- ], p.prototype, "switchBody", 2);
696
- f([
697
- U('label, input[type="checkbox"]')
698
- ], p.prototype, "focusTarget", 2);
699
- f([
700
- Ne()
701
- ], p.prototype, "_isAnimationAllowed", 2);
702
- p = f([
703
- ze("pie-switch")
704
- ], p);
716
+ m.styles = Nt(Gt);
717
+ b([
718
+ E({ type: String })
719
+ ], m.prototype, "label", 2);
720
+ b([
721
+ E({ type: String }),
722
+ zt(Yt, Jt, M.labelPlacement)
723
+ ], m.prototype, "labelPlacement", 2);
724
+ b([
725
+ E({ type: Object })
726
+ ], m.prototype, "aria", 2);
727
+ b([
728
+ E({ type: Boolean, reflect: !0 })
729
+ ], m.prototype, "checked", 2);
730
+ b([
731
+ E({ type: Boolean, reflect: !0 })
732
+ ], m.prototype, "defaultChecked", 2);
733
+ b([
734
+ E({ type: Boolean, reflect: !0 })
735
+ ], m.prototype, "required", 2);
736
+ b([
737
+ E({ type: String })
738
+ ], m.prototype, "value", 2);
739
+ b([
740
+ E({ type: String, reflect: !0 })
741
+ ], m.prototype, "name", 2);
742
+ b([
743
+ E({ type: Boolean, reflect: !0 })
744
+ ], m.prototype, "disabled", 2);
745
+ b([
746
+ jt({ context: Bt, subscribe: !0 }),
747
+ bt()
748
+ ], m.prototype, "_contextAria", 2);
749
+ b([
750
+ K('input[type="checkbox"]')
751
+ ], m.prototype, "input", 2);
752
+ b([
753
+ K(".c-switch")
754
+ ], m.prototype, "switchBody", 2);
755
+ b([
756
+ K('label, input[type="checkbox"]')
757
+ ], m.prototype, "focusTarget", 2);
758
+ b([
759
+ bt()
760
+ ], m.prototype, "_isAnimationAllowed", 2);
761
+ m = b([
762
+ qt("pie-switch")
763
+ ], m);
705
764
  export {
706
- rt as ON_SWITCH_CHANGED_EVENT,
707
- p as PieSwitch,
708
- x as defaultProps,
709
- Ue as labelPlacements
765
+ le as ON_SWITCH_CHANGED_EVENT,
766
+ m as PieSwitch,
767
+ M as defaultProps,
768
+ Jt as labelPlacements
710
769
  };
package/dist/react.d.ts CHANGED
@@ -43,6 +43,7 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInpu
43
43
  value: string;
44
44
  name: SwitchProps['name'];
45
45
  disabled: boolean;
46
+ private _contextAria?;
46
47
  private input;
47
48
  private switchBody;
48
49
  focusTarget: HTMLElement;
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.5.6",
4
+ "version": "2.6.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/justeattakeaway/pie",
@@ -44,8 +44,8 @@
44
44
  "license": "Apache-2.0",
45
45
  "devDependencies": {
46
46
  "@justeattakeaway/pie-components-config": "0.21.3",
47
- "@justeattakeaway/pie-css": "1.3.1",
48
- "@justeattakeaway/pie-monorepo-utils": "0.9.7",
47
+ "@justeattakeaway/pie-css": "1.3.2",
48
+ "@justeattakeaway/pie-monorepo-utils": "0.9.8",
49
49
  "@justeattakeaway/pie-wrapper-react": "0.14.5"
50
50
  },
51
51
  "dependencies": {
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import { property, query, state } from 'lit/decorators.js';
7
7
  import { classMap } from 'lit/directives/class-map.js';
8
8
  import { ifDefined } from 'lit/directives/if-defined.js';
9
9
  import { live } from 'lit/directives/live.js';
10
+ import { consume } from '@lit/context';
10
11
  import 'element-internals-polyfill';
11
12
 
12
13
  import {
@@ -16,7 +17,9 @@ import {
16
17
  AssociatedLabelMixin,
17
18
  wrapNativeEvent,
18
19
  safeCustomElement,
20
+ ariaContext,
19
21
  type PIEInputElement,
22
+ type ContextualAria,
20
23
  } from '@justeattakeaway/pie-webc-core';
21
24
  import '@justeattakeaway/pie-icons-webc/dist/IconCheck.js';
22
25
 
@@ -62,6 +65,12 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
62
65
  @property({ type: Boolean, reflect: true })
63
66
  public disabled = defaultProps.disabled;
64
67
 
68
+ // Optional ARIA supplied by an ancestor (for example a `pie-list-item`), folded into the
69
+ // input's ARIA below as a fallback behind the switch's own label. Undefined when standalone.
70
+ @consume({ context: ariaContext, subscribe: true })
71
+ @state()
72
+ private _contextAria?: ContextualAria;
73
+
65
74
  @query('input[type="checkbox"]')
66
75
  private input!: HTMLInputElement;
67
76
 
@@ -266,7 +275,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
266
275
  associatedLabelText,
267
276
  } = this;
268
277
 
269
- const ariaLabel = aria?.label || label || associatedLabelText;
278
+ const ariaLabel = aria?.label || label || this._contextAria?.label || associatedLabelText;
270
279
 
271
280
  const classes = {
272
281
  'c-switch-wrapper': true,
@@ -282,7 +291,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
282
291
  ?disabled=${disabled}>
283
292
  <div
284
293
  data-test-id="switch-component"
285
- class="c-switch"
294
+ class="${classMap({ 'c-switch': true, 'c-switch--in-interactive-container': Boolean(this._contextAria) })}"
286
295
  ?checked=${checked}>
287
296
  <input
288
297
  data-test-id="switch-input"
@@ -294,6 +303,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
294
303
  ?disabled="${disabled}"
295
304
  @change="${this.handleChange}"
296
305
  aria-label="${ifDefined(ariaLabel)}"
306
+ aria-description="${ifDefined(this._contextAria?.description)}"
297
307
  aria-describedby="${aria?.describedBy ? 'switch-description' : nothing}">
298
308
  <div class="c-switch-control">
299
309
  ${checked ? html`<icon-check></icon-check>` : nothing}
package/src/switch.scss CHANGED
@@ -68,6 +68,27 @@
68
68
  }
69
69
  }
70
70
 
71
+ // Inside an interactive container (such as a `pie-list-item`) the whole container is the click
72
+ // target, so the track should tint with the container rather than only on a direct hover of the
73
+ // switch. The container exposes its current hover/active tint as `--interactive-container-tint` (an
74
+ // inherited custom property that flows through the slot into this shadow tree); we layer it over
75
+ // the track. We also opt the switch out of its own hover/active tint here, so hovering the switch
76
+ // directly (which also hovers the container) does not tint twice. The class is added by the
77
+ // component when it consumes an ancestor's ARIA context.
78
+ .c-switch--in-interactive-container {
79
+ background-image: linear-gradient(var(--interactive-container-tint, transparent) 0 0);
80
+
81
+ &:hover:not(:disabled),
82
+ &:active:not(:disabled) {
83
+ --int-states-mixin-bg-color: var(--dt-color-interactive-form);
84
+ }
85
+
86
+ &[checked]:hover:not(:disabled),
87
+ &[checked]:active:not(:disabled) {
88
+ --int-states-mixin-bg-color: var(--dt-color-interactive-brand);
89
+ }
90
+ }
91
+
71
92
  .c-switch-input {
72
93
  @include p.visually-hidden;
73
94