@commmerce/ui 1.0.0 → 1.1.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.
@@ -3,10 +3,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _CmHeaderBar_instances, _CmHeaderBar_fire;
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _CmHeaderBar_instances, _CmHeaderBar_resize, _CmHeaderBar_locked, _CmHeaderBar_opener, _CmHeaderBar_searchEl, _CmHeaderBar_onSearchSlot, _CmHeaderBar_fire;
7
13
  import { html, css, nothing } from 'lit';
8
14
  import { base, define } from '../base.js';
9
15
  import { CmLocalizedElement, defineStrings } from '../localize.js';
16
+ import { lockScroll, unlockScroll, deepActiveElement } from '../overlay.js';
10
17
  import './icon.js';
11
18
  import './avatar.js';
12
19
  const strings = defineStrings('headerBar', {
@@ -16,6 +23,8 @@ const strings = defineStrings('headerBar', {
16
23
  store: 'Store: {store}. Switch store',
17
24
  balance: 'Wallet balance {balance}',
18
25
  account: 'Account: {name}',
26
+ /** Accessible name of the search button on narrow bars, and of the full-screen search layer it opens. */
27
+ search: 'Search',
19
28
  });
20
29
  /**
21
30
  * The white bar across the top of the admin: logo, store switcher, then account actions, the wallet
@@ -23,17 +32,42 @@ const strings = defineStrings('headerBar', {
23
32
  *
24
33
  * The bar adapts to its own width: under 900px the actions hide; under 640px the balance hides too and the user pill shrinks to the avatar; put those
25
34
  * destinations in the Mobile menu instead.
35
+ *
36
+ * Global search goes in the `search` slot (usually a `cm-global-search`): inline after the store switcher while the bar is wider
37
+ * than 900px; at 900px or narrower the bar shows a search button instead, which opens the search full screen.
26
38
  * @element cm-header-bar
27
39
  * @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
28
40
  * @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
29
41
  * @slot end - Anything after the user pill, e.g. a notifications button.
42
+ * @slot search - One search box for the whole product, usually `cm-global-search`. Inline on wide bars; behind a search button that opens a full-screen layer at 900px or narrower.
30
43
  * @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
31
44
  * @fires cm-wallet - When the wallet balance is pressed.
32
45
  * @fires cm-account - When the user pill is pressed. Open the account menu in response.
46
+ * @fires cm-search-toggle - When the full-screen search layer opens or closes (narrow bars), with `detail: { open }`.
47
+ * @csspart search-button - The search button shown on narrow bars.
48
+ * @csspart search-layer - The full-screen search layer (a modal `<dialog>`).
33
49
  */
34
50
  export class CmHeaderBar extends CmLocalizedElement {
51
+ /** True while the full-screen search layer is open. */
52
+ get searchOpen() { return this._searchOpen; }
53
+ /** Brings up the search: focuses it on wide bars, or opens the full-screen layer on narrow ones. */
54
+ openSearch() {
55
+ if (!this._narrow) {
56
+ __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_searchEl).call(this)?.focus();
57
+ return;
58
+ }
59
+ if (this._searchOpen)
60
+ return;
61
+ __classPrivateFieldSet(this, _CmHeaderBar_opener, deepActiveElement(), "f");
62
+ this._searchOpen = true;
63
+ }
64
+ /** Closes the full-screen search layer, and returns focus to the search button. */
65
+ closeSearch() {
66
+ if (this._searchOpen)
67
+ this._searchOpen = false;
68
+ }
35
69
  constructor() {
36
- super(...arguments);
70
+ super();
37
71
  _CmHeaderBar_instances.add(this);
38
72
  /** Current store's address or name, shown as the store switcher ("preprod.commmerce.com"). Empty hides it. */
39
73
  this.store = '';
@@ -43,6 +77,65 @@ export class CmHeaderBar extends CmLocalizedElement {
43
77
  this.userName = '';
44
78
  /** Avatar image URL. Without it, the initials of `user-name` are shown. */
45
79
  this.avatarSrc = '';
80
+ this._narrow = false;
81
+ this._hasSearch = false;
82
+ this._searchOpen = false;
83
+ _CmHeaderBar_resize.set(this, void 0);
84
+ _CmHeaderBar_locked.set(this, false);
85
+ _CmHeaderBar_opener.set(this, null);
86
+ // Choosing a result in the layer navigates: close it (even when the app cancels the link to route itself).
87
+ this.addEventListener('cm-select', (e) => {
88
+ const s = __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_searchEl).call(this);
89
+ if (this._searchOpen && s && e.composedPath().includes(s))
90
+ this.closeSearch();
91
+ });
92
+ }
93
+ connectedCallback() {
94
+ super.connectedCallback();
95
+ __classPrivateFieldSet(this, _CmHeaderBar_resize, new ResizeObserver(([entry]) => {
96
+ const narrow = entry.contentRect.width <= 900;
97
+ if (narrow !== this._narrow) {
98
+ this._narrow = narrow;
99
+ if (!narrow)
100
+ this.closeSearch();
101
+ }
102
+ }), "f");
103
+ __classPrivateFieldGet(this, _CmHeaderBar_resize, "f").observe(this);
104
+ }
105
+ disconnectedCallback() {
106
+ super.disconnectedCallback();
107
+ __classPrivateFieldGet(this, _CmHeaderBar_resize, "f")?.disconnect();
108
+ if (__classPrivateFieldGet(this, _CmHeaderBar_locked, "f")) {
109
+ unlockScroll();
110
+ __classPrivateFieldSet(this, _CmHeaderBar_locked, false, "f");
111
+ }
112
+ }
113
+ updated(changed) {
114
+ if (!changed.has('_searchOpen'))
115
+ return;
116
+ const d = this.renderRoot.querySelector('dialog.layer');
117
+ if (this._searchOpen && d && !d.open) {
118
+ d.showModal();
119
+ if (!__classPrivateFieldGet(this, _CmHeaderBar_locked, "f")) {
120
+ lockScroll();
121
+ __classPrivateFieldSet(this, _CmHeaderBar_locked, true, "f");
122
+ }
123
+ __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_searchEl).call(this)?.focus();
124
+ __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-search-toggle', { open: true });
125
+ }
126
+ else if (!this._searchOpen && changed.get('_searchOpen')) {
127
+ if (d?.open)
128
+ d.close();
129
+ if (__classPrivateFieldGet(this, _CmHeaderBar_locked, "f")) {
130
+ unlockScroll();
131
+ __classPrivateFieldSet(this, _CmHeaderBar_locked, false, "f");
132
+ }
133
+ const o = __classPrivateFieldGet(this, _CmHeaderBar_opener, "f") ?? this.renderRoot.querySelector('.search-btn');
134
+ __classPrivateFieldSet(this, _CmHeaderBar_opener, null, "f");
135
+ if (o?.isConnected)
136
+ o.focus();
137
+ __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-search-toggle', { open: false });
138
+ }
46
139
  }
47
140
  render() {
48
141
  return html `
@@ -50,8 +143,11 @@ export class CmHeaderBar extends CmLocalizedElement {
50
143
  <div class="logo"><slot name="logo"></slot></div>
51
144
  ${this.store ? html `<button type="button" class="store" part="store" aria-haspopup="true" aria-label=${this.t('store', { store: this.store })}
52
145
  @click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-store-switch')}><span>${this.store}</span><cm-icon name="chevron-down" size="20"></cm-icon></button>` : nothing}
146
+ ${this._narrow ? nothing : html `<div class="search${this._hasSearch ? ' has' : ''}" part="search"><slot name="search" @slotchange=${__classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_onSearchSlot)}></slot></div>`}
53
147
  <span class="grow"></span>
54
148
  <div class="end">
149
+ ${this._narrow && this._hasSearch ? html `<button type="button" class="search-btn" part="search-button" aria-label=${this.searchLabel}
150
+ aria-haspopup="dialog" aria-expanded=${this._searchOpen ? 'true' : 'false'} @click=${() => this.openSearch()}><cm-icon name="search" size="20"></cm-icon></button>` : nothing}
55
151
  <div class="actions"><slot name="actions"></slot></div>
56
152
  ${this.balance ? html `<button type="button" class="pill" part="balance" aria-label=${this.t('balance', { balance: this.balance })}
57
153
  @click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-wallet')}>${this.balance}</button>` : nothing}
@@ -61,11 +157,30 @@ export class CmHeaderBar extends CmLocalizedElement {
61
157
  <slot name="end"></slot>
62
158
  </div>
63
159
  </header>
160
+ ${this._narrow ? html `<dialog class="layer" part="search-layer" aria-label=${this.searchLabel}
161
+ @keydown=${(e) => {
162
+ // Handle Escape here rather than relying on the dialog's cancel event, which browsers may skip after
163
+ // repeated Escapes without other input. The search box claims the Escapes it uses with preventDefault.
164
+ if (e.key === 'Escape' && !e.defaultPrevented) {
165
+ e.preventDefault();
166
+ this.closeSearch();
167
+ }
168
+ }}
169
+ @cancel=${(e) => { e.preventDefault(); this.closeSearch(); }} @close=${() => this.closeSearch()}>
170
+ <div class="layer-bar">
171
+ <div class="layer-search"><slot name="search" @slotchange=${__classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_onSearchSlot)}></slot></div>
172
+ <button type="button" class="layer-close" aria-label=${this.t('close')} @click=${() => this.closeSearch()}><cm-icon name="close" size="20"></cm-icon></button>
173
+ </div>
174
+ </dialog>` : nothing}
64
175
  `;
65
176
  }
66
177
  }
67
- _CmHeaderBar_instances = new WeakSet(), _CmHeaderBar_fire = function _CmHeaderBar_fire(name) {
68
- this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true }));
178
+ _CmHeaderBar_resize = new WeakMap(), _CmHeaderBar_locked = new WeakMap(), _CmHeaderBar_opener = new WeakMap(), _CmHeaderBar_instances = new WeakSet(), _CmHeaderBar_searchEl = function _CmHeaderBar_searchEl() { return this.querySelector(':scope > [slot="search"]'); }, _CmHeaderBar_onSearchSlot = function _CmHeaderBar_onSearchSlot() {
179
+ // Read the light DOM, not the event's slot: the slot moves between the bar and the layer, and the old one
180
+ // reports an empty assignment after it is removed.
181
+ this._hasSearch = !!__classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_searchEl).call(this);
182
+ }, _CmHeaderBar_fire = function _CmHeaderBar_fire(name, detail) {
183
+ this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail }));
69
184
  };
70
185
  CmHeaderBar.properties = {
71
186
  store: {},
@@ -73,6 +188,10 @@ CmHeaderBar.properties = {
73
188
  userName: { attribute: 'user-name' },
74
189
  avatarSrc: { attribute: 'avatar-src' },
75
190
  label: { string: 'label' },
191
+ searchLabel: { attribute: 'search-label', string: 'search' },
192
+ _narrow: { state: true },
193
+ _hasSearch: { state: true },
194
+ _searchOpen: { state: true },
76
195
  };
77
196
  CmHeaderBar.styles = [
78
197
  base,
@@ -105,6 +224,27 @@ CmHeaderBar.styles = [
105
224
  border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full);
106
225
  }
107
226
  .avatar { --cm-avatar-size: 36px; }
227
+ .search { display: none; flex: 1 1 240px; min-width: 200px; max-width: 560px; }
228
+ .search.has { display: block; }
229
+ .search-btn {
230
+ display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0;
231
+ border-radius: var(--cm-radius-sm); background: none; color: var(--cm-icon-selected); cursor: pointer;
232
+ }
233
+ .search-btn:hover { background: var(--cm-bg-hover); }
234
+ .layer {
235
+ position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
236
+ background: var(--cm-bg-surface); color: var(--cm-text-default); font: inherit;
237
+ --cm-global-search-results-position: static; --cm-global-search-results-shadow: none; --cm-global-search-results-max-height: none;
238
+ }
239
+ .layer[open] { display: flex; flex-direction: column; }
240
+ .layer::backdrop { background: var(--cm-bg-surface); }
241
+ .layer-bar { display: flex; align-items: flex-start; gap: var(--cm-space-10); flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px var(--cm-space-15); }
242
+ .layer-search { flex: 1; min-width: 0; }
243
+ .layer-close {
244
+ display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0;
245
+ border-radius: var(--cm-radius-sm); background: none; color: var(--cm-icon-selected); cursor: pointer;
246
+ }
247
+ .layer-close:hover { background: var(--cm-bg-hover); }
108
248
  button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
109
249
  @container (max-width: 1300px) {
110
250
  .store { margin-inline-start: var(--cm-space-20); }
@@ -4,7 +4,7 @@ import { type IconName } from '@commmerce/icons';
4
4
  export declare const directionalIcons: readonly string[];
5
5
  /**
6
6
  * Line icon from @commmerce/icons. Decorative unless `label` is set.
7
- * Icons that point forward or back (chevron-left/right, arrow-left, arrow-up-right, send) are mirrored in
7
+ * Icons that point forward or back (chevron-left/right, arrow-left, arrow-up-right, send, log-out) are mirrored in
8
8
  * right-to-left text (`dir="rtl"`); all others never are.
9
9
  * @element cm-icon
10
10
  */
@@ -2,10 +2,10 @@ import { LitElement, svg, css, nothing } from 'lit';
2
2
  import { icons, dotted } from '@commmerce/icons';
3
3
  import { define } from '../base.js';
4
4
  /** Icons that point along the reading direction (back, forward, go). In right-to-left text they are mirrored. */
5
- export const directionalIcons = ['chevron-left', 'chevron-right', 'arrow-left', 'arrow-up-right', 'send'];
5
+ export const directionalIcons = ['chevron-left', 'chevron-right', 'arrow-left', 'arrow-up-right', 'send', 'log-out'];
6
6
  /**
7
7
  * Line icon from @commmerce/icons. Decorative unless `label` is set.
8
- * Icons that point forward or back (chevron-left/right, arrow-left, arrow-up-right, send) are mirrored in
8
+ * Icons that point forward or back (chevron-left/right, arrow-left, arrow-up-right, send, log-out) are mirrored in
9
9
  * right-to-left text (`dir="rtl"`); all others never are.
10
10
  * @element cm-icon
11
11
  */
@@ -2,10 +2,15 @@ import { LitElement } from 'lit';
2
2
  import { type Tone } from '../base.js';
3
3
  import { CmOverlay } from '../overlay.js';
4
4
  import './icon.js';
5
+ import './skeleton.js';
5
6
  /** One notification in `cm-notification-panel`. */
6
7
  export interface NotificationItem {
7
8
  /** What happened: "New order received". */
8
9
  label: string;
10
+ /** A second line under the label, in smaller grey text: "Follow-up due at 4 pm". */
11
+ description?: string;
12
+ /** Icon name from `@commmerce/icons` for the kind of notification ("user", "clock"). Shown in the tone's colours instead of the tone's own icon. */
13
+ icon?: string;
9
14
  /** When, as shown: "1 min ago". */
10
15
  time?: string;
11
16
  /** Colour and icon: `information` (default), `attention`, `success` or `critical`. */
@@ -26,6 +31,8 @@ declare const strings: {
26
31
  empty: string;
27
32
  /** Read before an unread notification. */
28
33
  unread: string;
34
+ /** The header button that marks every notification read (`mark-all-read`). */
35
+ markAllRead: string;
29
36
  };
30
37
  declare module '../localize.js' {
31
38
  interface CmStrings {
@@ -54,6 +61,12 @@ export declare class CmNotificationItem extends LitElement {
54
61
  value: {
55
62
  reflect: boolean;
56
63
  };
64
+ description: {
65
+ reflect: boolean;
66
+ };
67
+ icon: {
68
+ reflect: boolean;
69
+ };
57
70
  };
58
71
  /** When, as shown: "1 min ago". */
59
72
  time: string;
@@ -65,6 +78,10 @@ export declare class CmNotificationItem extends LitElement {
65
78
  unread: boolean;
66
79
  /** Identifies it in `cm-select`. */
67
80
  value: string;
81
+ /** A second line under the label, in smaller grey text: "Follow-up due at 4 pm". */
82
+ description: string;
83
+ /** Icon name from `@commmerce/icons` for the kind ("user", "clock"), shown in the tone's colours instead of the tone's icon. */
84
+ icon: string;
68
85
  static styles: import("lit").CSSResult;
69
86
  render(): null;
70
87
  }
@@ -77,10 +94,12 @@ export declare class CmNotificationItem extends LitElement {
77
94
  * `cm-close`, scrolling is locked, and focus returns to the bell.
78
95
  * @element cm-notification-panel
79
96
  * @slot - `cm-notification-item`s.
97
+ * @slot footer - A control under the list, such as a toggle for push notifications on this device.
80
98
  * @fires cm-select - When a notification is chosen. `detail: { value, item }`. Cancelable: `preventDefault()` stops a link, to route in your app.
81
99
  * @fires cm-open - After the panel opens.
82
100
  * @fires cm-close - Before it closes. `detail: { reason }`. Cancelable.
83
101
  * @fires cm-closed - After it has closed.
102
+ * @fires cm-mark-all-read - When "Mark all read" is pressed (`mark-all-read`). Clear `unread` on your notifications in response; the button hides when none are unread.
84
103
  */
85
104
  export declare class CmNotificationPanel extends CmOverlay {
86
105
  #private;
@@ -102,9 +121,24 @@ export declare class CmNotificationPanel extends CmOverlay {
102
121
  attribute: string;
103
122
  string: string;
104
123
  };
124
+ markAllRead: {
125
+ type: BooleanConstructor;
126
+ attribute: string;
127
+ };
128
+ markAllLabel: {
129
+ attribute: string;
130
+ string: string;
131
+ };
132
+ loading: {
133
+ type: BooleanConstructor;
134
+ reflect: boolean;
135
+ };
105
136
  _slotted: {
106
137
  state: boolean;
107
138
  };
139
+ _footer: {
140
+ state: boolean;
141
+ };
108
142
  open: {
109
143
  type: BooleanConstructor;
110
144
  reflect: boolean;
@@ -125,7 +159,14 @@ export declare class CmNotificationPanel extends CmOverlay {
125
159
  moreLabel: string;
126
160
  /** Shown when there are no notifications. Default: the built-in string `empty` ("No notifications yet."). */
127
161
  emptyText: string;
162
+ /** Shows a "Mark all read" button in the header while at least one notification is unread. Pressing it fires `cm-mark-all-read`. */
163
+ markAllRead: boolean;
164
+ /** Text of that button. Default: the built-in string `markAllRead` ("Mark all read"). */
165
+ markAllLabel: string;
166
+ /** Shows placeholder rows while you fetch the notifications, and announces "Loading" politely. */
167
+ loading: boolean;
128
168
  _slotted: NotificationItem[];
169
+ _footer: boolean;
129
170
  static styles: import("lit").CSSResult[];
130
171
  connectedCallback(): void;
131
172
  disconnectedCallback(): void;
@@ -9,12 +9,13 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _CmNotificationPanel_instances, _CmNotificationPanel_observer, _CmNotificationPanel_read, _CmNotificationPanel_choose, _CmNotificationPanel_row;
12
+ var _CmNotificationPanel_instances, _CmNotificationPanel_observer, _CmNotificationPanel_read, _CmNotificationPanel_choose, _CmNotificationPanel_row, _CmNotificationPanel_markAll, _CmNotificationPanel_onFooter;
13
13
  import { LitElement, html, css, nothing } from 'lit';
14
14
  import { define } from '../base.js';
15
15
  import { CmOverlay } from '../overlay.js';
16
16
  import { defineStrings } from '../localize.js';
17
17
  import './icon.js';
18
+ import './skeleton.js';
18
19
  const strings = defineStrings('notificationPanel', {
19
20
  /** Title in the header. */
20
21
  heading: 'Notifications',
@@ -24,6 +25,8 @@ const strings = defineStrings('notificationPanel', {
24
25
  empty: 'No notifications yet.',
25
26
  /** Read before an unread notification. */
26
27
  unread: 'Unread: ',
28
+ /** The header button that marks every notification read (`mark-all-read`). */
29
+ markAllRead: 'Mark all read',
27
30
  });
28
31
  const ICONS = { information: 'bag', attention: 'alert', success: 'check-circle', critical: 'x-circle' };
29
32
  /**
@@ -43,6 +46,10 @@ export class CmNotificationItem extends LitElement {
43
46
  this.unread = false;
44
47
  /** Identifies it in `cm-select`. */
45
48
  this.value = '';
49
+ /** A second line under the label, in smaller grey text: "Follow-up due at 4 pm". */
50
+ this.description = '';
51
+ /** Icon name from `@commmerce/icons` for the kind ("user", "clock"), shown in the tone's colours instead of the tone's icon. */
52
+ this.icon = '';
46
53
  }
47
54
  render() { return null; }
48
55
  }
@@ -52,6 +59,8 @@ CmNotificationItem.properties = {
52
59
  href: { reflect: true },
53
60
  unread: { type: Boolean, reflect: true },
54
61
  value: { reflect: true },
62
+ description: { reflect: true },
63
+ icon: { reflect: true },
55
64
  };
56
65
  CmNotificationItem.styles = css `:host { display: none; }`;
57
66
  define('cm-notification-item', CmNotificationItem);
@@ -64,10 +73,12 @@ define('cm-notification-item', CmNotificationItem);
64
73
  * `cm-close`, scrolling is locked, and focus returns to the bell.
65
74
  * @element cm-notification-panel
66
75
  * @slot - `cm-notification-item`s.
76
+ * @slot footer - A control under the list, such as a toggle for push notifications on this device.
67
77
  * @fires cm-select - When a notification is chosen. `detail: { value, item }`. Cancelable: `preventDefault()` stops a link, to route in your app.
68
78
  * @fires cm-open - After the panel opens.
69
79
  * @fires cm-close - Before it closes. `detail: { reason }`. Cancelable.
70
80
  * @fires cm-closed - After it has closed.
81
+ * @fires cm-mark-all-read - When "Mark all read" is pressed (`mark-all-read`). Clear `unread` on your notifications in response; the button hides when none are unread.
71
82
  */
72
83
  export class CmNotificationPanel extends CmOverlay {
73
84
  constructor() {
@@ -77,7 +88,12 @@ export class CmNotificationPanel extends CmOverlay {
77
88
  this.items = [];
78
89
  /** Link to all notifications. Empty hides it. */
79
90
  this.moreHref = '';
91
+ /** Shows a "Mark all read" button in the header while at least one notification is unread. Pressing it fires `cm-mark-all-read`. */
92
+ this.markAllRead = false;
93
+ /** Shows placeholder rows while you fetch the notifications, and announces "Loading" politely. */
94
+ this.loading = false;
80
95
  this._slotted = [];
96
+ this._footer = false;
81
97
  _CmNotificationPanel_observer.set(this, void 0);
82
98
  }
83
99
  connectedCallback() {
@@ -94,12 +110,21 @@ export class CmNotificationPanel extends CmOverlay {
94
110
  get notifications() { return this.items.length ? this.items : this._slotted; }
95
111
  render() {
96
112
  const list = this.notifications;
113
+ const markAll = this.markAllRead && !this.loading && list.some((it) => it.unread)
114
+ ? html `<button type="button" class="mark" part="mark-all-read" @click=${__classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_markAll)}>${this.markAllLabel}</button>`
115
+ : nothing;
116
+ const body = this.loading
117
+ ? html `<ul class="loading" part="list" aria-hidden="true">${[0, 1, 2].map(() => html `<li>
118
+ <cm-skeleton class="sk-ic" variant="block" style="--cm-skeleton-height:22px"></cm-skeleton><cm-skeleton class="sk-text"></cm-skeleton></li>`)}</ul>`
119
+ : list.length
120
+ ? html `<ul class="list" part="list">${list.map((it) => html `<li>${__classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_row).call(this, it)}</li>`)}</ul>`
121
+ : html `<p class="empty">${this.emptyText}</p>`;
97
122
  return this.renderDialog(html `<div class="panel" part="panel" tabindex="-1">
98
- ${this.renderHeader()}
99
- ${list.length
100
- ? html `<ul class="list" part="list">${list.map((it) => html `<li>${__classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_row).call(this, it)}</li>`)}</ul>`
101
- : html `<p class="empty">${this.emptyText}</p>`}
123
+ ${this.renderHeader(markAll)}
124
+ ${body}
125
+ <span class="vh" role="status">${this.loading ? this.t('loading') : ''}</span>
102
126
  ${this.moreHref ? html `<a class="more" part="more" href=${this.moreHref}>${this.moreLabel}</a>` : nothing}
127
+ <div class="footer" part="footer" ?hidden=${!this._footer}><slot name="footer" @slotchange=${__classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_onFooter)}></slot></div>
103
128
  <slot hidden></slot>
