@justeattakeaway/pie-checkbox-group 0.2.0 → 0.3.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
 
@@ -35,7 +35,7 @@
35
35
  "type": {
36
36
  "text": "DefaultProps"
37
37
  },
38
- "default": "{\n status: 'default',\n disabled: false,\n}"
38
+ "default": "{\n status: 'default',\n disabled: false,\n isInline: false,\n}"
39
39
  }
40
40
  ],
41
41
  "exports": [
@@ -73,6 +73,12 @@
73
73
  "kind": "class",
74
74
  "description": "",
75
75
  "name": "PieCheckboxGroup",
76
+ "slots": [
77
+ {
78
+ "description": "Default slot",
79
+ "name": ""
80
+ }
81
+ ],
76
82
  "members": [
77
83
  {
78
84
  "kind": "field",
@@ -101,6 +107,12 @@
101
107
  "privacy": "public",
102
108
  "attribute": "assistiveText"
103
109
  },
110
+ {
111
+ "kind": "field",
112
+ "name": "isInline",
113
+ "privacy": "public",
114
+ "attribute": "isInline"
115
+ },
104
116
  {
105
117
  "kind": "field",
106
118
  "name": "status",
@@ -173,6 +185,10 @@
173
185
  },
174
186
  "fieldName": "assistiveText"
175
187
  },
188
+ {
189
+ "name": "isInline",
190
+ "fieldName": "isInline"
191
+ },
176
192
  {
177
193
  "name": "status",
178
194
  "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
 
@@ -43,12 +47,14 @@ export declare const ON_CHECKBOX_GROUP_DISABLED = "pie-checkbox-group-disabled";
43
47
 
44
48
  /**
45
49
  * @tagname pie-checkbox-group
50
+ * @slot - Default slot
46
51
  * @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
47
52
  */
48
53
  export declare class PieCheckboxGroup extends PieCheckboxGroup_base implements CheckboxGroupProps {
49
54
  name?: CheckboxGroupProps['name'];
50
55
  label?: CheckboxGroupProps['label'];
51
56
  assistiveText?: CheckboxGroupProps['assistiveText'];
57
+ isInline: boolean;
52
58
  status: "default" | "error" | "success";
53
59
  disabled: boolean;
54
60
  _slottedChildren: Array<HTMLElement>;
package/dist/index.js CHANGED
@@ -1,86 +1,96 @@
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";
1
+ import { LitElement as x, html as d, unsafeCSS as g } from "lit";
2
+ import { property as r, queryAssignedElements as m } from "lit/decorators.js";
3
+ import { FormControlMixin as v, RtlMixin as k, validPropertyValues as y, defineCustomElement as G } from "@justeattakeaway/pie-webc-core";
4
4
  import { ifDefined as h } 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
+ `, w = ["default", "success", "error"], S = "pie-checkbox-group-disabled", 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 $ = Object.defineProperty, E = Object.getOwnPropertyDescriptor, s = (p, e, i, c) => {
14
+ for (var t = c > 1 ? void 0 : c ? E(e, i) : e, a = p.length - 1, l; a >= 0; a--)
15
+ (l = p[a]) && (t = (c ? l(e, i, t) : l(t)) || t);
16
+ return c && t && $(e, i, t), t;
15
17
  };
16
- const f = "pie-checkbox-group", c = "assistive-text";
17
- class i extends y(x(b)) {
18
+ const f = "pie-checkbox-group", b = "assistive-text";
19
+ class o extends v(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
+ this._slottedChildren && this._slottedChildren.forEach((e) => {
25
+ e.dispatchEvent(new CustomEvent(S, { bubbles: !1, composed: !1, detail: { disabled: this.disabled } }));
24
26
  });
25
27
  }
26
28
  _handleStatus() {
27
- this._slottedChildren && this._slottedChildren.forEach((t) => t.setAttribute("status", this.status));
29
+ this._slottedChildren && this._slottedChildren.forEach((e) => e.setAttribute("status", this.status));
28
30
  }
29
- updated(t) {
30
- t.has("disabled") && this._handleDisabled(), t.has("status") && this._handleStatus();
31
+ updated(e) {
32
+ e.has("disabled") && this._handleDisabled(), e.has("status") && this._handleStatus();
31
33
  }
32
34
  render() {
33
35
  const {
34
- name: t,
35
- label: o,
36
- assistiveText: s,
37
- status: e,
38
- disabled: r
39
- } = this;
40
- return p`
36
+ name: e,
37
+ label: i,
38
+ isInline: c,
39
+ assistiveText: t,
40
+ status: a,
41
+ disabled: l
42
+ } = this, u = {
43
+ "c-checkboxGroup": !0,
44
+ "c-checkboxGroup--inline": c
45
+ };
46
+ return d`
41
47
  <fieldset
42
- name=${h(t)}
43
- ?disabled=${r}
44
- aria-describedby="${h(s ? c : void 0)}"
48
+ name=${h(e)}
49
+ ?disabled=${l}
50
+ aria-describedby="${h(t ? b : void 0)}"
45
51
  data-test-id="pie-checkbox-group"
52
+ class="${_(u)}"
46
53
  >
47
- ${o && p`<legend>${o}</legend>`}
54
+ ${i && d`<legend class="c-checkboxGroup-label">${i}</legend>`}
48
55
  <slot></slot>
49
56
  </fieldset>
50
- ${s && p`
57
+ ${t && d`
51
58
  <pie-assistive-text
52
- id="${c}"
53
- variant=${e}
59
+ id="${b}"
60
+ variant=${a}
54
61
  data-test-id="pie-checkbox-group-assistive-text">
55
- ${s}
62
+ ${t}
56
63
  </pie-assistive-text>`}
57
64
  `;
58
65
  }
59
66
  }
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);
67
+ o.styles = g(C);
68
+ s([
69
+ r({ type: String })
70
+ ], o.prototype, "name", 2);
71
+ s([
72
+ r({ type: String })
73
+ ], o.prototype, "label", 2);
74
+ s([
75
+ r({ type: String })
76
+ ], o.prototype, "assistiveText", 2);
77
+ s([
78
+ r({ type: Boolean })
79
+ ], o.prototype, "isInline", 2);
80
+ s([
81
+ r({ type: String }),
82
+ y(f, w, n.status)
83
+ ], o.prototype, "status", 2);
84
+ s([
85
+ r({ type: Boolean, reflect: !0 })
86
+ ], o.prototype, "disabled", 2);
87
+ s([
88
+ m({})
89
+ ], o.prototype, "_slottedChildren", 2);
90
+ G(f, o);
81
91
  export {
82
- E as ON_CHECKBOX_GROUP_DISABLED,
83
- i as PieCheckboxGroup,
84
- u as defaultProps,
85
- S as statusTypes
92
+ S as ON_CHECKBOX_GROUP_DISABLED,
93
+ o as PieCheckboxGroup,
94
+ n as defaultProps,
95
+ w as statusTypes
86
96
  };
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
 
@@ -46,12 +50,14 @@ export declare const PieCheckboxGroup: React_2.ForwardRefExoticComponent<Checkbo
46
50
 
47
51
  /**
48
52
  * @tagname pie-checkbox-group
53
+ * @slot - Default slot
49
54
  * @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
50
55
  */
51
56
  declare class PieCheckboxGroup_2 extends PieCheckboxGroup_base implements CheckboxGroupProps {
52
57
  name?: CheckboxGroupProps['name'];
53
58
  label?: CheckboxGroupProps['label'];
54
59
  assistiveText?: CheckboxGroupProps['assistiveText'];
60
+ isInline: boolean;
55
61
  status: "default" | "error" | "success";
56
62
  disabled: boolean;
57
63
  _slottedChildren: Array<HTMLElement>;
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, defaultProps as P, 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",
@@ -16,10 +17,10 @@ const p = e({
16
17
  onPieCheckboxGroupDisabled: "pie-checkbox-group-disabled"
17
18
  // triggered after the disabled state of the checkbox group changes.
18
19
  }
19
- }), u = p;
20
+ }), x = p;
20
21
  export {
21
- h as ON_CHECKBOX_GROUP_DISABLED,
22
- u as PieCheckboxGroup,
23
- k as defaultProps,
24
- P as statusTypes
22
+ k as ON_CHECKBOX_GROUP_DISABLED,
23
+ x as PieCheckboxGroup,
24
+ P as defaultProps,
25
+ n as statusTypes
25
26
  };
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.3.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -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
  */
@@ -36,9 +41,10 @@ export interface CheckboxGroupProps {
36
41
  */
37
42
  export const ON_CHECKBOX_GROUP_DISABLED = 'pie-checkbox-group-disabled';
38
43
 
39
- export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;
44
+ export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled' | 'isInline'>;
40
45
 
41
46
  export const defaultProps: DefaultProps = {
42
47
  status: 'default',
43
48
  disabled: false,
49
+ isInline: false,
44
50
  };
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ 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,
@@ -26,6 +27,7 @@ const assistiveTextId = 'assistive-text';
26
27
 
27
28
  /**
28
29
  * @tagname pie-checkbox-group
30
+ * @slot - Default slot
29
31
  * @event {CustomEvent} pie-checkbox-group-disabled - triggered after the disabled state of the checkbox group changes.
30
32
  */
31
33
  export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) implements CheckboxGroupProps {
@@ -38,6 +40,9 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) imp
38
40
  @property({ type: String })
39
41
  public assistiveText?: CheckboxGroupProps['assistiveText'];
40
42
 
43
+ @property({ type: Boolean })
44
+ public isInline = defaultProps.isInline;
45
+
41
46
  @property({ type: String })
42
47
  @validPropertyValues(componentSelector, statusTypes, defaultProps.status)
43
48
  public status = defaultProps.status;
@@ -75,18 +80,26 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(LitElement)) imp
75
80
  const {
76
81
  name,
77
82
  label,
83
+ isInline,
78
84
  assistiveText,
79
85
  status,
80
86
  disabled,
81
87
  } = this;
88
+
89
+ const classes = {
90
+ 'c-checkboxGroup': true,
91
+ 'c-checkboxGroup--inline': isInline,
92
+ };
93
+
82
94
  return html`
83
95
  <fieldset
84
96
  name=${ifDefined(name)}
85
97
  ?disabled=${disabled}
86
98
  aria-describedby="${ifDefined(assistiveText ? assistiveTextId : undefined)}"
87
99
  data-test-id="pie-checkbox-group"
100
+ class="${classMap(classes)}"
88
101
  >
89
- ${label && html`<legend>${label}</legend>`}
102
+ ${label && html`<legend class="c-checkboxGroup-label">${label}</legend>`}
90
103
  <slot></slot>
91
104
  </fieldset>
92
105
  ${assistiveText && html`