@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 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
- 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>
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
- 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>
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
 
@@ -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 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";
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 g = `*,*:after,*:before{box-sizing:inherit}
7
- `, S = ["default", "success", "error"], E = "pie-checkbox-group-disabled", u = {
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 $ = 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;
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 f = "pie-checkbox-group", c = "assistive-text";
17
- class i extends y(x(b)) {
18
+ const u = "pie-checkbox-group", h = "assistive-text";
19
+ class o extends m(k(x)) {
18
20
  constructor() {
19
- super(...arguments), this.status = u.status, this.disabled = u.disabled;
21
+ super(...arguments), this.isInline = n.isInline, this.status = n.status, this.disabled = n.disabled;
20
22
  }
21
23
  _handleDisabled() {
22
- this._slottedChildren && this._slottedChildren.forEach((t) => {
23
- t.dispatchEvent(new CustomEvent(E, { bubbles: !1, composed: !1, detail: { disabled: this.disabled } }));
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
- this._slottedChildren && this._slottedChildren.forEach((t) => t.setAttribute("status", this.status));
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(t) {
30
- t.has("disabled") && this._handleDisabled(), t.has("status") && this._handleStatus();
37
+ updated(e) {
38
+ e.has("disabled") && this._handleDisabled(), e.has("status") && this._handleStatus();
31
39
  }
32
40
  render() {
33
41
  const {
34
- name: t,
35
- label: o,
42
+ name: e,
43
+ label: t,
44
+ isInline: c,
36
45
  assistiveText: s,
37
- status: e,
38
- disabled: r
39
- } = this;
40
- return p`
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=${h(t)}
43
- ?disabled=${r}
44
- aria-describedby="${h(s ? c : void 0)}"
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
- ${o && p`<legend>${o}</legend>`}
60
+ ${t && d`<legend class="c-checkboxGroup-label">${t}</legend>`}
48
61
  <slot></slot>
49
62
  </fieldset>
50
- ${s && p`
63
+ ${s && d`
51
64
  <pie-assistive-text
52
- id="${c}"
53
- variant=${e}
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
- 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);
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
- E as ON_CHECKBOX_GROUP_DISABLED,
83
- i as PieCheckboxGroup,
84
- u as defaultProps,
85
- S as statusTypes
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 h, defaultProps as k, statusTypes as P } from "./index.js";
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
- h as ON_CHECKBOX_GROUP_DISABLED,
24
+ k as ON_CHECKBOX_GROUP_DISABLED,
25
+ P as ON_CHECKBOX_GROUP_ERROR,
22
26
  u as PieCheckboxGroup,
23
- k as defaultProps,
24
- P as statusTypes
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.2.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.5.1",
43
+ "@justeattakeaway/pie-assistive-text": "0.6.0",
44
44
  "@justeattakeaway/pie-webc-core": "0.24.0"
45
45
  },
46
46
  "volta": {
@@ -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!: Array<HTMLElement>;
55
+ @queryAssignedElements({ selector: 'pie-checkbox' }) _slottedChildren: Array<HTMLElement> | undefined;
49
56
 
50
57
  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
- }
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
- if (this._slottedChildren) {
60
- this._slottedChildren.forEach((child) => child.setAttribute('status', this.status));
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>