104
129
  </div>`);
105
130
  }
@@ -109,7 +134,7 @@ _CmNotificationPanel_observer = new WeakMap(), _CmNotificationPanel_instances =
109
134
  const a = (n) => c.getAttribute(n) || undefined;
110
135
  return {
111
136
  label: (c.textContent ?? '').trim(), time: a('time'), tone: a('tone') ?? 'information', href: a('href'),
112
- unread: c.hasAttribute('unread') || undefined, value: a('value'),
137
+ unread: c.hasAttribute('unread') || undefined, value: a('value'), description: a('description'), icon: a('icon'),
113
138
  };
114
139
  });
115
140
  }, _CmNotificationPanel_choose = function _CmNotificationPanel_choose(e, it) {
@@ -123,13 +148,27 @@ _CmNotificationPanel_observer = new WeakMap(), _CmNotificationPanel_instances =
123
148
  this.requestClose('action');
124
149
  }, _CmNotificationPanel_row = function _CmNotificationPanel_row(it) {
125
150
  const tone = it.tone ?? 'information';
126
- const inner = html `<span class="ic ${tone}" aria-hidden="true"><cm-icon name=${ICONS[tone] ?? 'bell'} size="14"></cm-icon></span>
127
- <span class="label">${it.unread ? html `<span class="vh">${this.t('unread')}</span>` : nothing}${it.label}</span>
151
+ const label = it.description
152
+ ? html `<span class="title">${it.label}</span><span class="vh">, </span><span class="desc">${it.description}</span>`
153
+ : it.label;
154
+ const inner = html `<span class="ic ${tone}" aria-hidden="true"><cm-icon name=${it.icon || ICONS[tone] || 'bell'} size="14"></cm-icon></span>
155
+ <span class="label">${it.unread ? html `<span class="vh">${this.t('unread')}</span>` : nothing}${label}</span>
128
156
  ${it.time ? html `<time>${it.time}</time>` : nothing}`;
