@commmerce/ui 1.0.0-rc.5 → 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.
@@ -0,0 +1,152 @@
1
+ import { type PropertyValues } from 'lit';
2
+ import { CmLocalizedElement } from '../localize.js';
3
+ import './icon.js';
4
+ import './spinner.js';
5
+ /** One result in `cm-global-search`. */
6
+ export interface GlobalSearchItem {
7
+ /** The record's name: "Ravi Stores". */
8
+ title: string;
9
+ /** A second line in smaller grey text: "Lead · Mumbai · +91 98200 12345". */
10
+ description?: string;
11
+ /** The record's page. Every result is a link. */
12
+ href: string;
13
+ /** Icon name from `@commmerce/icons`, shown before the title. */
14
+ icon?: string;
15
+ /** Identifies the result in `cm-select`. Defaults to the href. */
16
+ value?: string;
17
+ }
18
+ /** A group of results of one kind ("Leads", "Deals") in `cm-global-search`. */
19
+ export interface GlobalSearchGroup {
20
+ /** Group heading: "Leads". */
21
+ label: string;
22
+ /** How many records of this kind match in total, shown next to the heading. Defaults to the number of items. */
23
+ total?: number;
24
+ /** The results shown, best first. Keep to about five per group. */
25
+ items: GlobalSearchItem[];
26
+ /** Link to every match of this kind (your list page filtered by the query). Shows a "See all" row. */
27
+ href?: string;
28
+ /** Text of that row, instead of the component's `see-all-label`. */
29
+ seeAllLabel?: string;
30
+ }
31
+ declare const strings: {
32
+ /** Accessible name and placeholder of the text box. */
33
+ label: string;
34
+ placeholder: string;
35
+ /** Shown and announced when nothing matches. */
36
+ noResults: string;
37
+ /** Announced as results arrive; also read after each group heading for its total. */
38
+ results: {
39
+ one: string;
40
+ other: string;
41
+ };
42
+ /** The row under a group that links to every match. */
43
+ seeAll: string;
44
+ /** Accessible name of the clear button. */
45
+ clear: string;
46
+ };
47
+ declare module '../localize.js' {
48
+ interface CmStrings {
49
+ globalSearch: typeof strings;
50
+ }
51
+ }
52
+ /**
53
+ * One box that searches everything (customers, orders, products…) and lists the matches grouped by kind, each a
54
+ * link to its page. Your app does the searching: listen for `cm-search`, fetch, then set `results` (and `loading`
55
+ * while it runs). Put it in the header bar's `search` slot: on narrow screens the bar shows a search button that
56
+ * opens it full screen.
57
+ *
58
+ * Unlike `cm-combobox`, which picks a value for a form, choosing a result navigates.
59
+ * Follows the WAI-ARIA combobox pattern with a grouped listbox: focus stays in the text box and the highlighted
60
+ * result is announced with `aria-activedescendant`.
61
+ * @element cm-global-search
62
+ * @fires cm-search - As the merchant types (and when the box is cleared), with `detail: { query }`. Fetch results and set `results`.
63
+ * @fires cm-select - When a result or a "See all" row is chosen, with `detail: { href, item, group }` (`item` is undefined for "See all"). Cancelable: `preventDefault()` stops the link, to route in your app.
64
+ * @csspart box - The bordered box around the icon and the text input.
65
+ * @csspart input - The text input.
66
+ * @csspart popover - The panel under the box that holds the results.
67
+ * @csspart listbox - The grouped list of results.
68
+ * @cssprop --cm-global-search-results-position - `position` of the results panel. Default `absolute` (over the page); the header bar's full-screen layer sets `static`.
69
+ * @cssprop --cm-global-search-results-max-height - Tallest the results panel gets before it scrolls. Default `min(480px, 100dvh - 140px)`.
70
+ * @cssprop --cm-global-search-results-shadow - Shadow of the results panel. Default `var(--cm-shadow-100)`.
71
+ */
72
+ export declare class CmGlobalSearch extends CmLocalizedElement {
73
+ #private;
74
+ static shadowRootOptions: {
75
+ delegatesFocus: boolean;
76
+ mode: ShadowRootMode;
77
+ serializable?: boolean;
78
+ slotAssignment?: SlotAssignmentMode;
79
+ };
80
+ static properties: {
81
+ label: {
82
+ string: string;
83
+ };
84
+ placeholder: {
85
+ string: string;
86
+ };
87
+ value: {};
88
+ results: {
89
+ type: ArrayConstructor;
90
+ };
91
+ loading: {
92
+ type: BooleanConstructor;
93
+ reflect: boolean;
94
+ };
95
+ open: {
96
+ type: BooleanConstructor;
97
+ reflect: boolean;
98
+ };
99
+ emptyText: {
100
+ attribute: string;
101
+ string: string;
102
+ };
103
+ loadingText: {
104
+ attribute: string;
105
+ string: string;
106
+ };
107
+ seeAllLabel: {
108
+ attribute: string;
109
+ string: string;
110
+ };
111
+ shortcut: {};
112
+ _active: {
113
+ state: boolean;
114
+ };
115
+ };
116
+ /** Accessible name of the box, read by screen readers but not shown. Default: the built-in string `label` ("Search"). */
117
+ label: string;
118
+ /** Example query in the empty box: "Search leads, deals, contacts". Default: the built-in string `placeholder` ("Search"). */
119
+ placeholder: string;
120
+ /** The query. Updated as the merchant types. */
121
+ value: string;
122
+ /** Results for the current query, grouped by kind. Set it when your search returns. Groups with no items are skipped. */
123
+ results: GlobalSearchGroup[];
124
+ /** Shows "Loading" with a spinner in place of the results while you fetch them. */
125
+ loading: boolean;
126
+ /** Whether the results panel is showing. It shows only while there is a query. */
127
+ open: boolean;
128
+ /** Shown when a query has no results. Default: the built-in string `noResults` ("No results"). */
129
+ emptyText: string;
130
+ /** Shown and announced while `loading`. Default: the built-in string `loading` ("Loading", shared with other components). */
131
+ loadingText: string;
132
+ /** Text of each group's "See all" row. Default: the built-in string `seeAll` ("See all"). */
133
+ seeAllLabel: string;
134
+ /**
135
+ * A key that moves focus to the box from anywhere on the page, e.g. `/`. Off by default: turn it on only for
136
+ * one search per page. It is ignored while the merchant is typing in a field or holding Ctrl, Alt or Cmd.
137
+ */
138
+ shortcut: string;
139
+ _active: number;
140
+ static styles: import("lit").CSSResult[];
141
+ connectedCallback(): void;
142
+ disconnectedCallback(): void;
143
+ willUpdate(changed: PropertyValues): void;
144
+ updated(changed: PropertyValues): void;
145
+ render(): import("lit-html").TemplateResult<1>;
146
+ }
147
+ declare global {
148
+ interface HTMLElementTagNameMap {
149
+ 'cm-global-search': CmGlobalSearch;
150
+ }
151
+ }
152
+ export {};
@@ -0,0 +1,303 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
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 _CmGlobalSearch_instances, _CmGlobalSearch_id, _CmGlobalSearch_stopOutside, _CmGlobalSearch_rows, _CmGlobalSearch_showing_get, _CmGlobalSearch_hide, _CmGlobalSearch_search, _CmGlobalSearch_onInput, _CmGlobalSearch_move, _CmGlobalSearch_onKeyDown, _CmGlobalSearch_onShortcut, _CmGlobalSearch_clear, _CmGlobalSearch_choose;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { live } from 'lit/directives/live.js';
15
+ import { base, define, nextId } from '../base.js';
16
+ import { CmLocalizedElement, defineStrings } from '../localize.js';
17
+ import { popoverStyles, closeOnOutsidePointer } from '../popover.js';
18
+ import './icon.js';
19
+ import './spinner.js';
20
+ const strings = defineStrings('globalSearch', {
21
+ /** Accessible name and placeholder of the text box. */
22
+ label: 'Search',
23
+ placeholder: 'Search',
24
+ /** Shown and announced when nothing matches. */
25
+ noResults: 'No results',
26
+ /** Announced as results arrive; also read after each group heading for its total. */
27
+ results: { one: '{count} result', other: '{count} results' },
28
+ /** The row under a group that links to every match. */
29
+ seeAll: 'See all',
30
+ /** Accessible name of the clear button. */
31
+ clear: 'Clear search',
32
+ });
33
+ /**
34
+ * One box that searches everything (customers, orders, products…) and lists the matches grouped by kind, each a
35
+ * link to its page. Your app does the searching: listen for `cm-search`, fetch, then set `results` (and `loading`
36
+ * while it runs). Put it in the header bar's `search` slot: on narrow screens the bar shows a search button that
37
+ * opens it full screen.
38
+ *
39
+ * Unlike `cm-combobox`, which picks a value for a form, choosing a result navigates.
40
+ * Follows the WAI-ARIA combobox pattern with a grouped listbox: focus stays in the text box and the highlighted
41
+ * result is announced with `aria-activedescendant`.
42
+ * @element cm-global-search
43
+ * @fires cm-search - As the merchant types (and when the box is cleared), with `detail: { query }`. Fetch results and set `results`.
44
+ * @fires cm-select - When a result or a "See all" row is chosen, with `detail: { href, item, group }` (`item` is undefined for "See all"). Cancelable: `preventDefault()` stops the link, to route in your app.
45
+ * @csspart box - The bordered box around the icon and the text input.
46
+ * @csspart input - The text input.
47
+ * @csspart popover - The panel under the box that holds the results.
48
+ * @csspart listbox - The grouped list of results.
49
+ * @cssprop --cm-global-search-results-position - `position` of the results panel. Default `absolute` (over the page); the header bar's full-screen layer sets `static`.
50
+ * @cssprop --cm-global-search-results-max-height - Tallest the results panel gets before it scrolls. Default `min(480px, 100dvh - 140px)`.
51
+ * @cssprop --cm-global-search-results-shadow - Shadow of the results panel. Default `var(--cm-shadow-100)`.
52
+ */
53
+ export class CmGlobalSearch extends CmLocalizedElement {
54
+ constructor() {
55
+ super(...arguments);
56
+ _CmGlobalSearch_instances.add(this);
57
+ /** The query. Updated as the merchant types. */
58
+ this.value = '';
59
+ /** Results for the current query, grouped by kind. Set it when your search returns. Groups with no items are skipped. */
60
+ this.results = [];
61
+ /** Shows "Loading" with a spinner in place of the results while you fetch them. */
62
+ this.loading = false;
63
+ /** Whether the results panel is showing. It shows only while there is a query. */
64
+ this.open = false;
65
+ /**
66
+ * A key that moves focus to the box from anywhere on the page, e.g. `/`. Off by default: turn it on only for
67
+ * one search per page. It is ignored while the merchant is typing in a field or holding Ctrl, Alt or Cmd.
68
+ */
69
+ this.shortcut = '';
70
+ this._active = -1;
71
+ _CmGlobalSearch_id.set(this, nextId('cm-gs'));
72
+ _CmGlobalSearch_stopOutside.set(this, void 0);
73
+ _CmGlobalSearch_onInput.set(this, (e) => {
74
+ this.value = e.target.value;
75
+ this._active = -1;
76
+ this.open = !!this.value.trim();
77
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_search).call(this);
78
+ });
79
+ _CmGlobalSearch_onKeyDown.set(this, (e) => {
80
+ switch (e.key) {
81
+ case 'ArrowDown':
82
+ case 'ArrowUp':
83
+ e.preventDefault();
84
+ if (!this.value.trim())
85
+ break;
86
+ if (!this.open)
87
+ this.open = true;
88
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_move).call(this, e.key === 'ArrowDown' ? 1 : -1);
89
+ break;
90
+ case 'Enter':
91
+ if (__classPrivateFieldGet(this, _CmGlobalSearch_instances, "a", _CmGlobalSearch_showing_get) && this._active >= 0) {
92
+ e.preventDefault();
93
+ this.renderRoot.querySelector(`#${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${this._active}`)?.click();
94
+ }
95
+ break;
96
+ case 'Escape':
97
+ if (__classPrivateFieldGet(this, _CmGlobalSearch_instances, "a", _CmGlobalSearch_showing_get)) {
98
+ e.preventDefault();
99
+ e.stopPropagation();
100
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this);
101
+ }
102
+ else if (this.value) {
103
+ e.preventDefault();
104
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_clear).call(this, false);
105
+ }
106
+ break;
107
+ case 'Tab':
108
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this);
109
+ break;
110
+ default:
111
+ }
112
+ });
113
+ _CmGlobalSearch_onShortcut.set(this, (e) => {
114
+ if (!this.shortcut || e.key !== this.shortcut || e.ctrlKey || e.metaKey || e.altKey || e.defaultPrevented)
115
+ return;
116
+ const t = e.composedPath()[0];
117
+ if (t && (t.isContentEditable || /^(input|textarea|select)$/i.test(t.localName ?? '')))
118
+ return;
119
+ if (!this.getClientRects().length)
120
+ return; // hidden, e.g. inside a closed layer
121
+ e.preventDefault();
122
+ this.focus();
123
+ });
124
+ }
125
+ connectedCallback() {
126
+ super.connectedCallback();
127
+ __classPrivateFieldSet(this, _CmGlobalSearch_stopOutside, closeOnOutsidePointer(this, () => this.open, () => __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this)), "f");
128
+ document.addEventListener('keydown', __classPrivateFieldGet(this, _CmGlobalSearch_onShortcut, "f"));
129
+ }
130
+ disconnectedCallback() {
131
+ super.disconnectedCallback();
132
+ __classPrivateFieldGet(this, _CmGlobalSearch_stopOutside, "f")?.call(this);
133
+ document.removeEventListener('keydown', __classPrivateFieldGet(this, _CmGlobalSearch_onShortcut, "f"));
134
+ }
135
+ willUpdate(changed) {
136
+ if (changed.has('results') || changed.has('loading') || changed.has('value')) {
137
+ if (this._active >= __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_rows).call(this).length)
138
+ this._active = -1;
139
+ }
140
+ }
141
+ updated(changed) {
142
+ if ((changed.has('_active') || changed.has('open')) && this.open && this._active >= 0) {
143
+ this.renderRoot.querySelector(`#${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${this._active}`)?.scrollIntoView({ block: 'nearest' });
144
+ }
145
+ }
146
+ render() {
147
+ const rows = __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_rows).call(this);
148
+ const showing = __classPrivateFieldGet(this, _CmGlobalSearch_instances, "a", _CmGlobalSearch_showing_get);
149
+ const items = rows.filter((r) => r.item).length;
150
+ const status = this.loading && showing ? this.loadingText
151
+ : !showing ? ''
152
+ : rows.length ? this.t('results', { count: items })
153
+ : this.emptyText;
154
+ let i = -1;
155
+ const groups = (this.results ?? []).filter((g) => g?.items?.length);
156
+ const option = (row, content, cls = '') => {
157
+ i++;
158
+ const n = i;
159
+ return html `<a role="option" id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${n}" class="${cls}${n === this._active ? ' active' : ''}" href=${row.href} tabindex="-1"
160
+ aria-selected=${n === this._active ? 'true' : 'false'} @pointerenter=${() => (this._active = n)}
161
+ @click=${(e) => __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_choose).call(this, e, row)}>${content}</a>`;
162
+ };
163
+ return html `<div class="wrap">
164
+ <div class="box" part="box" @click=${(e) => { if (e.target === e.currentTarget)
165
+ this.focus(); }}>
166
+ <cm-icon class="icon" name="search" size="14"></cm-icon>
167
+ <input id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-in" part="input" type="search" role="combobox" enterkeyhint="search" autocomplete="off" spellcheck="false"
168
+ aria-label=${this.label} placeholder=${this.placeholder || nothing} .value=${live(this.value)}
169
+ aria-autocomplete="list" aria-expanded=${showing ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-list"
170
+ aria-activedescendant=${showing && this._active >= 0 ? `${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${this._active}` : nothing}
171
+ aria-keyshortcuts=${this.shortcut || nothing}
172
+ @input=${__classPrivateFieldGet(this, _CmGlobalSearch_onInput, "f")} @keydown=${__classPrivateFieldGet(this, _CmGlobalSearch_onKeyDown, "f")}
173
+ @focus=${() => { if (this.value.trim())
174
+ this.open = true; }} @click=${() => { if (this.value.trim())
175
+ this.open = true; }} />
176
+ ${this.value
177
+ ? html `<button type="button" class="clear" part="clear" aria-label=${this.t('clear')} @click=${() => __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_clear).call(this)}><cm-icon name="close" size="14"></cm-icon></button>`
178
+ : this.shortcut ? html `<kbd aria-hidden="true">${this.shortcut}</kbd>` : nothing}
179
+ </div>
180
+ <div class="pop" part="popover" ?hidden=${!showing} @pointerdown=${(e) => e.preventDefault()}>
181
+ <div role="listbox" id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-list" part="listbox" aria-label=${this.label} ?hidden=${!rows.length}>
182
+ ${groups.map((g, gi) => {
183
+ const total = g.total ?? g.items.length;
184
+ return html `<div role="group" aria-labelledby="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-g${gi}">
185
+ <div role="presentation" class="gh" id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-g${gi}"><span>${g.label}</span><span class="count" aria-hidden="true">${this.formatNumber(total)}</span><span class="vh">, ${this.t('results', { count: total })}</span></div>
186
+ ${g.items.map((it) => option({ group: g, item: it, href: it.href }, html `${it.icon ? html `<cm-icon name=${it.icon} size="16"></cm-icon>` : nothing}<span class="text"><span class="title">${it.title}</span>${it.description ? html `<span class="vh">, </span><span class="desc">${it.description}</span>` : nothing}</span>`))}
187
+ ${g.href ? option({ group: g, href: g.href }, html `<span class="text">${g.seeAllLabel || this.seeAllLabel}</span>`, 'all') : nothing}
188
+ </div>`;
189
+ })}
190
+ </div>
191
+ ${this.loading
192
+ ? html `<p class="message"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span aria-hidden="true">${this.loadingText}</span></p>`
193
+ : !rows.length ? html `<p class="message" aria-hidden="true">${this.emptyText}</p>` : nothing}
194
+ </div>
195
+ <span class="vh" role="status" aria-live="polite">${status}</span>
196
+ </div>`;
197
+ }
198
+ }
199
+ _CmGlobalSearch_id = new WeakMap(), _CmGlobalSearch_stopOutside = new WeakMap(), _CmGlobalSearch_onInput = new WeakMap(), _CmGlobalSearch_onKeyDown = new WeakMap(), _CmGlobalSearch_onShortcut = new WeakMap(), _CmGlobalSearch_instances = new WeakSet(), _CmGlobalSearch_rows = function _CmGlobalSearch_rows() {
200
+ if (this.loading)
201
+ return [];
202
+ return (this.results ?? []).filter((g) => g?.items?.length).flatMap((group) => [
203
+ ...group.items.map((item) => ({ group, item, href: item.href })),
204
+ ...(group.href ? [{ group, href: group.href }] : []),
205
+ ]);
206
+ }, _CmGlobalSearch_showing_get = function _CmGlobalSearch_showing_get() { return this.open && !!this.value.trim(); }, _CmGlobalSearch_hide = function _CmGlobalSearch_hide() { this.open = false; this._active = -1; }, _CmGlobalSearch_search = function _CmGlobalSearch_search() {
207
+ this.dispatchEvent(new CustomEvent('cm-search', { detail: { query: this.value }, bubbles: true, composed: true }));
208
+ }, _CmGlobalSearch_move = function _CmGlobalSearch_move(step) {
209
+ const n = __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_rows).call(this).length;
210
+ if (!n) {
211
+ this._active = -1;
212
+ return;
213
+ }
214
+ if (this._active < 0)
215
+ this._active = step > 0 ? 0 : n - 1;
216
+ else
217
+ this._active = (this._active + step + n) % n;
218
+ }, _CmGlobalSearch_clear = function _CmGlobalSearch_clear(focus = true) {
219
+ this.value = '';
220
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this);
221
+ if (focus)
222
+ this.renderRoot.querySelector('input')?.focus();
223
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_search).call(this);
224
+ }, _CmGlobalSearch_choose = function _CmGlobalSearch_choose(e, row) {
225
+ const ok = this.dispatchEvent(new CustomEvent('cm-select', {
226
+ detail: { href: row.href, item: row.item, group: row.group }, bubbles: true, composed: true, cancelable: true,
227
+ }));
228
+ if (!ok)
229
+ e.preventDefault();
230
+ __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this);
231
+ };
232
+ CmGlobalSearch.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
233
+ CmGlobalSearch.properties = {
234
+ label: { string: 'label' },
235
+ placeholder: { string: 'placeholder' },
236
+ value: {},
237
+ results: { type: Array },
238
+ loading: { type: Boolean, reflect: true },
239
+ open: { type: Boolean, reflect: true },
240
+ emptyText: { attribute: 'empty-text', string: 'noResults' },
241
+ loadingText: { attribute: 'loading-text', string: 'loading' },
242
+ seeAllLabel: { attribute: 'see-all-label', string: 'seeAll' },
243
+ shortcut: {},
244
+ _active: { state: true },
245
+ };
246
+ CmGlobalSearch.styles = [
247
+ base,
248
+ popoverStyles,
249
+ css `
250
+ :host { display: block; position: relative; }
251
+ .wrap { position: relative; }
252
+ .box {
253
+ display: flex; align-items: center; gap: var(--cm-space-10); height: 42px; padding: 0 var(--cm-space-10);
254
+ background: var(--cm-bg-page); color: var(--cm-text-default);
255
+ border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
256
+ }
257
+ .box:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
258
+ .icon { flex: none; color: var(--cm-icon-selected); }
259
+ input {
260
+ flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: none; outline: none;
261
+ font: inherit; font-size: 14px; color: var(--cm-text-default);
262
+ }
263
+ input::placeholder { color: var(--cm-text-tertiary); }
264
+ input::-webkit-search-cancel-button { display: none; }
265
+ .clear {
266
+ flex: none; display: inline-flex; align-items: center; justify-content: center;
267
+ width: 28px; height: 28px; margin: 0 -4px; padding: 0; border: 0; border-radius: var(--cm-radius-sm);
268
+ background: none; color: var(--cm-icon-selected); cursor: pointer;
269
+ }
270
+ .clear:hover { background: var(--cm-bg-hover); }
271
+ .clear:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
272
+ kbd {
273
+ flex: none; min-width: 20px; padding: 0 5px; font: inherit; font-size: 12px; line-height: 18px; text-align: center;
274
+ color: var(--cm-text-tertiary); border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-xs);
275
+ }
276
+ .box:focus-within kbd { display: none; }
277
+ .pop {
278
+ position: var(--cm-global-search-results-position, absolute);
279
+ box-shadow: var(--cm-global-search-results-shadow, var(--cm-shadow-100));
280
+ overflow-y: auto; max-height: var(--cm-global-search-results-max-height, min(480px, calc(100dvh - 140px)));
281
+ }
282
+ [role='listbox'] { padding-block: 6px; }
283
+ [role='listbox'][hidden] { display: none; }
284
+ [role='group'] + [role='group'] { margin-block-start: 6px; padding-block-start: 6px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
285
+ .gh {
286
+ display: flex; align-items: baseline; gap: var(--cm-space-10); padding: 6px var(--cm-space-20) 2px;
287
+ font-size: 12px; line-height: 16px; font-weight: 600; color: var(--cm-text-default);
288
+ }
289
+ .gh .count { font-weight: 400; color: var(--cm-text-tertiary); }
290
+ [role='option'] {
291
+ display: flex; align-items: center; gap: var(--cm-space-10); min-height: 40px; padding: 6px var(--cm-space-20);
292
+ font-size: 14px; line-height: 20px; color: var(--cm-text-default); text-decoration: none; cursor: pointer;
293
+ }
294
+ [role='option'].active { background: var(--cm-bg-hover); box-shadow: inset 2px 0 0 var(--cm-border-strong); }
295
+ [role='option'].active:dir(rtl) { box-shadow: inset -2px 0 0 var(--cm-border-strong); }
296
+ [role='option'] cm-icon { flex: none; color: var(--cm-icon-selected); }
297
+ .text { flex: 1; min-width: 0; }
298
+ .title, .desc { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
299
+ .desc { font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); }
300
+ .all { font-size: 13px; text-decoration: underline; }
301
+ `,
302
+ ];
303
+ define('cm-global-search', CmGlobalSearch);
@@ -1,3 +1,4 @@
1
+ import { type PropertyValues } from 'lit';
1
2
  import { CmLocalizedElement } from '../localize.js';
