@justeattakeaway/pie-switch 0.18.4 → 0.19.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 +12 -6
- package/dist/index.d.ts +12 -2
- package/dist/index.js +14 -3
- package/dist/react.d.ts +13 -3
- package/dist/react.js +6 -6
- package/package.json +1 -1
- package/src/defs.ts +1 -1
- package/src/index.ts +14 -2
package/README.md
CHANGED
|
@@ -81,19 +81,25 @@ import { PieSwitch } from '@justeattakeaway/pie-switch/dist/react';
|
|
|
81
81
|
|
|
82
82
|
In your markup or JSX, you can then use these to set the properties for the `pie-switch` component:
|
|
83
83
|
|
|
84
|
+
### HTML
|
|
84
85
|
```html
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
<pie-switch isChecked isDisabled aria='{ "label": "Helpful label" }'></pie-switch>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### JSX
|
|
90
|
+
```js
|
|
91
|
+
const aria = {
|
|
92
|
+
label: 'Helpful label',
|
|
93
|
+
};
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
<PieSwitch></PieSwitch>
|
|
95
|
+
<PieSwitch isChecked isDisabled aria={aria}></PieSwitch>
|
|
90
96
|
```
|
|
91
97
|
|
|
92
98
|
## Events
|
|
93
99
|
|
|
94
100
|
| Event | Payload | Description |
|
|
95
|
-
|
|
|
96
|
-
| `
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| `change` | `event.target.checked` | Custom event to indicate a switch change. This event aims to mimic the native `change` event so that consumers can use the component as natively as possible. |
|
|
97
103
|
|
|
98
104
|
## Contributing
|
|
99
105
|
|
package/dist/index.d.ts
CHANGED
|
@@ -16,19 +16,29 @@ export declare const labelPlacements: readonly ["leading", "trailing"];
|
|
|
16
16
|
*
|
|
17
17
|
* @constant
|
|
18
18
|
*/
|
|
19
|
-
export declare const ON_SWITCH_CHANGED_EVENT = "
|
|
19
|
+
export declare const ON_SWITCH_CHANGED_EVENT = "change";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @tagname pie-switch
|
|
23
|
-
* @event {CustomEvent}
|
|
23
|
+
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
24
24
|
*/
|
|
25
25
|
export declare class PieSwitch extends PieSwitch_base implements SwitchProps {
|
|
26
26
|
label?: string;
|
|
27
27
|
labelPlacement: SwitchProps['labelPlacement'];
|
|
28
28
|
aria: AriaProps;
|
|
29
29
|
isChecked: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* This getter wraps the `isChecked` property to mimic native behaviour for the `change` event.
|
|
32
|
+
* You can access this with `event.target.checked` when listening to the `change` event.
|
|
33
|
+
* @returns The value of the property `isChecked`.
|
|
34
|
+
*/
|
|
35
|
+
get checked(): boolean;
|
|
30
36
|
isDisabled: boolean;
|
|
31
37
|
static styles: CSSResult;
|
|
38
|
+
/**
|
|
39
|
+
* The onChange function updates the checkbox state and emits an event for consumers.
|
|
40
|
+
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
41
|
+
*/
|
|
32
42
|
onChange(event: Event): void;
|
|
33
43
|
/**
|
|
34
44
|
* Renders the label for a switch if provided.
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { property as d } from "lit/decorators.js";
|
|
|
3
3
|
import { RtlMixin as v, validPropertyValues as u, defineCustomElement as f } from "@justeattakeaway/pie-webc-core";
|
|
4
4
|
import "@justeattakeaway/pie-icons-webc/IconCheck";
|
|
5
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 = "
|
|
6
|
+
`, m = ["leading", "trailing"], k = "change";
|
|
7
7
|
var y = Object.defineProperty, x = Object.getOwnPropertyDescriptor, l = (h, e, c, t) => {
|
|
8
8
|
for (var i = t > 1 ? void 0 : t ? x(e, c) : e, a = h.length - 1, r; a >= 0; a--)
|
|
9
9
|
(r = h[a]) && (i = (t ? r(e, c, i) : r(i)) || i);
|
|
@@ -14,6 +14,18 @@ class o extends v(w) {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments), this.labelPlacement = "leading", this.isChecked = !1, this.isDisabled = !1;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* This getter wraps the `isChecked` property to mimic native behaviour for the `change` event.
|
|
19
|
+
* You can access this with `event.target.checked` when listening to the `change` event.
|
|
20
|
+
* @returns The value of the property `isChecked`.
|
|
21
|
+
*/
|
|
22
|
+
get checked() {
|
|
23
|
+
return this.isChecked;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The onChange function updates the checkbox state and emits an event for consumers.
|
|
27
|
+
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
28
|
+
*/
|
|
17
29
|
onChange(e) {
|
|
18
30
|
const { checked: c } = e == null ? void 0 : e.currentTarget;
|
|
19
31
|
this.isChecked = c;
|
|
@@ -21,8 +33,7 @@ class o extends v(w) {
|
|
|
21
33
|
k,
|
|
22
34
|
{
|
|
23
35
|
bubbles: !0,
|
|
24
|
-
composed: !0
|
|
25
|
-
detail: this.isChecked
|
|
36
|
+
composed: !0
|
|
26
37
|
}
|
|
27
38
|
);
|
|
28
39
|
this.dispatchEvent(t);
|
package/dist/react.d.ts
CHANGED
|
@@ -18,23 +18,33 @@ export declare const labelPlacements: readonly ["leading", "trailing"];
|
|
|
18
18
|
*
|
|
19
19
|
* @constant
|
|
20
20
|
*/
|
|
21
|
-
export declare const ON_SWITCH_CHANGED_EVENT = "
|
|
21
|
+
export declare const ON_SWITCH_CHANGED_EVENT = "change";
|
|
22
22
|
|
|
23
23
|
export declare const PieSwitch: ReactWebComponent<PieSwitch_2, {
|
|
24
|
-
|
|
24
|
+
onChange: EventName<CustomEvent<any>>;
|
|
25
25
|
}>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @tagname pie-switch
|
|
29
|
-
* @event {CustomEvent}
|
|
29
|
+
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
30
30
|
*/
|
|
31
31
|
declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps {
|
|
32
32
|
label?: string;
|
|
33
33
|
labelPlacement: SwitchProps['labelPlacement'];
|
|
34
34
|
aria: AriaProps;
|
|
35
35
|
isChecked: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* This getter wraps the `isChecked` property to mimic native behaviour for the `change` event.
|
|
38
|
+
* You can access this with `event.target.checked` when listening to the `change` event.
|
|
39
|
+
* @returns The value of the property `isChecked`.
|
|
40
|
+
*/
|
|
41
|
+
get checked(): boolean;
|
|
36
42
|
isDisabled: boolean;
|
|
37
43
|
static styles: CSSResult;
|
|
44
|
+
/**
|
|
45
|
+
* The onChange function updates the checkbox state and emits an event for consumers.
|
|
46
|
+
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
47
|
+
*/
|
|
38
48
|
onChange(event: Event): void;
|
|
39
49
|
/**
|
|
40
50
|
* Renders the label for a switch if provided.
|
package/dist/react.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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 l, labelPlacements as w } 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
|
|
9
|
+
const n = t({
|
|
10
10
|
displayName: "PieSwitch",
|
|
11
11
|
elementClass: i,
|
|
12
12
|
react: e,
|
|
13
13
|
tagName: "pie-switch",
|
|
14
14
|
events: {
|
|
15
|
-
|
|
15
|
+
onChange: "change"
|
|
16
16
|
// when the switch checked state is changed.
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
l as ON_SWITCH_CHANGED_EVENT,
|
|
21
|
+
n as PieSwitch,
|
|
22
|
+
w as labelPlacements
|
|
23
23
|
};
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ const componentSelector = 'pie-switch';
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @tagname pie-switch
|
|
19
|
-
* @event {CustomEvent}
|
|
19
|
+
* @event {CustomEvent} change - when the switch checked state is changed.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export class PieSwitch extends RtlMixin(LitElement) implements SwitchProps {
|
|
@@ -33,11 +33,24 @@ export class PieSwitch extends RtlMixin(LitElement) implements SwitchProps {
|
|
|
33
33
|
@property({ type: Boolean, reflect: true })
|
|
34
34
|
public isChecked = false;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* This getter wraps the `isChecked` property to mimic native behaviour for the `change` event.
|
|
38
|
+
* You can access this with `event.target.checked` when listening to the `change` event.
|
|
39
|
+
* @returns The value of the property `isChecked`.
|
|
40
|
+
*/
|
|
41
|
+
public get checked () {
|
|
42
|
+
return this.isChecked;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
@property({ type: Boolean, reflect: true })
|
|
37
46
|
public isDisabled = false;
|
|
38
47
|
|
|
39
48
|
static styles = unsafeCSS(styles);
|
|
40
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The onChange function updates the checkbox state and emits an event for consumers.
|
|
52
|
+
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
53
|
+
*/
|
|
41
54
|
onChange (event: Event) {
|
|
42
55
|
const { checked } = event?.currentTarget as HTMLInputElement;
|
|
43
56
|
this.isChecked = checked;
|
|
@@ -46,7 +59,6 @@ export class PieSwitch extends RtlMixin(LitElement) implements SwitchProps {
|
|
|
46
59
|
{
|
|
47
60
|
bubbles: true,
|
|
48
61
|
composed: true,
|
|
49
|
-
detail: this.isChecked,
|
|
50
62
|
},
|
|
51
63
|
);
|
|
52
64
|
this.dispatchEvent(changedEvent);
|