129
157
  const cls = `row${it.unread ? ' unread' : ''}`;
130
158
  return it.href
131
159
  ? html `<a class=${cls} part="row" href=${it.href} @click=${(e) => __classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_choose).call(this, e, it)}>${inner}</a>`
132
160
  : html `<button type="button" class=${cls} part="row" @click=${(e) => __classPrivateFieldGet(this, _CmNotificationPanel_instances, "m", _CmNotificationPanel_choose).call(this, e, it)}>${inner}</button>`;
161
+ }, _CmNotificationPanel_markAll = async function _CmNotificationPanel_markAll(e) {
162
+ const btn = e.currentTarget;
163
+ this.dispatchEvent(new CustomEvent('cm-mark-all-read', { bubbles: true, composed: true }));
164
+ // The app clears `unread`, which removes the button: keep focus in the panel rather than losing it.
165
+ await new Promise((r) => setTimeout(r));
166
+ await this.updateComplete;
167
+ if (!btn.isConnected && this.open)
168
+ this.renderRoot.querySelector('.panel')?.focus();
169
+ }, _CmNotificationPanel_onFooter = function _CmNotificationPanel_onFooter(e) {
170
+ this._footer = e.target.assignedNodes({ flatten: true })
171
+ .some((n) => n.nodeType === Node.ELEMENT_NODE || (n.textContent ?? '').trim());
133
172
  };
