@justeattakeaway/pie-switch 2.0.5 → 2.0.7

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.
@@ -139,6 +139,15 @@
139
139
  },
140
140
  "privacy": "public"
141
141
  },
142
+ {
143
+ "kind": "field",
144
+ "name": "_isAnimationAllowed",
145
+ "type": {
146
+ "text": "boolean"
147
+ },
148
+ "privacy": "private",
149
+ "default": "false"
150
+ },
142
151
  {
143
152
  "kind": "method",
144
153
  "name": "handleFormAssociation",
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
40
40
  disabled: boolean;
41
41
  private input;
42
42
  focusTarget: HTMLElement;
43
+ private _isAnimationAllowed;
43
44
  protected firstUpdated(): void;
44
45
  protected updated(): void;
45
46
  static styles: CSSResult;
package/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { LitElement as Ft, nothing as L, html as N, unsafeCSS as It } from "lit";
2
- import { property as y, query as dt } from "lit/decorators.js";
3
- import { classMap as St } from "lit/directives/class-map.js";
4
- import { ifDefined as Vt } from "lit/directives/if-defined.js";
5
- import { FormControlMixin as Tt, RtlMixin as Lt, wrapNativeEvent as Nt, validPropertyValues as Ot, safeCustomElement as Pt } from "@justeattakeaway/pie-webc-core";
2
+ import { property as E, query as dt, state as St } from "lit/decorators.js";
3
+ import { classMap as Vt } from "lit/directives/class-map.js";
4
+ import { ifDefined as Tt } from "lit/directives/if-defined.js";
5
+ import { FormControlMixin as Lt, RtlMixin as Nt, wrapNativeEvent as Ot, validPropertyValues as Pt, safeCustomElement as _t } from "@justeattakeaway/pie-webc-core";
6
6
  import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
7
7
  const O = class O extends Ft {
8
8
  willUpdate() {
9
9
  this.getAttribute("v") || this.setAttribute("v", O.v);
10
10
  }
11
11
  };
12
- O.v = "2.0.5";
12
+ O.v = "2.0.7";
13
13
  let q = O;
14
14
  (function() {
15
15
  (function(n) {
16
- const l = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), F = {
16
+ const l = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), F = {
17
17
  ariaAtomic: "aria-atomic",
18
18
  ariaAutoComplete: "aria-autocomplete",
19
19
  ariaBusy: "aria-busy",
@@ -110,14 +110,14 @@ let q = O;
110
110
  o.setAttribute("internals-valid", d.validity.valid.toString()), o.setAttribute("internals-invalid", (!d.validity.valid).toString()), o.setAttribute("aria-invalid", (!d.validity.valid).toString()), C.delete(o);
111
111
  }
112
112
  if (o.localName === "form") {
113
- const d = g.get(o), w = document.createTreeWalker(o, NodeFilter.SHOW_ELEMENT, {
113
+ const d = y.get(o), v = document.createTreeWalker(o, NodeFilter.SHOW_ELEMENT, {
114
114
  acceptNode(z) {
115
115
  return c.has(z) && z.constructor.formAssociated && !(d && d.has(z)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
116
116
  }
117
117
  });
118
- let b = w.nextNode();
118
+ let b = v.nextNode();
119
119
  for (; b; )
120
- Y(b), b = w.nextNode();
120
+ Y(b), b = v.nextNode();
121
121
  }
122
122
  o.localName === "fieldset" && ((u = I.observe) === null || u === void 0 || u.call(I, o, Q), J(o, !0));
123
123
  }), s.forEach((o) => {
@@ -163,48 +163,48 @@ let q = O;
163
163
  t[0].id || (i = `${t[0].htmlFor}_Label`, t[0].id = i), e.setAttribute("aria-labelledby", i);
164
164
  }
165
165
  }, S = (e) => {
166
- const t = Array.from(e.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i = g.get(e) || [], a = Array.from(i).filter((s) => s.isConnected).map((s) => c.get(s).validity.valid), r = [...t, ...a].includes(!1);
166
+ const t = Array.from(e.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i = y.get(e) || [], a = Array.from(i).filter((s) => s.isConnected).map((s) => c.get(s).validity.valid), r = [...t, ...a].includes(!1);
167
167
  e.toggleAttribute("internals-invalid", r), e.toggleAttribute("internals-valid", !r);
168
168
  }, ft = (e) => {
169
169
  S(V(e.target));
170
170
  }, bt = (e) => {
171
171
  S(V(e.target));
172
- }, vt = (e) => {
172
+ }, wt = (e) => {
173
173
  const t = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${e.id ? `,${i}[form='${e.id}']` : ""}`).join(",");
174
174
  e.addEventListener("click", (i) => {
175
175
  if (i.target.closest(t)) {
176
- const r = g.get(e);
176
+ const r = y.get(e);
177
177
  if (e.noValidate)
178
178
  return;
179
179
  r.size && Array.from(r).reverse().map((u) => c.get(u).reportValidity()).includes(!1) && i.preventDefault();
180
180
  }
181
181
  });
182
- }, wt = (e) => {
183
- const t = g.get(e.target);
182
+ }, vt = (e) => {
183
+ const t = y.get(e.target);
184
184
  t && t.size && t.forEach((i) => {
185
185
  i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
186
186
  });
187
187
  }, et = (e, t, i) => {
188
188
  if (t) {
189
- const a = g.get(t);
189
+ const a = y.get(t);
190
190
  if (a)
191
191
  a.add(e);
192
192
  else {
193
193
  const r = /* @__PURE__ */ new Set();
194
- r.add(e), g.set(t, r), vt(t), t.addEventListener("reset", wt), t.addEventListener("input", ft), t.addEventListener("change", bt);
194
+ r.add(e), y.set(t, r), wt(t), t.addEventListener("reset", vt), t.addEventListener("input", ft), t.addEventListener("change", bt);
195
195
  }
196
- M.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
196
+ k.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
197
197
  e.formAssociatedCallback.apply(e, [t]);
198
198
  }, 0), S(t);
199
199
  }
200
200
  }, V = (e) => {
201
201
  let t = e.parentNode;
202
202
  return t && t.tagName !== "FORM" && (t = V(t)), t;
203
- }, v = (e, t, i = DOMException) => {
203
+ }, w = (e, t, i = DOMException) => {
204
204
  if (!e.constructor.formAssociated)
205
205
  throw new i(t);
206
206
  }, it = (e, t, i) => {
207
- const a = g.get(e);
207
+ const a = y.get(e);
208
208
  return a && a.size && a.forEach((r) => {
209
209
  c.get(r)[i]() || (t = !1);
210
210
  }), t;
@@ -307,10 +307,10 @@ let q = O;
307
307
  const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
308
308
  Object.defineProperty(HTMLFormElement.prototype, "elements", {
309
309
  get(...s) {
310
- const o = r.call(this, ...s), u = Array.from(g.get(this) || []);
310
+ const o = r.call(this, ...s), u = Array.from(y.get(this) || []);
311
311
  if (u.length === 0)
312
312
  return o;
313
- const d = Array.from(o).concat(u).sort((w, b) => w.compareDocumentPosition ? w.compareDocumentPosition(b) & 2 ? 1 : -1 : 0);
313
+ const d = Array.from(o).concat(u).sort((v, b) => v.compareDocumentPosition ? v.compareDocumentPosition(b) & 2 ? 1 : -1 : 0);
314
314
  return new xt(d);
315
315
  }
316
316
  });
@@ -327,7 +327,7 @@ let q = O;
327
327
  }
328
328
  checkValidity() {
329
329
  const t = l.get(this);
330
- if (v(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
330
+ if (w(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
331
331
  return !0;
332
332
  const i = h.get(this);
333
333
  if (!i.valid) {
@@ -342,19 +342,19 @@ let q = O;
342
342
  }
343
343
  get form() {
344
344
  const t = l.get(this);
345
- v(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
345
+ w(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
346
346
  let i;
347
347
  return t.constructor.formAssociated === !0 && (i = V(t)), i;
348
348
  }
349
349
  get labels() {
350
350
  const t = l.get(this);
351
- v(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
351
+ w(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
352
352
  const i = t.getAttribute("id"), a = t.getRootNode();
353
353
  return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
354
354
  }
355
355
  reportValidity() {
356
356
  const t = l.get(this);
357
- if (v(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
357
+ if (w(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
358
358
  return !0;
359
359
  const i = this.checkValidity(), a = j.get(this);
360
360
  if (a && !t.constructor.formAssociated)
@@ -363,7 +363,7 @@ let q = O;
363
363
  }
364
364
  setFormValue(t) {
365
365
  const i = l.get(this);
366
- if (v(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), X(this), t != null && !(t instanceof FormData)) {
366
+ if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), X(this), t != null && !(t instanceof FormData)) {
367
367
  if (i.getAttribute("name")) {
368
368
  const a = Z(i, this);
369
369
  a.value = t;
@@ -378,19 +378,19 @@ let q = O;
378
378
  }
379
379
  setValidity(t, i, a) {
380
380
  const r = l.get(this);
381
- if (v(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
381
+ if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
382
382
  throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
383
383
  j.set(this, a);
384
384
  const s = h.get(this), o = {};
385
- for (const w in t)
386
- o[w] = t[w];
385
+ for (const v in t)
386
+ o[v] = t[v];
387
387
  Object.keys(o).length === 0 && yt(s);
388
388
  const u = Object.assign(Object.assign({}, s), o);
389
389
  delete u.valid;
390
390
  const { valid: d } = Et(s, u, this.form);
391
391
  if (!d && !i)
392
392
  throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
393
- E.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : C.set(r, this);
393
+ g.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : C.set(r, this);
394
394
  }
395
395
  get shadowRoot() {
396
396
  const t = l.get(this), i = U.get(t);
@@ -398,15 +398,15 @@ let q = O;
398
398
  }
399
399
  get validationMessage() {
400
400
  const t = l.get(this);
401
- return v(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), E.get(this);
401
+ return w(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), g.get(this);
402
402
  }
403
403
  get validity() {
404
404
  const t = l.get(this);
405
- return v(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), h.get(this);
405
+ return w(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), h.get(this);
406
406
  }
407
407
  get willValidate() {
408
408
  const t = l.get(this);
409
- return v(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
409
+ return w(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
410
410
  }
411
411
  }
412
412
  function Ct() {
@@ -480,22 +480,22 @@ let q = O;
480
480
  return !!customElements.polyfillWrapFlushCallback || (Ct() ? typeof window < "u" && !window.CustomStateSet && W(HTMLElement.prototype.attachInternals) : ct(!1)), n.forceCustomStateSetPolyfill = W, n.forceElementInternalsPolyfill = ct, Object.defineProperty(n, "__esModule", { value: !0 }), n;
481
481
  })({});
482
482
  })();
483
- const _t = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);vertical-align:top;font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--int-states-mixin-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--int-states-mixin-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--hover-modifier)))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-form))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-form))}}.c-switch[checked]{--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--hover-modifier)))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-brand))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-brand))}}[disabled] .c-switch{--int-states-mixin-bg-color: var(--switch-bg-color--disabled);pointer-events:none}.c-switch:has(.c-switch-input:focus-visible){box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}@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-control .c-pieIcon--check{vertical-align:top}.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(--dt-color-interactive-brand)}@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}}", $t = ["leading", "trailing"], Gt = "change", k = {
483
+ const $t = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);vertical-align:top;font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--int-states-mixin-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--int-states-mixin-bg-color)}.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--hover-modifier)))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-form))}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-form))}}.c-switch[checked]{--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--hover-modifier)))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-brand))}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-brand))}}[disabled] .c-switch{--int-states-mixin-bg-color: var(--switch-bg-color--disabled);pointer-events:none}.c-switch:has(.c-switch-input:focus-visible){box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}.c-switch-wrapper--rtl .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-control .c-pieIcon--check{vertical-align:top}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--dt-color-interactive-brand)}.c-switch-input:disabled~.c-switch-control{color:var(--switch-bg-color--disabled)}.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--disabled)}.c-switch-label{color:var(--dt-color-content-default)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.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--allow-animation .c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation .c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--allow-animation.c-switch-wrapper--rtl .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}", Rt = ["leading", "trailing"], Yt = "change", M = {
484
484
  checked: !1,
485
485
  disabled: !1,
486
486
  labelPlacement: "leading",
487
487
  required: !1,
488
488
  value: "on"
489
489
  };
490
- var Rt = Object.defineProperty, Dt = Object.getOwnPropertyDescriptor, f = (n, l, h, m) => {
491
- for (var c = m > 1 ? void 0 : m ? Dt(l, h) : l, E = n.length - 1, M; E >= 0; E--)
492
- (M = n[E]) && (c = (m ? M(l, h, c) : M(c)) || c);
493
- return m && c && Rt(l, h, c), c;
490
+ var Dt = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, f = (n, l, h, m) => {
491
+ for (var c = m > 1 ? void 0 : m ? Ht(l, h) : l, g = n.length - 1, k; g >= 0; g--)
492
+ (k = n[g]) && (c = (m ? k(l, h, c) : k(c)) || c);
493
+ return m && c && Dt(l, h, c), c;
494
494
  };
495
- const Ht = "pie-switch";
496
- let p = class extends Tt(Lt(q)) {
495
+ const Wt = "pie-switch";
496
+ let p = class extends Lt(Nt(q)) {
497
497
  constructor() {
498
- super(...arguments), this.labelPlacement = k.labelPlacement, this.checked = k.checked, this.required = k.required, this.value = k.value, this.disabled = k.disabled;
498
+ super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.required = M.required, this.value = M.value, this.disabled = M.disabled, this._isAnimationAllowed = !1;
499
499
  }
500
500
  firstUpdated() {
501
501
  this.handleFormAssociation(), this.input.addEventListener("invalid", (n) => {
@@ -518,8 +518,8 @@ let p = class extends Tt(Lt(q)) {
518
518
  handleChange(n) {
519
519
  const { checked: l } = n == null ? void 0 : n.currentTarget;
520
520
  this.checked = l;
521
- const h = Nt(n);
522
- this.dispatchEvent(h), this.handleFormAssociation();
521
+ const h = Ot(n);
522
+ this._isAnimationAllowed || (this._isAnimationAllowed = !0), this.dispatchEvent(h), this.handleFormAssociation();
523
523
  }
524
524
  /**
525
525
  * Returns a boolean value which indicates validity of the value of the component. If the value is invalid, this method also fires the invalid event on the component.
@@ -590,13 +590,15 @@ let p = class extends Tt(Lt(q)) {
590
590
  checked: l,
591
591
  disabled: h,
592
592
  isRTL: m,
593
- required: c
593
+ required: c,
594
+ _isAnimationAllowed: g
594
595
  } = this;
595
596
  return N`
596
597
  <label
597
- class="${St({
598
+ class="${Vt({
598
599
  "c-switch-wrapper": !0,
599
- "c-switch-wrapper--rtl": m
600
+ "c-switch-wrapper--rtl": m,
601
+ "c-switch-wrapper--allow-animation": g
600
602
  })}"
601
603
  ?disabled=${h}>
602
604
  ${this.renderSwitchLabel("leading")}
@@ -613,7 +615,7 @@ let p = class extends Tt(Lt(q)) {
613
615
  .checked="${l}"
614
616
  .disabled="${h}"
615
617
  @change="${this.handleChange}"
616
- aria-label="${Vt(n == null ? void 0 : n.label)}"
618
+ aria-label="${Tt(n == null ? void 0 : n.label)}"
617
619
  aria-describedby="${n != null && n.describedBy ? "switch-description" : L}">
618
620
  <div class="c-switch-control">
619
621
  ${l ? N`<icon-check></icon-check>` : L}
@@ -624,31 +626,31 @@ let p = class extends Tt(Lt(q)) {
624
626
  </label>`;
625
627
  }
626
628
  };
627
- p.styles = It(_t);
629
+ p.styles = It($t);
628
630
  f([
629
- y({ type: String })
631
+ E({ type: String })
630
632
  ], p.prototype, "label", 2);
631
633
  f([
632
- y({ type: String }),
633
- Ot(Ht, $t, k.labelPlacement)
634
+ E({ type: String }),
635
+ Pt(Wt, Rt, M.labelPlacement)
634
636
  ], p.prototype, "labelPlacement", 2);
635
637
  f([
636
- y({ type: Object })
638
+ E({ type: Object })
637
639
  ], p.prototype, "aria", 2);
638
640
  f([
639
- y({ type: Boolean, reflect: !0 })
641
+ E({ type: Boolean, reflect: !0 })
640
642
  ], p.prototype, "checked", 2);
641
643
  f([
642
- y({ type: Boolean, reflect: !0 })
644
+ E({ type: Boolean, reflect: !0 })
643
645
  ], p.prototype, "required", 2);
644
646
  f([
645
- y({ type: String })
647
+ E({ type: String })
646
648
  ], p.prototype, "value", 2);
647
649
  f([
648
- y({ type: String, reflect: !0 })
650
+ E({ type: String, reflect: !0 })
649
651
  ], p.prototype, "name", 2);
650
652
  f([
651
- y({ type: Boolean, reflect: !0 })
653
+ E({ type: Boolean, reflect: !0 })
652
654
  ], p.prototype, "disabled", 2);
653
655
  f([
654
656
  dt('input[type="checkbox"]')
@@ -656,12 +658,15 @@ f([
656
658
  f([
657
659
  dt("label")
658
660
  ], p.prototype, "focusTarget", 2);
661
+ f([
662
+ St()
663
+ ], p.prototype, "_isAnimationAllowed", 2);
659
664
  p = f([
660
- Pt("pie-switch")
665
+ _t("pie-switch")
661
666
  ], p);
662
667
  export {
663
- Gt as ON_SWITCH_CHANGED_EVENT,
668
+ Yt as ON_SWITCH_CHANGED_EVENT,
664
669
  p as PieSwitch,
665
- k as defaultProps,
666
- $t as labelPlacements
670
+ M as defaultProps,
671
+ Rt as labelPlacements
667
672
  };
package/dist/react.d.ts CHANGED
@@ -43,6 +43,7 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInpu
43
43
  disabled: boolean;
44
44
  private input;
45
45
  focusTarget: HTMLElement;
46
+ private _isAnimationAllowed;
46
47
  protected firstUpdated(): void;
47
48
  protected updated(): void;
48
49
  static styles: CSSResult;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-switch",
3
3
  "description": "PIE Design System Switch built using Web Components",
4
- "version": "2.0.5",
4
+ "version": "2.0.7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/justeattakeaway/pie",
@@ -40,13 +40,13 @@
40
40
  "devDependencies": {
41
41
  "@custom-elements-manifest/analyzer": "0.9.0",
42
42
  "@justeattakeaway/pie-components-config": "0.21.0",
43
- "@justeattakeaway/pie-css": "0.18.0",
43
+ "@justeattakeaway/pie-css": "0.19.0",
44
44
  "@justeattakeaway/pie-monorepo-utils": "0.6.0",
45
45
  "@justeattakeaway/pie-wrapper-react": "0.14.3",
46
46
  "cem-plugin-module-file-extensions": "0.0.5"
47
47
  },
48
48
  "dependencies": {
49
- "@justeattakeaway/pie-icons-webc": "1.14.0",
49
+ "@justeattakeaway/pie-icons-webc": "1.14.1",
50
50
  "@justeattakeaway/pie-webc-core": "1.0.0",
51
51
  "element-internals-polyfill": "1.3.11"
52
52
  },
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  html, unsafeCSS, nothing,
3
3
  } from 'lit';
4
4
  import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
5
- import { property, query } from 'lit/decorators.js';
5
+ import { property, query, state } from 'lit/decorators.js';
6
6
  import { classMap } from 'lit/directives/class-map.js';
7
7
  import { ifDefined } from 'lit/directives/if-defined.js';
8
8
  import 'element-internals-polyfill';
@@ -58,6 +58,9 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
58
58
  @query('label')
59
59
  public focusTarget!: HTMLElement;
60
60
 
61
+ @state()
62
+ private _isAnimationAllowed = false;
63
+
61
64
  protected firstUpdated (): void {
62
65
  this.handleFormAssociation();
63
66
  // This ensures that invalid events triggered by checkValidity() are propagated to the custom element
@@ -101,6 +104,10 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
101
104
  this.checked = checked;
102
105
  const changedEvent = wrapNativeEvent(event);
103
106
 
107
+ if (!this._isAnimationAllowed) {
108
+ this._isAnimationAllowed = true;
109
+ }
110
+
104
111
  this.dispatchEvent(changedEvent);
105
112
  this.handleFormAssociation();
106
113
  }
@@ -191,11 +198,13 @@ export class PieSwitch extends FormControlMixin(RtlMixin(PieElement)) implements
191
198
  disabled,
192
199
  isRTL,
193
200
  required,
201
+ _isAnimationAllowed,
194
202
  } = this;
195
203
 
196
204
  const classes = {
197
205
  'c-switch-wrapper': true,
198
206
  'c-switch-wrapper--rtl': isRTL,
207
+ 'c-switch-wrapper--allow-animation': _isAnimationAllowed,
199
208
  };
200
209
 
201
210
  return html`
package/src/switch.scss CHANGED
@@ -49,15 +49,11 @@
49
49
  border-radius: var(--switch-radius);
50
50
  background-color: var(--int-states-mixin-bg-color);
51
51
 
52
- @include switch-transition(background-color);
53
-
54
52
  @include p.interactive-states('--dt-color-interactive-form');
55
53
 
56
54
  &[checked] {
57
55
  --int-states-mixin-bg-color: var(--dt-color-interactive-brand);
58
56
 
59
- @include switch-transition(background-color);
60
-
61
57
  @include p.interactive-states('--dt-color-interactive-brand');
62
58
  }
63
59
 
@@ -93,7 +89,6 @@
93
89
  .c-switch-control {
94
90
  position: absolute;
95
91
  left: 2px;
96
- @include switch-transition(transform);
97
92
  width: var(--switch-control-size);
98
93
  height: var(--switch-control-size);
99
94
  border-radius: var(--switch-radius);
@@ -111,11 +106,9 @@
111
106
  }
112
107
 
113
108
  .c-switch-input:checked + & {
114
- @include switch-transition(transform);
115
109
  transform: translateX(var(--switch-translation));
116
110
 
117
111
  .c-pieIcon--check {
118
- @include switch-transition(color);
119
112
  color: var(--dt-color-interactive-brand);
120
113
  }
121
114
  }
@@ -124,7 +117,6 @@
124
117
  color: var(--switch-bg-color--disabled);
125
118
 
126
119
  .c-pieIcon--check {
127
- @include switch-transition(color);
128
120
  color: var(--switch-bg-color--disabled);
129
121
  }
130
122
  }
@@ -141,7 +133,42 @@
141
133
 
142
134
  .c-switch-wrapper--rtl {
143
135
  .c-switch-input:checked + .c-switch-control {
144
- @include switch-transition(transform);
145
136
  transform: translateX(calc(-1 * var(--switch-translation)));
146
137
  }
147
138
  }
139
+
140
+ .c-switch-wrapper--allow-animation {
141
+ /* stylelint-disable-next-line no-descending-specificity */
142
+ .c-switch {
143
+ @include switch-transition(background-color);
144
+
145
+ &[checked] {
146
+ @include switch-transition(background-color);
147
+ }
148
+ }
149
+
150
+ /* stylelint-disable-next-line no-descending-specificity */
151
+ .c-switch-control {
152
+ @include switch-transition(transform);
153
+
154
+ .c-switch-input:checked + & {
155
+ @include switch-transition(transform);
156
+
157
+ .c-pieIcon--check {
158
+ @include switch-transition(color);
159
+ }
160
+ }
161
+
162
+ .c-switch-input:disabled ~ & {
163
+ .c-pieIcon--check {
164
+ @include switch-transition(color);
165
+ }
166
+ }
167
+ }
168
+
169
+ &.c-switch-wrapper--rtl {
170
+ .c-switch-input:checked + .c-switch-control {
171
+ @include switch-transition(transform);
172
+ }
173
+ }
174
+ }