@justeattakeaway/pie-list 0.3.0 → 0.5.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.
@@ -0,0 +1,339 @@
1
+ import { unsafeCSS as x, isServer as y, html as d, nothing as p } from "lit";
2
+ import { property as c, state as k } from "lit/decorators.js";
3
+ import { classMap as _ } from "lit/directives/class-map.js";
4
+ import { ifDefined as m } from "lit/directives/if-defined.js";
5
+ import { validPropertyValues as I, safeCustomElement as T, ariaContext as w, parentDisabledContext as C } from "@justeattakeaway/pie-webc-core";
6
+ import { P as A } from "./PieElement-DQQMEr70.js";
7
+ /**
8
+ * @license
9
+ * Copyright 2021 Google LLC
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ */
12
+ let f = class extends Event {
13
+ constructor(t, e, o, s) {
14
+ super("context-request", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e, this.callback = o, this.subscribe = s ?? !1;
15
+ }
16
+ };
17
+ /**
18
+ * @license
19
+ * Copyright 2021 Google LLC
20
+ * SPDX-License-Identifier: BSD-3-Clause
21
+ */
22
+ let g = class {
23
+ constructor(t, e, o, s) {
24
+ if (this.subscribe = !1, this.provided = !1, this.value = void 0, this.t = (r, n) => {
25
+ this.unsubscribe && (this.unsubscribe !== n && (this.provided = !1, this.unsubscribe()), this.subscribe || this.unsubscribe()), this.value = r, this.host.requestUpdate(), this.provided && !this.subscribe || (this.provided = !0, this.callback && this.callback(r, n)), this.unsubscribe = n;
26
+ }, this.host = t, e.context !== void 0) {
27
+ const r = e;
28
+ this.context = r.context, this.callback = r.callback, this.subscribe = r.subscribe ?? !1;
29
+ } else this.context = e, this.callback = o, this.subscribe = s ?? !1;
30
+ this.host.addController(this);
31
+ }
32
+ hostConnected() {
33
+ this.dispatchRequest();
34
+ }
35
+ hostDisconnected() {
36
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0);
37
+ }
38
+ dispatchRequest() {
39
+ this.host.dispatchEvent(new f(this.context, this.host, this.t, this.subscribe));
40
+ }
41
+ };
42
+ /**
43
+ * @license
44
+ * Copyright 2021 Google LLC
45
+ * SPDX-License-Identifier: BSD-3-Clause
46
+ */
47
+ class R {
48
+ get value() {
49
+ return this.o;
50
+ }
51
+ set value(t) {
52
+ this.setValue(t);
53
+ }
54
+ setValue(t, e = !1) {
55
+ const o = e || !Object.is(t, this.o);
56
+ this.o = t, o && this.updateObservers();
57
+ }
58
+ constructor(t) {
59
+ this.subscriptions = /* @__PURE__ */ new Map(), this.updateObservers = () => {
60
+ for (const [e, { disposer: o }] of this.subscriptions) e(this.o, o);
61
+ }, t !== void 0 && (this.value = t);
62
+ }
63
+ addCallback(t, e, o) {
64
+ if (!o) return void t(this.value);
65
+ this.subscriptions.has(t) || this.subscriptions.set(t, { disposer: () => {
66
+ this.subscriptions.delete(t);
67
+ }, consumerHost: e });
68
+ const { disposer: s } = this.subscriptions.get(t);
69
+ t(this.value, s);
70
+ }
71
+ clearCallbacks() {
72
+ this.subscriptions.clear();
73
+ }
74
+ }
75
+ /**
76
+ * @license
77
+ * Copyright 2021 Google LLC
78
+ * SPDX-License-Identifier: BSD-3-Clause
79
+ */
80
+ class L extends Event {
81
+ constructor(t, e) {
82
+ super("context-provider", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e;
83
+ }
84
+ }
85
+ class P extends R {
86
+ constructor(t, e, o) {
87
+ var s, r;
88
+ super(e.context !== void 0 ? e.initialValue : o), this.onContextRequest = (n) => {
89
+ if (n.context !== this.context) return;
90
+ const b = n.contextTarget ?? n.composedPath()[0];
91
+ b !== this.host && (n.stopPropagation(), this.addCallback(n.callback, b, n.subscribe));
92
+ }, this.onProviderRequest = (n) => {
93
+ if (n.context !== this.context || (n.contextTarget ?? n.composedPath()[0]) === this.host) return;
94
+ const b = /* @__PURE__ */ new Set();
95
+ for (const [u, { consumerHost: v }] of this.subscriptions) b.has(u) || (b.add(u), v.dispatchEvent(new f(this.context, v, u, !0)));
96
+ n.stopPropagation();
97
+ }, this.host = t, e.context !== void 0 ? this.context = e.context : this.context = e, this.attachListeners(), (r = (s = this.host).addController) == null || r.call(s, this);
98
+ }
99
+ attachListeners() {
100
+ this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest);
101
+ }
102
+ hostConnected() {
103
+ this.host.dispatchEvent(new L(this.context, this.host));
104
+ }
105
+ }
106
+ /**
107
+ * @license
108
+ * Copyright 2022 Google LLC
109
+ * SPDX-License-Identifier: BSD-3-Clause
110
+ */
111
+ function B({ context: i, subscribe: t }) {
112
+ return (e, o) => {
113
+ typeof o == "object" ? o.addInitializer((function() {
114
+ new g(this, { context: i, callback: (s) => {
115
+ e.set.call(this, s);
116
+ }, subscribe: t });
117
+ })) : e.constructor.addInitializer(((s) => {
118
+ new g(s, { context: i, callback: (r) => {
119
+ s[o] = r;
120
+ }, subscribe: t });
121
+ }));
122
+ };
123
+ }
124
+ const S = ["none", "radio", "checkbox", "switch", "link", "button"], h = {
125
+ isCompact: !1,
126
+ isBold: !1,
127
+ hasMedia: !1,
128
+ interactionType: "none",
129
+ disabled: !1
130
+ }, D = "*,*:after,*:before{box-sizing:inherit}:host{--list-item-inline-padding: var(--dt-spacing-d);--list-item-alignment: flex-start;--list-item-border: none;display:block}.c-listItem-container{--list-item-block-padding: var(--dt-spacing-d);--list-item-block-end-padding: calc(var(--list-item-block-padding) - var(--list-item-size-modifier));padding-inline-start:var(--list-item-inline-padding);padding-inline-end:var(--list-item-inline-padding);padding-block-start:var(--list-item-block-padding);padding-block-end:var(--list-item-block-end-padding, var(--list-item-block-padding));display:flex;align-items:var(--list-item-alignment);gap:var(--dt-spacing-c);min-height:56px;border-bottom:var(--list-item-border)}.c-listItem-container:has(.c-listItem-secondaryText){align-items:var(--list-item-alignment);min-height:76px}.c-listItem-container.is-compact{--list-item-block-padding: var(--dt-spacing-c);--list-item-alignment: center;align-items:var(--list-item-alignment);min-height:48px}.c-listItem-container.is-link,.c-listItem-container.is-button{position:relative}.c-listItem-container.is-selectable:not(.is-disabled),.c-listItem-container.is-link,.c-listItem-container.is-button:not(.is-disabled){--list-item-hover-bg: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--dt-color-hover-01));--list-item-active-bg: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--dt-color-active-01))}@supports (background-color: color-mix(in srgb,black,white)){.c-listItem-container.is-selectable:not(.is-disabled),.c-listItem-container.is-link,.c-listItem-container.is-button:not(.is-disabled){--list-item-hover-bg: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), transparent);--list-item-active-bg: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), transparent)}}.c-listItem-container.is-selectable:not(.is-disabled),.c-listItem-container.is-link,.c-listItem-container.is-button:not(.is-disabled){cursor:pointer}.c-listItem-container.is-selectable:not(.is-disabled):hover,.c-listItem-container.is-link:hover,.c-listItem-container.is-button:not(.is-disabled):hover{background-color:var(--list-item-hover-bg);--interactive-container-tint: var(--list-item-hover-bg)}.c-listItem-container.is-selectable:not(.is-disabled):active,.c-listItem-container.is-link:active,.c-listItem-container.is-button:not(.is-disabled):active{background-color:var(--list-item-active-bg);--interactive-container-tint: var(--list-item-active-bg)}.c-listItem-container.is-button:has(.c-listItem-action:active){background-color:var(--list-item-active-bg);--interactive-container-tint: var(--list-item-active-bg)}slot[name=link]::slotted(a),.c-listItem-action{position:absolute;top:0;right:0;bottom:0;left:0;z-index:1;border-radius:inherit}.c-listItem-action{padding:0;border:none;background:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;font:inherit;cursor:pointer}.c-listItem-action:disabled{cursor:default}slot[name=link]::slotted(a:focus-visible),.c-listItem-action:focus-visible{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-listItem-container.has-media:has(.c-listItem-primaryText:only-child){--list-item-block-padding: var(--dt-spacing-b)}.c-listItem-text{flex:1}slot[name=trailing]::slotted(*),.c-listItem-metaText{padding-inline-start:var(--dt-spacing-a)}.c-listItem-leading,slot[name=leading],.c-listItem-trailing,slot[name=trailing]{display:contents}.c-listItem-text>*{display:block}.c-listItem-trailing{margin-inline-start:auto}.c-listItem-metaText{display:block;max-width:33.3333333333%}::slotted(.c-pieIcon){--icon-size-override: 24px }.c-listItem-container.is-button.is-disabled .c-listItem-primaryText,.c-listItem-container.is-button.is-disabled .c-listItem-secondaryText,.c-listItem-container.is-button.is-disabled .c-listItem-metaText{color:var(--dt-color-content-disabled)}.c-listItem-container.is-button.is-disabled ::slotted(.c-pieIcon){color:var(--dt-color-disabled-01)}.c-listItem-primaryText{font-family:var(--dt-font-body-l-family);font-weight:var(--dt-font-body-l-weight);font-size:calc(var(--dt-font-body-l-size) * 1px);line-height:calc(var(--dt-font-body-l-line-height) * 1px);color:var(--dt-color-content-default)}.c-listItem-container.is-bold .c-listItem-primaryText{font-family:var(--dt-font-body-strong-l-family);font-weight:var(--dt-font-body-strong-l-weight);font-size:calc(var(--dt-font-body-strong-l-size) * 1px);line-height:calc(var(--dt-font-body-strong-l-line-height) * 1px)}.c-listItem-secondaryText,.c-listItem-metaText{font-family:var(--dt-font-body-s-family);font-weight:var(--dt-font-body-s-weight);font-size:calc(var(--dt-font-body-s-size) * 1px);line-height:calc(var(--dt-font-body-s-line-height) * 1px);color:var(--dt-color-content-subdued)}";
131
+ var $ = Object.defineProperty, z = Object.getOwnPropertyDescriptor, l = (i, t, e, o) => {
132
+ for (var s = o > 1 ? void 0 : o ? z(t, e) : t, r = i.length - 1, n; r >= 0; r--)
133
+ (n = i[r]) && (s = (o ? n(t, e, s) : n(s)) || s);
134
+ return o && s && $(t, e, s), s;
135
+ };
136
+ const q = "pie-list-item";
137
+ let a = class extends A {
138
+ constructor() {
139
+ super(...arguments), this.isCompact = h.isCompact, this.isBold = h.isBold, this.hasMedia = h.hasMedia, this.interactionType = h.interactionType, this.disabled = h.disabled, this._parentDisabled = !1, this._ariaProvider = y ? void 0 : new P(this, { context: w }), this._managedRole = null, this._linkAriaCaptured = !1, this._consumerNamedLink = !1, this._consumerDescribedLink = !1, this._handleHostClick = (i) => {
140
+ if (!this._isSelectable || this._isDisabled) return;
141
+ const t = this._control;
142
+ !t || i.composedPath().includes(t) || (t.click(), t.focus());
143
+ };
144
+ }
145
+ // A selection row hosts a slotted control (radio/checkbox/switch) and makes the whole row a
146
+ // toggle target. `link`/`button` are interactive too, but they are single navigation/action
147
+ // targets rather than selection controls, so they are deliberately excluded here.
148
+ get _isSelectable() {
149
+ return this.interactionType === "radio" || this.interactionType === "checkbox" || this.interactionType === "switch";
150
+ }
151
+ get _isLinkRow() {
152
+ return this.interactionType === "link";
153
+ }
154
+ get _isButtonRow() {
155
+ return this.interactionType === "button";
156
+ }
157
+ // A link and a button row share the same visual mechanic: an empty element stretched over the
158
+ // whole row as the interactive target, named by the item from its own text. They differ in who
159
+ // owns that element - a link is a consumer-slotted anchor, a button is one the item renders.
160
+ get _isOverlayRow() {
161
+ return this._isLinkRow || this._isButtonRow;
162
+ }
163
+ // True when the item lends its text as an interactive element's accessible name/description:
164
+ // selectable rows (radio/checkbox/switch) and overlay rows (link anchor / action button).
165
+ get _providesAria() {
166
+ return this._isSelectable || this._isOverlayRow;
167
+ }
168
+ // radio/checkbox are owned by a selection group, which is why the item becomes `presentation`
169
+ // (so the group owns the controls directly) and the radio is named on its host. A switch has
170
+ // no group, so the item stays a `listitem`.
171
+ get _ownedByGroup() {
172
+ return this.interactionType === "radio" || this.interactionType === "checkbox";
173
+ }
174
+ // True when the row should be treated as disabled: either its own `disabled` prop is set, or the
175
+ // containing group is disabled (provided via context). Declarative and reactive, so the styling
176
+ // and row-click guard react without observing the slotted control.
177
+ get _isDisabled() {
178
+ return this.disabled || this._parentDisabled;
179
+ }
180
+ // The interactive control (radio/checkbox/switch) slotted into this item, if any. Used only by
181
+ // the client-side row-click handler.
182
+ get _control() {
183
+ return this.querySelector("pie-radio, pie-checkbox, pie-switch");
184
+ }
185
+ connectedCallback() {
186
+ super.connectedCallback(), this._abortController = new AbortController(), this.addEventListener("click", this._handleHostClick, { signal: this._abortController.signal });
187
+ }
188
+ disconnectedCallback() {
189
+ super.disconnectedCallback(), this._abortController.abort();
190
+ }
191
+ updated() {
192
+ var i;
193
+ this._applyRole(), (i = this._ariaProvider) == null || i.setValue(this._providedAria), this._applyLinkAria();
194
+ }
195
+ /**
196
+ * Sets the item's role from `interactionType`: `presentation` for radio/checkbox (so the group
197
+ * owns those controls directly), otherwise `listitem` (static items, switches, links and
198
+ * buttons). A role set explicitly by the consumer is left untouched, even if it is added or
199
+ * removed dynamically after the element connects.
200
+ */
201
+ _applyRole() {
202
+ const i = this.getAttribute("role");
203
+ if (i !== null && i !== this._managedRole) return;
204
+ const t = this._ownedByGroup ? "presentation" : "listitem";
205
+ this._managedRole = t, this.setAttribute("role", t);
206
+ }
207
+ /**
208
+ * The accessible name and description this item provides to its interactive element, stitched
209
+ * from its text. Selection controls consume it via `ariaContext` (each applying it to the
210
+ * element that carries its role); the action button of a `button` row takes it directly as
211
+ * `aria-label`/`aria-description` in the template; a link anchor takes it via `_applyLinkAria`.
212
+ */
213
+ get _providedAria() {
214
+ if (!this._providesAria) return;
215
+ const i = [this.secondaryText, this.metaText].filter(Boolean).join(". ");
216
+ return { label: this.primaryText, description: i || void 0 };
217
+ }
218
+ /**
219
+ * On a link row, names the slotted (empty) anchor from the item's own text: the parent owns the
220
+ * child's aria. The anchor is plain light-DOM, so it cannot reference the shadow-DOM text via
221
+ * `aria-labelledby`; and it is not a PIE control that consumes `ariaContext`, so we set the
222
+ * attributes imperatively. The visible text is `aria-hidden` in the template, so nothing is
223
+ * announced twice. (A `button` row names its own rendered element in the template instead.)
224
+ *
225
+ * A consumer-provided name/description always wins: we capture (once) whether the anchor already
226
+ * carries `aria-label`/`aria-labelledby` or `aria-description`/`aria-describedby` and, if so,
227
+ * leave that attribute untouched. Otherwise we keep our generated value in sync with the text.
228
+ */
229
+ _applyLinkAria() {
230
+ if (!this._isLinkRow) {
231
+ if (this._linkAriaCaptured) {
232
+ const e = this.querySelector('a[slot="link"]');
233
+ e && (this._consumerNamedLink || e.removeAttribute("aria-label"), this._consumerDescribedLink || e.removeAttribute("aria-description")), this._linkAriaCaptured = !1, this._consumerNamedLink = !1, this._consumerDescribedLink = !1;
234
+ }
235
+ return;
236
+ }
237
+ const i = this.querySelector('a[slot="link"]');
238
+ if (!i) return;
239
+ this._linkAriaCaptured || (this._consumerNamedLink = i.hasAttribute("aria-label") || i.hasAttribute("aria-labelledby"), this._consumerDescribedLink = i.hasAttribute("aria-description") || i.hasAttribute("aria-describedby"), this._linkAriaCaptured = !0);
240
+ const t = this._providedAria;
241
+ this._consumerNamedLink || (t != null && t.label ? i.setAttribute("aria-label", t.label) : i.removeAttribute("aria-label")), this._consumerDescribedLink || (t != null && t.description ? i.setAttribute("aria-description", t.description) : i.removeAttribute("aria-description"));
242
+ }
243
+ _renderSecondaryText() {
244
+ const { secondaryText: i } = this;
245
+ return i ? d`<span class="c-listItem-secondaryText">${i}</span>` : p;
246
+ }
247
+ // metaText is another form of trailing content. The component can only ever display either slotted trailing content or the metaText string
248
+ _renderTrailingContent() {
249
+ const { metaText: i } = this;
250
+ return i ? d`<span class="c-listItem-metaText c-listItem-trailing" aria-hidden=${this._providesAria ? "true" : p}>${i}</span>` : d`<div class="c-listItem-trailing"><slot name="trailing"></slot></div>`;
251
+ }
252
+ /**
253
+ * The interactive target for a `button` row: an empty, native `<button>` stretched invisibly
254
+ * over the whole row (see the SCSS). The item renders and owns it - rather than the consumer
255
+ * slotting one - so it can name it from its own text and keep its attributes private (it is just
256
+ * an action box, not a configurable control). Being a real button, activation is native: pointer
257
+ * clicks and keyboard (Enter/Space) both fire a `click` that bubbles out, so consumers listen for
258
+ * `click` on the `pie-list-item`. It is `type="button"`, so it never submits a form.
259
+ */
260
+ _renderActionButton() {
261
+ var t, e;
262
+ const i = this._providedAria;
263
+ return d`<button
264
+ class="c-listItem-action"
265
+ type="button"
266
+ ?disabled=${this._isDisabled}
267
+ aria-label=${m(i == null ? void 0 : i.label)}
268
+ aria-description=${m(i == null ? void 0 : i.description)}
269
+ aria-haspopup=${m((e = (t = this.aria) == null ? void 0 : t.button) == null ? void 0 : e.haspopup)}></button>`;
270
+ }
271
+ render() {
272
+ const { primaryText: i } = this, t = {
273
+ "c-listItem-container": !0,
274
+ "is-compact": this.isCompact,
275
+ "is-bold": this.isBold,
276
+ "has-media": this.hasMedia,
277
+ "is-selectable": this._isSelectable,
278
+ "is-link": this._isLinkRow,
279
+ "is-button": this._isButtonRow,
280
+ "is-disabled": this._isDisabled
281
+ };
282
+ return d`
283
+ <div class=${_(t)}>
284
+ ${this._isLinkRow ? d`<slot name="link"></slot>` : p}
285
+ ${this._isButtonRow ? this._renderActionButton() : p}
286
+ <div class="c-listItem-leading">
287
+ <slot name="leading"></slot>
288
+ </div>
289
+
290
+ <div class="c-listItem-text" aria-hidden=${this._providesAria ? "true" : p}>
291
+ <span class="c-listItem-primaryText">${i}</span>
292
+ ${this._renderSecondaryText()}
293
+ </div>
294
+
295
+ ${this._renderTrailingContent()}
296
+ </div>`;
297
+ }
298
+ };
299
+ a.styles = x(D);
300
+ l([
301
+ c({ type: String })
302
+ ], a.prototype, "primaryText", 2);
303
+ l([
304
+ c({ type: String })
305
+ ], a.prototype, "secondaryText", 2);
306
+ l([
307
+ c({ type: String })
308
+ ], a.prototype, "metaText", 2);
309
+ l([
310
+ c({ type: Boolean })
311
+ ], a.prototype, "isCompact", 2);
312
+ l([
313
+ c({ type: Boolean })
314
+ ], a.prototype, "isBold", 2);
315
+ l([
316
+ c({ type: Boolean })
317
+ ], a.prototype, "hasMedia", 2);
318
+ l([
319
+ c({ type: String }),
320
+ I(q, S, h.interactionType)
321
+ ], a.prototype, "interactionType", 2);
322
+ l([
323
+ c({ type: Boolean })
324
+ ], a.prototype, "disabled", 2);
325
+ l([
326
+ c({ type: Object })
327
+ ], a.prototype, "aria", 2);
328
+ l([
329
+ B({ context: C, subscribe: !0 }),
330
+ k()
331
+ ], a.prototype, "_parentDisabled", 2);
332
+ a = l([
333
+ T("pie-list-item")
334
+ ], a);
335
+ export {
336
+ a as P,
337
+ h as d,
338
+ S as i
339
+ };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { html as n, unsafeCSS as m } from "lit";
2
- import { P as f } from "./PieElement-ab_PEQpW.js";
2
+ import { P as f } from "./PieElement-DQQMEr70.js";
3
3
  import { RtlMixin as d, safeCustomElement as p } from "@justeattakeaway/pie-webc-core";
