@justeattakeaway/pie-switch 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { FormControlMixin as Te, RtlMixin as Le, wrapNativeEvent as Ne, validPro
6
6
  import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
7
7
  (function() {
8
8
  (function(E) {
9
- const s = /* @__PURE__ */ new WeakMap(), d = /* @__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 = {
9
+ const o = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), v = /* @__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",
@@ -58,8 +58,8 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
58
58
  get() {
59
59
  return a;
60
60
  },
61
- set(o) {
62
- a = o, t.isConnected ? t.setAttribute(r, o) : A.set(t, e);
61
+ set(n) {
62
+ a = n, t.isConnected ? t.setAttribute(r, n) : A.set(t, e);
63
63
  }
64
64
  });
65
65
  }
@@ -70,8 +70,8 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
70
70
  }
71
71
  const Y = (t, e = !1) => {
72
72
  const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
73
- acceptNode(o) {
74
- return l.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
73
+ acceptNode(n) {
74
+ return l.has(n) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
75
75
  }
76
76
  });
77
77
  let a = i.nextNode();
@@ -89,21 +89,21 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
89
89
  }) : {};
90
90
  function P(t) {
91
91
  t.forEach((e) => {
92
- const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), o = Array.from(a);
93
- r.forEach((n) => {
92
+ const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), n = Array.from(a);
93
+ r.forEach((s) => {
94
94
  var h;
95
- if (l.has(n) && n.constructor.formAssociated && G(n), A.has(n)) {
96
- const c = A.get(n);
95
+ if (l.has(s) && s.constructor.formAssociated && G(s), A.has(s)) {
96
+ const c = A.get(s);
97
97
  Object.keys(F).filter((f) => c[f] !== null).forEach((f) => {
98
- n.setAttribute(F[f], c[f]);
99
- }), A.delete(n);
98
+ s.setAttribute(F[f], c[f]);
99
+ }), A.delete(s);
100
100
  }
101
- if (x.has(n)) {
102
- const c = x.get(n);
103
- n.setAttribute("internals-valid", c.validity.valid.toString()), n.setAttribute("internals-invalid", (!c.validity.valid).toString()), n.setAttribute("aria-invalid", (!c.validity.valid).toString()), x.delete(n);
101
+ if (x.has(s)) {
102
+ const c = x.get(s);
103
+ s.setAttribute("internals-valid", c.validity.valid.toString()), s.setAttribute("internals-invalid", (!c.validity.valid).toString()), s.setAttribute("aria-invalid", (!c.validity.valid).toString()), x.delete(s);
104
104
  }
105
- if (n.localName === "form") {
106
- const c = g.get(n), b = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
105
+ if (s.localName === "form") {
106
+ const c = v.get(s), b = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
107
107
  acceptNode(W) {
108
108
  return l.has(W) && W.constructor.formAssociated && !(c && c.has(W)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
109
109
  }
@@ -112,10 +112,10 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
112
112
  for (; f; )
113
113
  G(f), f = b.nextNode();
114
114
  }
115
- n.localName === "fieldset" && ((h = I.observe) === null || h === void 0 || h.call(I, n, J), Y(n, !0));
116
- }), o.forEach((n) => {
117
- const h = l.get(n);
118
- h && u.get(h) && Q(h), O.has(n) && O.get(n).disconnect();
115
+ s.localName === "fieldset" && ((h = I.observe) === null || h === void 0 || h.call(I, s, J), Y(s, !0));
116
+ }), n.forEach((s) => {
117
+ const h = l.get(s);
118
+ h && u.get(h) && Q(h), O.has(s) && O.get(s).disconnect();
119
119
  });
120
120
  });
121
121
  }
@@ -156,7 +156,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
156
156
  e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), t.setAttribute("aria-labelledby", i);
157
157
  }
158
158
  }, V = (t) => {
159
- const e = Array.from(t.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = g.get(t) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => l.get(o).validity.valid), r = [...e, ...a].includes(!1);
159
+ const e = Array.from(t.elements).filter((n) => !n.tagName.includes("-") && n.validity).map((n) => n.validity.valid), i = v.get(t) || [], a = Array.from(i).filter((n) => n.isConnected).map((n) => l.get(n).validity.valid), r = [...e, ...a].includes(!1);
160
160
  t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
161
161
  }, me = (t) => {
162
162
  V(S(t.target));
@@ -166,25 +166,25 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
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 = g.get(t);
169
+ const r = v.get(t);
170
170
  if (t.noValidate)
171
171
  return;
172
172
  r.size && Array.from(r).reverse().map((h) => l.get(h).reportValidity()).includes(!1) && i.preventDefault();
173
173
  }
174
174
  });
175
- }, ve = (t) => {
176
- const e = g.get(t.target);
175
+ }, ge = (t) => {
176
+ const e = v.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 = g.get(e);
182
+ const a = v.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), g.set(e, r), be(e), e.addEventListener("reset", ve), e.addEventListener("input", me), e.addEventListener("change", we);
187
+ r.add(t), v.set(e, r), be(e), e.addEventListener("reset", ge), 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]);
@@ -197,7 +197,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
197
197
  if (!t.constructor.formAssociated)
198
198
  throw new i(e);
199
199
  }, te = (t, e, i) => {
200
- const a = g.get(t);
200
+ const a = v.get(t);
201
201
  return a && a.size && a.forEach((r) => {
202
202
  l.get(r)[i]() || (e = !1);
203
203
  }), e;
@@ -210,7 +210,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
210
210
  function T() {
211
211
  return typeof MutationObserver < "u";
212
212
  }
213
- class ge {
213
+ class ve {
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
  }
@@ -259,7 +259,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
259
259
  return i === "m" ? a : i === "a" ? a.call(t) : a ? a.value : e.get(t);
260
260
  }
261
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");
262
+ 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");
263
263
  return e.set(t, i), i;
264
264
  }
265
265
  var C;
@@ -290,37 +290,37 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
290
290
  HTMLFormElement.prototype.checkValidity = i;
291
291
  const e = HTMLFormElement.prototype.reportValidity;
292
292
  HTMLFormElement.prototype.reportValidity = a;
293
- function i(...o) {
294
- let n = t.apply(this, o);
295
- return te(this, n, "checkValidity");
293
+ function i(...n) {
294
+ let s = t.apply(this, n);
295
+ return te(this, s, "checkValidity");
296
296
  }
297
- function a(...o) {
298
- let n = e.apply(this, o);
299
- return te(this, n, "reportValidity");
297
+ function a(...n) {
298
+ let s = e.apply(this, n);
299
+ return te(this, s, "reportValidity");
300
300
  }
301
301
  const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
302
302
  Object.defineProperty(HTMLFormElement.prototype, "elements", {
303
- get(...o) {
304
- const n = r.call(this, ...o), h = Array.from(g.get(this) || []);
303
+ get(...n) {
304
+ const s = r.call(this, ...n), h = Array.from(v.get(this) || []);
305
305
  if (h.length === 0)
306
- return n;
307
- const c = Array.from(n).concat(h).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
306
+ return s;
307
+ const c = Array.from(s).concat(h).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
308
308
  return new Ce(c);
309
309
  }
310
310
  });
311
311
  }
312
- class oe {
312
+ class ne {
313
313
  static get isPolyfilled() {
314
314
  return !0;
315
315
  }
316
316
  constructor(e) {
317
317
  if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
318
318
  throw new TypeError("Illegal constructor");
319
- const i = e.getRootNode(), a = new ge();
320
- this.states = new D(e), s.set(this, e), d.set(this, a), l.set(e, this), he(e, this), fe(e, this), Object.seal(this), i instanceof DocumentFragment && pe(i);
319
+ const i = e.getRootNode(), a = new ve();
320
+ this.states = new D(e), o.set(this, e), d.set(this, a), l.set(e, this), he(e, this), fe(e, this), Object.seal(this), i instanceof DocumentFragment && pe(i);
321
321
  }
322
322
  checkValidity() {
323
- const e = s.get(this);
323
+ const e = o.get(this);
324
324
  if (w(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
325
325
  return !0;
326
326
  const i = d.get(this);
@@ -335,19 +335,19 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
335
335
  return i.valid;
336
336
  }
337
337
  get form() {
338
- const e = s.get(this);
338
+ const e = o.get(this);
339
339
  w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
340
340
  let i;
341
341
  return e.constructor.formAssociated === !0 && (i = S(e)), i;
342
342
  }
343
343
  get labels() {
344
- const e = s.get(this);
344
+ const e = o.get(this);
345
345
  w(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
346
346
  const i = e.getAttribute("id"), a = e.getRootNode();
347
347
  return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
348
348
  }
349
349
  reportValidity() {
350
- const e = s.get(this);
350
+ const e = o.get(this);
351
351
  if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
352
352
  return !0;
353
353
  const i = this.checkValidity(), a = U.get(this);
@@ -356,7 +356,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
356
356
  return !i && a && (e.focus(), a.focus()), i;
357
357
  }
358
358
  setFormValue(e) {
359
- const i = s.get(this);
359
+ const i = o.get(this);
360
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)) {
361
361
  if (i.getAttribute("name")) {
362
362
  const a = X(i, this);
@@ -364,42 +364,42 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
364
364
  }
365
365
  } else e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
366
366
  if (typeof r == "string") {
367
- const o = X(i, this);
368
- o.name = a, o.value = r;
367
+ const n = X(i, this);
368
+ n.name = a, n.value = r;
369
369
  }
370
370
  });
371
371
  q.set(i, e);
372
372
  }
373
373
  setValidity(e, i, a) {
374
- const r = s.get(this);
374
+ const r = o.get(this);
375
375
  if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
376
376
  throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
377
377
  U.set(this, a);
378
- const o = d.get(this), n = {};
378
+ const n = d.get(this), s = {};
379
379
  for (const b in e)
380
- n[b] = e[b];
381
- Object.keys(n).length === 0 && ye(o);
382
- const h = Object.assign(Object.assign({}, o), n);
380
+ s[b] = e[b];
381
+ Object.keys(s).length === 0 && ye(n);
382
+ const h = Object.assign(Object.assign({}, n), s);
383
383
  delete h.valid;
384
- const { valid: c } = Ee(o, h, this.form);
384
+ const { valid: c } = Ee(n, h, this.form);
385
385
  if (!c && !i)
386
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.");
387
- v.set(this, c ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !c), r.toggleAttribute("internals-valid", c), r.setAttribute("aria-invalid", `${!c}`)) : x.set(r, this);
387
+ g.set(this, c ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !c), r.toggleAttribute("internals-valid", c), r.setAttribute("aria-invalid", `${!c}`)) : x.set(r, this);
388
388
  }
389
389
  get shadowRoot() {
390
- const e = s.get(this), i = B.get(e);
390
+ const e = o.get(this), i = B.get(e);
391
391
  return i || null;
392
392
  }
393
393
  get validationMessage() {
394
- const e = s.get(this);
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);
394
+ const e = o.get(this);
395
+ return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), g.get(this);
396
396
  }
397
397
  get validity() {
398
- const e = s.get(this);
398
+ const e = o.get(this);
399
399
  return w(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), d.get(this);
400
400
  }
401
401
  get willValidate() {
402
- const e = s.get(this);
402
+ const e = o.get(this);
403
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"));
404
404
  }
405
405
  }
@@ -427,22 +427,22 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
427
427
  "reportValidity"
428
428
  ].every((a) => a in i.internals);
429
429
  }
430
- let se = !1, ne = !1;
430
+ let oe = !1, se = !1;
431
431
  function H(t) {
432
- ne || (ne = !0, window.CustomStateSet = D, t && (HTMLElement.prototype.attachInternals = function(...e) {
432
+ se || (se = !0, window.CustomStateSet = D, t && (HTMLElement.prototype.attachInternals = function(...e) {
433
433
  const i = t.call(this, e);
434
434
  return i.states = new D(this), i;
435
435
  }));
436
436
  }
437
437
  function le(t = !0) {
438
- if (!se) {
439
- if (se = !0, typeof window < "u" && (window.ElementInternals = oe), typeof CustomElementRegistry < "u") {
438
+ if (!oe) {
439
+ if (oe = !0, typeof window < "u" && (window.ElementInternals = ne), typeof CustomElementRegistry < "u") {
440
440
  const e = CustomElementRegistry.prototype.define;
441
441
  CustomElementRegistry.prototype.define = function(i, a, r) {
442
442
  if (a.formAssociated) {
443
- const o = a.prototype.connectedCallback;
443
+ const n = a.prototype.connectedCallback;
444
444
  a.prototype.connectedCallback = function() {
445
- K.has(this) || (K.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), o != null && o.apply(this), ie(this);
445
+ K.has(this) || (K.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), n != null && n.apply(this), ie(this);
446
446
  };
447
447
  }
448
448
  e.call(this, i, a, r);
@@ -455,13 +455,13 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
455
455
  } else return {};
456
456
  if (l.has(this))
457
457
  throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
458
- return new oe(this);
458
+ return new ne(this);
459
459
  }), typeof Element < "u") {
460
460
  let e = function(...a) {
461
461
  const r = i.apply(this, a);
462
462
  if (B.set(this, r), T()) {
463
- const o = new MutationObserver(P);
464
- window.ShadyDOM ? o.observe(this, _) : o.observe(r, _), O.set(this, o);
463
+ const n = new MutationObserver(P);
464
+ window.ShadyDOM ? n.observe(this, _) : n.observe(r, _), O.set(this, n);
465
465
  }
466
466
  return r;
467
467
  };
@@ -474,25 +474,25 @@ import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
474
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;
475
475
  })({});
476
476
  })();
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 = {
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-label{color:var(--dt-color-content-default)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.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 = {
478
478
  checked: !1,
479
479
  disabled: !1,
480
480
  labelPlacement: "leading",
481
481
  required: !1,
482
482
  value: "on"
483
483
  };
484
- var Re = Object.defineProperty, m = (E, s, d, u) => {
485
- for (var l = void 0, v = E.length - 1, M; v >= 0; v--)
486
- (M = E[v]) && (l = M(s, d, l) || l);
487
- return l && Re(s, d, l), l;
484
+ var Re = Object.defineProperty, m = (E, o, d, u) => {
485
+ for (var l = void 0, g = E.length - 1, M; g >= 0; g--)
486
+ (M = E[g]) && (l = M(o, d, l) || l);
487
+ return l && Re(o, d, l), l;
488
488
  };
489
489
  const de = "pie-switch", z = class z extends Te(Le(Fe)) {
490
490
  constructor() {
491
491
  super(...arguments), this.labelPlacement = k.labelPlacement, this.checked = k.checked, this.required = k.required, this.value = k.value, this.disabled = k.disabled;
492
492
  }
493
493
  firstUpdated() {
494
- this.handleFormAssociation(), this.input.addEventListener("invalid", (s) => {
495
- this.dispatchEvent(new Event("invalid", s));
494
+ this.handleFormAssociation(), this.input.addEventListener("invalid", (o) => {
495
+ this.dispatchEvent(new Event("invalid", o));
496
496
  });
497
497
  }
498
498
  updated() {
@@ -508,10 +508,10 @@ const de = "pie-switch", z = class z extends Te(Le(Fe)) {
508
508
  * The handleChange function updates the checkbox state and emits an event for consumers.
509
509
  * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
510
510
  */
511
- handleChange(s) {
512
- const { checked: d } = s == null ? void 0 : s.currentTarget;
511
+ handleChange(o) {
512
+ const { checked: d } = o == null ? void 0 : o.currentTarget;
513
513
  this.checked = d;
514
- const u = Ne(s);
514
+ const u = Ne(o);
515
515
  this.dispatchEvent(u), this.handleFormAssociation();
516
516
  }
517
517
  /**
@@ -534,8 +534,8 @@ const de = "pie-switch", z = class z extends Te(Le(Fe)) {
534
534
  * Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
535
535
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
536
536
  */
537
- setCustomValidity(s) {
538
- this.input.setCustomValidity(s), this._internals.setValidity(this.validity, this.validationMessage, this.input);
537
+ setCustomValidity(o) {
538
+ this.input.setCustomValidity(o), this._internals.setValidity(this.validity, this.validationMessage, this.input);
539
539
  }
540
540
  /**
541
541
  * (Read-only) returns a ValidityState with the validity states that this element is in.
@@ -558,16 +558,18 @@ const de = "pie-switch", z = class z extends Te(Le(Fe)) {
558
558
  *
559
559
  * @private
560
560
  */
561
- renderSwitchLabel(s) {
561
+ renderSwitchLabel(o) {
562
562
  const { label: d, labelPlacement: u } = this;
563
- return !d || u !== s ? L : N`
564
- <span data-test-id="switch-label-${u}">
563
+ return !d || u !== o ? L : N`
564
+ <span
565
+ data-test-id="switch-label-${u}"
566
+ class="c-switch-label">
565
567
  ${d}
566
568
  </span>`;
567
569
  }
568
570
  renderAriaDescription() {
569
- var s;
570
- return (s = this.aria) != null && s.describedBy ? N`
571
+ var o;
572
+ return (o = this.aria) != null && o.describedBy ? N`
571
573
  <div
572
574
  id="switch-description"
573
575
  data-test-id="switch-description"
@@ -577,11 +579,11 @@ const de = "pie-switch", z = class z extends Te(Le(Fe)) {
577
579
  }
578
580
  render() {
579
581
  const {
580
- aria: s,
582
+ aria: o,
581
583
  checked: d,
582
584
  disabled: u,
583
585
  isRTL: l,
584
- required: v
586
+ required: g
585
587
  } = this;
586
588
  return N`
587
589
  <label
@@ -600,12 +602,12 @@ const de = "pie-switch", z = class z extends Te(Le(Fe)) {
600
602
  role="switch"
601
603
  type="checkbox"
602
604
  class="c-switch-input"
603
- .required=${v}
605
+ .required=${g}
604
606
  .checked="${d}"
605
607
  .disabled="${u}"
606
608
  @change="${this.handleChange}"
607
- aria-label="${Se(s == null ? void 0 : s.label)}"
608
- aria-describedby="${s != null && s.describedBy ? "switch-description" : L}">
609
+ aria-label="${Se(o == null ? void 0 : o.label)}"
610
+ aria-describedby="${o != null && o.describedBy ? "switch-description" : L}">
609
611
  <div class="c-switch-control">
610
612
  ${d ? N`<icon-check></icon-check>` : L}
611
613
  </div>
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": "1.0.1",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -37,11 +37,11 @@
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.13.1",
40
+ "@justeattakeaway/pie-css": "0.14.1",
41
41
  "cem-plugin-module-file-extensions": "0.0.5"
42
42
  },
43
43
  "dependencies": {
44
- "@justeattakeaway/pie-icons-webc": "1.2.0",
44
+ "@justeattakeaway/pie-icons-webc": "1.3.0",
45
45
  "@justeattakeaway/pie-webc-core": "0.24.2",
46
46
  "@justeattakeaway/pie-wrapper-react": "0.14.2",
47
47
  "element-internals-polyfill": "1.3.11"
package/src/index.ts CHANGED
@@ -160,7 +160,9 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
160
160
  }
161
161
 
162
162
  return html`
163
- <span data-test-id="switch-label-${labelPlacement}">
163
+ <span
164
+ data-test-id="switch-label-${labelPlacement}"
165
+ class="c-switch-label">
164
166
  ${label}
165
167
  </span>`;
166
168
  }
package/src/switch.scss CHANGED
@@ -137,6 +137,10 @@
137
137
  }
138
138
  }
139
139
 
140
+ .c-switch-label {
141
+ color: var(--dt-color-content-default);
142
+ }
143
+
140
144
  // The description is only required for screen readers so we need to visually hide the description
141
145
  .c-switch-description {
142
146
  @include p.visually-hidden;