@justeattakeaway/pie-checkbox-group 1.1.6 → 1.2.1

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
@@ -43,7 +43,7 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
43
43
 
44
44
  | **Slot** | **Description** |
45
45
  |--------------|----------------------------------------------------------------------------------|
46
- | `default` | Pass `PieCheckbox` components as direct children for the `CheckboxGroup`. |
46
+ | `default` | Either `pie-checkbox` components, or [`pie-list-item`](https://webc.pie.design/?path=/docs/components-list--overview) components that each slot a `pie-checkbox` for a list-style layout (see [List items in a checkbox group](#list-items-in-a-checkbox-group)). Do not add other HTML. |
47
47
  | `label` | Pass `PieFormLabel` to render the checkbox group label. |
48
48
 
49
49
  ### CSS Variables
@@ -107,6 +107,44 @@ import { PieFormLabel } from '@justeattakeaway/pie-webc/react/form-label.js';
107
107
  </PieCheckboxGroup>
108
108
  ```
109
109
 
110
+ ### List items in a checkbox group
111
+
112
+ For a list-style layout (each option on its own row with primary and secondary text, and dividers between rows), wrap each `pie-checkbox` in a [`pie-list-item`](https://webc.pie.design/?path=/docs/components-list--overview) with `selection-type="checkbox"` and place them inside the group. The checkbox goes in the item's `leading` (or `trailing`) slot, and you provide the label through the item's `primaryText` rather than as the checkbox's content.
113
+
114
+ `selection-type="checkbox"` makes each item a selectable row:
115
+
116
+ - the item takes a `presentation` role, so the group still owns its checkbox descendants directly;
117
+ - the item's `primaryText` becomes the checkbox's accessible name, and its `secondaryText` and `metaText` its description (applied to the checkbox's internal input), so you do not pass label text to the checkbox itself;
118
+ - the visible item text is hidden from assistive technology so it is not announced twice;
119
+ - clicking anywhere on a row toggles that row's checkbox.
120
+
121
+ Set `disabled` on a `pie-list-item` to disable that row (alongside the checkbox's own `disabled`); disabling the group disables every row.
122
+
123
+ The group lays the items out as a single divided list; selection is independent per checkbox, exactly as in a standard checkbox group.
124
+
125
+ ```js
126
+ import '@justeattakeaway/pie-webc/components/checkbox-group.js';
127
+ import '@justeattakeaway/pie-webc/components/checkbox.js';
128
+ import '@justeattakeaway/pie-webc/components/list-item.js';
129
+ ```
130
+
131
+ ```html
132
+ <pie-checkbox-group>
133
+ <pie-list-item selection-type="checkbox" primaryText="Cheese" secondaryText="Extra mature" metaText="Free">
134
+ <pie-checkbox slot="leading" name="cheese"></pie-checkbox>
135
+ </pie-list-item>
136
+ <pie-list-item selection-type="checkbox" primaryText="Pepperoni" secondaryText="Spicy">
137
+ <pie-checkbox slot="leading" name="pepperoni"></pie-checkbox>
138
+ </pie-list-item>
139
+ <pie-list-item selection-type="checkbox" disabled primaryText="Mushrooms">
140
+ <pie-checkbox slot="leading" name="mushrooms" disabled></pie-checkbox>
141
+ </pie-list-item>
142
+ <pie-list-item selection-type="checkbox" primaryText="Olives" metaText="£0.50">
143
+ <pie-checkbox slot="leading" name="olives"></pie-checkbox>
144
+ </pie-list-item>
145
+ </pie-checkbox-group>
146
+ ```
147
+
110
148
  ## Questions and Support
111
149
 
112
150
  If you work at Just Eat Takeaway.com, please contact us on **#help-designsystem**. Otherwise, please raise an issue on [Github](https://github.com/justeattakeaway/pie/issues).
@@ -147,12 +147,20 @@
147
147
  "attribute": "disabled",
148
148
  "reflects": true
149
149
  },
150
+ {
151
+ "kind": "field",
152
+ "name": "_disabledProvider",
153
+ "privacy": "private"
154
+ },
150
155
  {
151
156
  "kind": "field",
152
157
  "name": "_slottedChildren",
153
158
  "type": {
154
- "text": "Array<HTMLElement>"
155
- }
159
+ "text": "HTMLElement[]"
160
+ },
161
+ "privacy": "private",
162
+ "description": "The checkboxes in the group. This uses a subtree query rather than immediate slotted\nchildren so checkboxes wrapped in other components (at any depth) are discovered.",
163
+ "readonly": true
156
164
  },
157
165
  {
158
166
  "kind": "method",
package/dist/index.d.ts CHANGED
@@ -57,7 +57,12 @@ export declare class PieCheckboxGroup extends PieCheckboxGroup_base implements C
57
57
  isInline: boolean;
58
58
  status: "default" | "success" | "error";
59
59
  disabled: boolean;
60
- _slottedChildren: Array<HTMLElement>;
60
+ private _disabledProvider;
61
+ /**
62
+ * The checkboxes in the group. This uses a subtree query rather than immediate slotted
63
+ * children so checkboxes wrapped in other components (at any depth) are discovered.
64
+ */
65
+ private get _slottedChildren();
61
66
  private _handleDisabled;
62
67
  private _handleStatus;
63
68
  /**
package/dist/index.js CHANGED
@@ -1,41 +1,122 @@
1
- import { LitElement as x, html as n, unsafeCSS as g } from "lit";
2
- import { state as v, property as l, queryAssignedElements as k } from "lit/decorators.js";
3
- import { FormControlMixin as m, RtlMixin as y, validPropertyValues as _, safeCustomElement as G } from "@justeattakeaway/pie-webc-core";
4
- import { ifDefined as u } from "lit/directives/if-defined.js";
5
- import { classMap as C } from "lit/directives/class-map.js";
1
+ import { LitElement as m, isServer as k, html as p, unsafeCSS as y } from "lit";
2
+ import { state as C, property as d } from "lit/decorators.js";
3
+ import { FormControlMixin as _, RtlMixin as G, parentDisabledContext as E, validPropertyValues as S, safeCustomElement as O } from "@justeattakeaway/pie-webc-core";
4
+ import { ifDefined as v } from "lit/directives/if-defined.js";
5
+ import { classMap as P } from "lit/directives/class-map.js";
6
6
  import "@justeattakeaway/pie-assistive-text";
7
- const d = class d extends x {
7
+ const u = class u extends m {
8
8
  willUpdate() {
9
- this.getAttribute("v") || this.setAttribute("v", d.v);
9
+ this.getAttribute("v") || this.setAttribute("v", u.v);
10
10
  }
11
11
  };
12
- d.v = "1.1.6";
13
- let b = d;
14
- const S = "*,*:after,*:before{box-sizing:inherit}:host{display:block}.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 ::slotted(pie-form-label){display:block;padding-block-end:var(--checkbox-group-label-offset)}.c-checkboxGroup:not(.c-checkboxGroup--inline) ::slotted(pie-checkbox:not(:last-child)){margin-block-end:var(--checkbox-group-offset)}.c-checkboxGroup--inline{display:flex;align-items:flex-start;flex-wrap:wrap}.c-checkboxGroup.c-checkboxGroup--inline{margin:calc(-1 * var(--checkbox-group-offset) / 2) calc(-1 * var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline ::slotted(pie-checkbox){margin:calc(var(--checkbox-group-offset) / 2) calc(var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline ::slotted(pie-form-label){margin:0 calc(var(--checkbox-group-offset--inline) / 2) calc(-1 * (var(--checkbox-group-offset) / 2 - var(--checkbox-group-label-offset)));padding-block-end:0}.c-checkboxGroup-assistiveText{--checkbox-group-assistive-text-offset: var(--dt-spacing-a);display:block;margin-block-start:var(--checkbox-group-assistive-text-offset)}", E = ["default", "success", "error"], O = "pie-checkbox-group-disabled", $ = "pie-checkbox-group-error", p = {
12
+ u.v = "1.2.1";
13
+ let x = u;
14
+ /**
15
+ * @license
16
+ * Copyright 2021 Google LLC
17
+ * SPDX-License-Identifier: BSD-3-Clause
18
+ */
19
+ let w = class extends Event {
20
+ constructor(t, e, o, i) {
21
+ super("context-request", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e, this.callback = o, this.subscribe = i ?? !1;
22
+ }
23
+ };
24
+ /**
25
+ * @license
26
+ * Copyright 2021 Google LLC
27
+ * SPDX-License-Identifier: BSD-3-Clause
28
+ */
29
+ class T {
30
+ get value() {
31
+ return this.o;
32
+ }
33
+ set value(t) {
34
+ this.setValue(t);
35
+ }
36
+ setValue(t, e = !1) {
37
+ const o = e || !Object.is(t, this.o);
38
+ this.o = t, o && this.updateObservers();
39
+ }
40
+ constructor(t) {
41
+ this.subscriptions = /* @__PURE__ */ new Map(), this.updateObservers = () => {
42
+ for (const [e, { disposer: o }] of this.subscriptions) e(this.o, o);
43
+ }, t !== void 0 && (this.value = t);
44
+ }
45
+ addCallback(t, e, o) {
46
+ if (!o) return void t(this.value);
47
+ this.subscriptions.has(t) || this.subscriptions.set(t, { disposer: () => {
48
+ this.subscriptions.delete(t);
49
+ }, consumerHost: e });
50
+ const { disposer: i } = this.subscriptions.get(t);
51
+ t(this.value, i);
52
+ }
53
+ clearCallbacks() {
54
+ this.subscriptions.clear();
55
+ }
56
+ }
57
+ /**
58
+ * @license
59
+ * Copyright 2021 Google LLC
60
+ * SPDX-License-Identifier: BSD-3-Clause
61
+ */
62
+ class L extends Event {
63
+ constructor(t, e) {
64
+ super("context-provider", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e;
65
+ }
66
+ }
67
+ class $ extends T {
68
+ constructor(t, e, o) {
69
+ var i, c;
70
+ super(e.context !== void 0 ? e.initialValue : o), this.onContextRequest = (r) => {
71
+ if (r.context !== this.context) return;
72
+ const n = r.contextTarget ?? r.composedPath()[0];
73
+ n !== this.host && (r.stopPropagation(), this.addCallback(r.callback, n, r.subscribe));
74
+ }, this.onProviderRequest = (r) => {
75
+ if (r.context !== this.context || (r.contextTarget ?? r.composedPath()[0]) === this.host) return;
76
+ const n = /* @__PURE__ */ new Set();
77
+ for (const [b, { consumerHost: f }] of this.subscriptions) n.has(b) || (n.add(b), f.dispatchEvent(new w(this.context, f, b, !0)));
78
+ r.stopPropagation();
79
+ }, this.host = t, e.context !== void 0 ? this.context = e.context : this.context = e, this.attachListeners(), (c = (i = this.host).addController) == null || c.call(i, this);
80
+ }
81
+ attachListeners() {
82
+ this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest);
83
+ }
84
+ hostConnected() {
85
+ this.host.dispatchEvent(new L(this.context, this.host));
86
+ }
87
+ }
88
+ const R = "*,*:after,*:before{box-sizing:inherit}:host{display:block}:host ::slotted(pie-list-item:not(:last-of-type)){--list-item-size-modifier: 1px;--list-item-border: var(--list-item-size-modifier) solid var(--dt-color-divider-default)}.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 ::slotted(pie-form-label){display:block;padding-block-end:var(--checkbox-group-label-offset)}.c-checkboxGroup:not(.c-checkboxGroup--inline) ::slotted(pie-checkbox:not(:last-child)){margin-block-end:var(--checkbox-group-offset)}.c-checkboxGroup--inline{display:flex;align-items:flex-start;flex-wrap:wrap}.c-checkboxGroup.c-checkboxGroup--inline{margin:calc(-1 * var(--checkbox-group-offset) / 2) calc(-1 * var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline ::slotted(pie-checkbox){margin:calc(var(--checkbox-group-offset) / 2) calc(var(--checkbox-group-offset--inline) / 2)}.c-checkboxGroup.c-checkboxGroup--inline ::slotted(pie-form-label){margin:0 calc(var(--checkbox-group-offset--inline) / 2) calc(-1 * (var(--checkbox-group-offset) / 2 - var(--checkbox-group-label-offset)));padding-block-end:0}.c-checkboxGroup-assistiveText{--checkbox-group-assistive-text-offset: var(--dt-spacing-a);display:block;margin-block-start:var(--checkbox-group-assistive-text-offset)}", D = ["default", "success", "error"], q = "pie-checkbox-group-disabled", A = "pie-checkbox-group-error", h = {
15
89
  status: "default",
16
90
  disabled: !1,
17
91
  isInline: !1
18
92
  };
19
- var T = Object.defineProperty, w = Object.getOwnPropertyDescriptor, i = (e, o, a, c) => {
20
- for (var s = c > 1 ? void 0 : c ? w(o, a) : o, r = e.length - 1, h; r >= 0; r--)
21
- (h = e[r]) && (s = (c ? h(o, a, s) : h(s)) || s);
22
- return c && s && T(o, a, s), s;
93
+ var I = Object.defineProperty, V = Object.getOwnPropertyDescriptor, l = (s, t, e, o) => {
94
+ for (var i = o > 1 ? void 0 : o ? V(t, e) : t, c = s.length - 1, r; c >= 0; c--)
95
+ (r = s[c]) && (i = (o ? r(t, e, i) : r(i)) || i);
96
+ return o && i && I(t, e, i), i;
23
97
  };
24
- const L = "pie-checkbox-group", f = "assistive-text";
25
- let t = class extends m(y(b)) {
98
+ const B = "pie-checkbox-group", g = "assistive-text";
99
+ let a = class extends _(G(x)) {
26
100
  constructor() {
27
- super(...arguments), this._hasLabel = !1, this.isInline = p.isInline, this.status = p.status, this.disabled = p.disabled;
101
+ super(...arguments), this._hasLabel = !1, this.isInline = h.isInline, this.status = h.status, this.disabled = h.disabled, this._disabledProvider = k ? void 0 : new $(this, { context: E, initialValue: h.disabled });
102
+ }
103
+ /**
104
+ * The checkboxes in the group. This uses a subtree query rather than immediate slotted
105
+ * children so checkboxes wrapped in other components (at any depth) are discovered.
106
+ */
107
+ get _slottedChildren() {
108
+ return Array.from(this.querySelectorAll("pie-checkbox"));
28
109
  }
29
110
  _handleDisabled() {
30
- this._slottedChildren.forEach((e) => e.dispatchEvent(new CustomEvent(O, {
111
+ this._slottedChildren.forEach((s) => s.dispatchEvent(new CustomEvent(q, {
31
112
  bubbles: !1,
32
113
  composed: !1,
33
114
  detail: { disabled: this.disabled }
34
115
  })));
35
116
  }
36
117
  _handleStatus() {
37
- this._slottedChildren.forEach((e) => {
38
- e.setAttribute("status", this.status), this.status === "error" && this.assistiveText && (e.setAttribute("assistiveText", this.assistiveText), e.dispatchEvent(new CustomEvent($, { bubbles: !1, composed: !1, detail: { error: !0 } })));
118
+ this._slottedChildren.forEach((s) => {
119
+ s.setAttribute("status", this.status), this.status === "error" && this.assistiveText && (s.setAttribute("assistiveText", this.assistiveText), s.dispatchEvent(new CustomEvent(A, { bubbles: !1, composed: !1, detail: { error: !0 } })));
39
120
  });
40
121
  }
41
122
  /**
@@ -43,9 +124,9 @@ let t = class extends m(y(b)) {
43
124
  * when the label slot receives content.
44
125
  * @private
45
126
  */
46
- handleSlotChange(e) {
47
- const o = e.target.assignedNodes({ flatten: !0 });
48
- this._hasLabel = o.length > 0;
127
+ handleSlotChange(s) {
128
+ const t = s.target.assignedNodes({ flatten: !0 });
129
+ this._hasLabel = t.length > 0;
49
130
  }
50
131
  /**
51
132
  * Template for the label slot to correctly wrap it into a legend element when it has content.
@@ -53,74 +134,72 @@ let t = class extends m(y(b)) {
53
134
  * @private
54
135
  */
55
136
  renderWrappedLabel() {
56
- return this._hasLabel ? n`<legend><slot name='label' @slotchange=${this.handleSlotChange}></slot></legend>` : n`<slot name='label' @slotchange=${this.handleSlotChange}></slot>`;
137
+ return this._hasLabel ? p`<legend><slot name='label' @slotchange=${this.handleSlotChange}></slot></legend>` : p`<slot name='label' @slotchange=${this.handleSlotChange}></slot>`;
57
138
  }
58
- updated(e) {
59
- e.has("disabled") && this._handleDisabled(), e.has("status") && this._handleStatus();
139
+ updated(s) {
140
+ var t;
141
+ s.has("disabled") && ((t = this._disabledProvider) == null || t.setValue(this.disabled), this._handleDisabled()), s.has("status") && this._handleStatus();
60
142
  }
61
143
  render() {
62
144
  const {
63
- name: e,
64
- isInline: o,
65
- assistiveText: a,
66
- status: c,
67
- disabled: s
68
- } = this, r = {
145
+ name: s,
146
+ isInline: t,
147
+ assistiveText: e,
148
+ status: o,
149
+ disabled: i
150
+ } = this, c = {
69
151
  "c-checkboxGroup": !0,
70
- "c-checkboxGroup--inline": o
152
+ "c-checkboxGroup--inline": t
71
153
  };
72
- return n`
154
+ return p`
73
155
  <fieldset
74
- name=${u(e)}
75
- ?disabled=${s}
76
- aria-describedby="${u(a ? f : void 0)}"
156
+ name=${v(s)}
157
+ ?disabled=${i}
158
+ aria-describedby="${v(e ? g : void 0)}"
77
159
  data-test-id="pie-checkbox-group-fieldset"
78
- class="${C(r)}"
160
+ class="${P(c)}"
79
161
  >
80
162
  ${this.renderWrappedLabel()}
81
163
  <slot></slot>
82
164
  </fieldset>
83
- ${a && n`
165
+ ${e && p`
84
166
  <pie-assistive-text
85
- id="${f}"
86
- variant=${c}
87
- message=${a}
167
+ id="${g}"
168
+ variant=${o}
169
+ message=${e}
88
170
  class="c-checkboxGroup-assistiveText"
89
171
  data-test-id="pie-checkbox-group-assistive-text">
90
172
  </pie-assistive-text>`}
91
173
  `;
92
174
  }
93
175
  };
94
- t.styles = g(S);
95
- i([
96
- v()
97
- ], t.prototype, "_hasLabel", 2);
98
- i([
99
- l({ type: String, reflect: !0 })
100
- ], t.prototype, "name", 2);
101
- i([
102
- l({ type: String })
103
- ], t.prototype, "assistiveText", 2);
104
- i([
105
- l({ type: Boolean })
106
- ], t.prototype, "isInline", 2);
107
- i([
108
- l({ type: String }),
109
- _(L, E, p.status)
110
- ], t.prototype, "status", 2);
111
- i([
112
- l({ type: Boolean, reflect: !0 })
113
- ], t.prototype, "disabled", 2);
114
- i([
115
- k({ selector: "pie-checkbox" })
116
- ], t.prototype, "_slottedChildren", 2);
117
- t = i([
118
- G("pie-checkbox-group")
119
- ], t);
176
+ a.styles = y(R);
177
+ l([
178
+ C()
179
+ ], a.prototype, "_hasLabel", 2);
180
+ l([
181
+ d({ type: String, reflect: !0 })
182
+ ], a.prototype, "name", 2);
183
+ l([
184
+ d({ type: String })
185
+ ], a.prototype, "assistiveText", 2);
186
+ l([
187
+ d({ type: Boolean })
188
+ ], a.prototype, "isInline", 2);
189
+ l([
190
+ d({ type: String }),
191
+ S(B, D, h.status)
192
+ ], a.prototype, "status", 2);
193
+ l([
194
+ d({ type: Boolean, reflect: !0 })
195
+ ], a.prototype, "disabled", 2);
196
+ a = l([
197
+ O("pie-checkbox-group")
198
+ ], a);
120
199
  export {
121
- O as ON_CHECKBOX_GROUP_DISABLED,
122
- $ as ON_CHECKBOX_GROUP_ERROR,
123
- t as PieCheckboxGroup,
124
- p as defaultProps,
125
- E as statusTypes
200
+ q as ON_CHECKBOX_GROUP_DISABLED,
201
+ A as ON_CHECKBOX_GROUP_ERROR,
202
+ a as PieCheckboxGroup,
203
+ h as defaultProps,
204
+ D as statusTypes
126
205
  };
package/dist/react.d.ts CHANGED
@@ -60,7 +60,12 @@ declare class PieCheckboxGroup_2 extends PieCheckboxGroup_base implements Checkb
60
60
  isInline: boolean;
61
61
  status: "default" | "success" | "error";
62
62
  disabled: boolean;
63
- _slottedChildren: Array<HTMLElement>;
63
+ private _disabledProvider;
64
+ /**
65
+ * The checkboxes in the group. This uses a subtree query rather than immediate slotted
66
+ * children so checkboxes wrapped in other components (at any depth) are discovered.
67
+ */
68
+ private get _slottedChildren();
64
69
  private _handleDisabled;
65
70
  private _handleStatus;
66
71
  /**
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": "1.1.6",
4
+ "version": "1.2.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/justeattakeaway/pie",
@@ -43,14 +43,15 @@
43
43
  "author": "Just Eat Takeaway.com - Design System Team",
44
44
  "license": "Apache-2.0",
45
45
  "devDependencies": {
46
- "@justeattakeaway/pie-checkbox": "1.3.6",
46
+ "@justeattakeaway/pie-checkbox": "1.4.1",
47
47
  "@justeattakeaway/pie-components-config": "0.21.3",
48
- "@justeattakeaway/pie-css": "1.3.1",
49
- "@justeattakeaway/pie-monorepo-utils": "0.9.7"
48
+ "@justeattakeaway/pie-css": "1.3.2",
49
+ "@justeattakeaway/pie-monorepo-utils": "0.9.8"
50
50
  },
51
51
  "dependencies": {
52
- "@justeattakeaway/pie-assistive-text": "1.0.6",
53
- "@justeattakeaway/pie-webc-core": "16.1.0"
52
+ "@justeattakeaway/pie-assistive-text": "1.0.7",
53
+ "@justeattakeaway/pie-webc-core": "16.1.1",
54
+ "@lit/context": "1.1.6"
54
55
  },
55
56
  "customElements": "custom-elements.json",
56
57
  "sideEffects": [
@@ -2,6 +2,10 @@
2
2
 
3
3
  :host {
4
4
  display: block;
5
+
6
+ // Applies the divider between adjacent `pie-list-item`s when checkboxes are wrapped in them.
7
+ // Direct-child checkboxes are unaffected (the selector only matches `pie-list-item`).
8
+ @include p.list-item-divider;
5
9
  }
6
10
 
7
11
  .c-checkboxGroup {
package/src/index.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import {
2
- html, unsafeCSS, type PropertyValues, type TemplateResult,
2
+ html, isServer, unsafeCSS, type PropertyValues, type TemplateResult,
3
3
  } from 'lit';
4
4
  import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
5
5
  import {
6
- property, queryAssignedElements, state,
6
+ property, state,
7
7
  } from 'lit/decorators.js';
8
+ import { ContextProvider } from '@lit/context';
8
9
  import {
9
10
  RtlMixin,
10
11
  FormControlMixin,
11
12
  validPropertyValues,
12
13
  safeCustomElement,
14
+ parentDisabledContext,
13
15
  } from '@justeattakeaway/pie-webc-core';
14
16
  import { ifDefined } from 'lit/directives/if-defined.js';
15
17
  import { classMap } from 'lit/directives/class-map.js';
@@ -57,7 +59,26 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(PieElement)) imp
57
59
  @property({ type: Boolean, reflect: true })
58
60
  public disabled = defaultProps.disabled;
59
61
 
60
- @queryAssignedElements({ selector: 'pie-checkbox' }) _slottedChildren!: Array<HTMLElement>;
62
+ // Provided to descendant `pie-list-item`s so a fully-disabled group also disables the list rows
63
+ // (suppressing their hover/active states), and kept in sync in `updated()`.
64
+ //
65
+ // Created manually (rather than via the `@provide` decorator) so it can be guarded with
66
+ // `isServer`: `@lit/context`'s ContextProvider attaches `context-request` listeners to the host
67
+ // in its constructor (via `host.addEventListener`). During SSR/prerender the element is
68
+ // constructed without a DOM host, so that call throws and breaks the build. The provider is
69
+ // client-only anyway (context is delivered after `connectedCallback`, which SSR never runs), so
70
+ // it is safe to skip on the server.
71
+ private _disabledProvider = isServer
72
+ ? undefined
73
+ : new ContextProvider(this, { context: parentDisabledContext, initialValue: defaultProps.disabled });
74
+
75
+ /**
76
+ * The checkboxes in the group. This uses a subtree query rather than immediate slotted
77
+ * children so checkboxes wrapped in other components (at any depth) are discovered.
78
+ */
79
+ private get _slottedChildren (): HTMLElement[] {
80
+ return Array.from(this.querySelectorAll('pie-checkbox'));
81
+ }
61
82
 
62
83
  private _handleDisabled () : void {
63
84
  this._slottedChildren.forEach((child) => child.dispatchEvent(new CustomEvent(ON_CHECKBOX_GROUP_DISABLED, {
@@ -97,6 +118,7 @@ export class PieCheckboxGroup extends FormControlMixin(RtlMixin(PieElement)) imp
97
118
 
98
119
  protected updated (_changedProperties: PropertyValues<this>): void {
99
120
  if (_changedProperties.has('disabled')) {
121
+ this._disabledProvider?.setValue(this.disabled);
100
122
  this._handleDisabled();
101
123
  }
102
124