@justeattakeaway/pie-checkbox 0.5.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 +13 -11
- package/custom-elements.json +49 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +68 -55
- package/dist/react.d.ts +13 -2
- package/dist/react.js +8 -6
- package/package.json +2 -1
- package/src/defs.ts +14 -2
- package/src/index.ts +20 -6
package/README.md
CHANGED
|
@@ -71,17 +71,19 @@ import { PieCheckbox } from '@justeattakeaway/pie-checkbox/dist/react';
|
|
|
71
71
|
|
|
72
72
|
## Props
|
|
73
73
|
|
|
74
|
-
| Property | Type
|
|
75
|
-
|
|
76
|
-
| `name` | `string`
|
|
77
|
-
| `value` | `string`
|
|
78
|
-
| `required` | `boolean`
|
|
79
|
-
| `label` | `string`
|
|
80
|
-
| `disabled` | `boolean`
|
|
81
|
-
| `checked` | `boolean`
|
|
82
|
-
| `defaultChecked` | `boolean`
|
|
83
|
-
| `indeterminate` | `boolean`
|
|
84
|
-
| `aria` | `object`
|
|
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. |
|
|
85
87
|
|
|
86
88
|
In your markup or JSX, you can then use these to set the properties for the `pie-checkbox` component:
|
|
87
89
|
|
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 defaultChecked: 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",
|
|
@@ -135,6 +151,24 @@
|
|
|
135
151
|
},
|
|
136
152
|
"privacy": "private"
|
|
137
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
|
+
},
|
|
138
172
|
{
|
|
139
173
|
"kind": "field",
|
|
140
174
|
"name": "validity",
|
|
@@ -266,6 +300,20 @@
|
|
|
266
300
|
"text": "CheckboxProps['aria']"
|
|
267
301
|
},
|
|
268
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"
|
|
269
317
|
}
|
|
270
318
|
],
|
|
271
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 {
|
|
@@ -51,9 +50,17 @@ export declare interface CheckboxProps {
|
|
|
51
50
|
* Various ARIA attributes.
|
|
52
51
|
*/
|
|
53
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];
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked'>;
|
|
63
|
+
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
57
64
|
|
|
58
65
|
export declare const defaultProps: DefaultProps;
|
|
59
66
|
|
|
@@ -77,6 +84,8 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
|
|
|
77
84
|
indeterminate?: CheckboxProps['indeterminate'];
|
|
78
85
|
aria: CheckboxProps['aria'];
|
|
79
86
|
private checkbox;
|
|
87
|
+
assistiveText?: CheckboxProps['assistiveText'];
|
|
88
|
+
status?: CheckboxProps['status'];
|
|
80
89
|
/**
|
|
81
90
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
82
91
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -112,4 +121,6 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
|
|
|
112
121
|
|
|
113
122
|
declare const PieCheckbox_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
114
123
|
|
|
124
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
125
|
+
|
|
115
126
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,27 +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,
|
|
12
13
|
defaultChecked: !1,
|
|
13
14
|
indeterminate: !1,
|
|
14
|
-
checked: !1
|
|
15
|
+
checked: !1,
|
|
16
|
+
status: "default"
|
|
15
17
|
};
|
|
16
|
-
var
|
|
17
|
-
for (var o = a > 1 ? void 0 : a ?
|
|
18
|
-
(l =
|
|
19
|
-
return a && o &&
|
|
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;
|
|
20
22
|
};
|
|
21
|
-
const
|
|
22
|
-
class t extends
|
|
23
|
+
const v = "pie-checkbox", b = "assistive-text";
|
|
24
|
+
class t extends F(E(y)) {
|
|
23
25
|
constructor() {
|
|
24
|
-
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;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -56,9 +58,9 @@ class t extends y(k(u)) {
|
|
|
56
58
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
57
59
|
*/
|
|
58
60
|
handleChange(e) {
|
|
59
|
-
const { checked:
|
|
60
|
-
this.checked =
|
|
61
|
-
const a =
|
|
61
|
+
const { checked: r } = e == null ? void 0 : e.currentTarget;
|
|
62
|
+
this.checked = r;
|
|
63
|
+
const a = S(e);
|
|
62
64
|
this.dispatchEvent(a), this.handleFormAssociation();
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
@@ -76,68 +78,79 @@ class t extends y(k(u)) {
|
|
|
76
78
|
render() {
|
|
77
79
|
const {
|
|
78
80
|
checked: e,
|
|
79
|
-
value:
|
|
81
|
+
value: r,
|
|
80
82
|
name: a,
|
|
81
83
|
label: o,
|
|
82
|
-
disabled:
|
|
84
|
+
disabled: d,
|
|
83
85
|
required: l,
|
|
84
|
-
indeterminate:
|
|
85
|
-
aria:
|
|
86
|
+
indeterminate: k,
|
|
87
|
+
aria: c,
|
|
88
|
+
assistiveText: u,
|
|
89
|
+
status: x
|
|
86
90
|
} = this;
|
|
87
91
|
return f`
|
|
88
92
|
<label data-test-id="checkbox-component">
|
|
89
93
|
<input
|
|
90
94
|
type="checkbox"
|
|
91
|
-
.value=${
|
|
92
|
-
.checked=${
|
|
93
|
-
name=${
|
|
94
|
-
?disabled=${
|
|
95
|
+
.value=${r}
|
|
96
|
+
.checked=${$(e)}
|
|
97
|
+
name=${m(a)}
|
|
98
|
+
?disabled=${d}
|
|
95
99
|
?required=${l}
|
|
96
|
-
.indeterminate=${!!
|
|
97
|
-
aria-label=${(
|
|
98
|
-
aria-labelledby=${o ?
|
|
99
|
-
aria-describedby
|
|
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)}
|
|
100
104
|
@change=${this.handleChange}
|
|
101
105
|
data-test-id="checkbox-input"
|
|
102
106
|
/>
|
|
103
107
|
${o}
|
|
104
|
-
</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}`;
|
|
105
110
|
}
|
|
106
111
|
}
|
|
107
|
-
t.shadowRootOptions = { ...
|
|
108
|
-
t.styles =
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
t.shadowRootOptions = { ...y.shadowRootOptions, delegatesFocus: !0 };
|
|
113
|
+
t.styles = g(O);
|
|
114
|
+
s([
|
|
115
|
+
i({ type: String })
|
|
111
116
|
], t.prototype, "value", 2);
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
s([
|
|
118
|
+
i({ type: String })
|
|
114
119
|
], t.prototype, "label", 2);
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
s([
|
|
121
|
+
i({ type: String })
|
|
117
122
|
], t.prototype, "name", 2);
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
s([
|
|
124
|
+
i({ type: Boolean, reflect: !0 })
|
|
120
125
|
], t.prototype, "checked", 2);
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
s([
|
|
127
|
+
i({ type: Boolean, reflect: !0 })
|
|
123
128
|
], t.prototype, "defaultChecked", 2);
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
s([
|
|
130
|
+
i({ type: Boolean, reflect: !0 })
|
|
126
131
|
], t.prototype, "disabled", 2);
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
s([
|
|
133
|
+
i({ type: Boolean, reflect: !0 })
|
|
129
134
|
], t.prototype, "required", 2);
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
s([
|
|
136
|
+
i({ type: Boolean, reflect: !0 })
|
|
132
137
|
], t.prototype, "indeterminate", 2);
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
s([
|
|
139
|
+
i({ type: Object })
|
|
135
140
|
], t.prototype, "aria", 2);
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
s([
|
|
142
|
+
C('input[type="checkbox"]')
|
|
138
143
|
], t.prototype, "checkbox", 2);
|
|
139
|
-
|
|
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);
|
|
140
152
|
export {
|
|
141
153
|
t as PieCheckbox,
|
|
142
|
-
|
|
154
|
+
n as defaultProps,
|
|
155
|
+
P as statusTypes
|
|
143
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 {
|
|
@@ -52,9 +51,17 @@ export declare interface CheckboxProps {
|
|
|
52
51
|
* Various ARIA attributes.
|
|
53
52
|
*/
|
|
54
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];
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked'>;
|
|
64
|
+
export declare type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
58
65
|
|
|
59
66
|
export declare const defaultProps: DefaultProps;
|
|
60
67
|
|
|
@@ -80,6 +87,8 @@ declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
|
|
|
80
87
|
indeterminate?: CheckboxProps['indeterminate'];
|
|
81
88
|
aria: CheckboxProps['aria'];
|
|
82
89
|
private checkbox;
|
|
90
|
+
assistiveText?: CheckboxProps['assistiveText'];
|
|
91
|
+
status?: CheckboxProps['status'];
|
|
83
92
|
/**
|
|
84
93
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
85
94
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -121,4 +130,6 @@ declare type PieCheckboxEvents = {
|
|
|
121
130
|
|
|
122
131
|
declare type ReactBaseType = React_2.InputHTMLAttributes<HTMLInputElement>;
|
|
123
132
|
|
|
133
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
134
|
+
|
|
124
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
|
/**
|
|
@@ -51,9 +52,19 @@ export interface CheckboxProps {
|
|
|
51
52
|
* Various ARIA attributes.
|
|
52
53
|
*/
|
|
53
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];
|
|
54
65
|
}
|
|
55
66
|
|
|
56
|
-
export type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked'>;
|
|
67
|
+
export type DefaultProps = ComponentDefaultPropsGeneric<CheckboxProps, 'value' | 'required' | 'indeterminate' | 'checked' | 'defaultChecked' | 'status'>;
|
|
57
68
|
|
|
58
69
|
export const defaultProps: DefaultProps = {
|
|
59
70
|
// a default value for the html <input type="checkbox" /> value attribute.
|
|
@@ -63,4 +74,5 @@ export const defaultProps: DefaultProps = {
|
|
|
63
74
|
defaultChecked: false,
|
|
64
75
|
indeterminate: false,
|
|
65
76
|
checked: false,
|
|
77
|
+
status: 'default',
|
|
66
78
|
};
|
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
|
|
@@ -56,6 +60,13 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
56
60
|
@query('input[type="checkbox"]')
|
|
57
61
|
private checkbox!: HTMLInputElement;
|
|
58
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;
|
|
69
|
+
|
|
59
70
|
/**
|
|
60
71
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
61
72
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
@@ -139,6 +150,8 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
139
150
|
required,
|
|
140
151
|
indeterminate,
|
|
141
152
|
aria,
|
|
153
|
+
assistiveText,
|
|
154
|
+
status,
|
|
142
155
|
} = this;
|
|
143
156
|
|
|
144
157
|
return html`
|
|
@@ -153,12 +166,13 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
153
166
|
.indeterminate=${!!indeterminate}
|
|
154
167
|
aria-label=${aria?.label || nothing}
|
|
155
168
|
aria-labelledby=${label ? nothing : aria?.labelledby || nothing}
|
|
156
|
-
aria-describedby
|
|
169
|
+
aria-describedby=${ifDefined(assistiveText ? assistiveTextIdValue : undefined)}
|
|
157
170
|
@change=${this.handleChange}
|
|
158
171
|
data-test-id="checkbox-input"
|
|
159
172
|
/>
|
|
160
173
|
${label}
|
|
161
|
-
</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}`;
|
|
162
176
|
}
|
|
163
177
|
|
|
164
178
|
// Renders a `CSSResult` generated from SCSS by Vite
|