@justeattakeaway/pie-switch 0.18.0 → 0.18.2
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 +61 -95
- package/dist/react.js +6 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,65 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { property as
|
|
1
|
+
import { LitElement as w, html as n, nothing as s, unsafeCSS as b } from "lit";
|
|
2
|
+
import { property as d } from "lit/decorators.js";
|
|
3
|
+
import { RtlMixin as v, validPropertyValues as u, defineCustomElement as f } from "@justeattakeaway/pie-webc-core";
|
|
3
4
|
import "@justeattakeaway/pie-icons-webc/IconCheck";
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* from the document's root element. This inference is not available during SSR.
|
|
11
|
-
* In all other cases, it will return `false`, indicating a left-to-right (LTR) text direction.
|
|
12
|
-
*
|
|
13
|
-
* @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
|
|
14
|
-
*/
|
|
15
|
-
get isRTL() {
|
|
16
|
-
return this.dir ? this.dir === "rtl" : !b && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return c;
|
|
20
|
-
}, g = (i, c, e) => function(t, s) {
|
|
21
|
-
const o = `#${s}`;
|
|
22
|
-
Object.defineProperty(t, s, {
|
|
23
|
-
get() {
|
|
24
|
-
return this[o];
|
|
25
|
-
},
|
|
26
|
-
set(p) {
|
|
27
|
-
c.includes(p) ? this[o] = p : (console.error(
|
|
28
|
-
`<${i}> Invalid value "${p}" provided for property "${s}".`,
|
|
29
|
-
`Must be one of: ${c.join(" | ")}.`,
|
|
30
|
-
`Falling back to default value: "${e}"`
|
|
31
|
-
), this[o] = e);
|
|
32
|
-
},
|
|
33
|
-
configurable: !0
|
|
34
|
-
});
|
|
35
|
-
};
|
|
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
|
-
}
|
|
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;
|
|
5
|
+
const g = `*,*: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}}
|
|
6
|
+
`, m = ["leading", "trailing"], k = "pie-switch-changed";
|
|
7
|
+
var y = Object.defineProperty, x = Object.getOwnPropertyDescriptor, l = (h, e, c, t) => {
|
|
8
|
+
for (var i = t > 1 ? void 0 : t ? x(e, c) : e, a = h.length - 1, r; a >= 0; a--)
|
|
9
|
+
(r = h[a]) && (i = (t ? r(e, c, i) : r(i)) || i);
|
|
10
|
+
return t && i && y(e, c, i), i;
|
|
45
11
|
};
|
|
46
|
-
const
|
|
47
|
-
class
|
|
12
|
+
const p = "pie-switch";
|
|
13
|
+
class o extends v(w) {
|
|
48
14
|
constructor() {
|
|
49
15
|
super(...arguments), this.labelPlacement = "leading", this.isChecked = !1, this.isDisabled = !1;
|
|
50
16
|
}
|
|
51
|
-
onChange(
|
|
52
|
-
const { checked:
|
|
53
|
-
this.isChecked =
|
|
54
|
-
const
|
|
55
|
-
|
|
17
|
+
onChange(e) {
|
|
18
|
+
const { checked: c } = e == null ? void 0 : e.currentTarget;
|
|
19
|
+
this.isChecked = c;
|
|
20
|
+
const t = new CustomEvent(
|
|
21
|
+
k,
|
|
56
22
|
{
|
|
57
23
|
bubbles: !0,
|
|
58
24
|
composed: !0,
|
|
59
25
|
detail: this.isChecked
|
|
60
26
|
}
|
|
61
27
|
);
|
|
62
|
-
this.dispatchEvent(
|
|
28
|
+
this.dispatchEvent(t);
|
|
63
29
|
}
|
|
64
30
|
/**
|
|
65
31
|
* Renders the label for a switch if provided.
|
|
@@ -68,73 +34,73 @@ class n extends f(v) {
|
|
|
68
34
|
* @private
|
|
69
35
|
*/
|
|
70
36
|
renderSwitchLabel() {
|
|
71
|
-
const { label:
|
|
72
|
-
return
|
|
37
|
+
const { label: e, labelPlacement: c } = this;
|
|
38
|
+
return e ? n`
|
|
73
39
|
<label
|
|
74
40
|
for="switch"
|
|
75
|
-
data-test-id="switch-label-${
|
|
76
|
-
${
|
|
77
|
-
</label>` :
|
|
41
|
+
data-test-id="switch-label-${c}">
|
|
42
|
+
${e}
|
|
43
|
+
</label>` : n``;
|
|
78
44
|
}
|
|
79
45
|
render() {
|
|
80
46
|
const {
|
|
81
|
-
labelPlacement:
|
|
82
|
-
aria:
|
|
83
|
-
isChecked:
|
|
84
|
-
isDisabled:
|
|
85
|
-
isRTL:
|
|
86
|
-
} = this,
|
|
87
|
-
return
|
|
47
|
+
labelPlacement: e,
|
|
48
|
+
aria: c,
|
|
49
|
+
isChecked: t,
|
|
50
|
+
isDisabled: i,
|
|
51
|
+
isRTL: a
|
|
52
|
+
} = this, r = "switch-description";
|
|
53
|
+
return n`
|
|
88
54
|
<div
|
|
89
55
|
class="c-switch-wrapper"
|
|
90
|
-
?isRTL=${
|
|
91
|
-
?isDisabled=${
|
|
92
|
-
${
|
|
56
|
+
?isRTL=${a}
|
|
57
|
+
?isDisabled=${i}>
|
|
58
|
+
${e === "leading" ? this.renderSwitchLabel() : s}
|
|
93
59
|
<label
|
|
94
60
|
data-test-id="switch-component"
|
|
95
61
|
class="c-switch"
|
|
96
|
-
?isChecked=${
|
|
62
|
+
?isChecked=${t}>
|
|
97
63
|
<input
|
|
98
64
|
id="switch"
|
|
99
65
|
data-test-id="switch-input"
|
|
100
66
|
role="switch"
|
|
101
67
|
type="checkbox"
|
|
102
68
|
class="c-switch-input"
|
|
103
|
-
.checked="${
|
|
104
|
-
.disabled="${
|
|
69
|
+
.checked="${t}"
|
|
70
|
+
.disabled="${i}"
|
|
105
71
|
@change="${this.onChange}"
|
|
106
|
-
aria-label="${(
|
|
107
|
-
aria-describedby="${
|
|
72
|
+
aria-label="${(c == null ? void 0 : c.label) || s}"
|
|
73
|
+
aria-describedby="${c != null && c.describedBy ? r : s}">
|
|
108
74
|
<div class="c-switch-control">
|
|
109
|
-
${
|
|
75
|
+
${t ? n`<icon-check></icon-check>` : s}
|
|
110
76
|
</div>
|
|
111
77
|
</label>
|
|
112
|
-
${
|
|
113
|
-
${
|
|
78
|
+
${c != null && c.describedBy ? n`<div id="${r}" data-test-id="${r}" class="c-switch-description">${c == null ? void 0 : c.describedBy}</div>` : s}
|
|
79
|
+
${e === "trailing" ? this.renderSwitchLabel() : s}
|
|
114
80
|
</div>
|
|
115
81
|
`;
|
|
116
82
|
}
|
|
117
83
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
],
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
],
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
],
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
],
|
|
135
|
-
|
|
84
|
+
o.styles = b(g);
|
|
85
|
+
l([
|
|
86
|
+
d({ type: String })
|
|
87
|
+
], o.prototype, "label", 2);
|
|
88
|
+
l([
|
|
89
|
+
d({ type: String }),
|
|
90
|
+
u(p, m, "leading")
|
|
91
|
+
], o.prototype, "labelPlacement", 2);
|
|
92
|
+
l([
|
|
93
|
+
d({ type: Object })
|
|
94
|
+
], o.prototype, "aria", 2);
|
|
95
|
+
l([
|
|
96
|
+
d({ type: Boolean, reflect: !0 })
|
|
97
|
+
], o.prototype, "isChecked", 2);
|
|
98
|
+
l([
|
|
99
|
+
d({ type: Boolean, reflect: !0 })
|
|
100
|
+
], o.prototype, "isDisabled", 2);
|
|
101
|
+
f(p, o);
|
|
136
102
|
export {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
103
|
+
k as ON_SWITCH_CHANGED_EVENT,
|
|
104
|
+
o as PieSwitch,
|
|
105
|
+
m as labelPlacements
|
|
140
106
|
};
|
package/dist/react.js
CHANGED
|
@@ -1,11 +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
|
|
4
|
+
import { ON_SWITCH_CHANGED_EVENT as w, labelPlacements as l } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
6
|
import "lit/decorators.js";
|
|
7
|
+
import "@justeattakeaway/pie-webc-core";
|
|
7
8
|
import "@justeattakeaway/pie-icons-webc/IconCheck";
|
|
8
|
-
const
|
|
9
|
+
const s = t({
|
|
9
10
|
displayName: "PieSwitch",
|
|
10
11
|
elementClass: i,
|
|
11
12
|
react: e,
|
|
@@ -16,7 +17,7 @@ const p = t({
|
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
w as ON_SWITCH_CHANGED_EVENT,
|
|
21
|
+
s as PieSwitch,
|
|
22
|
+
l as labelPlacements
|
|
22
23
|
};
|
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.18.
|
|
4
|
+
"version": "0.18.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"author": "Just Eat Takeaway.com - Design System Team",
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@justeattakeaway/pie-components-config": "0.6.
|
|
31
|
+
"@justeattakeaway/pie-components-config": "0.6.1"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@justeattakeaway/pie-icons-webc": "0.
|
|
35
|
-
"@justeattakeaway/pie-webc-core": "0.
|
|
34
|
+
"@justeattakeaway/pie-icons-webc": "0.13.0",
|
|
35
|
+
"@justeattakeaway/pie-webc-core": "0.13.0"
|
|
36
36
|
},
|
|
37
37
|
"volta": {
|
|
38
38
|
"extends": "../../../package.json"
|