@justeattakeaway/pie-checkbox 0.4.0 → 0.6.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 +16 -15
- package/custom-elements.json +72 -2
- package/dist/index.d.ts +26 -4
- package/dist/index.js +88 -59
- package/dist/react.d.ts +26 -4
- package/dist/react.js +8 -6
- package/package.json +2 -1
- package/src/defs.ts +21 -4
- package/src/index.ts +45 -10
package/README.md
CHANGED
|
@@ -30,11 +30,9 @@ This component can be easily integrated into various frontend frameworks and cus
|
|
|
30
30
|
To install `pie-checkbox` in your application, run the following on your command line:
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
|
|
34
|
-
$ npm i @justeattakeaway/pie-checkbox
|
|
33
|
+
npm i @justeattakeaway/pie-checkbox
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
$ yarn add @justeattakeaway/pie-checkbox
|
|
35
|
+
yarn add @justeattakeaway/pie-checkbox
|
|
38
36
|
```
|
|
39
37
|
|
|
40
38
|
For full information on using PIE components as part of an application, check out the [Getting Started Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components).
|
|
@@ -73,16 +71,19 @@ import { PieCheckbox } from '@justeattakeaway/pie-checkbox/dist/react';
|
|
|
73
71
|
|
|
74
72
|
## Props
|
|
75
73
|
|
|
76
|
-
| Property | Type
|
|
77
|
-
|
|
78
|
-
| `name` | `string`
|
|
79
|
-
| `value` | `string`
|
|
80
|
-
| `required` | `boolean`
|
|
81
|
-
| `label` | `string`
|
|
82
|
-
| `disabled` | `boolean`
|
|
83
|
-
| `checked` | `boolean`
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
74
|
+
| Property | Type | Default | Description |
|
|
75
|
+
|---|-------------------------------------|-----------|---|
|
|
76
|
+
| `name` | `string` | - | The name of the checkbox (used as a key/value pair with `value`). This is required in order to work properly with forms. |
|
|
77
|
+
| `value` | `string` | `'on'` | The value of the input (used as a key/value pair in HTML forms with `name`). If not passed falls back to the html default value "on". |
|
|
78
|
+
| `required` | `boolean` | `false` | If true, the checkbox is required to be checked before submitting the form. If it is not in checked state, the component validity state will be invalid. |
|
|
79
|
+
| `label` | `string` | `''` | Text associated with the checkbox. If there is no label to provide, make sure to pass label, labelledby or describedby to the aria property. |
|
|
80
|
+
| `disabled` | `boolean` | `false` | Indicates whether or not the checkbox is disabled. |
|
|
81
|
+
| `checked` | `boolean` | `false` | Controls whether or not the checkbox is checked. |
|
|
82
|
+
| `defaultChecked` | `boolean` | `false` | Sets the default checked state for the checkbox. This does not directly set the initial checked state when the page loads, use `checked` for that. If the checkbox is inside a form which is reset, the `checked` state will be updated to match `defaultChecked`. |
|
|
83
|
+
| `indeterminate` | `boolean` | `false` | Indicates whether the checkbox visually shows a horizontal line in the box instead of a check/tick. It has no impact on whether the checkbox's value is used in a form submission. That is decided by the checked state, regardless of the indeterminate state. |
|
|
84
|
+
| `aria` | `object` | {} | accepts `label`, `labeledby` and `describedby` keys with string values. |
|
|
85
|
+
| `assistiveText` | `string` | `''` | Allows assistive text to be displayed below the checkbox element. |
|
|
86
|
+
| `status` | `'default'`, `'error'`, `'success'` | `'default'` | The status of the checkbox component / assistive text. If you use `status` you must provide an `assistiveText` prop value for accessibility purposes. |
|
|
86
87
|
|
|
87
88
|
In your markup or JSX, you can then use these to set the properties for the `pie-checkbox` component:
|
|
88
89
|
|
|
@@ -107,4 +108,4 @@ In your markup or JSX, you can then use these to set the properties for the `pie
|
|
|
107
108
|
|
|
108
109
|
## Contributing
|
|
109
110
|
|
|
110
|
-
Check out our [contributing guide](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide) for more information on [local development](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#local-development) and how to run specific [component tests](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#testing).
|
|
111
|
+
Check out our [contributing guide](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide) for more information on [local development](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#local-development) and how to run specific [component tests](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#testing).
|
package/custom-elements.json
CHANGED
|
@@ -12,16 +12,32 @@
|
|
|
12
12
|
"kind": "javascript-module",
|
|
13
13
|
"path": "src/defs.js",
|
|
14
14
|
"declarations": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "variable",
|
|
17
|
+
"name": "statusTypes",
|
|
18
|
+
"type": {
|
|
19
|
+
"text": "['default', 'success', 'error']"
|
|
20
|
+
},
|
|
21
|
+
"default": "['default', 'success', 'error']"
|
|
22
|
+
},
|
|
15
23
|
{
|
|
16
24
|
"kind": "variable",
|
|
17
25
|
"name": "defaultProps",
|
|
18
26
|
"type": {
|
|
19
27
|
"text": "DefaultProps"
|
|
20
28
|
},
|
|
21
|
-
"default": "{\n // a default value for the html <input type=\"checkbox\" /> value attribute.\n // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value\n value: 'on',\n required: false,\n indeterminate: false,\n checked: false,\n}"
|
|
29
|
+
"default": "{\n // a default value for the html <input type=\"checkbox\" /> value attribute.\n // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value\n value: 'on',\n required: false,\n defaultChecked: false,\n indeterminate: false,\n checked: false,\n status: 'default',\n}"
|
|
22
30
|
}
|
|
23
31
|
],
|
|
24
32
|
"exports": [
|
|
33
|
+
{
|
|
34
|
+
"kind": "js",
|
|
35
|
+
"name": "statusTypes",
|
|
36
|
+
"declaration": {
|
|
37
|
+
"name": "statusTypes",
|
|
38
|
+
"module": "src/defs.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
25
41
|
{
|
|
26
42
|
"kind": "js",
|
|
27
43
|
"name": "defaultProps",
|
|
@@ -81,6 +97,13 @@
|
|
|
81
97
|
"attribute": "checked",
|
|
82
98
|
"reflects": true
|
|
83
99
|
},
|
|
100
|
+
{
|
|
101
|
+
"kind": "field",
|
|
102
|
+
"name": "defaultChecked",
|
|
103
|
+
"privacy": "public",
|
|
104
|
+
"attribute": "defaultChecked",
|
|
105
|
+
"reflects": true
|
|
106
|
+
},
|
|
84
107
|
{
|
|
85
108
|
"kind": "field",
|
|
86
109
|
"name": "disabled",
|
|
@@ -124,10 +147,28 @@
|
|
|
124
147
|
"kind": "field",
|
|
125
148
|
"name": "checkbox",
|
|
126
149
|
"type": {
|
|
127
|
-
"text": "HTMLInputElement
|
|
150
|
+
"text": "HTMLInputElement"
|
|
128
151
|
},
|
|
129
152
|
"privacy": "private"
|
|
130
153
|
},
|
|
154
|
+
{
|
|
155
|
+
"kind": "field",
|
|
156
|
+
"name": "assistiveText",
|
|
157
|
+
"type": {
|
|
158
|
+
"text": "CheckboxProps['assistiveText'] | undefined"
|
|
159
|
+
},
|
|
160
|
+
"privacy": "public",
|
|
161
|
+
"attribute": "assistiveText"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"kind": "field",
|
|
165
|
+
"name": "status",
|
|
166
|
+
"type": {
|
|
167
|
+
"text": "CheckboxProps['status'] | undefined"
|
|
168
|
+
},
|
|
169
|
+
"privacy": "public",
|
|
170
|
+
"attribute": "status"
|
|
171
|
+
},
|
|
131
172
|
{
|
|
132
173
|
"kind": "field",
|
|
133
174
|
"name": "validity",
|
|
@@ -183,6 +224,17 @@
|
|
|
183
224
|
}
|
|
184
225
|
],
|
|
185
226
|
"description": "Captures the native change event and wraps it in a custom event."
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"kind": "method",
|
|
230
|
+
"name": "formResetCallback",
|
|
231
|
+
"privacy": "public",
|
|
232
|
+
"return": {
|
|
233
|
+
"type": {
|
|
234
|
+
"text": "void"
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
"description": "Called when the form that contains this component is reset.\nIf the current checked state is different to the default checked state,\nthe checked state is reset to the default checked state and a `change` event is emitted."
|
|
186
238
|
}
|
|
187
239
|
],
|
|
188
240
|
"events": [
|
|
@@ -217,6 +269,10 @@
|
|
|
217
269
|
"name": "checked",
|
|
218
270
|
"fieldName": "checked"
|
|
219
271
|
},
|
|
272
|
+
{
|
|
273
|
+
"name": "defaultChecked",
|
|
274
|
+
"fieldName": "defaultChecked"
|
|
275
|
+
},
|
|
220
276
|
{
|
|
221
277
|
"name": "disabled",
|
|
222
278
|
"type": {
|
|
@@ -244,6 +300,20 @@
|
|
|
244
300
|
"text": "CheckboxProps['aria']"
|
|
245
301
|
},
|
|
246
302
|
"fieldName": "aria"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"name": "assistiveText",
|
|
306
|
+
"type": {
|
|
307
|
+
"text": "CheckboxProps['assistiveText'] | undefined"
|
|
308
|
+
},
|
|
309
|
+
"fieldName": "assistiveText"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"name": "status",
|
|
313
|
+
"type": {
|
|
314
|
+
"text": "CheckboxProps['status'] | undefined"
|
|
315
|
+
},
|
|
316
|
+
"fieldName": "status"
|
|
247
317
|
}
|
|
248
318
|
],
|
|
249
319
|
"mixins": [
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type { TemplateResult } from 'lit-html';
|
|
|
10
10
|
export declare type AriaProps = {
|
|
11
11
|
label?: string;
|
|
12
12
|
labelledby?: string;
|
|
13
|
-
describedby?: string;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
export declare interface CheckboxProps {
|
|
@@ -31,7 +30,11 @@ export declare interface CheckboxProps {
|
|
|
31
30
|
*/
|
|
32
31
|
disabled?: boolean;
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
33
|
+
* The default checked state of the checkbox (not necessarily the same as the current checked state).
|
|
34
|
+
*/
|
|
35
|
+
defaultChecked?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The checked state of the checkbox.
|
|
35
38
|
*/
|
|
36
39
|
checked?: boolean;
|
|
37
40
|
/**
|
|
@@ -47,9 +50,17 @@ export declare interface CheckboxProps {
|
|
|
47
50
|
* Various ARIA attributes.
|
|
48
51
|
*/
|
|
49
52
|
aria?: AriaProps;
|
|
53
|
+
/**
|
|
54
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
55
|
+
*/
|
|
56
|
+
assistiveText?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
59
|
+
*/
|
|
60
|
+
status?: typeof statusTypes[number];
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked'>;
|
|
63
|
+
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
53
64
|
|
|
54
65
|
export declare const defaultProps: DefaultProps;
|
|
55
66
|
|
|
@@ -67,11 +78,14 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
|
|
|
67
78
|
label?: CheckboxProps['label'];
|
|
68
79
|
name?: CheckboxProps['name'];
|
|
69
80
|
checked: boolean;
|
|
81
|
+
defaultChecked: boolean;
|
|
70
82
|
disabled?: CheckboxProps['disabled'];
|
|
71
83
|
required?: CheckboxProps['required'];
|
|
72
84
|
indeterminate?: CheckboxProps['indeterminate'];
|
|
73
85
|
aria: CheckboxProps['aria'];
|
|
74
|
-
private checkbox
|
|
86
|
+
private checkbox;
|
|
87
|
+
assistiveText?: CheckboxProps['assistiveText'];
|
|
88
|
+
status?: CheckboxProps['status'];
|
|
75
89
|
/**
|
|
76
90
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
77
91
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -95,10 +109,18 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
|
|
|
95
109
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
96
110
|
*/
|
|
97
111
|
private handleChange;
|
|
112
|
+
/**
|
|
113
|
+
* Called when the form that contains this component is reset.
|
|
114
|
+
* If the current checked state is different to the default checked state,
|
|
115
|
+
* the checked state is reset to the default checked state and a `change` event is emitted.
|
|
116
|
+
*/
|
|
117
|
+
formResetCallback(): void;
|
|
98
118
|
render(): TemplateResult<1>;
|
|
99
119
|
static styles: CSSResult;
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
declare const PieCheckbox_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
103
123
|
|
|
124
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
125
|
+
|
|
104
126
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { LitElement as y, html as f, nothing as p, unsafeCSS as g } from "lit";
|
|
2
|
+
import { property as i, query as C } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as m } from "lit/directives/if-defined.js";
|
|
4
|
+
import { live as $ } from "lit/directives/live.js";
|
|
5
|
+
import { FormControlMixin as F, RtlMixin as E, wrapNativeEvent as S, validPropertyValues as q, defineCustomElement as A } from "@justeattakeaway/pie-webc-core";
|
|
6
|
+
import "@justeattakeaway/pie-assistive-text";
|
|
7
|
+
const O = `*,*:after,*:before{box-sizing:inherit}
|
|
8
|
+
`, P = ["default", "success", "error"], n = {
|
|
8
9
|
// a default value for the html <input type="checkbox" /> value attribute.
|
|
9
10
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
|
|
10
11
|
value: "on",
|
|
11
12
|
required: !1,
|
|
13
|
+
defaultChecked: !1,
|
|
12
14
|
indeterminate: !1,
|
|
13
|
-
checked: !1
|
|
15
|
+
checked: !1,
|
|
16
|
+
status: "default"
|
|
14
17
|
};
|
|
15
|
-
var _ = Object.defineProperty,
|
|
16
|
-
for (var o =
|
|
17
|
-
(
|
|
18
|
-
return
|
|
18
|
+
var _ = Object.defineProperty, w = Object.getOwnPropertyDescriptor, s = (h, e, r, a) => {
|
|
19
|
+
for (var o = a > 1 ? void 0 : a ? w(e, r) : e, d = h.length - 1, l; d >= 0; d--)
|
|
20
|
+
(l = h[d]) && (o = (a ? l(e, r, o) : l(o)) || o);
|
|
21
|
+
return a && o && _(e, r, o), o;
|
|
19
22
|
};
|
|
20
|
-
const
|
|
21
|
-
class t extends
|
|
23
|
+
const v = "pie-checkbox", b = "assistive-text";
|
|
24
|
+
class t extends F(E(y)) {
|
|
22
25
|
constructor() {
|
|
23
|
-
super(...arguments), this.value =
|
|
26
|
+
super(...arguments), this.value = n.value, this.checked = n.checked, this.defaultChecked = n.defaultChecked, this.required = n.required, this.indeterminate = n.indeterminate, this.status = n.status;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -33,7 +36,7 @@ class t extends y(v(u)) {
|
|
|
33
36
|
* Ensures that the form value is in sync with the component.
|
|
34
37
|
*/
|
|
35
38
|
handleFormAssociation() {
|
|
36
|
-
!!this.
|
|
39
|
+
!!this.form && !!this.name && this._internals.setFormValue(this.checked ? this.value : null);
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Called after the disabled state of the element changes,
|
|
@@ -55,73 +58,99 @@ class t extends y(v(u)) {
|
|
|
55
58
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
56
59
|
*/
|
|
57
60
|
handleChange(e) {
|
|
58
|
-
const { checked:
|
|
59
|
-
this.checked =
|
|
60
|
-
const
|
|
61
|
-
this.dispatchEvent(
|
|
61
|
+
const { checked: r } = e == null ? void 0 : e.currentTarget;
|
|
62
|
+
this.checked = r;
|
|
63
|
+
const a = S(e);
|
|
64
|
+
this.dispatchEvent(a), this.handleFormAssociation();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Called when the form that contains this component is reset.
|
|
68
|
+
* If the current checked state is different to the default checked state,
|
|
69
|
+
* the checked state is reset to the default checked state and a `change` event is emitted.
|
|
70
|
+
*/
|
|
71
|
+
formResetCallback() {
|
|
72
|
+
if (this.checked === this.defaultChecked)
|
|
73
|
+
return;
|
|
74
|
+
this.checked = this.defaultChecked;
|
|
75
|
+
const e = new Event("change", { bubbles: !0, composed: !0 });
|
|
76
|
+
this.dispatchEvent(e), this.handleFormAssociation();
|
|
62
77
|
}
|
|
63
78
|
render() {
|
|
64
79
|
const {
|
|
65
80
|
checked: e,
|
|
66
|
-
value:
|
|
67
|
-
name:
|
|
81
|
+
value: r,
|
|
82
|
+
name: a,
|
|
68
83
|
label: o,
|
|
69
|
-
disabled:
|
|
70
|
-
required:
|
|
71
|
-
indeterminate:
|
|
72
|
-
aria:
|
|
84
|
+
disabled: d,
|
|
85
|
+
required: l,
|
|
86
|
+
indeterminate: k,
|
|
87
|
+
aria: c,
|
|
88
|
+
assistiveText: u,
|
|
89
|
+
status: x
|
|
73
90
|
} = this;
|
|
74
|
-
return
|
|
91
|
+
return f`
|
|
75
92
|
<label data-test-id="checkbox-component">
|
|
76
93
|
<input
|
|
77
94
|
type="checkbox"
|
|
78
|
-
.value=${
|
|
79
|
-
|
|
80
|
-
name=${
|
|
81
|
-
?disabled=${
|
|
82
|
-
?required=${
|
|
83
|
-
.indeterminate=${
|
|
84
|
-
aria-label=${(
|
|
85
|
-
aria-labelledby=${o ?
|
|
86
|
-
aria-describedby
|
|
95
|
+
.value=${r}
|
|
96
|
+
.checked=${$(e)}
|
|
97
|
+
name=${m(a)}
|
|
98
|
+
?disabled=${d}
|
|
99
|
+
?required=${l}
|
|
100
|
+
.indeterminate=${!!k}
|
|
101
|
+
aria-label=${(c == null ? void 0 : c.label) || p}
|
|
102
|
+
aria-labelledby=${o ? p : (c == null ? void 0 : c.labelledby) || p}
|
|
103
|
+
aria-describedby=${m(u ? b : void 0)}
|
|
87
104
|
@change=${this.handleChange}
|
|
88
105
|
data-test-id="checkbox-input"
|
|
89
106
|
/>
|
|
90
107
|
${o}
|
|
91
|
-
</label
|
|
108
|
+
</label>
|
|
109
|
+
${u ? f`<pie-assistive-text id="${b}" variant=${m(x)} data-test-id="pie-checkbox-assistive-text">${u}</pie-assistive-text>` : p}`;
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
|
-
t.shadowRootOptions = { ...
|
|
95
|
-
t.styles =
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
t.shadowRootOptions = { ...y.shadowRootOptions, delegatesFocus: !0 };
|
|
113
|
+
t.styles = g(O);
|
|
114
|
+
s([
|
|
115
|
+
i({ type: String })
|
|
98
116
|
], t.prototype, "value", 2);
|
|
99
|
-
|
|
100
|
-
|
|
117
|
+
s([
|
|
118
|
+
i({ type: String })
|
|
101
119
|
], t.prototype, "label", 2);
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
s([
|
|
121
|
+
i({ type: String })
|
|
104
122
|
], t.prototype, "name", 2);
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
s([
|
|
124
|
+
i({ type: Boolean, reflect: !0 })
|
|
107
125
|
], t.prototype, "checked", 2);
|
|
108
|
-
|
|
109
|
-
|
|
126
|
+
s([
|
|
127
|
+
i({ type: Boolean, reflect: !0 })
|
|
128
|
+
], t.prototype, "defaultChecked", 2);
|
|
129
|
+
s([
|
|
130
|
+
i({ type: Boolean, reflect: !0 })
|
|
110
131
|
], t.prototype, "disabled", 2);
|
|
111
|
-
|
|
112
|
-
|
|
132
|
+
s([
|
|
133
|
+
i({ type: Boolean, reflect: !0 })
|
|
113
134
|
], t.prototype, "required", 2);
|
|
114
|
-
|
|
115
|
-
|
|
135
|
+
s([
|
|
136
|
+
i({ type: Boolean, reflect: !0 })
|
|
116
137
|
], t.prototype, "indeterminate", 2);
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
s([
|
|
139
|
+
i({ type: Object })
|
|
119
140
|
], t.prototype, "aria", 2);
|
|
120
|
-
|
|
121
|
-
|
|
141
|
+
s([
|
|
142
|
+
C('input[type="checkbox"]')
|
|
122
143
|
], t.prototype, "checkbox", 2);
|
|
123
|
-
|
|
144
|
+
s([
|
|
145
|
+
i({ type: String })
|
|
146
|
+
], t.prototype, "assistiveText", 2);
|
|
147
|
+
s([
|
|
148
|
+
i({ type: String }),
|
|
149
|
+
q(v, P, n.status)
|
|
150
|
+
], t.prototype, "status", 2);
|
|
151
|
+
A(v, t);
|
|
124
152
|
export {
|
|
125
153
|
t as PieCheckbox,
|
|
126
|
-
|
|
154
|
+
n as defaultProps,
|
|
155
|
+
P as statusTypes
|
|
127
156
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { TemplateResult } from 'lit-html';
|
|
|
11
11
|
export declare type AriaProps = {
|
|
12
12
|
label?: string;
|
|
13
13
|
labelledby?: string;
|
|
14
|
-
describedby?: string;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export declare interface CheckboxProps {
|
|
@@ -32,7 +31,11 @@ export declare interface CheckboxProps {
|
|
|
32
31
|
*/
|
|
33
32
|
disabled?: boolean;
|
|
34
33
|
/**
|
|
35
|
-
*
|
|
34
|
+
* The default checked state of the checkbox (not necessarily the same as the current checked state).
|
|
35
|
+
*/
|
|
36
|
+
defaultChecked?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The checked state of the checkbox.
|
|
36
39
|
*/
|
|
37
40
|
checked?: boolean;
|
|
38
41
|
/**
|
|
@@ -48,9 +51,17 @@ export declare interface CheckboxProps {
|
|
|
48
51
|
* Various ARIA attributes.
|
|
49
52
|
*/
|
|
50
53
|
aria?: AriaProps;
|
|
54
|
+
/**
|
|
55
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
56
|
+
*/
|
|
57
|
+
assistiveText?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
60
|
+
*/
|
|
61
|
+
status?: typeof statusTypes[number];
|
|
51
62
|
}
|
|
52
63
|
|
|
53
|
-
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked'>;
|
|
64
|
+
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
54
65
|
|
|
55
66
|
export declare const defaultProps: DefaultProps;
|
|
56
67
|
|
|
@@ -70,11 +81,14 @@ declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
|
|
|
70
81
|
label?: CheckboxProps['label'];
|
|
71
82
|
name?: CheckboxProps['name'];
|
|
72
83
|
checked: boolean;
|
|
84
|
+
defaultChecked: boolean;
|
|
73
85
|
disabled?: CheckboxProps['disabled'];
|
|
74
86
|
required?: CheckboxProps['required'];
|
|
75
87
|
indeterminate?: CheckboxProps['indeterminate'];
|
|
76
88
|
aria: CheckboxProps['aria'];
|
|
77
|
-
private checkbox
|
|
89
|
+
private checkbox;
|
|
90
|
+
assistiveText?: CheckboxProps['assistiveText'];
|
|
91
|
+
status?: CheckboxProps['status'];
|
|
78
92
|
/**
|
|
79
93
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
80
94
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -98,6 +112,12 @@ declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
|
|
|
98
112
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
99
113
|
*/
|
|
100
114
|
private handleChange;
|
|
115
|
+
/**
|
|
116
|
+
* Called when the form that contains this component is reset.
|
|
117
|
+
* If the current checked state is different to the default checked state,
|
|
118
|
+
* the checked state is reset to the default checked state and a `change` event is emitted.
|
|
119
|
+
*/
|
|
120
|
+
formResetCallback(): void;
|
|
101
121
|
render(): TemplateResult<1>;
|
|
102
122
|
static styles: CSSResult;
|
|
103
123
|
}
|
|
@@ -110,4 +130,6 @@ declare type PieCheckboxEvents = {
|
|
|
110
130
|
|
|
111
131
|
declare type ReactBaseType = React_2.InputHTMLAttributes<HTMLInputElement>;
|
|
112
132
|
|
|
133
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
134
|
+
|
|
113
135
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
2
|
import { createComponent as o } from "@lit/react";
|
|
3
3
|
import { PieCheckbox as t } from "./index.js";
|
|
4
|
-
import { defaultProps as
|
|
4
|
+
import { defaultProps as k, statusTypes as P } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
|
-
import "@justeattakeaway/pie-webc-core";
|
|
7
|
-
import "lit/directives/live.js";
|
|
8
6
|
import "lit/decorators.js";
|
|
9
7
|
import "lit/directives/if-defined.js";
|
|
8
|
+
import "lit/directives/live.js";
|
|
9
|
+
import "@justeattakeaway/pie-webc-core";
|
|
10
|
+
import "@justeattakeaway/pie-assistive-text";
|
|
10
11
|
const r = o({
|
|
11
12
|
displayName: "PieCheckbox",
|
|
12
13
|
elementClass: t,
|
|
@@ -16,8 +17,9 @@ const r = o({
|
|
|
16
17
|
onChange: "change"
|
|
17
18
|
// when checked state is changed.
|
|
18
19
|
}
|
|
19
|
-
}),
|
|
20
|
+
}), x = r;
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
x as PieCheckbox,
|
|
23
|
+
k as defaultProps,
|
|
24
|
+
P as statusTypes
|
|
23
25
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-checkbox",
|
|
3
3
|
"description": "PIE Design System Checkbox built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@justeattakeaway/pie-assistive-text": "0.5.0",
|
|
43
44
|
"@justeattakeaway/pie-webc-core": "0.23.0"
|
|
44
45
|
},
|
|
45
46
|
"volta": {
|
package/src/defs.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
|
|
3
|
+
export const statusTypes = ['default', 'success', 'error'] as const;
|
|
4
|
+
|
|
3
5
|
export type AriaProps = {
|
|
4
6
|
label?: string;
|
|
5
7
|
labelledby?: string;
|
|
6
|
-
describedby?: string;
|
|
7
8
|
};
|
|
8
9
|
export interface CheckboxProps {
|
|
9
10
|
/**
|
|
@@ -27,7 +28,12 @@ export interface CheckboxProps {
|
|
|
27
28
|
disabled?: boolean;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
+
* The default checked state of the checkbox (not necessarily the same as the current checked state).
|
|
32
|
+
*/
|
|
33
|
+
defaultChecked?: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The checked state of the checkbox.
|
|
31
37
|
*/
|
|
32
38
|
checked?: boolean;
|
|
33
39
|
|
|
@@ -46,16 +52,27 @@ export interface CheckboxProps {
|
|
|
46
52
|
* Various ARIA attributes.
|
|
47
53
|
*/
|
|
48
54
|
aria?: AriaProps;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
58
|
+
*/
|
|
59
|
+
assistiveText?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
63
|
+
*/
|
|
64
|
+
status?: typeof statusTypes[number];
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
export type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' >;
|
|
67
|
+
export type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
52
68
|
|
|
53
69
|
export const defaultProps: DefaultProps = {
|
|
54
70
|
// a default value for the html <input type="checkbox" /> value attribute.
|
|
55
71
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
|
|
56
72
|
value: 'on',
|
|
57
73
|
required: false,
|
|
74
|
+
defaultChecked: false,
|
|
58
75
|
indeterminate: false,
|
|
59
76
|
checked: false,
|
|
77
|
+
status: 'default',
|
|
60
78
|
};
|
|
61
|
-
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LitElement, html, unsafeCSS, PropertyValues, nothing,
|
|
3
3
|
} from 'lit';
|
|
4
|
+
import { property, query } from 'lit/decorators.js';
|
|
5
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
6
|
+
import { live } from 'lit/directives/live.js';
|
|
7
|
+
|
|
4
8
|
import {
|
|
5
9
|
RtlMixin,
|
|
6
10
|
defineCustomElement,
|
|
7
11
|
wrapNativeEvent,
|
|
8
12
|
FormControlMixin,
|
|
13
|
+
validPropertyValues,
|
|
9
14
|
} from '@justeattakeaway/pie-webc-core';
|
|
10
|
-
import
|
|
11
|
-
import { property, query } from 'lit/decorators.js';
|
|
12
|
-
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
15
|
+
import '@justeattakeaway/pie-assistive-text';
|
|
13
16
|
|
|
14
17
|
import styles from './checkbox.scss?inline';
|
|
15
|
-
import { CheckboxProps, defaultProps } from './defs';
|
|
18
|
+
import { CheckboxProps, defaultProps, statusTypes } from './defs';
|
|
16
19
|
|
|
17
20
|
// Valid values available to consumers
|
|
18
21
|
export * from './defs';
|
|
19
22
|
|
|
20
23
|
const componentSelector = 'pie-checkbox';
|
|
24
|
+
const assistiveTextIdValue = 'assistive-text';
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* @tagname pie-checkbox
|
|
@@ -38,6 +42,9 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
38
42
|
@property({ type: Boolean, reflect: true })
|
|
39
43
|
public checked = defaultProps.checked;
|
|
40
44
|
|
|
45
|
+
@property({ type: Boolean, reflect: true })
|
|
46
|
+
public defaultChecked = defaultProps.defaultChecked;
|
|
47
|
+
|
|
41
48
|
@property({ type: Boolean, reflect: true })
|
|
42
49
|
public disabled?: CheckboxProps['disabled'];
|
|
43
50
|
|
|
@@ -51,7 +58,14 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
51
58
|
public aria: CheckboxProps['aria'];
|
|
52
59
|
|
|
53
60
|
@query('input[type="checkbox"]')
|
|
54
|
-
private checkbox
|
|
61
|
+
private checkbox!: HTMLInputElement;
|
|
62
|
+
|
|
63
|
+
@property({ type: String })
|
|
64
|
+
public assistiveText?: CheckboxProps['assistiveText'];
|
|
65
|
+
|
|
66
|
+
@property({ type: String })
|
|
67
|
+
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
|
|
68
|
+
public status?: CheckboxProps['status'] = defaultProps.status;
|
|
55
69
|
|
|
56
70
|
/**
|
|
57
71
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -65,7 +79,7 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
65
79
|
* Ensures that the form value is in sync with the component.
|
|
66
80
|
*/
|
|
67
81
|
private handleFormAssociation () : void {
|
|
68
|
-
const isFormAssociated = !!this.
|
|
82
|
+
const isFormAssociated = !!this.form && !!this.name;
|
|
69
83
|
if (isFormAssociated) {
|
|
70
84
|
this._internals.setFormValue(this.checked ? this.value : null);
|
|
71
85
|
}
|
|
@@ -108,6 +122,24 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
108
122
|
this.handleFormAssociation();
|
|
109
123
|
}
|
|
110
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Called when the form that contains this component is reset.
|
|
127
|
+
* If the current checked state is different to the default checked state,
|
|
128
|
+
* the checked state is reset to the default checked state and a `change` event is emitted.
|
|
129
|
+
*/
|
|
130
|
+
public formResetCallback () : void {
|
|
131
|
+
if (this.checked === this.defaultChecked) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.checked = this.defaultChecked;
|
|
136
|
+
|
|
137
|
+
const changeEvent = new Event('change', { bubbles: true, composed: true });
|
|
138
|
+
this.dispatchEvent(changeEvent);
|
|
139
|
+
|
|
140
|
+
this.handleFormAssociation();
|
|
141
|
+
}
|
|
142
|
+
|
|
111
143
|
render () {
|
|
112
144
|
const {
|
|
113
145
|
checked,
|
|
@@ -118,6 +150,8 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
118
150
|
required,
|
|
119
151
|
indeterminate,
|
|
120
152
|
aria,
|
|
153
|
+
assistiveText,
|
|
154
|
+
status,
|
|
121
155
|
} = this;
|
|
122
156
|
|
|
123
157
|
return html`
|
|
@@ -125,19 +159,20 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
125
159
|
<input
|
|
126
160
|
type="checkbox"
|
|
127
161
|
.value=${value}
|
|
128
|
-
|
|
162
|
+
.checked=${live(checked)}
|
|
129
163
|
name=${ifDefined(name)}
|
|
130
164
|
?disabled=${disabled}
|
|
131
165
|
?required=${required}
|
|
132
|
-
.indeterminate=${indeterminate}
|
|
166
|
+
.indeterminate=${!!indeterminate}
|
|
133
167
|
aria-label=${aria?.label || nothing}
|
|
134
168
|
aria-labelledby=${label ? nothing : aria?.labelledby || nothing}
|
|
135
|
-
aria-describedby
|
|
169
|
+
aria-describedby=${ifDefined(assistiveText ? assistiveTextIdValue : undefined)}
|
|
136
170
|
@change=${this.handleChange}
|
|
137
171
|
data-test-id="checkbox-input"
|
|
138
172
|
/>
|
|
139
173
|
${label}
|
|
140
|
-
</label
|
|
174
|
+
</label>
|
|
175
|
+
${assistiveText ? html`<pie-assistive-text id="${assistiveTextIdValue}" variant=${ifDefined(status)} data-test-id="pie-checkbox-assistive-text">${assistiveText}</pie-assistive-text>` : nothing}`;
|
|
141
176
|
}
|
|
142
177
|
|
|
143
178
|
// Renders a `CSSResult` generated from SCSS by Vite
|