4
4
  const c = "*,*: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)}";
5
5
  var b = Object.getOwnPropertyDescriptor, u = (s, r, a, l) => {
@@ -1,6 +1,11 @@
1
1
  import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
2
- export declare const selectionTypes: readonly ["none", "radio", "checkbox", "switch"];
3
- export type SelectionType = typeof selectionTypes[number];
2
+ type AriaProps = {
3
+ button?: {
4
+ haspopup?: 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog' | 'true';
5
+ };
6
+ };
7
+ export declare const interactionTypes: readonly ["none", "radio", "checkbox", "switch", "link", "button"];
8
+ export type InteractionType = typeof interactionTypes[number];
4
9
  export interface ListItemProps {
5
10
  /**
6
11
  * **Required:** Provides an overview of the content.
@@ -31,20 +36,27 @@ export interface ListItemProps {
31
36
  */
32
37
  hasMedia?: boolean;
33
38
  /**
34
- * The kind of interactive control this item hosts in its `leading` or `trailing` slot. This
35
- * makes the whole row a selectable target: the item takes the appropriate role, provides its
36
- * text as the control's accessible name/description, hides the duplicated visible text, and
37
- * forwards row clicks to the control.
39
+ * How the whole row behaves. A single prop drives the row's role, its accessible naming, whether
40
+ * it forwards clicks, and its interactive (hover/active) states. The item always generates the
41
+ * accessible name and description of whatever it hosts from its own text (`primaryText`,
42
+ * `secondaryText`, `metaText`), so you never set ARIA on the item or its slotted content yourself.
38
43
  *
39
44
  * - `none` (default) - a static, non-selectable list item (`role="listitem"`).
40
45
  * - `radio` - hosts a `pie-radio` (used inside a `pie-radio-group`); the item is `presentation`.
41
46
  * - `checkbox` - hosts a `pie-checkbox` (used inside a `pie-checkbox-group`); the item is `presentation`.
42
47
  * - `switch` - hosts a `pie-switch`; there is no group, so the item stays `role="listitem"`.
48
+ * - `link` - the whole row is a single navigation link. Slot an empty `<a slot="link" href="...">`;
49
+ * it is stretched over the entire row as the clickable target and named from the item's text.
50
+ * - `button` - the whole row is a single button (for an in-page action rather than navigation).
51
+ * The item renders the button for you (no slotting); it is stretched invisibly over the entire
52
+ * row, named from the item's text, and dispatches a native `click` (pointer and keyboard).
53
+ * Listen for `click` on the `pie-list-item`. It is not a form control.
43
54
  *
44
- * Set this on each selectable row. When the rows sit inside a `pie-radio-group`, the group lays
45
- * them out as a divided list automatically; this prop governs the row's role and behaviour.
55
+ * Set this on each interactive row. When radio/checkbox rows sit inside a `pie-radio-group` /
56
+ * `pie-checkbox-group`, the group lays them out as a divided list automatically; this prop
57
+ * governs the row's own role and behaviour.
46
58
  */
47
- selectionType?: typeof selectionTypes[number];
59
+ interactionType?: typeof interactionTypes[number];
48
60
  /**
49
61
  * Marks the row as disabled: it takes on the disabled styling and stops forwarding row clicks to
50
62
  * its control. Set it alongside the slotted control's own `disabled` (the control still governs
@@ -52,7 +64,14 @@ export interface ListItemProps {
52
64
  * (static) item.
53
65
  */
54
66
  disabled?: boolean;
67
+ /**
68
+ * Additional ARIA properties that the item cannot derive from its text props. `button.haspopup`
69
+ * applies when `interactionType="button"`: its value is forwarded to the internal `<button>`.
70
+ * Set it when the button row triggers a popup such as a dialog or menu.
71
+ */
72
+ aria?: AriaProps;
55
73
  }
56
74
  export type DefaultProps = ComponentDefaultProps<ListItemProps, keyof Omit<ListItemProps, 'primaryText' | 'secondaryText' | 'metaText'>>;
57
75
  export declare const defaultProps: DefaultProps;
76
+ export {};
58
77
  //# sourceMappingURL=defs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../src/pie-list-item/defs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,eAAO,MAAM,cAAc,kDAAmD,CAAC;AAE/E,MAAM,MAAM,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAE1D,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;IAE7C;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,MAAM,YAAY,GAAG,qBAAqB,CAAC,aAAa,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC;AAEzI,eAAO,MAAM,YAAY,EAAE,YAM1B,CAAC"}
1
+ {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../src/pie-list-item/defs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,KAAK,SAAS,GAAG;IACb,MAAM,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;KACvE,CAAC;CACL,CAAC;AAEF,eAAO,MAAM,gBAAgB,oEAAqE,CAAC;AAEnG,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,eAAe,CAAC,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAA;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,qBAAqB,CAAC,aAAa,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC;AAEzI,eAAO,MAAM,YAAY,EAAE,YAM1B,CAAC"}
@@ -6,6 +6,7 @@ declare const componentSelector = "pie-list-item";
6
6
  * @tagname pie-list-item
7
7
  * @slot leading - Content shown at the start of the item (for example an icon, avatar, or a slotted radio/checkbox).
8
8
  * @slot trailing - Content shown at the end of the item. Mutually exclusive with `metaText`.
9
+ * @slot link - Rendered only when `interactionType="link"`. Slot one empty anchor (e.g. `<a slot="link" href="/x">`) stretched over the whole row as the link target. Must contain no text.
9
10
  */
10
11
  export declare class PieListItem extends PieElement implements ListItemProps {
11
12
  primaryText: ListItemProps['primaryText'];
@@ -14,13 +15,21 @@ export declare class PieListItem extends PieElement implements ListItemProps {
14
15
  isCompact: boolean;
15
16
  isBold: boolean;
16
17
  hasMedia: boolean;
17
- selectionType: "checkbox" | "none" | "radio" | "switch";
18
+ interactionType: "button" | "checkbox" | "link" | "none" | "radio" | "switch";
18
19
  disabled: boolean;
20
+ aria: ListItemProps['aria'];
19
21
  private _parentDisabled;
20
22
  private _ariaProvider;
21
23
  private _abortController;
22
- private _hasExplicitRole;
24
+ private _managedRole;
25
+ private _linkAriaCaptured;
26
+ private _consumerNamedLink;
27
+ private _consumerDescribedLink;
23
28
  private get _isSelectable();
29
+ private get _isLinkRow();
30
+ private get _isButtonRow();
31
+ private get _isOverlayRow();
32
+ private get _providesAria();
24
33
  private get _ownedByGroup();
25
34
  private get _isDisabled();
26
35
  private get _control();
@@ -28,18 +37,17 @@ export declare class PieListItem extends PieElement implements ListItemProps {
28
37
  disconnectedCallback(): void;
29
38
  protected updated(): void;
30
39
  /**
31
- * Sets the item's role from `selectionType`: `presentation` for radio/checkbox (so the group
32
- * owns those controls directly), otherwise `listitem` (static items and switches). A role set
33
- * explicitly by the consumer is left untouched.
40
+ * Sets the item's role from `interactionType`: `presentation` for radio/checkbox (so the group
41
+ * owns those controls directly), otherwise `listitem` (static items, switches, links and
42
+ * buttons). A role set explicitly by the consumer is left untouched, even if it is added or
43
+ * removed dynamically after the element connects.
34
44
  */
35
45
  private _applyRole;
36
46
  /**
37
- * The accessible name and description this item provides to its slotted control, stitched from
38
- * its text. Only provided in a selectable list. Each control consumes this via `ariaContext`
39
- * and decides how to apply it: `pie-radio` names its host (which carries `role="radio"`),
40
- * while `pie-checkbox` / `pie-switch` name their internal input (their host is role-less, so
41
- * `aria-label` there would be invalid). Context reaches across the shadow boundary that
42
- * `aria-labelledby` cannot.
47
+ * The accessible name and description this item provides to its interactive element, stitched
48
+ * from its text. Selection controls consume it via `ariaContext` (each applying it to the
49
+ * element that carries its role); the action button of a `button` row takes it directly as
50
+ * `aria-label`/`aria-description` in the template; a link anchor takes it via `_applyLinkAria`.
43
51
  */
44
52
  private get _providedAria();
45
53
  /**
@@ -47,8 +55,29 @@ export declare class PieListItem extends PieElement implements ListItemProps {
47
55
  * target. Skips clicks that already landed on the control, to avoid a double toggle.
48
56
  */
49
57
  private _handleHostClick;
58
+ /**
59
+ * On a link row, names the slotted (empty) anchor from the item's own text: the parent owns the
60
+ * child's aria. The anchor is plain light-DOM, so it cannot reference the shadow-DOM text via
61
+ * `aria-labelledby`; and it is not a PIE control that consumes `ariaContext`, so we set the
62
+ * attributes imperatively. The visible text is `aria-hidden` in the template, so nothing is
63
+ * announced twice. (A `button` row names its own rendered element in the template instead.)
64
+ *
65
+ * A consumer-provided name/description always wins: we capture (once) whether the anchor already
66
+ * carries `aria-label`/`aria-labelledby` or `aria-description`/`aria-describedby` and, if so,
67
+ * leave that attribute untouched. Otherwise we keep our generated value in sync with the text.
68
+ */
69
+ private _applyLinkAria;
50
70
  _renderSecondaryText(): import('lit-html').TemplateResult<1> | typeof nothing;
51
71
  _renderTrailingContent(): import('lit-html').TemplateResult<1>;
72
+ /**
73
+ * The interactive target for a `button` row: an empty, native `<button>` stretched invisibly
74
+ * over the whole row (see the SCSS). The item renders and owns it - rather than the consumer
75
+ * slotting one - so it can name it from its own text and keep its attributes private (it is just
76
+ * an action box, not a configurable control). Being a real button, activation is native: pointer
77
+ * clicks and keyboard (Enter/Space) both fire a `click` that bubbles out, so consumers listen for
78
+ * `click` on the `pie-list-item`. It is `type="button"`, so it never submits a form.
79
+ */
80
+ _renderActionButton(): import('lit-html').TemplateResult<1>;
52
81
  render(): import('lit-html').TemplateResult<1>;
53
82
  static styles: import('lit').CSSResult;
54
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pie-list-item/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACa,OAAO,EAC1B,MAAM,KAAK,CAAC;AAWb,OAAO,EAAE,UAAU,EAAE,MAAM,yDAAyD,CAAC;AACrF,OAAO,EAAE,KAAK,aAA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MAAM,0BAAqB;CACrC;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAC;KACpC;CACJ"}
@@ -1,9 +1,10 @@
1
1
  import "lit";
2
2
  import "lit/decorators.js";
3
3
  import "lit/directives/class-map.js";
4
- import { P as s } from "../index-mqipXuiX.js";
4
+ import "lit/directives/if-defined.js";
5
+ import { P } from "../index-BH08tWcm.js";
5
6
  import "@justeattakeaway/pie-webc-core";
6
- import "../PieElement-ab_PEQpW.js";
7
+ import "../PieElement-DQQMEr70.js";
7
8
  export {
8
- s as PieListItem
9
+ P as PieListItem
9
10
  };
@@ -1,16 +1,16 @@
1
1
  import * as e from "react";
2
2
  import { createComponent as t } from "@lit/react";
3
- import { P as s } from "../index-mqipXuiX.js";
4
- import { d as c, s as n } from "../index-mqipXuiX.js";
5
- const i = t({
3
+ import { P as i } from "../index-BH08tWcm.js";
4
+ import { d as n, i as c } from "../index-BH08tWcm.js";
5
+ const s = t({
6
6
  displayName: "PieListItem",
7
- elementClass: s,
7
+ elementClass: i,
8
8
  react: e,
9
9
  tagName: "pie-list-item",
10
10
  events: {}
11
- }), a = i;
11
+ }), o = s;
12
12
  export {
13
- a as PieListItem,
14
- c as defaultProps,
15
- n as selectionTypes
13
+ o as PieListItem,
14
+ n as defaultProps,
15
+ c as interactionTypes
16
16
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-list",
3
3
  "description": "PIE Design System List built using Web Components",
4
- "version": "0.3.0",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -38,11 +38,11 @@
38
38
  "license": "Apache-2.0",
39
39
  "devDependencies": {
40
40
  "@justeattakeaway/pie-components-config": "0.21.3",
41
- "@justeattakeaway/pie-css": "1.3.1",
41
+ "@justeattakeaway/pie-css": "1.3.2",
42
42
  "@justeattakeaway/pie-monorepo-utils": "0.9.8"
43
43
  },
44
44
  "dependencies": {
45
- "@justeattakeaway/pie-webc-core": "16.1.0",
45
+ "@justeattakeaway/pie-webc-core": "16.1.1",
46
46
  "@lit/context": "1.1.6"
47
47
  },
48
48
  "customElements": "custom-elements.json",