@justeattakeaway/pie-checkbox-group 0.2.0 → 0.4.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 +7 -24
- package/custom-elements.json +41 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +75 -58
- package/dist/react.d.ts +12 -2
- package/dist/react.js +9 -5
- package/package.json +2 -2
- package/src/checkbox-group.scss +52 -0
- package/src/defs.ts +8 -1
- package/src/index.ts +28 -10
- package/src/react.ts +2 -0
package/README.md
CHANGED
|
@@ -87,34 +87,16 @@ In your markup or JSX, you can then use these to set the properties for the `pie
|
|
|
87
87
|
```html
|
|
88
88
|
<!-- Native HTML -->
|
|
89
89
|
<pie-checkbox-group name="TESTNAME">
|
|
90
|
-
<pie-checkbox
|
|
91
|
-
|
|
92
|
-
|
|
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>
|
|
90
|
+
<pie-checkbox name="my-checkbox-one">Checkbox Label 1</pie-checkbox>
|
|
91
|
+
<pie-checkbox name="my-checkbox-two">Checkbox Label 2</pie-checkbox>
|
|
92
|
+
<pie-checkbox name="my-checkbox-three">Checkbox Label 3</pie-checkbox>
|
|
102
93
|
</pie-checkbox-group>
|
|
103
94
|
|
|
104
95
|
<!-- JSX -->
|
|
105
96
|
<PieCheckboxGroup name="TESTNAME">
|
|
106
|
-
<PieCheckbox
|
|
107
|
-
|
|
108
|
-
|
|
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>
|
|
97
|
+
<PieCheckbox name="my-checkbox-one">Checkbox Label 1</PieCheckbox>
|
|
98
|
+
<PieCheckbox name="my-checkbox-two">Checkbox Label 2</PieCheckbox>
|
|
99
|
+
<PieCheckbox name="my-checkbox-three">Checkbox Label 3</PieCheckbox>
|
|
118
100
|
</PieCheckboxGroup>
|
|
119
101
|
```
|
|
120
102
|
|
|
@@ -122,6 +104,7 @@ In your markup or JSX, you can then use these to set the properties for the `pie
|
|
|
122
104
|
| Event | Type | Description |
|
|
123
105
|
|-------|------|-------------|
|
|
124
106
|
| `pie-checkbox-group-disabled` | `CustomEvent` | Triggered after the disabled state of the checkbox group changes. |
|
|
107
|
+
| `pie-checkbox-group-error` | `CustomEvent` | Triggered after the state of the checkbox group changes to error. |
|
|
125
108
|
|
|
126
109
|
## Contributing
|
|
127
110
|
|
package/custom-elements.json
CHANGED
|
@@ -29,13 +29,21 @@
|
|
|
29
29
|
"default": "'pie-checkbox-group-disabled'",
|
|
30
30
|
"description": "Event name for when checkbox group becomes disabled."
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
"kind": "variable",
|
|
34
|
+
"name": "ON_CHECKBOX_GROUP_ERROR",
|
|
35
|
+
"type": {
|
|
36
|
+
"text": "string"
|
|
37
|
+
},
|
|
38
|
+
"default": "'pie-checkbox-group-error'"
|
|
39
|
+
},
|
|
32
40
|
{
|
|
33
41
|
"kind": "variable",
|
|
34
42
|
"name": "defaultProps",
|
|
35
43
|
"type": {
|
|
36
44
|
"text": "DefaultProps"
|
|
37
45
|
},
|
|
38
|
-
"default": "{\n status: 'default',\n disabled: false,\n}"
|
|
46
|
+
"default": "{\n status: 'default',\n disabled: false,\n isInline: false,\n}"
|
|
39
47
|
}
|
|
40
48
|
],
|
|
41
49
|
"exports": [
|
|
@@ -55,6 +63,14 @@
|
|
|
55
63
|
"module": "src/defs.js"
|
|
56
64
|
}
|
|
57
65
|
},
|
|
66
|
+
{
|
|
67
|
+
"kind": "js",
|
|
68
|
+
"name": "ON_CHECKBOX_GROUP_ERROR",
|
|
69
|
+
"declaration": {
|
|
70
|
+
"name": "ON_CHECKBOX_GROUP_ERROR",
|
|
71
|
+
"module": "src/defs.js"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
58
74
|
{
|
|
59
75
|
"kind": "js",
|
|
60
76
|
"name": "defaultProps",
|
|
@@ -73,6 +89,12 @@
|
|
|
73
89
|
"kind": "class",
|
|
74
90
|
"description": "",
|
|
75
91
|
"name": "PieCheckboxGroup",
|
|
92
|
+
"slots": [
|
|
93
|
+
{
|
|
94
|
+
"description": "Default slot",
|
|
95
|
+
"name": ""
|
|
96
|
+
}
|
|
97
|
+
],
|
|
76
98
|
"members": [
|
|
77
99
|
{
|
|
78
100
|
"kind": "field",
|
|
@@ -101,6 +123,12 @@
|
|
|
101
123
|
"privacy": "public",
|
|
102
124
|
"attribute": "assistiveText"
|
|
103
125
|
},
|
|
126
|
+
{
|
|
127
|
+
"kind": "field",
|
|
128
|
+
"name": "isInline",
|
|
129
|
+
"privacy": "public",
|
|
130
|
+
"attribute": "isInline"
|
|
131
|
+
},
|
|
104
132
|
{
|
|
105
133
|
"kind": "field",
|
|
106
134
|
"name": "status",
|
|
@@ -118,7 +146,7 @@
|
|
|
118
146
|
"kind": "field",
|
|
119
147
|
"name": "_slottedChildren",
|
|
120
148
|
"type": {
|
|
121
|
-
"text": "Array<HTMLElement>"
|
|
149
|
+
"text": "Array<HTMLElement> | undefined"
|
|
122
150
|
}
|
|
123
151
|
},
|
|
124
152
|
{
|
|
@@ -149,6 +177,13 @@
|
|
|
149
177
|
},
|
|
150
178
|
"description": "triggered after the disabled state of the checkbox group changes.",
|
|
151
179
|
"name": "pie-checkbox-group-disabled"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"type": {
|
|
183
|
+
"text": "CustomEvent"
|
|
184
|
+
},
|
|
185
|
+
"description": "triggered after the state of the checkbox group changes to error.",
|
|
186
|
+
"name": "pie-checkbox-group-error"
|
|
152
187
|
}
|
|
153
188
|
],
|
|
154
189
|
"attributes": [
|
|
@@ -173,6 +208,10 @@
|
|
|
173
208
|
},
|
|
174
209
|
"fieldName": "assistiveText"
|
|
175
210
|
},
|
|
211
|
+
{
|
|
212
|
+
"name": "isInline",
|
|
213
|
+
"fieldName": "isInline"
|
|
214
|
+
},
|
|
176
215
|
{
|
|
177
216
|
"name": "status",
|
|
178
217
|
"fieldName": "status"
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ export declare interface CheckboxGroupProps {
|
|
|
16
16
|
* The label value of the component
|
|
17
17
|
*/
|
|
18
18
|
label?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Inline (horizontal) positioning of checkbox items
|
|
21
|
+
*/
|
|
22
|
+
isInline?: boolean;
|
|
19
23
|
/**
|
|
20
24
|
* An optional assistive text to display below the checkbox group.
|
|
21
25
|
*/
|
|
@@ -30,7 +34,7 @@ export declare interface CheckboxGroupProps {
|
|
|
30
34
|
status?: typeof statusTypes[number];
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
37
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled' | 'isInline'>;
|
|
34
38
|
|
|
35
39
|
export declare const defaultProps: DefaultProps;
|
|
36
40
|
|
|
@@ -41,17 +45,22 @@ export declare const defaultProps: DefaultProps;
|
|
|
41
45
|
*/
|
|
42
46
|
export declare const ON_CHECKBOX_GROUP_DISABLED = "pie-checkbox-group-disabled";
|
|
43
47
|
|
|
48
|
+
export declare const ON_CHECKBOX_GROUP_ERROR = "pie-checkbox-group-error";
|
|
49
|
+
|
|
44
50
|
/**
|
|
45
51
|
* @tagname pie-checkbox-group
|
|
52
|
+
* @slot - Default slot
|
|
46
53
|
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
54
|
+
* @event {CustomEvent} pie-checkbox-group-error - triggered after the state of the checkbox group changes to error.
|
|
47
55
|
*/
|
|
48
56
|
export declare class PieCheckboxGroup extends PieCheckboxGroup_base implements CheckboxGroupProps {
|
|
49
57
|
name?: CheckboxGroupProps['name'];
|
|
50
58
|
label?: CheckboxGroupProps['label'];
|
|
51
59
|
assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
60
|
+
isInline: boolean;
|
|
52
61
|
status: "default" | "error" | "success";
|
|
53
62
|
disabled: boolean;
|
|
54
|
-
_slottedChildren: Array<HTMLElement
|
|
63
|
+
_slottedChildren: Array<HTMLElement> | undefined;
|
|
55
64
|
private _handleDisabled;
|
|
56
65
|
private _handleStatus;
|
|
57
66
|
protected updated(_changedProperties: PropertyValues<this>): void;
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,103 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import { FormControlMixin as
|
|
4
|
-
import { ifDefined as
|
|
1
|
+
import { LitElement as x, html as d, unsafeCSS as g } from "lit";
|
|
2
|
+
import { property as r, queryAssignedElements as v } from "lit/decorators.js";
|
|
3
|
+
import { FormControlMixin as m, RtlMixin as k, validPropertyValues as y, defineCustomElement as G } from "@justeattakeaway/pie-webc-core";
|
|
4
|
+
import { ifDefined as b } from "lit/directives/if-defined.js";
|
|
5
|
+
import { classMap as _ } from "lit/directives/class-map.js";
|
|
5
6
|
import "@justeattakeaway/pie-assistive-text";
|
|
6
|
-
const
|
|
7
|
-
`,
|
|
7
|
+
const C = `*,*:after,*:before{box-sizing:inherit}.c-checkboxGroup{--checkbox-group-offset: var(--dt-spacing-c);--checkbox-group-offset--inline: var(--dt-spacing-e);--checkbox-group-label-offset: var(--dt-spacing-a);margin:0;padding:0;border:0;min-width:0}.c-checkboxGroup ::slotted(pie-checkbox){display:flex}.c-checkboxGroup:not(.c-checkboxGroup--inline) ::slotted(pie-checkbox:not(:first-child)){margin-block-start:var(--checkbox-group-offset)}.c-checkboxGroup--inline{display:flex;align-items:flex-start;flex-wrap:wrap}.c-checkboxGroup-label{max-width:100%;white-space:normal;padding:0;font-size:calc(var(--dt-font-body-strong-s-size) * 1px);line-height:calc(var(--dt-font-body-strong-s-line-height) * 1px);font-weight:var(--dt-font-body-strong-s-weight);color:var(--dt-color-content-default);margin-block-end:var(--checkbox-group-label-offset)}.c-checkboxGroup.c-checkboxGroup--inline{margin:calc(-1 * var(--checkbox-group-offset--inline) / 2) calc(-1 * var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline ::slotted(pie-checkbox){margin:calc(var(--checkbox-group-offset--inline) / 2) calc(var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline .c-checkboxGroup-label{margin:0 calc(var(--checkbox-group-offset--inline) / 2) calc(-1 * (var(--checkbox-group-offset--inline) / 2 - var(--checkbox-group-label-offset)))}
|
|
8
|
+
`, E = ["default", "success", "error"], w = "pie-checkbox-group-disabled", O = "pie-checkbox-group-error", n = {
|
|
8
9
|
status: "default",
|
|
9
|
-
disabled: !1
|
|
10
|
+
disabled: !1,
|
|
11
|
+
isInline: !1
|
|
10
12
|
};
|
|
11
|
-
var
|
|
12
|
-
for (var
|
|
13
|
-
(
|
|
14
|
-
return
|
|
13
|
+
var S = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, i = (p, e, t, c) => {
|
|
14
|
+
for (var s = c > 1 ? void 0 : c ? $(e, t) : e, a = p.length - 1, l; a >= 0; a--)
|
|
15
|
+
(l = p[a]) && (s = (c ? l(e, t, s) : l(s)) || s);
|
|
16
|
+
return c && s && S(e, t, s), s;
|
|
15
17
|
};
|
|
16
|
-
const
|
|
17
|
-
class
|
|
18
|
+
const u = "pie-checkbox-group", h = "assistive-text";
|
|
19
|
+
class o extends m(k(x)) {
|
|
18
20
|
constructor() {
|
|
19
|
-
super(...arguments), this.status =
|
|
21
|
+
super(...arguments), this.isInline = n.isInline, this.status = n.status, this.disabled = n.disabled;
|
|
20
22
|
}
|
|
21
23
|
_handleDisabled() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
var e;
|
|
25
|
+
(e = this._slottedChildren) == null || e.forEach((t) => t.dispatchEvent(new CustomEvent(w, {
|
|
26
|
+
bubbles: !1,
|
|
27
|
+
composed: !1,
|
|
28
|
+
detail: { disabled: this.disabled }
|
|
29
|
+
})));
|
|
25
30
|
}
|
|
26
31
|
_handleStatus() {
|
|
27
|
-
|
|
32
|
+
var e;
|
|
33
|
+
(e = this._slottedChildren) == null || e.forEach((t) => {
|
|
34
|
+
t.setAttribute("status", this.status), this.status === "error" && this.assistiveText && (t.setAttribute("assistiveText", this.assistiveText), t.dispatchEvent(new CustomEvent(O, { bubbles: !1, composed: !1, detail: { error: !0 } })));
|
|
35
|
+
});
|
|
28
36
|
}
|
|
29
|
-
updated(
|
|
30
|
-
|
|
37
|
+
updated(e) {
|
|
38
|
+
e.has("disabled") && this._handleDisabled(), e.has("status") && this._handleStatus();
|
|
31
39
|
}
|
|
32
40
|
render() {
|
|
33
41
|
const {
|
|
34
|
-
name:
|
|
35
|
-
label:
|
|
42
|
+
name: e,
|
|
43
|
+
label: t,
|
|
44
|
+
isInline: c,
|
|
36
45
|
assistiveText: s,
|
|
37
|
-
status:
|
|
38
|
-
disabled:
|
|
39
|
-
} = this
|
|
40
|
-
|
|
46
|
+
status: a,
|
|
47
|
+
disabled: l
|
|
48
|
+
} = this, f = {
|
|
49
|
+
"c-checkboxGroup": !0,
|
|
50
|
+
"c-checkboxGroup--inline": c
|
|
51
|
+
};
|
|
52
|
+
return d`
|
|
41
53
|
<fieldset
|
|
42
|
-
name=${
|
|
43
|
-
?disabled=${
|
|
44
|
-
aria-describedby="${
|
|
54
|
+
name=${b(e)}
|
|
55
|
+
?disabled=${l}
|
|
56
|
+
aria-describedby="${b(s ? h : void 0)}"
|
|
45
57
|
data-test-id="pie-checkbox-group"
|
|
58
|
+
class="${_(f)}"
|
|
46
59
|
>
|
|
47
|
-
${
|
|
60
|
+
${t && d`<legend class="c-checkboxGroup-label">${t}</legend>`}
|
|
48
61
|
<slot></slot>
|
|
49
62
|
</fieldset>
|
|
50
|
-
${s &&
|
|
63
|
+
${s && d`
|
|
51
64
|
<pie-assistive-text
|
|
52
|
-
id="${
|
|
53
|
-
variant=${
|
|
65
|
+
id="${h}"
|
|
66
|
+
variant=${a}
|
|
54
67
|
data-test-id="pie-checkbox-group-assistive-text">
|
|
55
68
|
${s}
|
|
56
69
|
</pie-assistive-text>`}
|
|
57
70
|
`;
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
],
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
],
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
],
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
],
|
|
80
|
-
|
|
73
|
+
o.styles = g(C);
|
|
74
|
+
i([
|
|
75
|
+
r({ type: String })
|
|
76
|
+
], o.prototype, "name", 2);
|
|
77
|
+
i([
|
|
78
|
+
r({ type: String })
|
|
79
|
+
], o.prototype, "label", 2);
|
|
80
|
+
i([
|
|
81
|
+
r({ type: String })
|
|
82
|
+
], o.prototype, "assistiveText", 2);
|
|
83
|
+
i([
|
|
84
|
+
r({ type: Boolean })
|
|
85
|
+
], o.prototype, "isInline", 2);
|
|
86
|
+
i([
|
|
87
|
+
r({ type: String }),
|
|
88
|
+
y(u, E, n.status)
|
|
89
|
+
], o.prototype, "status", 2);
|
|
90
|
+
i([
|
|
91
|
+
r({ type: Boolean, reflect: !0 })
|
|
92
|
+
], o.prototype, "disabled", 2);
|
|
93
|
+
i([
|
|
94
|
+
v({ selector: "pie-checkbox" })
|
|
95
|
+
], o.prototype, "_slottedChildren", 2);
|
|
96
|
+
G(u, o);
|
|
81
97
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
w as ON_CHECKBOX_GROUP_DISABLED,
|
|
99
|
+
O as ON_CHECKBOX_GROUP_ERROR,
|
|
100
|
+
o as PieCheckboxGroup,
|
|
101
|
+
n as defaultProps,
|
|
102
|
+
E as statusTypes
|
|
86
103
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export declare interface CheckboxGroupProps {
|
|
|
17
17
|
* The label value of the component
|
|
18
18
|
*/
|
|
19
19
|
label?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Inline (horizontal) positioning of checkbox items
|
|
22
|
+
*/
|
|
23
|
+
isInline?: boolean;
|
|
20
24
|
/**
|
|
21
25
|
* An optional assistive text to display below the checkbox group.
|
|
22
26
|
*/
|
|
@@ -31,7 +35,7 @@ export declare interface CheckboxGroupProps {
|
|
|
31
35
|
status?: typeof statusTypes[number];
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
38
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled' | 'isInline'>;
|
|
35
39
|
|
|
36
40
|
export declare const defaultProps: DefaultProps;
|
|
37
41
|
|
|
@@ -42,19 +46,24 @@ export declare const defaultProps: DefaultProps;
|
|
|
42
46
|
*/
|
|
43
47
|
export declare const ON_CHECKBOX_GROUP_DISABLED = "pie-checkbox-group-disabled";
|
|
44
48
|
|
|
49
|
+
export declare const ON_CHECKBOX_GROUP_ERROR = "pie-checkbox-group-error";
|
|
50
|
+
|
|
45
51
|
export declare const PieCheckboxGroup: React_2.ForwardRefExoticComponent<CheckboxGroupProps & React_2.RefAttributes<PieCheckboxGroup_2> & PieCheckboxGroupEvents & ReactBaseType>;
|
|
46
52
|
|
|
47
53
|
/**
|
|
48
54
|
* @tagname pie-checkbox-group
|
|
55
|
+
* @slot - Default slot
|
|
49
56
|
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
57
|
+
* @event {CustomEvent} pie-checkbox-group-error - triggered after the state of the checkbox group changes to error.
|
|
50
58
|
*/
|
|
51
59
|
declare class PieCheckboxGroup_2 extends PieCheckboxGroup_base implements CheckboxGroupProps {
|
|
52
60
|
name?: CheckboxGroupProps['name'];
|
|
53
61
|
label?: CheckboxGroupProps['label'];
|
|
54
62
|
assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
63
|
+
isInline: boolean;
|
|
55
64
|
status: "default" | "error" | "success";
|
|
56
65
|
disabled: boolean;
|
|
57
|
-
_slottedChildren: Array<HTMLElement
|
|
66
|
+
_slottedChildren: Array<HTMLElement> | undefined;
|
|
58
67
|
private _handleDisabled;
|
|
59
68
|
private _handleStatus;
|
|
60
69
|
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
@@ -66,6 +75,7 @@ declare const PieCheckboxGroup_base: GenericConstructor<FormControlInterface> &
|
|
|
66
75
|
|
|
67
76
|
declare type PieCheckboxGroupEvents = {
|
|
68
77
|
onPieCheckboxGroupDisabled?: (event: CustomEvent) => void;
|
|
78
|
+
onPieCheckboxGroupError?: (event: CustomEvent) => void;
|
|
69
79
|
};
|
|
70
80
|
|
|
71
81
|
declare type ReactBaseType = React_2.FieldsetHTMLAttributes<HTMLFieldSetElement>;
|
package/dist/react.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as o from "react";
|
|
2
2
|
import { createComponent as e } from "@lit/react";
|
|
3
3
|
import { PieCheckboxGroup as r } from "./index.js";
|
|
4
|
-
import { ON_CHECKBOX_GROUP_DISABLED as
|
|
4
|
+
import { ON_CHECKBOX_GROUP_DISABLED as k, ON_CHECKBOX_GROUP_ERROR as P, defaultProps as G, statusTypes as n } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
6
|
import "lit/decorators.js";
|
|
7
7
|
import "@justeattakeaway/pie-webc-core";
|
|
8
8
|
import "lit/directives/if-defined.js";
|
|
9
|
+
import "lit/directives/class-map.js";
|
|
9
10
|
import "@justeattakeaway/pie-assistive-text";
|
|
10
11
|
const p = e({
|
|
11
12
|
displayName: "PieCheckboxGroup",
|
|
@@ -13,13 +14,16 @@ const p = e({
|
|
|
13
14
|
react: o,
|
|
14
15
|
tagName: "pie-checkbox-group",
|
|
15
16
|
events: {
|
|
16
|
-
onPieCheckboxGroupDisabled: "pie-checkbox-group-disabled"
|
|
17
|
+
onPieCheckboxGroupDisabled: "pie-checkbox-group-disabled",
|
|
17
18
|
// triggered after the disabled state of the checkbox group changes.
|
|
19
|
+
onPieCheckboxGroupError: "pie-checkbox-group-error"
|
|
20
|
+
// triggered after the state of the checkbox group changes to error.
|
|
18
21
|
}
|
|
19
22
|
}), u = p;
|
|
20
23
|
export {
|
|
21
|
-
|
|
24
|
+
k as ON_CHECKBOX_GROUP_DISABLED,
|
|
25
|
+
P as ON_CHECKBOX_GROUP_ERROR,
|
|
22
26
|
u as PieCheckboxGroup,
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
G as defaultProps,
|
|
28
|
+
n as statusTypes
|
|
25
29
|
};
|
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.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@justeattakeaway/pie-assistive-text": "0.
|
|
43
|
+
"@justeattakeaway/pie-assistive-text": "0.6.0",
|
|
44
44
|
"@justeattakeaway/pie-webc-core": "0.24.0"
|
|
45
45
|
},
|
|
46
46
|
"volta": {
|
package/src/checkbox-group.scss
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
1
|
@use '@justeattakeaway/pie-css/scss' as p;
|
|
2
|
+
|
|
3
|
+
.c-checkboxGroup {
|
|
4
|
+
--checkbox-group-offset: var(--dt-spacing-c);
|
|
5
|
+
--checkbox-group-offset--inline: var(--dt-spacing-e);
|
|
6
|
+
--checkbox-group-label-offset: var(--dt-spacing-a);
|
|
7
|
+
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: 0;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
|
|
13
|
+
::slotted(pie-checkbox) {
|
|
14
|
+
display: flex;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&:not(.c-checkboxGroup--inline) {
|
|
18
|
+
::slotted(pie-checkbox:not(:first-child)) {
|
|
19
|
+
margin-block-start: var(--checkbox-group-offset);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.c-checkboxGroup--inline {
|
|
25
|
+
display: flex;
|
|
26
|
+
|
|
27
|
+
align-items: flex-start;
|
|
28
|
+
flex-wrap: wrap;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.c-checkboxGroup-label {
|
|
32
|
+
max-width: 100%;
|
|
33
|
+
white-space: normal;
|
|
34
|
+
padding: 0;
|
|
35
|
+
font-size: p.font-size(--dt-font-body-strong-s-size);
|
|
36
|
+
line-height: p.line-height(--dt-font-body-strong-s-line-height);
|
|
37
|
+
font-weight: var(--dt-font-body-strong-s-weight);
|
|
38
|
+
color: var(--dt-color-content-default);
|
|
39
|
+
|
|
40
|
+
margin-block-end: var(--checkbox-group-label-offset);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.c-checkboxGroup.c-checkboxGroup--inline {
|
|
44
|
+
margin: calc(-1 * var(--checkbox-group-offset--inline) / 2) calc(-1 * var(--checkbox-group-offset--inline) / 2);
|
|
45
|
+
|
|
46
|
+
::slotted(pie-checkbox) {
|
|
47
|
+
margin: calc(var(--checkbox-group-offset--inline) / 2) calc(var(--checkbox-group-offset--inline) / 2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.c-checkboxGroup-label {
|
|
51
|
+
margin: 0 calc(var(--checkbox-group-offset--inline) / 2) calc(-1 * (var(--checkbox-group-offset--inline) / 2 - var(--checkbox-group-label-offset)));
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/defs.ts
CHANGED
|
@@ -13,6 +13,11 @@ export interface CheckboxGroupProps {
|
|
|
13
13
|
*/
|
|
14
14
|
label?: string;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Inline (horizontal) positioning of checkbox items
|
|
18
|
+
*/
|
|
19
|
+
isInline?: boolean;
|
|
20
|
+
|
|
16
21
|
/**
|
|
17
22
|
* An optional assistive text to display below the checkbox group.
|
|
18
23
|
*/
|
|
@@ -35,10 +40,12 @@ export interface CheckboxGroupProps {
|
|
|
35
40
|
* @constant
|
|
36
41
|
*/
|
|
37
42
|
export const ON_CHECKBOX_GROUP_DISABLED = 'pie-checkbox-group-disabled';
|
|
43
|
+
export const ON_CHECKBOX_GROUP_ERROR = 'pie-checkbox-group-error';
|
|
38
44
|
|
|
39
|
-
export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
|
|
45
|
+
export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled' | 'isInline'>;
|
|
40
46
|
|
|
41
47
|
export const defaultProps: DefaultProps = {
|
|
42
48
|
status: 'default',
|
|
43
49
|
disabled: false,
|
|
50
|
+
isInline: false,
|
|
44
51
|
};
|
package/src/index.ts
CHANGED
|
@@ -9,9 +9,11 @@ import {
|
|
|
9
9
|
validPropertyValues,
|
|
10
10
|
} from '@justeattakeaway/pie-webc-core';
|
|
11
11
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
12
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
12
13
|
import styles from './checkbox-group.scss?inline';
|
|
13
14
|
import {
|
|
14
15
|
ON_CHECKBOX_GROUP_DISABLED,
|
|
16
|
+
ON_CHECKBOX_GROUP_ERROR,
|
|
15
17
|
CheckboxGroupProps,
|
|
16
18
|
defaultProps,
|
|
17
19
|
statusTypes,
|
|
@@ -26,7 +28,9 @@ const assistiveTextId = 'assistive-text';
|
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* @tagname pie-checkbox-group
|
|
31
|
+
* @slot - Default slot
|
|
29
32
|
* @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
|
|
33
|
+
* @event {CustomEvent} pie-checkbox-group-error - triggered after the state of the checkbox group changes to error.
|
|
30
34
|
*/
|
|
31
35
|
export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) implements CheckboxGroupProps {
|
|
32
36
|
@property({ type: String })
|
|
@@ -38,6 +42,9 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) imp
|
|
|
38
42
|
@property({ type: String })
|
|
39
43
|
public assistiveText?: CheckboxGroupProps['assistiveText'];
|
|
40
44
|
|
|
45
|
+
@property({ type: Boolean })
|
|
46
|
+
public isInline = defaultProps.isInline;
|
|
47
|
+
|
|
41
48
|
@property({ type: String })
|
|
42
49
|
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
|
|
43
50
|
public status = defaultProps.status;
|
|
@@ -45,20 +52,23 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) imp
|
|
|
45
52
|
@property({ type: Boolean, reflect: true })
|
|
46
53
|
public disabled = defaultProps.disabled;
|
|
47
54
|
|
|
48
|
-
@queryAssignedElements({}) _slottedChildren
|
|
55
|
+
@queryAssignedElements({ selector: 'pie-checkbox' }) _slottedChildren: Array<HTMLElement> | undefined;
|
|
49
56
|
|
|
50
57
|
private _handleDisabled () : void {
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
58
|
+
this._slottedChildren?.forEach((child) => child.dispatchEvent(new CustomEvent(ON_CHECKBOX_GROUP_DISABLED, {
|
|
59
|
+
bubbles: false, composed: false, detail: { disabled: this.disabled },
|
|
60
|
+
})));
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
private _handleStatus () : void {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
this._slottedChildren?.forEach((child) => {
|
|
65
|
+
child.setAttribute('status', this.status);
|
|
66
|
+
|
|
67
|
+
if (this.status === 'error' && this.assistiveText) {
|
|
68
|
+
child.setAttribute('assistiveText', this.assistiveText);
|
|
69
|
+
child.dispatchEvent(new CustomEvent(ON_CHECKBOX_GROUP_ERROR, { bubbles: false, composed: false, detail: { error: true } }));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
protected updated (_changedProperties: PropertyValues<this>): void {
|
|
@@ -75,18 +85,26 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) imp
|
|
|
75
85
|
const {
|
|
76
86
|
name,
|
|
77
87
|
label,
|
|
88
|
+
isInline,
|
|
78
89
|
assistiveText,
|
|
79
90
|
status,
|
|
80
91
|
disabled,
|
|
81
92
|
} = this;
|
|
93
|
+
|
|
94
|
+
const classes = {
|
|
95
|
+
'c-checkboxGroup': true,
|
|
96
|
+
'c-checkboxGroup--inline': isInline,
|
|
97
|
+
};
|
|
98
|
+
|
|
82
99
|
return html`
|
|
83
100
|
<fieldset
|
|
84
101
|
name=${ifDefined(name)}
|
|
85
102
|
?disabled=${disabled}
|
|
86
103
|
aria-describedby="${ifDefined(assistiveText ? assistiveTextId : undefined)}"
|
|
87
104
|
data-test-id="pie-checkbox-group"
|
|
105
|
+
class="${classMap(classes)}"
|
|
88
106
|
>
|
|
89
|
-
${label && html`<legend>${label}</legend>`}
|
|
107
|
+
${label && html`<legend class="c-checkboxGroup-label">${label}</legend>`}
|
|
90
108
|
<slot></slot>
|
|
91
109
|
</fieldset>
|
|
92
110
|
${assistiveText && html`
|
package/src/react.ts
CHANGED
|
@@ -12,6 +12,7 @@ const PieCheckboxGroupReact = createComponent({
|
|
|
12
12
|
tagName: 'pie-checkbox-group',
|
|
13
13
|
events: {
|
|
14
14
|
onPieCheckboxGroupDisabled: 'pie-checkbox-group-disabled' as EventName<CustomEvent>, // triggered after the disabled state of the checkbox group changes.
|
|
15
|
+
onPieCheckboxGroupError: 'pie-checkbox-group-error' as EventName<CustomEvent>, // triggered after the state of the checkbox group changes to error.
|
|
15
16
|
},
|
|
16
17
|
});
|
|
17
18
|
|
|
@@ -19,6 +20,7 @@ type ReactBaseType = React.FieldsetHTMLAttributes<HTMLFieldSetElement>
|
|
|
19
20
|
|
|
20
21
|
type PieCheckboxGroupEvents = {
|
|
21
22
|
onPieCheckboxGroupDisabled?: (event: CustomEvent) => void;
|
|
23
|
+
onPieCheckboxGroupError?: (event: CustomEvent) => void;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export const PieCheckboxGroup = PieCheckboxGroupReact as React.ForwardRefExoticComponent<React.PropsWithoutRef<CheckboxGroupProps>
|