@justeattakeaway/pie-switch 2.4.2 → 2.5.1
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 -0
- package/custom-elements.json +34 -13
- package/dist/index.d.ts +14 -8
- package/dist/index.js +250 -231
- package/dist/react.d.ts +14 -8
- package/package.json +4 -4
- package/src/defs.ts +6 -0
- package/src/index.ts +63 -33
- package/src/switch.scss +7 -0
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
|
|
|
36
36
|
| Prop | Options | Description | Default |
|
|
37
37
|
|------------------|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------|
|
|
38
38
|
| `checked` | `true`, `false` | Same as the HTML `checked` attribute; indicates whether the switch is on or off. | `false` |
|
|
39
|
+
| `defaultChecked` | `true`, `false` | Sets the default checked state for the switch. This does not directly set the initial checked state when the page loads, use `checked` for that. If the switch is inside a form which is reset, the `checked` state will be updated to match `defaultChecked`. | `false` |
|
|
39
40
|
| `disabled` | `true`, `false` | Same as the HTML `disabled` attribute; indicates whether the switch is disabled or not. | `false` |
|
|
40
41
|
| `required` | `true`, `false` | Same as the HTML `required` attribute; indicates whether the switch must be turned on when submitted as part of a form. | `false` |
|
|
41
42
|
| `label` | — | The label text for the switch. | — |
|
package/custom-elements.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"type": {
|
|
36
36
|
"text": "DefaultProps"
|
|
37
37
|
},
|
|
38
|
-
"default": "{ checked: false, disabled: false, labelPlacement: 'leading', required: false, value: 'on', }"
|
|
38
|
+
"default": "{ checked: false, defaultChecked: false, disabled: false, labelPlacement: 'leading', required: false, value: 'on', }"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
41
|
"exports": [
|
|
@@ -105,6 +105,13 @@
|
|
|
105
105
|
"attribute": "checked",
|
|
106
106
|
"reflects": true
|
|
107
107
|
},
|
|
108
|
+
{
|
|
109
|
+
"kind": "field",
|
|
110
|
+
"name": "defaultChecked",
|
|
111
|
+
"privacy": "public",
|
|
112
|
+
"attribute": "defaultChecked",
|
|
113
|
+
"reflects": true
|
|
114
|
+
},
|
|
108
115
|
{
|
|
109
116
|
"kind": "field",
|
|
110
117
|
"name": "required",
|
|
@@ -143,6 +150,14 @@
|
|
|
143
150
|
},
|
|
144
151
|
"privacy": "private"
|
|
145
152
|
},
|
|
153
|
+
{
|
|
154
|
+
"kind": "field",
|
|
155
|
+
"name": "switchBody",
|
|
156
|
+
"type": {
|
|
157
|
+
"text": "HTMLElement"
|
|
158
|
+
},
|
|
159
|
+
"privacy": "private"
|
|
160
|
+
},
|
|
146
161
|
{
|
|
147
162
|
"kind": "field",
|
|
148
163
|
"name": "focusTarget",
|
|
@@ -235,6 +250,17 @@
|
|
|
235
250
|
],
|
|
236
251
|
"description": "Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity"
|
|
237
252
|
},
|
|
253
|
+
{
|
|
254
|
+
"kind": "method",
|
|
255
|
+
"name": "formResetCallback",
|
|
256
|
+
"privacy": "public",
|
|
257
|
+
"return": {
|
|
258
|
+
"type": {
|
|
259
|
+
"text": "void"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"description": "Called when the containing form is reset.\nResets checked state back to defaultChecked and emits a change event when needed."
|
|
263
|
+
},
|
|
238
264
|
{
|
|
239
265
|
"kind": "field",
|
|
240
266
|
"name": "validity",
|
|
@@ -257,21 +283,12 @@
|
|
|
257
283
|
},
|
|
258
284
|
{
|
|
259
285
|
"kind": "method",
|
|
260
|
-
"name": "
|
|
261
|
-
"privacy": "private"
|
|
262
|
-
"parameters": [
|
|
263
|
-
{
|
|
264
|
-
"name": "placement",
|
|
265
|
-
"type": {
|
|
266
|
-
"text": "SwitchProps['labelPlacement']"
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
],
|
|
270
|
-
"description": "If a label is provided, renders it if `labelPlacement` matches the given position.\nIf no label is provided, or `labelPlacement` does not match the given position, nothing is rendered."
|
|
286
|
+
"name": "renderAriaDescription",
|
|
287
|
+
"privacy": "private"
|
|
271
288
|
},
|
|
272
289
|
{
|
|
273
290
|
"kind": "method",
|
|
274
|
-
"name": "
|
|
291
|
+
"name": "renderSwitchLabel",
|
|
275
292
|
"privacy": "private"
|
|
276
293
|
}
|
|
277
294
|
],
|
|
@@ -313,6 +330,10 @@
|
|
|
313
330
|
"name": "checked",
|
|
314
331
|
"fieldName": "checked"
|
|
315
332
|
},
|
|
333
|
+
{
|
|
334
|
+
"name": "defaultChecked",
|
|
335
|
+
"fieldName": "defaultChecked"
|
|
336
|
+
},
|
|
316
337
|
{
|
|
317
338
|
"name": "required",
|
|
318
339
|
"fieldName": "required"
|
package/dist/index.d.ts
CHANGED
|
@@ -33,11 +33,13 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
33
33
|
labelPlacement: "leading" | "trailing";
|
|
34
34
|
aria: SwitchProps['aria'];
|
|
35
35
|
checked: boolean;
|
|
36
|
+
defaultChecked: boolean;
|
|
36
37
|
required: boolean;
|
|
37
38
|
value: string;
|
|
38
39
|
name: SwitchProps['name'];
|
|
39
40
|
disabled: boolean;
|
|
40
41
|
private input;
|
|
42
|
+
private switchBody;
|
|
41
43
|
focusTarget: HTMLElement;
|
|
42
44
|
private _abortController;
|
|
43
45
|
private _isAnimationAllowed;
|
|
@@ -72,6 +74,11 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
72
74
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
|
|
73
75
|
*/
|
|
74
76
|
setCustomValidity(message: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Called when the containing form is reset.
|
|
79
|
+
* Resets checked state back to defaultChecked and emits a change event when needed.
|
|
80
|
+
*/
|
|
81
|
+
formResetCallback(): void;
|
|
75
82
|
/**
|
|
76
83
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
77
84
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -83,15 +90,9 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PI
|
|
|
83
90
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage
|
|
84
91
|
*/
|
|
85
92
|
get validationMessage(): string;
|
|
86
|
-
/**
|
|
87
|
-
* If a label is provided, renders it if `labelPlacement` matches the given position.
|
|
88
|
-
* If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
|
|
89
|
-
*
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
private renderSwitchLabel;
|
|
93
93
|
private renderAriaDescription;
|
|
94
|
-
|
|
94
|
+
private renderSwitchLabel;
|
|
95
|
+
render(): TemplateResult;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
declare const PieSwitch_base: GenericConstructor<FormControlInterface> & typeof PieElement;
|
|
@@ -105,6 +106,11 @@ export declare interface SwitchProps {
|
|
|
105
106
|
* Same as the HTML checked attribute - indicates whether the switch is on or off
|
|
106
107
|
*/
|
|
107
108
|
checked?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The default checked state of the switch (not necessarily the same as the current checked state).
|
|
111
|
+
* Used when the switch is part of a form that is reset.
|
|
112
|
+
*/
|
|
113
|
+
defaultChecked?: boolean;
|
|
108
114
|
/**
|
|
109
115
|
* Same as the HTML required attribute - indicates whether the switch must be turned or not
|
|
110
116
|
*/
|