@justeattakeaway/pie-checkbox-group 0.1.0 → 0.2.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 +43 -6
- package/custom-elements.json +166 -3
- package/dist/index.d.ts +47 -1
- package/dist/index.js +81 -9
- package/dist/react.d.ts +53 -3
- package/dist/react.js +17 -7
- package/package.json +2 -1
- package/src/defs-react.ts +2 -7
- package/src/defs.ts +44 -3
- package/src/index.ts +88 -6
- package/src/react.ts +10 -4
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
|
|
22
22
|
`pie-checkbox-group` is a Web Component built using the Lit library.
|
|
23
23
|
|
|
24
|
+
It is a helper component that groups PieCheckbox components into a visual and functional group.
|
|
25
|
+
|
|
24
26
|
This component can be easily integrated into various frontend frameworks and customized through a set of properties.
|
|
25
27
|
|
|
26
28
|
|
|
@@ -29,10 +31,9 @@ This component can be easily integrated into various frontend frameworks and cus
|
|
|
29
31
|
To install `pie-checkbox-group` in your application, run the following on your command line:
|
|
30
32
|
|
|
31
33
|
```bash
|
|
32
|
-
# npm
|
|
33
34
|
$ npm i @justeattakeaway/pie-checkbox-group
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
```
|
|
36
|
+
```bash
|
|
36
37
|
$ yarn add @justeattakeaway/pie-checkbox-group
|
|
37
38
|
```
|
|
38
39
|
|
|
@@ -74,18 +75,54 @@ import { PieCheckboxGroup } from '@justeattakeaway/pie-checkbox-group/dist/react
|
|
|
74
75
|
|
|
75
76
|
| Property | Type | Default | Description |
|
|
76
77
|
|---|---|---|---|
|
|
77
|
-
|
|
|
78
|
+
| `name` | string | - | The name associated with the group. |
|
|
79
|
+
| `label` | string | - | The label value of the component |
|
|
80
|
+
| `disabled` | boolean | - | Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled. |
|
|
81
|
+
| `assistiveText` | `string` | - | Allows assistive text to be displayed below the checkbox group. |
|
|
82
|
+
| `status` | `'default'`, `'error'`, `'success'` | `'default'` | The status of the checkbox group / assistive text. If you use `status` you must provide an `assistiveText` prop value for accessibility purposes. |
|
|
83
|
+
|
|
78
84
|
|
|
79
85
|
In your markup or JSX, you can then use these to set the properties for the `pie-checkbox-group` component:
|
|
80
86
|
|
|
81
87
|
```html
|
|
82
88
|
<!-- Native HTML -->
|
|
83
|
-
<pie-checkbox-group
|
|
89
|
+
<pie-checkbox-group name="TESTNAME">
|
|
90
|
+
<pie-checkbox
|
|
91
|
+
name="my-checkbox-one"
|
|
92
|
+
label="Checkbox Label 1">
|
|
93
|
+
</pie-checkbox>
|
|
94
|
+
<pie-checkbox
|
|
95
|
+
name="my-checkbox-two"
|
|
96
|
+
label="Checkbox Label 2">
|
|
97
|
+
</pie-checkbox>
|
|
98
|
+
<pie-checkbox
|
|
99
|
+
name="my-checkbox-three"
|
|
100
|
+
label="Checkbox Label 3">
|
|
101
|
+
</pie-checkbox>
|
|
102
|
+
</pie-checkbox-group>
|
|
84
103
|
|
|
85
104
|
<!-- JSX -->
|
|
86
|
-
<PieCheckboxGroup
|
|
105
|
+
<PieCheckboxGroup name="TESTNAME">
|
|
106
|
+
<PieCheckbox
|
|
107
|
+
name="my-checkbox-one"
|
|
108
|
+
label="Checkbox Label 1">
|
|
109
|
+
</PieCheckbox>
|
|
110
|
+
<PieCheckbox
|
|
111
|
+
name="my-checkbox-two"
|
|
112
|
+
label="Checkbox Label 2">
|
|
113
|
+
</PieCheckbox>
|
|
114
|
+
<PieCheckbox
|
|
115
|
+
name="my-checkbox-three"
|
|
116
|
+
label="Checkbox Label 3">
|
|
117
|
+
</PieCheckbox>
|
|
118
|
+
</PieCheckboxGroup>
|
|
87
119
|
```
|
|
88
120
|
|
|
121
|
+
## Events
|
|
122
|
+
| Event | Type | Description |
|
|
123
|
+
|-------|------|-------------|
|
|
124
|
+
| `pie-checkbox-group-disabled` | `CustomEvent` | Triggered after the disabled state of the checkbox group changes. |
|
|
125
|
+
|
|
89
126
|
## Contributing
|
|
90
127
|
|
|
91
128
|
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
|
@@ -11,8 +11,59 @@
|
|
|
11
11
|
{
|
|
12
12
|
"kind": "javascript-module",
|
|
13
13
|
"path": "src/defs.js",
|
|
14
|
-
"declarations": [
|
|
15
|
-
|
|
14
|
+
"declarations": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "variable",
|
|
17
|
+
"name": "statusTypes",
|
|
18
|
+
"type": {
|
|
19
|
+
"text": "['default', 'success', 'error']"
|
|
20
|
+
},
|
|
21
|
+
"default": "['default', 'success', 'error']"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"kind": "variable",
|
|
25
|
+
"name": "ON_CHECKBOX_GROUP_DISABLED",
|
|
26
|
+
"type": {
|
|
27
|
+
"text": "string"
|
|
28
|
+
},
|
|
29
|
+
"default": "'pie-checkbox-group-disabled'",
|
|
30
|
+
"description": "Event name for when checkbox group becomes disabled."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"kind": "variable",
|
|
34
|
+
"name": "defaultProps",
|
|
35
|
+
"type": {
|
|
36
|
+
"text": "DefaultProps"
|
|
37
|
+
},
|
|
38
|
+
"default": "{\n status: 'default',\n disabled: false,\n}"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"exports": [
|
|
42
|
+
{
|
|
43
|
+
"kind": "js",
|
|
44
|
+
"name": "statusTypes",
|
|
45
|
+
"declaration": {
|
|
46
|
+
"name": "statusTypes",
|
|
47
|
+
"module": "src/defs.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"kind": "js",
|
|
52
|
+
"name": "ON_CHECKBOX_GROUP_DISABLED",
|
|
53
|
+
"declaration": {
|
|
54
|
+
"name": "ON_CHECKBOX_GROUP_DISABLED",
|
|
55
|
+
"module": "src/defs.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"kind": "js",
|
|
60
|
+
"name": "defaultProps",
|
|
61
|
+
"declaration": {
|
|
62
|
+
"name": "defaultProps",
|
|
63
|
+
"module": "src/defs.js"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
16
67
|
},
|
|
17
68
|
{
|
|
18
69
|
"kind": "javascript-module",
|
|
@@ -22,8 +73,120 @@
|
|
|
22
73
|
"kind": "class",
|
|
23
74
|
"description": "",
|
|
24
75
|
"name": "PieCheckboxGroup",
|
|
25
|
-
"members": [
|
|
76
|
+
"members": [
|
|
77
|
+
{
|
|
78
|
+
"kind": "field",
|
|
79
|
+
"name": "name",
|
|
80
|
+
"type": {
|
|
81
|
+
"text": "CheckboxGroupProps['name'] | undefined"
|
|
82
|
+
},
|
|
83
|
+
"privacy": "public",
|
|
84
|
+
"attribute": "name"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"kind": "field",
|
|
88
|
+
"name": "label",
|
|
89
|
+
"type": {
|
|
90
|
+
"text": "CheckboxGroupProps['label'] | undefined"
|
|
91
|
+
},
|
|
92
|
+
"privacy": "public",
|
|
93
|
+
"attribute": "label"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"kind": "field",
|
|
97
|
+
"name": "assistiveText",
|
|
98
|
+
"type": {
|
|
99
|
+
"text": "CheckboxGroupProps['assistiveText'] | undefined"
|
|
100
|
+
},
|
|
101
|
+
"privacy": "public",
|
|
102
|
+
"attribute": "assistiveText"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"kind": "field",
|
|
106
|
+
"name": "status",
|
|
107
|
+
"privacy": "public",
|
|
108
|
+
"attribute": "status"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"kind": "field",
|
|
112
|
+
"name": "disabled",
|
|
113
|
+
"privacy": "public",
|
|
114
|
+
"attribute": "disabled",
|
|
115
|
+
"reflects": true
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"kind": "field",
|
|
119
|
+
"name": "_slottedChildren",
|
|
120
|
+
"type": {
|
|
121
|
+
"text": "Array<HTMLElement>"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"kind": "method",
|
|
126
|
+
"name": "_handleDisabled",
|
|
127
|
+
"privacy": "private",
|
|
128
|
+
"return": {
|
|
129
|
+
"type": {
|
|
130
|
+
"text": "void"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"kind": "method",
|
|
136
|
+
"name": "_handleStatus",
|
|
137
|
+
"privacy": "private",
|
|
138
|
+
"return": {
|
|
139
|
+
"type": {
|
|
140
|
+
"text": "void"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"events": [
|
|
146
|
+
{
|
|
147
|
+
"type": {
|
|
148
|
+
"text": "CustomEvent"
|
|
149
|
+
},
|
|
150
|
+
"description": "triggered after the disabled state of the checkbox group changes.",
|
|
151
|
+
"name": "pie-checkbox-group-disabled"
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"attributes": [
|
|
155
|
+
{
|
|
156
|
+
"name": "name",
|
|
157
|
+
"type": {
|
|
158
|
+
"text": "CheckboxGroupProps['name'] | undefined"
|
|
159
|
+
},
|
|
160
|
+
"fieldName": "name"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": "label",
|
|
164
|
+
"type": {
|
|
165
|
+
"text": "CheckboxGroupProps['label'] | undefined"
|
|
166
|
+
},
|
|
167
|
+
"fieldName": "label"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "assistiveText",
|
|
171
|
+
"type": {
|
|
172
|
+
"text": "CheckboxGroupProps['assistiveText'] | undefined"
|
|
173
|
+
},
|
|
174
|
+
"fieldName": "assistiveText"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "status",
|
|
178
|
+
"fieldName": "status"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"name": "disabled",
|
|
182
|
+
"fieldName": "disabled"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
26
185
|
"mixins": [
|
|
186
|
+
{
|
|
187
|
+
"name": "FormControlMixin",
|
|
188
|
+
"package": "@justeattakeaway/pie-webc-core"
|
|
189
|
+
},
|
|
27
190
|
{
|
|
28
191
|
"name": "RtlMixin",
|
|
29
192
|
"package": "@justeattakeaway/pie-webc-core"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,66 @@
|
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
1
2
|
import type { CSSResult } from 'lit';
|
|
3
|
+
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
2
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
3
5
|
import type { LitElement } from 'lit';
|
|
6
|
+
import type { PropertyValues } from 'lit';
|
|
4
7
|
import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
5
8
|
import type { TemplateResult } from 'lit-html';
|
|
6
9
|
|
|
7
10
|
export declare interface CheckboxGroupProps {
|
|
11
|
+
/**
|
|
12
|
+
* The name associated with the group.
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The label value of the component
|
|
17
|
+
*/
|
|
18
|
+
label?: string;
|
|
19
|
+
/**
|
|
20
|
+
* An optional assistive text to display below the checkbox group.
|
|
21
|
+
*/
|
|
22
|
+
assistiveText?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled.
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
29
|
+
*/
|
|
30
|
+
status?: typeof statusTypes[number];
|
|
8
31
|
}
|
|
9
32
|
|
|
33
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
34
|
+
|
|
35
|
+
export declare const defaultProps: DefaultProps;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Event name for when checkbox group becomes disabled.
|
|
39
|
+
*
|
|
40
|
+
* @constant
|
|
41
|
+
*/
|
|
42
|
+
export declare const ON_CHECKBOX_GROUP_DISABLED = "pie-checkbox-group-disabled";
|
|
43
|
+
|
|
10
44
|
/**
|
|
11
45
|
* @tagname pie-checkbox-group
|
|
46
|
+
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
12
47
|
*/
|
|
13
48
|
export declare class PieCheckboxGroup extends PieCheckboxGroup_base implements CheckboxGroupProps {
|
|
49
|
+
name?: CheckboxGroupProps['name'];
|
|
50
|
+
label?: CheckboxGroupProps['label'];
|
|
51
|
+
assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
52
|
+
status: "default" | "error" | "success";
|
|
53
|
+
disabled: boolean;
|
|
54
|
+
_slottedChildren: Array<HTMLElement>;
|
|
55
|
+
private _handleDisabled;
|
|
56
|
+
private _handleStatus;
|
|
57
|
+
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
14
58
|
render(): TemplateResult<1>;
|
|
15
59
|
static styles: CSSResult;
|
|
16
60
|
}
|
|
17
61
|
|
|
18
|
-
declare const PieCheckboxGroup_base: GenericConstructor<RTLInterface> & typeof LitElement;
|
|
62
|
+
declare const PieCheckboxGroup_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
63
|
+
|
|
64
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
19
65
|
|
|
20
66
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,86 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { LitElement as b, html as p, unsafeCSS as m } from "lit";
|
|
2
|
+
import { property as l, queryAssignedElements as v } from "lit/decorators.js";
|
|
3
|
+
import { FormControlMixin as y, RtlMixin as x, validPropertyValues as _, defineCustomElement as C } from "@justeattakeaway/pie-webc-core";
|
|
4
|
+
import { ifDefined as h } from "lit/directives/if-defined.js";
|
|
5
|
+
import "@justeattakeaway/pie-assistive-text";
|
|
6
|
+
const g = `*,*:after,*:before{box-sizing:inherit}
|
|
7
|
+
`, S = ["default", "success", "error"], E = "pie-checkbox-group-disabled", u = {
|
|
8
|
+
status: "default",
|
|
9
|
+
disabled: !1
|
|
10
|
+
};
|
|
11
|
+
var $ = Object.defineProperty, D = Object.getOwnPropertyDescriptor, a = (d, t, o, s) => {
|
|
12
|
+
for (var e = s > 1 ? void 0 : s ? D(t, o) : t, r = d.length - 1, n; r >= 0; r--)
|
|
13
|
+
(n = d[r]) && (e = (s ? n(t, o, e) : n(e)) || e);
|
|
14
|
+
return s && e && $(t, o, e), e;
|
|
15
|
+
};
|
|
16
|
+
const f = "pie-checkbox-group", c = "assistive-text";
|
|
17
|
+
class i extends y(x(b)) {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments), this.status = u.status, this.disabled = u.disabled;
|
|
20
|
+
}
|
|
21
|
+
_handleDisabled() {
|
|
22
|
+
this._slottedChildren && this._slottedChildren.forEach((t) => {
|
|
23
|
+
t.dispatchEvent(new CustomEvent(E, { bubbles: !1, composed: !1, detail: { disabled: this.disabled } }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
_handleStatus() {
|
|
27
|
+
this._slottedChildren && this._slottedChildren.forEach((t) => t.setAttribute("status", this.status));
|
|
28
|
+
}
|
|
29
|
+
updated(t) {
|
|
30
|
+
t.has("disabled") && this._handleDisabled(), t.has("status") && this._handleStatus();
|
|
31
|
+
}
|
|
6
32
|
render() {
|
|
7
|
-
|
|
33
|
+
const {
|
|
34
|
+
name: t,
|
|
35
|
+
label: o,
|
|
36
|
+
assistiveText: s,
|
|
37
|
+
status: e,
|
|
38
|
+
disabled: r
|
|
39
|
+
} = this;
|
|
40
|
+
return p`
|
|
41
|
+
<fieldset
|
|
42
|
+
name=${h(t)}
|
|
43
|
+
?disabled=${r}
|
|
44
|
+
aria-describedby="${h(s ? c : void 0)}"
|
|
45
|
+
data-test-id="pie-checkbox-group"
|
|
46
|
+
>
|
|
47
|
+
${o && p`<legend>${o}</legend>`}
|
|
48
|
+
<slot></slot>
|
|
49
|
+
</fieldset>
|
|
50
|
+
${s && p`
|
|
51
|
+
<pie-assistive-text
|
|
52
|
+
id="${c}"
|
|
53
|
+
variant=${e}
|
|
54
|
+
data-test-id="pie-checkbox-group-assistive-text">
|
|
55
|
+
${s}
|
|
56
|
+
</pie-assistive-text>`}
|
|
57
|
+
`;
|
|
8
58
|
}
|
|
9
59
|
}
|
|
10
|
-
|
|
11
|
-
|
|
60
|
+
i.styles = m(g);
|
|
61
|
+
a([
|
|
62
|
+
l({ type: String })
|
|
63
|
+
], i.prototype, "name", 2);
|
|
64
|
+
a([
|
|
65
|
+
l({ type: String })
|
|
66
|
+
], i.prototype, "label", 2);
|
|
67
|
+
a([
|
|
68
|
+
l({ type: String })
|
|
69
|
+
], i.prototype, "assistiveText", 2);
|
|
70
|
+
a([
|
|
71
|
+
l({ type: String }),
|
|
72
|
+
_(f, S, u.status)
|
|
73
|
+
], i.prototype, "status", 2);
|
|
74
|
+
a([
|
|
75
|
+
l({ type: Boolean, reflect: !0 })
|
|
76
|
+
], i.prototype, "disabled", 2);
|
|
77
|
+
a([
|
|
78
|
+
v({})
|
|
79
|
+
], i.prototype, "_slottedChildren", 2);
|
|
80
|
+
C(f, i);
|
|
12
81
|
export {
|
|
13
|
-
|
|
82
|
+
E as ON_CHECKBOX_GROUP_DISABLED,
|
|
83
|
+
i as PieCheckboxGroup,
|
|
84
|
+
u as defaultProps,
|
|
85
|
+
S as statusTypes
|
|
14
86
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,25 +1,75 @@
|
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
1
2
|
import type { CSSResult } from 'lit';
|
|
3
|
+
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
2
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
3
5
|
import type { LitElement } from 'lit';
|
|
6
|
+
import type { PropertyValues } from 'lit';
|
|
4
7
|
import * as React_2 from 'react';
|
|
5
8
|
import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
|
|
6
9
|
import type { TemplateResult } from 'lit-html';
|
|
7
10
|
|
|
8
11
|
export declare interface CheckboxGroupProps {
|
|
12
|
+
/**
|
|
13
|
+
* The name associated with the group.
|
|
14
|
+
*/
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The label value of the component
|
|
18
|
+
*/
|
|
19
|
+
label?: string;
|
|
20
|
+
/**
|
|
21
|
+
* An optional assistive text to display below the checkbox group.
|
|
22
|
+
*/
|
|
23
|
+
assistiveText?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled.
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
30
|
+
*/
|
|
31
|
+
status?: typeof statusTypes[number];
|
|
9
32
|
}
|
|
10
33
|
|
|
11
|
-
export declare
|
|
34
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
35
|
+
|
|
36
|
+
export declare const defaultProps: DefaultProps;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Event name for when checkbox group becomes disabled.
|
|
40
|
+
*
|
|
41
|
+
* @constant
|
|
42
|
+
*/
|
|
43
|
+
export declare const ON_CHECKBOX_GROUP_DISABLED = "pie-checkbox-group-disabled";
|
|
44
|
+
|
|
45
|
+
export declare const PieCheckboxGroup: React_2.ForwardRefExoticComponent<CheckboxGroupProps & React_2.RefAttributes<PieCheckboxGroup_2> & PieCheckboxGroupEvents & ReactBaseType>;
|
|
12
46
|
|
|
13
47
|
/**
|
|
14
48
|
* @tagname pie-checkbox-group
|
|
49
|
+
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
15
50
|
*/
|
|
16
51
|
declare class PieCheckboxGroup_2 extends PieCheckboxGroup_base implements CheckboxGroupProps {
|
|
52
|
+
name?: CheckboxGroupProps['name'];
|
|
53
|
+
label?: CheckboxGroupProps['label'];
|
|
54
|
+
assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
55
|
+
status: "default" | "error" | "success";
|
|
56
|
+
disabled: boolean;
|
|
57
|
+
_slottedChildren: Array<HTMLElement>;
|
|
58
|
+
private _handleDisabled;
|
|
59
|
+
private _handleStatus;
|
|
60
|
+
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
17
61
|
render(): TemplateResult<1>;
|
|
18
62
|
static styles: CSSResult;
|
|
19
63
|
}
|
|
20
64
|
|
|
21
|
-
declare const PieCheckboxGroup_base: GenericConstructor<RTLInterface> & typeof LitElement;
|
|
65
|
+
declare const PieCheckboxGroup_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
66
|
+
|
|
67
|
+
declare type PieCheckboxGroupEvents = {
|
|
68
|
+
onPieCheckboxGroupDisabled?: (event: CustomEvent) => void;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
declare type ReactBaseType = React_2.FieldsetHTMLAttributes<HTMLFieldSetElement>;
|
|
22
72
|
|
|
23
|
-
declare
|
|
73
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
24
74
|
|
|
25
75
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
1
|
+
import * as o from "react";
|
|
2
|
+
import { createComponent as e } from "@lit/react";
|
|
3
3
|
import { PieCheckboxGroup as r } from "./index.js";
|
|
4
|
+
import { ON_CHECKBOX_GROUP_DISABLED as h, defaultProps as k, statusTypes as P } from "./index.js";
|
|
4
5
|
import "lit";
|
|
6
|
+
import "lit/decorators.js";
|
|
5
7
|
import "@justeattakeaway/pie-webc-core";
|
|
6
|
-
|
|
8
|
+
import "lit/directives/if-defined.js";
|
|
9
|
+
import "@justeattakeaway/pie-assistive-text";
|
|
10
|
+
const p = e({
|
|
7
11
|
displayName: "PieCheckboxGroup",
|
|
8
12
|
elementClass: r,
|
|
9
|
-
react:
|
|
13
|
+
react: o,
|
|
10
14
|
tagName: "pie-checkbox-group",
|
|
11
|
-
events: {
|
|
12
|
-
|
|
15
|
+
events: {
|
|
16
|
+
onPieCheckboxGroupDisabled: "pie-checkbox-group-disabled"
|
|
17
|
+
// triggered after the disabled state of the checkbox group changes.
|
|
18
|
+
}
|
|
19
|
+
}), u = p;
|
|
13
20
|
export {
|
|
14
|
-
|
|
21
|
+
h as ON_CHECKBOX_GROUP_DISABLED,
|
|
22
|
+
u as PieCheckboxGroup,
|
|
23
|
+
k as defaultProps,
|
|
24
|
+
P as statusTypes
|
|
15
25
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-checkbox-group",
|
|
3
3
|
"description": "PIE Design System Checkbox Group built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.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.1",
|
|
43
44
|
"@justeattakeaway/pie-webc-core": "0.24.0"
|
|
44
45
|
},
|
|
45
46
|
"volta": {
|
package/src/defs-react.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Use the React IntrinsicElements interface to find how to map standard HTML elements to existing React Interfaces
|
|
5
|
-
* Example: an HTML button maps to `React.ButtonHTMLAttributes<HTMLButtonElement>`
|
|
6
|
-
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0bb210867d16170c4a08d9ce5d132817651a0f80/types/react/index.d.ts#L2829
|
|
7
|
-
*/
|
|
8
|
-
export type ReactBaseType = React.HTMLAttributes<HTMLElement>
|
|
2
|
+
|
|
3
|
+
export type ReactBaseType = React.FieldsetHTMLAttributes<HTMLFieldSetElement>
|
package/src/defs.ts
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
|
+
|
|
3
|
+
export const statusTypes = ['default', 'success', 'error'] as const;
|
|
4
|
+
|
|
5
|
+
export interface CheckboxGroupProps {
|
|
6
|
+
/**
|
|
7
|
+
* The name associated with the group.
|
|
8
|
+
*/
|
|
9
|
+
name?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The label value of the component
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An optional assistive text to display below the checkbox group.
|
|
18
|
+
*/
|
|
19
|
+
assistiveText?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled.
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The status of the checkbox component / assistive text. Can be default, success or error.
|
|
28
|
+
*/
|
|
29
|
+
status?: typeof statusTypes[number];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Event name for when checkbox group becomes disabled.
|
|
34
|
+
*
|
|
35
|
+
* @constant
|
|
36
|
+
*/
|
|
37
|
+
export const ON_CHECKBOX_GROUP_DISABLED = 'pie-checkbox-group-disabled';
|
|
38
|
+
|
|
39
|
+
export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
40
|
+
|
|
41
|
+
export const defaultProps: DefaultProps = {
|
|
42
|
+
status: 'default',
|
|
43
|
+
disabled: false,
|
|
44
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
LitElement, html, unsafeCSS, PropertyValues,
|
|
3
|
+
} from 'lit';
|
|
4
|
+
import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
5
|
+
import {
|
|
6
|
+
RtlMixin,
|
|
7
|
+
defineCustomElement,
|
|
8
|
+
FormControlMixin,
|
|
9
|
+
validPropertyValues,
|
|
10
|
+
} from '@justeattakeaway/pie-webc-core';
|
|
11
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
12
|
import styles from './checkbox-group.scss?inline';
|
|
5
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ON_CHECKBOX_GROUP_DISABLED,
|
|
15
|
+
CheckboxGroupProps,
|
|
16
|
+
defaultProps,
|
|
17
|
+
statusTypes,
|
|
18
|
+
} from './defs';
|
|
19
|
+
import '@justeattakeaway/pie-assistive-text';
|
|
6
20
|
|
|
7
21
|
// Valid values available to consumers
|
|
8
22
|
export * from './defs';
|
|
9
23
|
|
|
10
24
|
const componentSelector = 'pie-checkbox-group';
|
|
25
|
+
const assistiveTextId = 'assistive-text';
|
|
11
26
|
|
|
12
27
|
/**
|
|
13
28
|
* @tagname pie-checkbox-group
|
|
29
|
+
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
14
30
|
*/
|
|
15
|
-
export class PieCheckboxGroup extends RtlMixin(LitElement) implements CheckboxGroupProps {
|
|
31
|
+
export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) implements CheckboxGroupProps {
|
|
32
|
+
@property({ type: String })
|
|
33
|
+
public name?: CheckboxGroupProps['name'];
|
|
34
|
+
|
|
35
|
+
@property({ type: String })
|
|
36
|
+
public label?: CheckboxGroupProps['label'];
|
|
37
|
+
|
|
38
|
+
@property({ type: String })
|
|
39
|
+
public assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
40
|
+
|
|
41
|
+
@property({ type: String })
|
|
42
|
+
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
|
|
43
|
+
public status = defaultProps.status;
|
|
44
|
+
|
|
45
|
+
@property({ type: Boolean, reflect: true })
|
|
46
|
+
public disabled = defaultProps.disabled;
|
|
47
|
+
|
|
48
|
+
@queryAssignedElements({}) _slottedChildren!: Array<HTMLElement>;
|
|
49
|
+
|
|
50
|
+
private _handleDisabled () : void {
|
|
51
|
+
if (this._slottedChildren) {
|
|
52
|
+
this._slottedChildren.forEach((child) => {
|
|
53
|
+
child.dispatchEvent(new CustomEvent(ON_CHECKBOX_GROUP_DISABLED, { bubbles: false, composed: false, detail: { disabled: this.disabled } }));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _handleStatus () : void {
|
|
59
|
+
if (this._slottedChildren) {
|
|
60
|
+
this._slottedChildren.forEach((child) => child.setAttribute('status', this.status));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected updated (_changedProperties: PropertyValues<this>): void {
|
|
65
|
+
if (_changedProperties.has('disabled')) {
|
|
66
|
+
this._handleDisabled();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (_changedProperties.has('status')) {
|
|
70
|
+
this._handleStatus();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
16
74
|
render () {
|
|
17
|
-
|
|
75
|
+
const {
|
|
76
|
+
name,
|
|
77
|
+
label,
|
|
78
|
+
assistiveText,
|
|
79
|
+
status,
|
|
80
|
+
disabled,
|
|
81
|
+
} = this;
|
|
82
|
+
return html`
|
|
83
|
+
<fieldset
|
|
84
|
+
name=${ifDefined(name)}
|
|
85
|
+
?disabled=${disabled}
|
|
86
|
+
aria-describedby="${ifDefined(assistiveText ? assistiveTextId : undefined)}"
|
|
87
|
+
data-test-id="pie-checkbox-group"
|
|
88
|
+
>
|
|
89
|
+
${label && html`<legend>${label}</legend>`}
|
|
90
|
+
<slot></slot>
|
|
91
|
+
</fieldset>
|
|
92
|
+
${assistiveText && html`
|
|
93
|
+
<pie-assistive-text
|
|
94
|
+
id="${assistiveTextId}"
|
|
95
|
+
variant=${status}
|
|
96
|
+
data-test-id="pie-checkbox-group-assistive-text">
|
|
97
|
+
${assistiveText}
|
|
98
|
+
</pie-assistive-text>`}
|
|
99
|
+
`;
|
|
18
100
|
}
|
|
19
101
|
|
|
20
102
|
// Renders a `CSSResult` generated from SCSS by Vite
|
package/src/react.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createComponent } from '@lit/react';
|
|
2
|
+
import { createComponent, EventName } from '@lit/react';
|
|
3
3
|
import { PieCheckboxGroup as PieCheckboxGroupLit } from './index';
|
|
4
4
|
import { CheckboxGroupProps } from './defs';
|
|
5
5
|
|
|
@@ -10,10 +10,16 @@ const PieCheckboxGroupReact = createComponent({
|
|
|
10
10
|
elementClass: PieCheckboxGroupLit,
|
|
11
11
|
react: React,
|
|
12
12
|
tagName: 'pie-checkbox-group',
|
|
13
|
-
events: {
|
|
13
|
+
events: {
|
|
14
|
+
onPieCheckboxGroupDisabled: 'pie-checkbox-group-disabled' as EventName<CustomEvent>, // triggered after the disabled state of the checkbox group changes.
|
|
15
|
+
},
|
|
14
16
|
});
|
|
15
17
|
|
|
16
|
-
type ReactBaseType = React.
|
|
18
|
+
type ReactBaseType = React.FieldsetHTMLAttributes<HTMLFieldSetElement>
|
|
19
|
+
|
|
20
|
+
type PieCheckboxGroupEvents = {
|
|
21
|
+
onPieCheckboxGroupDisabled?: (event: CustomEvent) => void;
|
|
22
|
+
};
|
|
17
23
|
|
|
18
24
|
export const PieCheckboxGroup = PieCheckboxGroupReact as React.ForwardRefExoticComponent<React.PropsWithoutRef<CheckboxGroupProps>
|
|
19
|
-
& React.RefAttributes<PieCheckboxGroupLit> & ReactBaseType>;
|
|
25
|
+
& React.RefAttributes<PieCheckboxGroupLit> & PieCheckboxGroupEvents & ReactBaseType>;
|