@justeattakeaway/pie-switch 0.17.2 → 0.18.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/README.md +1 -1
- package/dist/index.js +36 -36
- package/dist/react.d.ts +2 -2
- package/dist/react.js +10 -64
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ import '@justeattakeaway/pie-switch';
|
|
|
56
56
|
```js
|
|
57
57
|
// React
|
|
58
58
|
// For React, you will need to import our React-specific component build
|
|
59
|
-
// which wraps the web component using
|
|
59
|
+
// which wraps the web component using @lit/react
|
|
60
60
|
import { PieSwitch } from '@justeattakeaway/pie-switch/dist/react';
|
|
61
61
|
```
|
|
62
62
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isServer as
|
|
1
|
+
import { isServer as b, unsafeCSS as u, html as d, nothing as a, LitElement as v } from "lit";
|
|
2
2
|
import { property as l } from "lit/decorators.js";
|
|
3
3
|
import "@justeattakeaway/pie-icons-webc/IconCheck";
|
|
4
|
-
const
|
|
5
|
-
class c extends
|
|
4
|
+
const f = (i) => {
|
|
5
|
+
class c extends i {
|
|
6
6
|
/**
|
|
7
7
|
* A getter to determine whether the text direction is right-to-left (RTL).
|
|
8
8
|
* If the `dir` property is present on the component, it will be used to determine the text direction.
|
|
@@ -13,53 +13,53 @@ const g = (r) => {
|
|
|
13
13
|
* @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
|
|
14
14
|
*/
|
|
15
15
|
get isRTL() {
|
|
16
|
-
return this.dir ? this.dir === "rtl" : !
|
|
16
|
+
return this.dir ? this.dir === "rtl" : !b && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
return c;
|
|
20
|
-
},
|
|
21
|
-
const
|
|
20
|
+
}, g = (i, c, e) => function(t, s) {
|
|
21
|
+
const o = `#${s}`;
|
|
22
22
|
Object.defineProperty(t, s, {
|
|
23
23
|
get() {
|
|
24
|
-
return this[
|
|
24
|
+
return this[o];
|
|
25
25
|
},
|
|
26
26
|
set(p) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`<${r}> Invalid value "${p}" provided for property "${s}".`,
|
|
27
|
+
c.includes(p) ? this[o] = p : (console.error(
|
|
28
|
+
`<${i}> Invalid value "${p}" provided for property "${s}".`,
|
|
30
29
|
`Must be one of: ${c.join(" | ")}.`,
|
|
31
30
|
`Falling back to default value: "${e}"`
|
|
32
|
-
), this[
|
|
33
|
-
}
|
|
31
|
+
), this[o] = e);
|
|
32
|
+
},
|
|
33
|
+
configurable: !0
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
|
-
function
|
|
37
|
-
customElements.get(
|
|
36
|
+
function m(i, c) {
|
|
37
|
+
customElements.get(i) ? console.warn(`PIE Web Component: "${i}" has already been defined. Please ensure the component is only being defined once in your application.`) : customElements.define(i, c);
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
`,
|
|
41
|
-
var
|
|
42
|
-
for (var t =
|
|
43
|
-
(
|
|
44
|
-
return
|
|
39
|
+
const k = `*,*: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[isDisabled]{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[isChecked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[isChecked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[isChecked]: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[isChecked]:focus,.c-switch[isChecked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[isChecked]: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)))}[isDisabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{appearance:none;margin: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}}
|
|
40
|
+
`, y = ["leading", "trailing"], $ = "pie-switch-changed";
|
|
41
|
+
var x = Object.defineProperty, C = Object.getOwnPropertyDescriptor, h = (i, c, e, r) => {
|
|
42
|
+
for (var t = r > 1 ? void 0 : r ? C(c, e) : c, s = i.length - 1, o; s >= 0; s--)
|
|
43
|
+
(o = i[s]) && (t = (r ? o(c, e, t) : o(t)) || t);
|
|
44
|
+
return r && t && x(c, e, t), t;
|
|
45
45
|
};
|
|
46
46
|
const w = "pie-switch";
|
|
47
|
-
class n extends
|
|
47
|
+
class n extends f(v) {
|
|
48
48
|
constructor() {
|
|
49
49
|
super(...arguments), this.labelPlacement = "leading", this.isChecked = !1, this.isDisabled = !1;
|
|
50
50
|
}
|
|
51
51
|
onChange(c) {
|
|
52
52
|
const { checked: e } = c == null ? void 0 : c.currentTarget;
|
|
53
53
|
this.isChecked = e;
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const r = new CustomEvent(
|
|
55
|
+
$,
|
|
56
56
|
{
|
|
57
57
|
bubbles: !0,
|
|
58
58
|
composed: !0,
|
|
59
59
|
detail: this.isChecked
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
|
-
this.dispatchEvent(
|
|
62
|
+
this.dispatchEvent(r);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Renders the label for a switch if provided.
|
|
@@ -80,10 +80,10 @@ class n extends g(f) {
|
|
|
80
80
|
const {
|
|
81
81
|
labelPlacement: c,
|
|
82
82
|
aria: e,
|
|
83
|
-
isChecked:
|
|
83
|
+
isChecked: r,
|
|
84
84
|
isDisabled: t,
|
|
85
85
|
isRTL: s
|
|
86
|
-
} = this,
|
|
86
|
+
} = this, o = "switch-description";
|
|
87
87
|
return d`
|
|
88
88
|
<div
|
|
89
89
|
class="c-switch-wrapper"
|
|
@@ -93,35 +93,35 @@ class n extends g(f) {
|
|
|
93
93
|
<label
|
|
94
94
|
data-test-id="switch-component"
|
|
95
95
|
class="c-switch"
|
|
96
|
-
?isChecked=${
|
|
96
|
+
?isChecked=${r}>
|
|
97
97
|
<input
|
|
98
98
|
id="switch"
|
|
99
99
|
data-test-id="switch-input"
|
|
100
100
|
role="switch"
|
|
101
101
|
type="checkbox"
|
|
102
102
|
class="c-switch-input"
|
|
103
|
-
.checked="${
|
|
103
|
+
.checked="${r}"
|
|
104
104
|
.disabled="${t}"
|
|
105
105
|
@change="${this.onChange}"
|
|
106
106
|
aria-label="${(e == null ? void 0 : e.label) || a}"
|
|
107
|
-
aria-describedby="${e != null && e.describedBy ?
|
|
107
|
+
aria-describedby="${e != null && e.describedBy ? o : a}">
|
|
108
108
|
<div class="c-switch-control">
|
|
109
|
-
${
|
|
109
|
+
${r ? d`<icon-check></icon-check>` : a}
|
|
110
110
|
</div>
|
|
111
111
|
</label>
|
|
112
|
-
${e != null && e.describedBy ? d`<div id="${
|
|
112
|
+
${e != null && e.describedBy ? d`<div id="${o}" data-test-id="${o}" class="c-switch-description">${e == null ? void 0 : e.describedBy}</div>` : a}
|
|
113
113
|
${c === "trailing" ? this.renderSwitchLabel() : a}
|
|
114
114
|
</div>
|
|
115
115
|
`;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
n.styles =
|
|
118
|
+
n.styles = u(k);
|
|
119
119
|
h([
|
|
120
120
|
l({ type: String })
|
|
121
121
|
], n.prototype, "label", 2);
|
|
122
122
|
h([
|
|
123
123
|
l({ type: String }),
|
|
124
|
-
|
|
124
|
+
g(w, y, "leading")
|
|
125
125
|
], n.prototype, "labelPlacement", 2);
|
|
126
126
|
h([
|
|
127
127
|
l({ type: Object })
|
|
@@ -132,9 +132,9 @@ h([
|
|
|
132
132
|
h([
|
|
133
133
|
l({ type: Boolean, reflect: !0 })
|
|
134
134
|
], n.prototype, "isDisabled", 2);
|
|
135
|
-
|
|
135
|
+
m(w, n);
|
|
136
136
|
export {
|
|
137
|
-
|
|
137
|
+
$ as ON_SWITCH_CHANGED_EVENT,
|
|
138
138
|
n as PieSwitch,
|
|
139
|
-
|
|
139
|
+
y as labelPlacements
|
|
140
140
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSResult } from 'lit';
|
|
2
|
-
import type { EventName } from '@lit
|
|
2
|
+
import type { EventName } from '@lit/react';
|
|
3
3
|
import type { LitElement } from 'lit';
|
|
4
|
-
import type { ReactWebComponent } from '@lit
|
|
4
|
+
import type { ReactWebComponent } from '@lit/react';
|
|
5
5
|
import type { TemplateResult } from 'lit';
|
|
6
6
|
|
|
7
7
|
export declare type AriaProps = {
|
package/dist/react.js
CHANGED
|
@@ -1,68 +1,14 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import * as e from "react";
|
|
2
|
+
import { createComponent as t } from "@lit/react";
|
|
3
|
+
import { PieSwitch as i } from "./index.js";
|
|
4
|
+
import { ON_SWITCH_CHANGED_EVENT as n, labelPlacements as w } from "./index.js";
|
|
4
5
|
import "lit";
|
|
5
6
|
import "lit/decorators.js";
|
|
6
7
|
import "@justeattakeaway/pie-icons-webc/IconCheck";
|
|
7
|
-
|
|
8
|
-
* @license
|
|
9
|
-
* Copyright 2018 Google LLC
|
|
10
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
-
*/
|
|
12
|
-
const S = /* @__PURE__ */ new Set(["children", "localName", "ref", "style", "className"]), y = /* @__PURE__ */ new WeakMap(), C = (t, i, h, d, m) => {
|
|
13
|
-
const o = m == null ? void 0 : m[i];
|
|
14
|
-
o === void 0 || h === d ? h == null && i in HTMLElement.prototype ? t.removeAttribute(i) : t[i] = h : ((a, n, p) => {
|
|
15
|
-
let r = y.get(a);
|
|
16
|
-
r === void 0 && y.set(a, r = /* @__PURE__ */ new Map());
|
|
17
|
-
let l = r.get(n);
|
|
18
|
-
p !== void 0 ? l === void 0 ? (r.set(n, l = { handleEvent: p }), a.addEventListener(n, l)) : l.handleEvent = p : l !== void 0 && (r.delete(n), a.removeEventListener(n, l));
|
|
19
|
-
})(t, o, h);
|
|
20
|
-
}, P = (t, i) => {
|
|
21
|
-
typeof t == "function" ? t(i) : t.current = i;
|
|
22
|
-
};
|
|
23
|
-
function b(t = window.React, i, h, d, m) {
|
|
24
|
-
let o, a, n;
|
|
25
|
-
if (i === void 0) {
|
|
26
|
-
const c = t;
|
|
27
|
-
({ tagName: a, elementClass: n, events: d, displayName: m } = c), o = c.react;
|
|
28
|
-
} else
|
|
29
|
-
o = t, n = h, a = i;
|
|
30
|
-
const p = o.Component, r = o.createElement, l = new Set(Object.keys(d ?? {}));
|
|
31
|
-
class f extends p {
|
|
32
|
-
constructor() {
|
|
33
|
-
super(...arguments), this.o = null;
|
|
34
|
-
}
|
|
35
|
-
t(e) {
|
|
36
|
-
if (this.o !== null)
|
|
37
|
-
for (const u in this.i)
|
|
38
|
-
C(this.o, u, this.props[u], e ? e[u] : void 0, d);
|
|
39
|
-
}
|
|
40
|
-
componentDidMount() {
|
|
41
|
-
var e;
|
|
42
|
-
this.t(), (e = this.o) === null || e === void 0 || e.removeAttribute("defer-hydration");
|
|
43
|
-
}
|
|
44
|
-
componentDidUpdate(e) {
|
|
45
|
-
this.t(e);
|
|
46
|
-
}
|
|
47
|
-
render() {
|
|
48
|
-
const { _$Gl: e, ...u } = this.props;
|
|
49
|
-
this.h !== e && (this.u = (s) => {
|
|
50
|
-
e !== null && P(e, s), this.o = s, this.h = e;
|
|
51
|
-
}), this.i = {};
|
|
52
|
-
const v = { ref: this.u };
|
|
53
|
-
for (const [s, w] of Object.entries(u))
|
|
54
|
-
S.has(s) ? v[s === "className" ? "class" : s] = w : l.has(s) || s in n.prototype ? this.i[s] = w : v[s] = w;
|
|
55
|
-
return v.suppressHydrationWarning = !0, r(a, v);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
f.displayName = m ?? n.name;
|
|
59
|
-
const N = o.forwardRef((c, e) => r(f, { ...c, _$Gl: e }, c == null ? void 0 : c.children));
|
|
60
|
-
return N.displayName = f.displayName, N;
|
|
61
|
-
}
|
|
62
|
-
const A = b({
|
|
8
|
+
const p = t({
|
|
63
9
|
displayName: "PieSwitch",
|
|
64
|
-
elementClass:
|
|
65
|
-
react:
|
|
10
|
+
elementClass: i,
|
|
11
|
+
react: e,
|
|
66
12
|
tagName: "pie-switch",
|
|
67
13
|
events: {
|
|
68
14
|
onPieSwitchChanged: "pie-switch-changed"
|
|
@@ -70,7 +16,7 @@ const A = b({
|
|
|
70
16
|
}
|
|
71
17
|
});
|
|
72
18
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
19
|
+
n as ON_SWITCH_CHANGED_EVENT,
|
|
20
|
+
p as PieSwitch,
|
|
21
|
+
w as labelPlacements
|
|
76
22
|
};
|
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.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"@justeattakeaway/pie-components-config": "0.6.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@justeattakeaway/pie-icons-webc": "0.11.1"
|
|
34
|
+
"@justeattakeaway/pie-icons-webc": "0.11.1",
|
|
35
|
+
"@justeattakeaway/pie-webc-core": "0.12.0"
|
|
35
36
|
},
|
|
36
37
|
"volta": {
|
|
37
38
|
"extends": "../../../package.json"
|