134
173
  CmNotificationPanel.properties = {
135
174
  ...CmOverlay.properties,
@@ -138,7 +177,11 @@ CmNotificationPanel.properties = {
138
177
  heading: { string: 'heading' },
139
178
  moreLabel: { attribute: 'more-label', string: 'more' },
140
179
  emptyText: { attribute: 'empty-text', string: 'empty' },
180
+ markAllRead: { type: Boolean, attribute: 'mark-all-read' },
181
+ markAllLabel: { attribute: 'mark-all-label', string: 'markAllRead' },
182
+ loading: { type: Boolean, reflect: true },
141
183
  _slotted: { state: true },
184
+ _footer: { state: true },
142
185
  };
143
186
  CmNotificationPanel.styles = [
144
187
  ...CmOverlay.overlayStyles,
@@ -164,6 +207,22 @@ CmNotificationPanel.styles = [
164
207
  .critical { background: var(--cm-bg-critical); color: var(--cm-text-critical); }
165
208
  .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
166
209
  .unread .label { font-weight: 600; }
210
+ .desc { display: block; font-weight: 400; font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); }
211
+ .row:has(.desc) { align-items: flex-start; }
212
+ .row:has(.desc) .ic, .row:has(.desc) time { margin-block-start: 1px; }
213
+ .mark {
214
+ flex: none; padding: 4px 6px; border: 0; border-radius: var(--cm-radius-sm); background: none; color: inherit;
215
+ font: inherit; font-size: 12px; line-height: 16px; text-decoration: underline; cursor: pointer;
216
+ }
217
+ .mark:hover { text-decoration-thickness: 2px; }
218
+ .mark:focus-visible { outline: 2px solid var(--cm-text-on-dark); outline-offset: 0; }
219
+ .loading { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0; list-style: none; }
220
+ .loading li { display: flex; align-items: center; gap: var(--cm-space-10); min-height: 40px; padding: 8px var(--cm-space-15); }
221
+ .loading li:nth-child(even) { background: var(--cm-bg-hover); }
222
+ .loading .sk-ic { flex: none; width: 22px; }
223
+ .loading .sk-text { flex: 1; }
224
+ .footer { flex: none; padding: var(--cm-space-10) var(--cm-space-15); font-size: 13px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
225
+ .footer[hidden] { display: none; }
167
226
  time { flex: none; font-size: 11px; color: var(--cm-text-tertiary); }
168
227
  .vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
169
228
  .more {
@@ -1,9 +1,14 @@
1
1
  import { CmLocalizedElement } from '../localize.js';
2
2
  import { type NavItem } from './nav-item.js';
3
3
  import './icon.js';
4
+ import './tooltip.js';
4
5
  declare const strings: {
5
6
  /** Accessible name of the navigation landmark. */
6
7
  label: string;
8
+ /** The built-in collapse button, while the full menu is shown. */
9
+ collapse: string;
10
+ /** The built-in collapse button, while only icons are shown. */
11
+ expand: string;
7
12
  };
8
13
  declare module '../localize.js' {
9
14
  interface CmStrings {
@@ -16,12 +21,20 @@ declare module '../localize.js' {
16
21
  * apps are shown inside the admin, which already has this menu.
17
22
  *
18
23
  * Items come from `cm-nav-item` children or the `items` property, so every Commmerce product can use it.
24
+ *
25
+ * `collapsed` turns it into a narrow rail of icons, to give wide pages (tables, reports) more room. Each item's
26
+ * label is still its accessible name and shows as a tooltip on hover and focus; badges become a dot (or a small
27
+ * count when the badge is a number). Add `collapsible` for a built-in button that switches between the two: it
28
+ * fires `cm-collapse` so the app can remember the choice.
19
29
  * @element cm-side-navigation
20
30
  * @slot - `cm-nav-item` elements (nest them for sub-items).
21
31
  * @slot header - Optional content above the items, such as a store switcher on narrow layouts.
22
32
  * @slot footer - Optional content below the items.
23
33
  * @fires cm-navigate - When an item is chosen. `detail: { item, value, href }`. Cancelable: call `preventDefault()` to route in your app instead of following the link.
24
34
  * @fires cm-expand - When a section opens or closes. `detail: { item, expanded }`.
35
+ * @fires cm-collapse - When the merchant collapses the menu to icons or expands it again: from the built-in button (`collapsible`), or by choosing a section while collapsed (that expands the menu and opens the section). `detail: { collapsed }`. Cancelable: call `preventDefault()` to keep the current state. Not fired when you set `collapsed` yourself.
36
+ * @cssprop --cm-side-navigation-width - Width of the full menu. Default `250px`.
37
+ * @cssprop --cm-side-navigation-collapsed-width - Width of the icon rail (`collapsed`). Default `72px`.
25
38
  */
26
39
  export declare class CmSideNavigation extends CmLocalizedElement {
27
40
  #private;
@@ -32,6 +45,14 @@ export declare class CmSideNavigation extends CmLocalizedElement {
32
45
  label: {
33
46
  string: string;
34
47
  };
48
+ collapsed: {
49
+ type: BooleanConstructor;
50
+ reflect: boolean;
51
+ };
52
+ collapsible: {
53
+ type: BooleanConstructor;
54
+ reflect: boolean;
55
+ };
35
56
  _slotted: {
36
57
  state: boolean;
37
58
  };
@@ -43,6 +64,10 @@ export declare class CmSideNavigation extends CmLocalizedElement {
43
64
  items: NavItem[];
44
65
  /** Accessible name of the navigation landmark. Default: the built-in string `label` ("Main"). */
45
66
  label: string;
67
+ /** Shows only the icons, in a narrow rail. Labels become tooltips and stay the items' accessible names; sub-items are hidden. */
68
+ collapsed: boolean;
69
+ /** Adds a button at the bottom that collapses the menu to icons and expands it again, firing `cm-collapse`. */
70
+ collapsible: boolean;
46
71
  _slotted: NavItem[];
47
72
  _open: Set<string>;
48
73
  static styles: import("lit").CSSResult[];