@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.
@@ -1,265 +0,0 @@
1
- import { unsafeCSS as x, isServer as f, html as p, nothing as m } from "lit";
2
- import { property as c, state as y } from "lit/decorators.js";
3
- import { classMap as k } from "lit/directives/class-map.js";
4
- import { validPropertyValues as _, safeCustomElement as T, ariaContext as I, parentDisabledContext as C } from "@justeattakeaway/pie-webc-core";
5
- import { P as w } from "./PieElement-ab_PEQpW.js";
6
- /**
7
- * @license
8
- * Copyright 2021 Google LLC
9
- * SPDX-License-Identifier: BSD-3-Clause
10
- */
11
- let g = class extends Event {
12
- constructor(t, e, o, s) {
13
- super("context-request", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e, this.callback = o, this.subscribe = s ?? !1;
14
- }
15
- };
16
- /**
17
- * @license
18
- * Copyright 2021 Google LLC
19
- * SPDX-License-Identifier: BSD-3-Clause
20
- */
21
- let v = class {
22
- constructor(t, e, o, s) {
23
- if (this.subscribe = !1, this.provided = !1, this.value = void 0, this.t = (r, a) => {
24
- this.unsubscribe && (this.unsubscribe !== a && (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, a)), this.unsubscribe = a;
25
- }, this.host = t, e.context !== void 0) {
26
- const r = e;
27
- this.context = r.context, this.callback = r.callback, this.subscribe = r.subscribe ?? !1;
28
- } else this.context = e, this.callback = o, this.subscribe = s ?? !1;
29
- this.host.addController(this);
30
- }
31
- hostConnected() {
32
- this.dispatchRequest();
33
- }
34
- hostDisconnected() {
35
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0);
36
- }
37
- dispatchRequest() {
38
- this.host.dispatchEvent(new g(this.context, this.host, this.t, this.subscribe));
39
- }
40
- };
41
- /**
42
- * @license
43
- * Copyright 2021 Google LLC
44
- * SPDX-License-Identifier: BSD-3-Clause
45
- */
46
- class P {
47
- get value() {
48
- return this.o;
49
- }
50
- set value(t) {
51
- this.setValue(t);
52
- }
53
- setValue(t, e = !1) {
54
- const o = e || !Object.is(t, this.o);
55
- this.o = t, o && this.updateObservers();
56
- }
57
- constructor(t) {
58
- this.subscriptions = /* @__PURE__ */ new Map(), this.updateObservers = () => {
59
- for (const [e, { disposer: o }] of this.subscriptions) e(this.o, o);
60
- }, t !== void 0 && (this.value = t);
61
- }
62
- addCallback(t, e, o) {
63
- if (!o) return void t(this.value);
64
- this.subscriptions.has(t) || this.subscriptions.set(t, { disposer: () => {
65
- this.subscriptions.delete(t);
66
- }, consumerHost: e });
67
- const { disposer: s } = this.subscriptions.get(t);
68
- t(this.value, s);
69
- }
70
- clearCallbacks() {
71
- this.subscriptions.clear();
72
- }
73
- }
74
- /**
75
- * @license
76
- * Copyright 2021 Google LLC
77
- * SPDX-License-Identifier: BSD-3-Clause
78
- */
79
- class S extends Event {
80
- constructor(t, e) {
81
- super("context-provider", { bubbles: !0, composed: !0 }), this.context = t, this.contextTarget = e;
82
- }
83
- }
84
- class E extends P {
85
- constructor(t, e, o) {
86
- var s, r;
87
- super(e.context !== void 0 ? e.initialValue : o), this.onContextRequest = (a) => {
88
- if (a.context !== this.context) return;
89
- const h = a.contextTarget ?? a.composedPath()[0];
90
- h !== this.host && (a.stopPropagation(), this.addCallback(a.callback, h, a.subscribe));
91
- }, this.onProviderRequest = (a) => {
92
- if (a.context !== this.context || (a.contextTarget ?? a.composedPath()[0]) === this.host) return;
93
- const h = /* @__PURE__ */ new Set();
94
- for (const [b, { consumerHost: u }] of this.subscriptions) h.has(b) || (h.add(b), u.dispatchEvent(new g(this.context, u, b, !0)));
95
- a.stopPropagation();
96
- }, 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);
97
- }
98
- attachListeners() {
99
- this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest);
100
- }
101
- hostConnected() {
102
- this.host.dispatchEvent(new S(this.context, this.host));
103
- }
104
- }
105
- /**
106
- * @license
107
- * Copyright 2022 Google LLC
108
- * SPDX-License-Identifier: BSD-3-Clause
109
- */
110
- function B({ context: i, subscribe: t }) {
111
- return (e, o) => {
112
- typeof o == "object" ? o.addInitializer((function() {
113
- new v(this, { context: i, callback: (s) => {
114
- e.set.call(this, s);
115
- }, subscribe: t });
116
- })) : e.constructor.addInitializer(((s) => {
117
- new v(s, { context: i, callback: (r) => {
118
- s[o] = r;
119
- }, subscribe: t });
120
- }));
121
- };
122
- }
123
- const z = ["none", "radio", "checkbox", "switch"], d = {
124
- isCompact: !1,
125
- isBold: !1,
126
- hasMedia: !1,
127
- selectionType: "none",
128
- disabled: !1
129
- }, R = "*,*: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-selectable: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){--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){cursor:pointer}.c-listItem-container.is-selectable:not(.is-disabled):hover{background-color:var(--list-item-hover-bg)}.c-listItem-container.is-selectable:not(.is-disabled):active{background-color:var(--list-item-active-bg)}.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-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)}";
130
- var q = Object.defineProperty, D = Object.getOwnPropertyDescriptor, l = (i, t, e, o) => {
131
- for (var s = o > 1 ? void 0 : o ? D(t, e) : t, r = i.length - 1, a; r >= 0; r--)
132
- (a = i[r]) && (s = (o ? a(t, e, s) : a(s)) || s);
133
- return o && s && q(t, e, s), s;
134
- };
135
- const $ = "pie-list-item";
136
- let n = class extends w {
137
- constructor() {
138
- super(...arguments), this.isCompact = d.isCompact, this.isBold = d.isBold, this.hasMedia = d.hasMedia, this.selectionType = d.selectionType, this.disabled = d.disabled, this._parentDisabled = !1, this._ariaProvider = f ? void 0 : new E(this, { context: I }), this._hasExplicitRole = !1, this._handleHostClick = (i) => {
139
- if (!this._isSelectable || this._isDisabled) return;
140
- const t = this._control;
141
- !t || i.composedPath().includes(t) || (t.click(), t.focus());
142
- };
143
- }
144
- get _isSelectable() {
145
- return this.selectionType !== "none";
146
- }
147
- // radio/checkbox are owned by a selection group, which is why the item becomes `presentation`
148
- // (so the group owns the controls directly) and the radio is named on its host. A switch has
149
- // no group, so the item stays a `listitem`.
150
- get _ownedByGroup() {
151
- return this.selectionType === "radio" || this.selectionType === "checkbox";
152
- }
153
- // True when the row should be treated as disabled: either its own `disabled` prop is set, or the
154
- // containing group is disabled (provided via context). Declarative and reactive, so the styling
155
- // and row-click guard react without observing the slotted control.
156
- get _isDisabled() {
157
- return this.disabled || this._parentDisabled;
158
- }
159
- // The interactive control (radio/checkbox/switch) slotted into this item, if any. Used only by
160
- // the client-side row-click handler.
161
- get _control() {
162
- return this.querySelector("pie-radio, pie-checkbox, pie-switch");
163
- }
164
- connectedCallback() {
165
- super.connectedCallback(), this._hasExplicitRole = this.hasAttribute("role"), this._abortController = new AbortController(), this.addEventListener("click", this._handleHostClick, { signal: this._abortController.signal });
166
- }
167
- disconnectedCallback() {
168
- super.disconnectedCallback(), this._abortController.abort();
169
- }
170
- updated() {
171
- var i;
172
- this._applyRole(), (i = this._ariaProvider) == null || i.setValue(this._providedAria);
173
- }
174
- /**
175
- * Sets the item's role from `selectionType`: `presentation` for radio/checkbox (so the group
176
- * owns those controls directly), otherwise `listitem` (static items and switches). A role set
177
- * explicitly by the consumer is left untouched.
178
- */
179
- _applyRole() {
180
- this._hasExplicitRole || this.setAttribute("role", this._ownedByGroup ? "presentation" : "listitem");
181
- }
182
- /**
183
- * The accessible name and description this item provides to its slotted control, stitched from
184
- * its text. Only provided in a selectable list. Each control consumes this via `ariaContext`
185
- * and decides how to apply it: `pie-radio` names its host (which carries `role="radio"`),
186
- * while `pie-checkbox` / `pie-switch` name their internal input (their host is role-less, so
187
- * `aria-label` there would be invalid). Context reaches across the shadow boundary that
188
- * `aria-labelledby` cannot.
189
- */
190
- get _providedAria() {
191
- if (!this._isSelectable) return;
192
- const i = [this.secondaryText, this.metaText].filter(Boolean).join(". ");
193
- return { label: this.primaryText, description: i || void 0 };
194
- }
195
- _renderSecondaryText() {
196
- const { secondaryText: i } = this;
197
- return i ? p`<span class="c-listItem-secondaryText">${i}</span>` : m;
198
- }
199
- // metaText is another form of trailing content. The component can only ever display either slotted trailing content or the metaText string
200
- _renderTrailingContent() {
201
- const { metaText: i } = this;
202
- return i ? p`<span class="c-listItem-metaText c-listItem-trailing" aria-hidden=${this._isSelectable ? "true" : m}>${i}</span>` : p`<div class="c-listItem-trailing"><slot name="trailing"></slot></div>`;
203
- }
204
- render() {
205
- const { primaryText: i } = this, t = {
206
- "c-listItem-container": !0,
207
- "is-compact": this.isCompact,
208
- "is-bold": this.isBold,
209
- "has-media": this.hasMedia,
210
- "is-selectable": this._isSelectable,
211
- "is-disabled": this._isDisabled
212
- };
213
- return p`
214
- <div class=${k(t)}>
215
- <div class="c-listItem-leading">
216
- <slot name="leading"></slot>
217
- </div>
218
-
219
- <div class="c-listItem-text" aria-hidden=${this._isSelectable ? "true" : m}>
220
- <span class="c-listItem-primaryText">${i}</span>
221
- ${this._renderSecondaryText()}
222
- </div>
223
-
224
- ${this._renderTrailingContent()}
225
- </div>`;
226
- }
227
- };
228
- n.styles = x(R);
229
- l([
230
- c({ type: String })
231
- ], n.prototype, "primaryText", 2);
232
- l([
233
- c({ type: String })
234
- ], n.prototype, "secondaryText", 2);
235
- l([
236
- c({ type: String })
237
- ], n.prototype, "metaText", 2);
238
- l([
239
- c({ type: Boolean })
240
- ], n.prototype, "isCompact", 2);
241
- l([
242
- c({ type: Boolean })
243
- ], n.prototype, "isBold", 2);
244
- l([
245
- c({ type: Boolean })
246
- ], n.prototype, "hasMedia", 2);
247
- l([
248
- c({ type: String }),
249
- _($, z, d.selectionType)
250
- ], n.prototype, "selectionType", 2);
251
- l([
252
- c({ type: Boolean })
253
- ], n.prototype, "disabled", 2);
254
- l([
255
- B({ context: C, subscribe: !0 }),
256
- y()
257
- ], n.prototype, "_parentDisabled", 2);
258
- n = l([
259
- T("pie-list-item")
260
- ], n);
261
- export {
262
- n as P,
263
- d,
264
- z as s
265
- };