2
3
  import './icon.js';
3
4
  import './avatar.js';
@@ -8,6 +9,8 @@ declare const strings: {
8
9
  store: string;
9
10
  balance: string;
10
11
  account: string;
12
+ /** Accessible name of the search button on narrow bars, and of the full-screen search layer it opens. */
13
+ search: string;
11
14
  };
12
15
  declare module '../localize.js' {
13
16
  interface CmStrings {
@@ -20,13 +23,20 @@ declare module '../localize.js' {
20
23
  *
21
24
  * 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
22
25
  * destinations in the Mobile menu instead.
26
+ *
27
+ * Global search goes in the `search` slot (usually a `cm-global-search`): inline after the store switcher while the bar is wider
28
+ * than 900px; at 900px or narrower the bar shows a search button instead, which opens the search full screen.
23
29
  * @element cm-header-bar
24
30
  * @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
25
31
  * @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
26
32
  * @slot end - Anything after the user pill, e.g. a notifications button.
33
+ * @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.
27
34
  * @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
28
35
  * @fires cm-wallet - When the wallet balance is pressed.
29
36
  * @fires cm-account - When the user pill is pressed. Open the account menu in response.
37
+ * @fires cm-search-toggle - When the full-screen search layer opens or closes (narrow bars), with `detail: { open }`.
38
+ * @csspart search-button - The search button shown on narrow bars.
39
+ * @csspart search-layer - The full-screen search layer (a modal `<dialog>`).
30
40
  */
31
41
  export declare class CmHeaderBar extends CmLocalizedElement {
32
42
  #private;
@@ -42,6 +52,19 @@ export declare class CmHeaderBar extends CmLocalizedElement {
42
52
  label: {
43
53
  string: string;
44
54
  };
55
+ searchLabel: {
56
+ attribute: string;
57
+ string: string;
58
+ };
59
+ _narrow: {
60
+ state: boolean;
61
+ };
62
+ _hasSearch: {
63
+ state: boolean;
64
+ };
65
+ _searchOpen: {
66
+ state: boolean;
67
+ };
45
68
  };
46
69
  /** Current store's address or name, shown as the store switcher ("preprod.commmerce.com"). Empty hides it. */
47
70
  store: string;
@@ -53,6 +76,21 @@ export declare class CmHeaderBar extends CmLocalizedElement {
53
76
  avatarSrc: string;
54
77
  /** Accessible name of the header's toolbar region. Default: the built-in string `label` ("Admin"). */
55
78
  label: string;
79
+ /** Accessible name of the search button on narrow bars and of the search layer. Default: the built-in string `search` ("Search"). */
80
+ searchLabel: string;
81
+ _narrow: boolean;
82
+ _hasSearch: boolean;
83
+ _searchOpen: boolean;
84
+ /** True while the full-screen search layer is open. */
85
+ get searchOpen(): boolean;
86
+ /** Brings up the search: focuses it on wide bars, or opens the full-screen layer on narrow ones. */
87
+ openSearch(): void;
88
+ /** Closes the full-screen search layer, and returns focus to the search button. */
89
+ closeSearch(): void;
90
+ constructor();
91
+ connectedCallback(): void;
92
+ disconnectedCallback(): void;
93
+ updated(changed: PropertyValues): void;
56
94
  static styles: import("lit").CSSResult[];
57
95
  render(): import("lit-html").TemplateResult<1>;
58
96
  }