@justeattakeaway/pie-switch 0.23.0 → 0.24.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.
@@ -2,6 +2,12 @@
2
2
  "schemaVersion": "1.0.0",
3
3
  "readme": "",
4
4
  "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/defs-react.js",
8
+ "declarations": [],
9
+ "exports": []
10
+ },
5
11
  {
6
12
  "kind": "javascript-module",
7
13
  "path": "src/defs.js",
package/dist/index.d.ts CHANGED
@@ -100,7 +100,7 @@ export declare interface SwitchProps {
100
100
  /**
101
101
  * Same as the HTML required attribute - indicates whether the switch must be turned or not
102
102
  */
103
- required: boolean;
103
+ required?: boolean;
104
104
  /**
105
105
  * Same as the HTML disabled attribute - indicates whether the switch is disabled or not
106
106
  */
@@ -120,7 +120,7 @@ export declare interface SwitchProps {
120
120
  /**
121
121
  * Same as the HTML value attribute - indicates the value of the switch (for use with forms). Defaults to 'on'.
122
122
  */
123
- value: string;
123
+ value?: string;
124
124
  }
125
125
 
126
126
  export { }
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { LitElement as vt, html as C, nothing as x, unsafeCSS as yt } from "lit";
1
+ import { LitElement as vt, html as A, nothing as x, unsafeCSS as yt } from "lit";
2
2
  import { query as Et, property as k } from "lit/decorators.js";
3
- import { FormControlMixin as kt, RtlMixin as Mt, validPropertyValues as xt, defineCustomElement as Ft } from "@justeattakeaway/pie-webc-core";
3
+ import { FormControlMixin as kt, RtlMixin as Mt, wrapNativeEvent as xt, validPropertyValues as Ft, defineCustomElement as At } from "@justeattakeaway/pie-webc-core";
4
4
  import "@justeattakeaway/pie-icons-webc/IconCheck";
5
5
  const Ct = `*,*:before,*:after{box-sizing:border-box;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-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[isRTL] .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-wrapper[isRTL] .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper[isRTL] .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
6
- `, At = ["leading", "trailing"], It = "change";
6
+ `, It = ["leading", "trailing"], Pt = "change";
7
7
  (function() {
8
- const h = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), V = {
8
+ const h = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), V = {
9
9
  ariaAtomic: "aria-atomic",
10
10
  ariaAutoComplete: "aria-autocomplete",
11
11
  ariaBusy: "aria-busy",
@@ -57,7 +57,7 @@ const Ct = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
57
57
  return a;
58
58
  },
59
59
  set(n) {
60
- a = n, i.isConnected ? i.setAttribute(r, n) : A.set(i, t);
60
+ a = n, i.isConnected ? i.setAttribute(r, n) : C.set(i, t);
61
61
  }
62
62
  });
63
63
  }
@@ -90,11 +90,11 @@ const Ct = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
90
90
  const { addedNodes: e, removedNodes: a } = t, r = Array.from(e), n = Array.from(a);
91
91
  r.forEach((o) => {
92
92
  var u;
93
- if (l.has(o) && o.constructor.formAssociated && B(o), A.has(o)) {
94
- const d = A.get(o);
93
+ if (l.has(o) && o.constructor.formAssociated && B(o), C.has(o)) {
94
+ const d = C.get(o);
95
95
  Object.keys(V).filter((w) => d[w] !== null).forEach((w) => {
96
96
  o.setAttribute(V[w], d[w]);
97
- }), A.delete(o);
97
+ }), C.delete(o);
98
98
  }
99
99
  if (I.has(o)) {
100
100
  const d = I.get(o);
@@ -511,13 +511,7 @@ class f extends kt(Mt(vt)) {
511
511
  onChange(c) {
512
512
  const { checked: s } = c == null ? void 0 : c.currentTarget;
513
513
  this.checked = s;
514
- const l = new CustomEvent(
515
- It,
516
- {
517
- bubbles: !0,
518
- composed: !0
519
- }
520
- );
514
+ const l = xt(c);
521
515
  this.dispatchEvent(l), this.handleFormAssociation();
522
516
  }
523
517
  /**
@@ -567,12 +561,12 @@ class f extends kt(Mt(vt)) {
567
561
  */
568
562
  renderSwitchLabel() {
569
563
  const { label: c, labelPlacement: s } = this;
570
- return c ? C`
564
+ return c ? A`
571
565
  <label
572
566
  for="switch"
573
567
  data-test-id="switch-label-${s}">
574
568
  ${c}
575
- </label>` : C``;
569
+ </label>` : A``;
576
570
  }
577
571
  render() {
578
572
  const {
@@ -583,7 +577,7 @@ class f extends kt(Mt(vt)) {
583
577
  disabled: E,
584
578
  isRTL: b
585
579
  } = this, m = "switch-description";
586
- return C`
580
+ return A`
587
581
  <div
588
582
  class="c-switch-wrapper"
589
583
  ?isRTL=${b}
@@ -606,10 +600,10 @@ class f extends kt(Mt(vt)) {
606
600
  aria-label="${(s == null ? void 0 : s.label) || x}"
607
601
  aria-describedby="${s != null && s.describedBy ? m : x}">
608
602
  <div class="c-switch-control">
609
- ${l ? C`<icon-check></icon-check>` : x}
603
+ ${l ? A`<icon-check></icon-check>` : x}
610
604
  </div>
611
605
  </label>
612
- ${s != null && s.describedBy ? C`<div id="${m}" data-test-id="${m}" class="c-switch-description">${s == null ? void 0 : s.describedBy}</div>` : x}
606
+ ${s != null && s.describedBy ? A`<div id="${m}" data-test-id="${m}" class="c-switch-description">${s == null ? void 0 : s.describedBy}</div>` : x}
613
607
  ${c === "trailing" ? this.renderSwitchLabel() : x}
614
608
  </div>
615
609
  `;
@@ -624,7 +618,7 @@ y([
624
618
  ], f.prototype, "label", 2);
625
619
  y([
626
620
  k({ type: String }),
627
- xt(it, At, "leading")
621
+ Ft(it, It, "leading")
628
622
  ], f.prototype, "labelPlacement", 2);
629
623
  y([
630
624
  k({ type: Object })
@@ -644,9 +638,9 @@ y([
644
638
  y([
645
639
  k({ type: Boolean, reflect: !0 })
646
640
  ], f.prototype, "disabled", 2);
647
- Ft(it, f);
641
+ At(it, f);
648
642
  export {
649
- It as ON_SWITCH_CHANGED_EVENT,
643
+ Pt as ON_SWITCH_CHANGED_EVENT,
650
644
  f as PieSwitch,
651
- At as labelPlacements
645
+ It as labelPlacements
652
646
  };
package/dist/react.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import type { CSSResult } from 'lit';
2
- import type { EventName } from '@lit/react';
3
2
  import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
4
3
  import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
5
4
  import type { LitElement } from 'lit';
6
5
  import type { PropertyValues } from 'lit';
7
- import type { ReactWebComponent } from '@lit/react';
6
+ import * as React_2 from 'react';
8
7
  import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
9
8
  import type { TemplateResult } from 'lit';
10
9
 
@@ -24,10 +23,7 @@ export declare const labelPlacements: readonly ["leading", "trailing"];
24
23
  */
25
24
  export declare const ON_SWITCH_CHANGED_EVENT = "change";
26
25
 
27
- export declare const PieSwitch: ReactWebComponent<PieSwitch_2, {
28
- onInvalid: EventName<Event>;
29
- onChange: EventName<CustomEvent<any>>;
30
- }>;
26
+ export declare const PieSwitch: React_2.ForwardRefExoticComponent<SwitchProps & React_2.RefAttributes<PieSwitch_2> & PieSwitchEvents & ReactBaseType>;
31
27
 
32
28
  /**
33
29
  * @tagname pie-switch
@@ -95,6 +91,13 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps {
95
91
 
96
92
  declare const PieSwitch_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
97
93
 
94
+ declare type PieSwitchEvents = {
95
+ onInvalid?: (event: Event<any>) => void;
96
+ onChange?: (event: CustomEvent<any>) => void;
97
+ };
98
+
99
+ declare type ReactBaseType = React_2.InputHTMLAttributes<HTMLInputElement>;
100
+
98
101
  export declare interface SwitchProps {
99
102
  /**
100
103
  * The ARIA labels used for the switch.
@@ -107,7 +110,7 @@ export declare interface SwitchProps {
107
110
  /**
108
111
  * Same as the HTML required attribute - indicates whether the switch must be turned or not
109
112
  */
110
- required: boolean;
113
+ required?: boolean;
111
114
  /**
112
115
  * Same as the HTML disabled attribute - indicates whether the switch is disabled or not
113
116
  */
@@ -127,7 +130,7 @@ export declare interface SwitchProps {
127
130
  /**
128
131
  * Same as the HTML value attribute - indicates the value of the switch (for use with forms). Defaults to 'on'.
129
132
  */
130
- value: string;
133
+ value?: string;
131
134
  }
132
135
 
133
136
  export { }
package/dist/react.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import * as e from "react";
2
2
  import { createComponent as t } from "@lit/react";
3
3
  import { PieSwitch as i } from "./index.js";
4
- import { ON_SWITCH_CHANGED_EVENT as h, labelPlacements as w } from "./index.js";
4
+ import { ON_SWITCH_CHANGED_EVENT as w, labelPlacements as P } from "./index.js";
5
5
  import "lit";
6
6
  import "lit/decorators.js";
7
7
  import "@justeattakeaway/pie-webc-core";
8
8
  import "@justeattakeaway/pie-icons-webc/IconCheck";
9
- const c = t({
9
+ const o = t({
10
10
  displayName: "PieSwitch",
11
11
  elementClass: i,
12
12
  react: e,
@@ -16,9 +16,9 @@ const c = t({
16
16
  onChange: "change"
17
17
  // when the switch checked state is changed.
18
18
  }
19
- });
19
+ }), s = o;
20
20
  export {
21
- h as ON_SWITCH_CHANGED_EVENT,
22
- c as PieSwitch,
23
- w as labelPlacements
21
+ w as ON_SWITCH_CHANGED_EVENT,
22
+ s as PieSwitch,
23
+ P as labelPlacements
24
24
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-switch",
3
3
  "description": "PIE Design System Switch built using Web Components",
4
- "version": "0.23.0",
4
+ "version": "0.24.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -32,13 +32,13 @@
32
32
  "license": "Apache-2.0",
33
33
  "devDependencies": {
34
34
  "@custom-elements-manifest/analyzer": "0.9.0",
35
- "@justeattakeaway/pie-components-config": "0.8.0",
35
+ "@justeattakeaway/pie-components-config": "0.9.0",
36
36
  "cem-plugin-module-file-extensions": "0.0.5"
37
37
  },
38
38
  "dependencies": {
39
- "@justeattakeaway/pie-icons-webc": "0.17.0",
40
- "@justeattakeaway/pie-webc-core": "0.16.0",
41
- "@justeattakeaway/pie-wrapper-react": "0.12.0",
39
+ "@justeattakeaway/pie-icons-webc": "0.17.1",
40
+ "@justeattakeaway/pie-webc-core": "0.17.0",
41
+ "@justeattakeaway/pie-wrapper-react": "0.13.0",
42
42
  "element-internals-polyfill": "1.3.9"
43
43
  },
44
44
  "volta": {
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+
3
+ export type ReactBaseType = React.InputHTMLAttributes<HTMLInputElement>
package/src/defs.ts CHANGED
@@ -19,7 +19,7 @@ export interface SwitchProps {
19
19
  /**
20
20
  * Same as the HTML required attribute - indicates whether the switch must be turned or not
21
21
  */
22
- required: boolean;
22
+ required?: boolean;
23
23
  /**
24
24
  * Same as the HTML disabled attribute - indicates whether the switch is disabled or not
25
25
  */
@@ -39,7 +39,7 @@ export interface SwitchProps {
39
39
  /**
40
40
  * Same as the HTML value attribute - indicates the value of the switch (for use with forms). Defaults to 'on'.
41
41
  */
42
- value: string;
42
+ value?: string;
43
43
  }
44
44
 
45
45
  /**
package/src/index.ts CHANGED
@@ -3,11 +3,11 @@ import {
3
3
  } from 'lit';
4
4
  import { property, query } from 'lit/decorators.js';
5
5
  import {
6
- RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin,
6
+ RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin, wrapNativeEvent,
7
7
  } from '@justeattakeaway/pie-webc-core';
8
8
  import styles from './switch.scss?inline';
9
9
  import {
10
- SwitchProps, ON_SWITCH_CHANGED_EVENT, AriaProps, labelPlacements,
10
+ SwitchProps, AriaProps, labelPlacements,
11
11
  } from './defs';
12
12
  import 'element-internals-polyfill';
13
13
  import '@justeattakeaway/pie-icons-webc/IconCheck';
@@ -94,13 +94,7 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
94
94
  onChange (event: Event) {
95
95
  const { checked } = event?.currentTarget as HTMLInputElement;
96
96
  this.checked = checked;
97
- const changedEvent = new CustomEvent(
98
- ON_SWITCH_CHANGED_EVENT,
99
- {
100
- bubbles: true,
101
- composed: true,
102
- },
103
- );
97
+ const changedEvent = wrapNativeEvent(event);
104
98
 
105
99
  this.dispatchEvent(changedEvent);
106
100
  this.handleFormAssociation();
package/src/react.ts CHANGED
@@ -1,13 +1,13 @@
1
-
2
1
  import * as React from 'react';
3
2
  import { createComponent, EventName } from '@lit/react';
4
- import { PieSwitch as PieSwitchReact } from './index';
3
+ import { PieSwitch as PieSwitchLit } from './index';
4
+ import { SwitchProps } from './defs';
5
5
 
6
6
  export * from './defs';
7
7
 
8
- export const PieSwitch = createComponent({
8
+ const PieSwitchReact = createComponent({
9
9
  displayName: 'PieSwitch',
10
- elementClass: PieSwitchReact,
10
+ elementClass: PieSwitchLit,
11
11
  react: React,
12
12
  tagName: 'pie-switch',
13
13
  events: {
@@ -15,3 +15,12 @@ export const PieSwitch = createComponent({
15
15
  onChange: 'change' as EventName<CustomEvent>, // when the switch checked state is changed.
16
16
  },
17
17
  });
18
+
19
+ type ReactBaseType = React.InputHTMLAttributes<HTMLInputElement>
20
+
21
+ type PieSwitchEvents = {
22
+ onInvalid?: (event: Event<any>) => void;
23
+ onChange?: (event: CustomEvent<any>) => void;
24
+ };
25
+
26
+ export const PieSwitch = PieSwitchReact as React.ForwardRefExoticComponent<React.PropsWithoutRef<SwitchProps> & React.RefAttributes<PieSwitchLit> & PieSwitchEvents & ReactBaseType>;