@commmerce/ui 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/README.md +41 -2
- package/dist/base.d.ts +7 -0
- package/dist/base.js +22 -0
- package/dist/cdn.js +1958 -0
- package/dist/components/accordion.d.ts +43 -0
- package/dist/components/accordion.js +83 -0
- package/dist/components/action-bar.d.ts +42 -0
- package/dist/components/action-bar.js +84 -0
- package/dist/components/action-menu.d.ts +89 -0
- package/dist/components/action-menu.js +283 -0
- package/dist/components/app-card.d.ts +57 -0
- package/dist/components/app-card.js +100 -0
- package/dist/components/avatar.d.ts +48 -0
- package/dist/components/avatar.js +82 -0
- package/dist/components/badge.d.ts +23 -0
- package/dist/components/badge.js +35 -0
- package/dist/components/banner.d.ts +36 -0
- package/dist/components/banner.js +88 -0
- package/dist/components/bottom-navigation.d.ts +48 -0
- package/dist/components/bottom-navigation.js +98 -0
- package/dist/components/bottom-sheet.d.ts +54 -0
- package/dist/components/bottom-sheet.js +133 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +101 -0
- package/dist/components/card.d.ts +37 -0
- package/dist/components/card.js +58 -0
- package/dist/components/checkbox.d.ts +68 -0
- package/dist/components/checkbox.js +114 -0
- package/dist/components/comment.d.ts +76 -0
- package/dist/components/comment.js +170 -0
- package/dist/components/data-table.d.ts +132 -0
- package/dist/components/data-table.js +331 -0
- package/dist/components/empty-state.d.ts +49 -0
- package/dist/components/empty-state.js +94 -0
- package/dist/components/file-upload.d.ts +102 -0
- package/dist/components/file-upload.js +243 -0
- package/dist/components/filter-panel.d.ts +86 -0
- package/dist/components/filter-panel.js +128 -0
- package/dist/components/flash-offer-bar.d.ts +34 -0
- package/dist/components/flash-offer-bar.js +73 -0
- package/dist/components/grid.d.ts +39 -0
- package/dist/components/grid.js +42 -0
- package/dist/components/header-bar.d.ts +48 -0
- package/dist/components/header-bar.js +121 -0
- package/dist/components/icon.d.ts +30 -0
- package/dist/components/icon.js +36 -0
- package/dist/components/info-panel.d.ts +63 -0
- package/dist/components/info-panel.js +108 -0
- package/dist/components/layout.d.ts +45 -0
- package/dist/components/layout.js +67 -0
- package/dist/components/link-tabs.d.ts +40 -0
- package/dist/components/link-tabs.js +85 -0
- package/dist/components/menu-item.d.ts +68 -0
- package/dist/components/menu-item.js +64 -0
- package/dist/components/mobile-menu.d.ts +69 -0
- package/dist/components/mobile-menu.js +184 -0
- package/dist/components/modal.d.ts +46 -0
- package/dist/components/modal.js +59 -0
- package/dist/components/nav-item.d.ts +98 -0
- package/dist/components/nav-item.js +84 -0
- package/dist/components/nested-list.d.ts +105 -0
- package/dist/components/nested-list.js +279 -0
- package/dist/components/notification-panel.d.ts +121 -0
- package/dist/components/notification-panel.js +174 -0
- package/dist/components/option-group.d.ts +74 -0
- package/dist/components/option-group.js +172 -0
- package/dist/components/page-header.d.ts +58 -0
- package/dist/components/page-header.js +121 -0
- package/dist/components/page.d.ts +34 -0
- package/dist/components/page.js +41 -0
- package/dist/components/pagination.d.ts +64 -0
- package/dist/components/pagination.js +160 -0
- package/dist/components/progress-bar.d.ts +45 -0
- package/dist/components/progress-bar.js +81 -0
- package/dist/components/radio.d.ts +131 -0
- package/dist/components/radio.js +252 -0
- package/dist/components/report-tile.d.ts +65 -0
- package/dist/components/report-tile.js +112 -0
- package/dist/components/resource-list.d.ts +143 -0
- package/dist/components/resource-list.js +335 -0
- package/dist/components/save-bar.d.ts +58 -0
- package/dist/components/save-bar.js +128 -0
- package/dist/components/search.d.ts +78 -0
- package/dist/components/search.js +144 -0
- package/dist/components/select.d.ts +106 -0
- package/dist/components/select.js +338 -0
- package/dist/components/side-navigation.d.ts +51 -0
- package/dist/components/side-navigation.js +194 -0
- package/dist/components/side-panel.d.ts +50 -0
- package/dist/components/side-panel.js +73 -0
- package/dist/components/skeleton-display.d.ts +32 -0
- package/dist/components/skeleton-display.js +70 -0
- package/dist/components/skeleton.d.ts +41 -0
- package/dist/components/skeleton.js +59 -0
- package/dist/components/smart-tip.d.ts +62 -0
- package/dist/components/smart-tip.js +128 -0
- package/dist/components/spinner.d.ts +27 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/stack.d.ts +45 -0
- package/dist/components/stack.js +49 -0
- package/dist/components/status-tabs.d.ts +65 -0
- package/dist/components/status-tabs.js +158 -0
- package/dist/components/table-header.d.ts +84 -0
- package/dist/components/table-header.js +151 -0
- package/dist/components/tag.d.ts +39 -0
- package/dist/components/tag.js +68 -0
- package/dist/components/text-field.d.ts +101 -0
- package/dist/components/text-field.js +162 -0
- package/dist/components/thumbnail.d.ts +40 -0
- package/dist/components/thumbnail.js +61 -0
- package/dist/components/toast.d.ts +108 -0
- package/dist/components/toast.js +268 -0
- package/dist/components/toggle.d.ts +60 -0
- package/dist/components/toggle.js +108 -0
- package/dist/components/tooltip.d.ts +56 -0
- package/dist/components/tooltip.js +267 -0
- package/dist/custom-elements.json +13222 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +56 -0
- package/dist/overlay.d.ts +57 -0
- package/dist/overlay.js +205 -0
- package/dist/spacing.d.ts +6 -0
- package/dist/spacing.js +7 -0
- package/package.json +59 -4
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CmSearch_instances, _CmSearch_internals, _CmSearch_id, _CmSearch_defaultValue, _CmSearch_fire, _CmSearch_onInput, _CmSearch_onKeyDown, _CmSearch_clear;
|
|
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 './icon.js';
|
|
17
|
+
/**
|
|
18
|
+
* Search box for the top of lists and tables, with an optional filter button.
|
|
19
|
+
* Participates in native forms.
|
|
20
|
+
* @element cm-search
|
|
21
|
+
* @fires input - On every keystroke, and when cleared.
|
|
22
|
+
* @fires change - When the value is committed (Enter or blur after typing, or clear).
|
|
23
|
+
* @fires cm-search - When the merchant presses Enter. `detail.value` is the query.
|
|
24
|
+
* @fires cm-filter - When the filter button is pressed. Open a filter panel in response.
|
|
25
|
+
*/
|
|
26
|
+
export class CmSearch extends LitElement {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
_CmSearch_instances.add(this);
|
|
30
|
+
/** Accessible name, read by screen readers but not shown. Say what is searched: "Search orders". */
|
|
31
|
+
this.label = 'Search';
|
|
32
|
+
/** Form field name. */
|
|
33
|
+
this.name = '';
|
|
34
|
+
/** Current query. Updated on every keystroke. */
|
|
35
|
+
this.value = '';
|
|
36
|
+
/** Example query, shown in text-tertiary. */
|
|
37
|
+
this.placeholder = 'Search';
|
|
38
|
+
/** Shows the filter button at the end of the box. */
|
|
39
|
+
this.filter = false;
|
|
40
|
+
/** Accessible name of the filter button. */
|
|
41
|
+
this.filterLabel = 'Filter';
|
|
42
|
+
/** Number of filters applied; shown on the filter button when above 0. */
|
|
43
|
+
this.filterCount = 0;
|
|
44
|
+
/** `default` is 42px (table headers, mobile); `large` is 46px (page-level search). */
|
|
45
|
+
this.size = 'default';
|
|
46
|
+
/** Blocks interaction. Also set by a disabled `<fieldset>`. */
|
|
47
|
+
this.disabled = false;
|
|
48
|
+
_CmSearch_internals.set(this, this.attachInternals());
|
|
49
|
+
_CmSearch_id.set(this, nextId('cm-search'));
|
|
50
|
+
_CmSearch_defaultValue.set(this, '');
|
|
51
|
+
}
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
super.connectedCallback();
|
|
54
|
+
__classPrivateFieldSet(this, _CmSearch_defaultValue, this.value, "f");
|
|
55
|
+
}
|
|
56
|
+
get form() { return __classPrivateFieldGet(this, _CmSearch_internals, "f").form; }
|
|
57
|
+
checkValidity() { return __classPrivateFieldGet(this, _CmSearch_internals, "f").checkValidity(); }
|
|
58
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmSearch_defaultValue, "f"); }
|
|
59
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
60
|
+
formStateRestoreCallback(state) { this.value = state; }
|
|
61
|
+
updated() { __classPrivateFieldGet(this, _CmSearch_internals, "f").setFormValue(this.value); }
|
|
62
|
+
render() {
|
|
63
|
+
const big = this.size === 'large';
|
|
64
|
+
return html `<div class="box" part="box">
|
|
65
|
+
<cm-icon class="icon" name="search" size=${big ? 16 : 14}></cm-icon>
|
|
66
|
+
<input id=${__classPrivateFieldGet(this, _CmSearch_id, "f")} part="input" type="search" enterkeyhint="search" autocomplete="off"
|
|
67
|
+
aria-label=${this.label} .value=${live(this.value)} placeholder=${this.placeholder || nothing} ?disabled=${this.disabled}
|
|
68
|
+
@input=${__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_onInput)} @change=${() => __classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_fire).call(this, 'change')} @keydown=${__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_onKeyDown)} />
|
|
69
|
+
${this.value && !this.disabled
|
|
70
|
+
? html `<button type="button" class="clear" part="clear" aria-label="Clear search" @click=${__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_clear)}><cm-icon name="close" size="14"></cm-icon></button>`
|
|
71
|
+
: nothing}
|
|
72
|
+
${this.filter
|
|
73
|
+
? html `<button type="button" class="filter" part="filter" ?disabled=${this.disabled}
|
|
74
|
+
aria-label=${this.filterCount > 0 ? `${this.filterLabel} (${this.filterCount} applied)` : this.filterLabel}
|
|
75
|
+
@click=${() => __classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_fire).call(this, 'cm-filter')}><cm-icon name="filter" size="18"></cm-icon>${this.filterCount > 0 ? html `<span class="count" aria-hidden="true">${this.filterCount}</span>` : nothing}</button>`
|
|
76
|
+
: nothing}
|
|
77
|
+
</div>`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
_CmSearch_internals = new WeakMap(), _CmSearch_id = new WeakMap(), _CmSearch_defaultValue = new WeakMap(), _CmSearch_instances = new WeakSet(), _CmSearch_fire = function _CmSearch_fire(type, detail) {
|
|
81
|
+
this.dispatchEvent(detail === undefined
|
|
82
|
+
? new Event(type, { bubbles: true, composed: true })
|
|
83
|
+
: new CustomEvent(type, { bubbles: true, composed: true, detail }));
|
|
84
|
+
}, _CmSearch_onInput = function _CmSearch_onInput(e) { this.value = e.target.value; }, _CmSearch_onKeyDown = function _CmSearch_onKeyDown(e) {
|
|
85
|
+
if (e.key === 'Enter')
|
|
86
|
+
__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_fire).call(this, 'cm-search', { value: this.value });
|
|
87
|
+
else if (e.key === 'Escape' && this.value) {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_clear).call(this);
|
|
90
|
+
}
|
|
91
|
+
}, _CmSearch_clear = function _CmSearch_clear() {
|
|
92
|
+
this.value = '';
|
|
93
|
+
this.renderRoot.querySelector('input')?.focus();
|
|
94
|
+
__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_fire).call(this, 'input');
|
|
95
|
+
__classPrivateFieldGet(this, _CmSearch_instances, "m", _CmSearch_fire).call(this, 'change');
|
|
96
|
+
};
|
|
97
|
+
CmSearch.formAssociated = true;
|
|
98
|
+
CmSearch.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
99
|
+
CmSearch.properties = {
|
|
100
|
+
label: {},
|
|
101
|
+
name: { reflect: true },
|
|
102
|
+
value: {},
|
|
103
|
+
placeholder: {},
|
|
104
|
+
filter: { type: Boolean },
|
|
105
|
+
filterLabel: { attribute: 'filter-label' },
|
|
106
|
+
filterCount: { type: Number, attribute: 'filter-count' },
|
|
107
|
+
size: { reflect: true },
|
|
108
|
+
disabled: { type: Boolean, reflect: true },
|
|
109
|
+
};
|
|
110
|
+
CmSearch.styles = [
|
|
111
|
+
base,
|
|
112
|
+
css `
|
|
113
|
+
:host { display: block; }
|
|
114
|
+
.box {
|
|
115
|
+
display: flex; align-items: center; gap: var(--cm-space-10); height: 42px; padding: 0 var(--cm-space-10);
|
|
116
|
+
background: var(--cm-bg-page); color: var(--cm-text-default);
|
|
117
|
+
border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
|
|
118
|
+
}
|
|
119
|
+
:host([size='large']) .box { height: 46px; padding: 0 var(--cm-space-15); }
|
|
120
|
+
.box:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
|
|
121
|
+
.icon { flex: none; color: var(--cm-icon-selected); }
|
|
122
|
+
input {
|
|
123
|
+
flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: none; outline: none;
|
|
124
|
+
font: inherit; font-size: 14px; color: var(--cm-text-default);
|
|
125
|
+
}
|
|
126
|
+
input::placeholder { color: var(--cm-text-tertiary); }
|
|
127
|
+
input::-webkit-search-cancel-button { display: none; }
|
|
128
|
+
button {
|
|
129
|
+
position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
|
|
130
|
+
width: 28px; height: 28px; margin: 0 -4px; padding: 0; border: 0; border-radius: var(--cm-radius-sm);
|
|
131
|
+
background: none; color: var(--cm-icon-selected); cursor: pointer;
|
|
132
|
+
}
|
|
133
|
+
button:hover { background: var(--cm-bg-hover); }
|
|
134
|
+
button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
|
|
135
|
+
.count {
|
|
136
|
+
position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--cm-radius-full);
|
|
137
|
+
background: var(--cm-action-primary); color: var(--cm-action-primary-text); font-size: 10px; line-height: 16px;
|
|
138
|
+
}
|
|
139
|
+
:host([disabled]) .box { background: var(--cm-bg-input-filled); border-color: var(--cm-border-default); }
|
|
140
|
+
:host([disabled]) input { color: var(--cm-text-secondary); cursor: not-allowed; }
|
|
141
|
+
:host([disabled]) button { cursor: not-allowed; }
|
|
142
|
+
`,
|
|
143
|
+
];
|
|
144
|
+
define('cm-search', CmSearch);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
export interface SelectOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Dropdown field: a labelled box that opens a list of options and shows the chosen one.
|
|
10
|
+
* A custom listbox (the WAI-ARIA "select-only combobox" pattern) so the open list can match the
|
|
11
|
+
* design; it keeps native-select keyboard behaviour. Participates in native forms.
|
|
12
|
+
*
|
|
13
|
+
* Options come from `<option>` children (easy in plain HTML, PHP and EJS) or the `options` property.
|
|
14
|
+
* @element cm-select
|
|
15
|
+
* @slot - `<option value="…">Label</option>` elements. `disabled` and `selected` are honoured.
|
|
16
|
+
* @fires change - When the merchant picks a different option.
|
|
17
|
+
* @fires input - Same moment as `change`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CmSelect extends LitElement {
|
|
20
|
+
#private;
|
|
21
|
+
static formAssociated: boolean;
|
|
22
|
+
static shadowRootOptions: {
|
|
23
|
+
delegatesFocus: boolean;
|
|
24
|
+
mode: ShadowRootMode;
|
|
25
|
+
serializable?: boolean;
|
|
26
|
+
slotAssignment?: SlotAssignmentMode;
|
|
27
|
+
};
|
|
28
|
+
static properties: {
|
|
29
|
+
label: {};
|
|
30
|
+
helpText: {
|
|
31
|
+
attribute: string;
|
|
32
|
+
};
|
|
33
|
+
error: {
|
|
34
|
+
reflect: boolean;
|
|
35
|
+
};
|
|
36
|
+
name: {
|
|
37
|
+
reflect: boolean;
|
|
38
|
+
};
|
|
39
|
+
value: {};
|
|
40
|
+
placeholder: {};
|
|
41
|
+
options: {
|
|
42
|
+
type: ArrayConstructor;
|
|
43
|
+
};
|
|
44
|
+
required: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
reflect: boolean;
|
|
47
|
+
};
|
|
48
|
+
disabled: {
|
|
49
|
+
type: BooleanConstructor;
|
|
50
|
+
reflect: boolean;
|
|
51
|
+
};
|
|
52
|
+
open: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
reflect: boolean;
|
|
55
|
+
};
|
|
56
|
+
_active: {
|
|
57
|
+
state: boolean;
|
|
58
|
+
};
|
|
59
|
+
_slotted: {
|
|
60
|
+
state: boolean;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** Visible label above the box. Required for accessibility unless the element has an aria-label. */
|
|
64
|
+
label: string;
|
|
65
|
+
/** One sentence under the box in text-tertiary. */
|
|
66
|
+
helpText: string;
|
|
67
|
+
/** Error message; turns the border critical and sets aria-invalid. */
|
|
68
|
+
error: string;
|
|
69
|
+
/** Form field name. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** Value of the chosen option; empty when nothing is chosen. */
|
|
72
|
+
value: string;
|
|
73
|
+
/** Shown while nothing is chosen, e.g. "Select customer". */
|
|
74
|
+
placeholder: string;
|
|
75
|
+
/** Options as strings or `{ value, label, disabled }`. Used instead of `<option>` children when set. */
|
|
76
|
+
options: Array<string | SelectOption>;
|
|
77
|
+
/** The form will not submit until an option is chosen. */
|
|
78
|
+
required: boolean;
|
|
79
|
+
/** Blocks interaction. Also set by a disabled `<fieldset>`. */
|
|
80
|
+
disabled: boolean;
|
|
81
|
+
/** Whether the list is showing. */
|
|
82
|
+
open: boolean;
|
|
83
|
+
_active: number;
|
|
84
|
+
_slotted: SelectOption[];
|
|
85
|
+
static styles: import("lit").CSSResult[];
|
|
86
|
+
connectedCallback(): void;
|
|
87
|
+
disconnectedCallback(): void;
|
|
88
|
+
get form(): HTMLFormElement | null;
|
|
89
|
+
get validity(): ValidityState;
|
|
90
|
+
get validationMessage(): string;
|
|
91
|
+
checkValidity(): boolean;
|
|
92
|
+
reportValidity(): boolean;
|
|
93
|
+
formResetCallback(): void;
|
|
94
|
+
formDisabledCallback(d: boolean): void;
|
|
95
|
+
formStateRestoreCallback(state: string): void;
|
|
96
|
+
/** The options in use, normalised. */
|
|
97
|
+
get items(): SelectOption[];
|
|
98
|
+
firstUpdated(): void;
|
|
99
|
+
updated(changed: Map<string, unknown>): void;
|
|
100
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
101
|
+
}
|
|
102
|
+
declare global {
|
|
103
|
+
interface HTMLElementTagNameMap {
|
|
104
|
+
'cm-select': CmSelect;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
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 _CmSelect_instances, _CmSelect_internals, _CmSelect_id, _CmSelect_defaultValue, _CmSelect_typed, _CmSelect_typedAt, _CmSelect_observer, _CmSelect_readChildren, _CmSelect_enabledIndexes, _CmSelect_show, _CmSelect_hide, _CmSelect_commit, _CmSelect_move, _CmSelect_typeahead, _CmSelect_onKeyDown, _CmSelect_onOutside, _CmSelect_onBoxClick, _CmSelect_focusBox;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { base, define, nextId } from '../base.js';
|
|
15
|
+
import './icon.js';
|
|
16
|
+
/**
|
|
17
|
+
* Dropdown field: a labelled box that opens a list of options and shows the chosen one.
|
|
18
|
+
* A custom listbox (the WAI-ARIA "select-only combobox" pattern) so the open list can match the
|
|
19
|
+
* design; it keeps native-select keyboard behaviour. Participates in native forms.
|
|
20
|
+
*
|
|
21
|
+
* Options come from `<option>` children (easy in plain HTML, PHP and EJS) or the `options` property.
|
|
22
|
+
* @element cm-select
|
|
23
|
+
* @slot - `<option value="…">Label</option>` elements. `disabled` and `selected` are honoured.
|
|
24
|
+
* @fires change - When the merchant picks a different option.
|
|
25
|
+
* @fires input - Same moment as `change`.
|
|
26
|
+
*/
|
|
27
|
+
export class CmSelect extends LitElement {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
_CmSelect_instances.add(this);
|
|
31
|
+
/** Visible label above the box. Required for accessibility unless the element has an aria-label. */
|
|
32
|
+
this.label = '';
|
|
33
|
+
/** One sentence under the box in text-tertiary. */
|
|
34
|
+
this.helpText = '';
|
|
35
|
+
/** Error message; turns the border critical and sets aria-invalid. */
|
|
36
|
+
this.error = '';
|
|
37
|
+
/** Form field name. */
|
|
38
|
+
this.name = '';
|
|
39
|
+
/** Value of the chosen option; empty when nothing is chosen. */
|
|
40
|
+
this.value = '';
|
|
41
|
+
/** Shown while nothing is chosen, e.g. "Select customer". */
|
|
42
|
+
this.placeholder = '';
|
|
43
|
+
/** Options as strings or `{ value, label, disabled }`. Used instead of `<option>` children when set. */
|
|
44
|
+
this.options = [];
|
|
45
|
+
/** The form will not submit until an option is chosen. */
|
|
46
|
+
this.required = false;
|
|
47
|
+
/** Blocks interaction. Also set by a disabled `<fieldset>`. */
|
|
48
|
+
this.disabled = false;
|
|
49
|
+
/** Whether the list is showing. */
|
|
50
|
+
this.open = false;
|
|
51
|
+
this._active = -1;
|
|
52
|
+
this._slotted = [];
|
|
53
|
+
_CmSelect_internals.set(this, this.attachInternals());
|
|
54
|
+
_CmSelect_id.set(this, nextId('cm-sel'));
|
|
55
|
+
_CmSelect_defaultValue.set(this, '');
|
|
56
|
+
_CmSelect_typed.set(this, '');
|
|
57
|
+
_CmSelect_typedAt.set(this, 0);
|
|
58
|
+
_CmSelect_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_readChildren).call(this)));
|
|
59
|
+
_CmSelect_onKeyDown.set(this, (e) => {
|
|
60
|
+
if (this.disabled)
|
|
61
|
+
return;
|
|
62
|
+
const k = e.key;
|
|
63
|
+
if (!this.open) {
|
|
64
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(k)) {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_show).call(this);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (k === 'Home' || k === 'End') {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_show).call(this);
|
|
72
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, k === 'Home' ? 'first' : 'last');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (k.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
76
|
+
const i = __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_typeahead).call(this, k);
|
|
77
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_show).call(this, i >= 0 ? i : undefined);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
switch (k) {
|
|
82
|
+
case 'ArrowDown':
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
if (e.altKey)
|
|
85
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, this._active);
|
|
86
|
+
else
|
|
87
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, 1);
|
|
88
|
+
break;
|
|
89
|
+
case 'ArrowUp':
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
if (e.altKey)
|
|
92
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, this._active);
|
|
93
|
+
else
|
|
94
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, -1);
|
|
95
|
+
break;
|
|
96
|
+
case 'Home':
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, 'first');
|
|
99
|
+
break;
|
|
100
|
+
case 'End':
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, 'last');
|
|
103
|
+
break;
|
|
104
|
+
case 'PageDown':
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, 10);
|
|
107
|
+
break;
|
|
108
|
+
case 'PageUp':
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_move).call(this, -10);
|
|
111
|
+
break;
|
|
112
|
+
case 'Enter':
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, this._active);
|
|
115
|
+
break;
|
|
116
|
+
case 'Escape':
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this);
|
|
120
|
+
break;
|
|
121
|
+
case 'Tab':
|
|
122
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, this._active);
|
|
123
|
+
break;
|
|
124
|
+
case ' ':
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
if (__classPrivateFieldGet(this, _CmSelect_typed, "f") && Date.now() - __classPrivateFieldGet(this, _CmSelect_typedAt, "f") < 500) {
|
|
127
|
+
const i = __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_typeahead).call(this, ' ');
|
|
128
|
+
if (i >= 0)
|
|
129
|
+
this._active = i;
|
|
130
|
+
}
|
|
131
|
+
else
|
|
132
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, this._active);
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
if (k.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
136
|
+
const i = __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_typeahead).call(this, k);
|
|
137
|
+
if (i >= 0)
|
|
138
|
+
this._active = i;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
_CmSelect_onOutside.set(this, (e) => {
|
|
143
|
+
if (this.open && !e.composedPath().includes(this))
|
|
144
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this);
|
|
145
|
+
});
|
|
146
|
+
_CmSelect_onBoxClick.set(this, () => {
|
|
147
|
+
if (this.disabled)
|
|
148
|
+
return;
|
|
149
|
+
if (this.open)
|
|
150
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this);
|
|
151
|
+
else
|
|
152
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_show).call(this);
|
|
153
|
+
});
|
|
154
|
+
_CmSelect_focusBox.set(this, () => this.renderRoot.querySelector('.box')?.focus());
|
|
155
|
+
}
|
|
156
|
+
connectedCallback() {
|
|
157
|
+
super.connectedCallback();
|
|
158
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_readChildren).call(this);
|
|
159
|
+
__classPrivateFieldGet(this, _CmSelect_observer, "f").observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['value', 'label', 'disabled', 'selected'] });
|
|
160
|
+
document.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmSelect_onOutside, "f"), true);
|
|
161
|
+
}
|
|
162
|
+
disconnectedCallback() {
|
|
163
|
+
super.disconnectedCallback();
|
|
164
|
+
__classPrivateFieldGet(this, _CmSelect_observer, "f").disconnect();
|
|
165
|
+
document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmSelect_onOutside, "f"), true);
|
|
166
|
+
}
|
|
167
|
+
get form() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").form; }
|
|
168
|
+
get validity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").validity; }
|
|
169
|
+
get validationMessage() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").validationMessage; }
|
|
170
|
+
checkValidity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").checkValidity(); }
|
|
171
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").reportValidity(); }
|
|
172
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmSelect_defaultValue, "f"); this.open = false; }
|
|
173
|
+
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
174
|
+
this.open = false; }
|
|
175
|
+
formStateRestoreCallback(state) { this.value = state; }
|
|
176
|
+
/** The options in use, normalised. */
|
|
177
|
+
get items() {
|
|
178
|
+
if (!this.options.length)
|
|
179
|
+
return this._slotted;
|
|
180
|
+
return this.options.map((o) => (typeof o === 'string' ? { value: o, label: o } : o));
|
|
181
|
+
}
|
|
182
|
+
firstUpdated() { __classPrivateFieldSet(this, _CmSelect_defaultValue, __classPrivateFieldGet(this, _CmSelect_defaultValue, "f") || this.value, "f"); }
|
|
183
|
+
updated(changed) {
|
|
184
|
+
__classPrivateFieldGet(this, _CmSelect_internals, "f").setFormValue(this.value || null, this.value);
|
|
185
|
+
const box = this.renderRoot.querySelector('.box') ?? undefined;
|
|
186
|
+
if (this.error)
|
|
187
|
+
__classPrivateFieldGet(this, _CmSelect_internals, "f").setValidity({ customError: true }, this.error, box);
|
|
188
|
+
else if (this.required && !this.value)
|
|
189
|
+
__classPrivateFieldGet(this, _CmSelect_internals, "f").setValidity({ valueMissing: true }, 'Please select an item in the list.', box);
|
|
190
|
+
else
|
|
191
|
+
__classPrivateFieldGet(this, _CmSelect_internals, "f").setValidity({});
|
|
192
|
+
if ((changed.has('_active') || changed.has('open')) && this.open) {
|
|
193
|
+
this.renderRoot.querySelector(`#${__classPrivateFieldGet(this, _CmSelect_id, "f")}-o${this._active}`)?.scrollIntoView({ block: 'nearest' });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
render() {
|
|
197
|
+
const items = this.items;
|
|
198
|
+
const current = items.find((o) => o.value === this.value);
|
|
199
|
+
const described = [this.error && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-help`].filter(Boolean).join(' ');
|
|
200
|
+
const hostLabel = this.getAttribute('aria-label');
|
|
201
|
+
return html `<div class="field">
|
|
202
|
+
${this.label
|
|
203
|
+
? html `<span class="label" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-l" part="label" @click=${__classPrivateFieldGet(this, _CmSelect_focusBox, "f")}>${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>`
|
|
204
|
+
: nothing}
|
|
205
|
+
<div class="wrap">
|
|
206
|
+
<div class="box" part="box" role="combobox" tabindex=${this.disabled ? '-1' : '0'}
|
|
207
|
+
aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-l` : nothing}
|
|
208
|
+
aria-label=${!this.label && hostLabel ? hostLabel : nothing}
|
|
209
|
+
aria-haspopup="listbox" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-list"
|
|
210
|
+
aria-activedescendant=${this.open && this._active >= 0 ? `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-o${this._active}` : nothing}
|
|
211
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${this.error ? 'true' : nothing}
|
|
212
|
+
aria-disabled=${this.disabled ? 'true' : nothing} aria-describedby=${described || nothing}
|
|
213
|
+
@click=${__classPrivateFieldGet(this, _CmSelect_onBoxClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmSelect_onKeyDown, "f")} @blur=${() => __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this)}>
|
|
214
|
+
<span class="text ${current ? '' : 'placeholder'}" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-v">${current ? current.label : this.placeholder}</span>
|
|
215
|
+
<cm-icon class="chev" name="chevron-down" size="16"></cm-icon>
|
|
216
|
+
</div>
|
|
217
|
+
<ul role="listbox" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-list" part="listbox" tabindex="-1" aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-l` : nothing}
|
|
218
|
+
aria-label=${!this.label && hostLabel ? hostLabel : nothing} ?hidden=${!this.open}
|
|
219
|
+
@pointerdown=${(e) => e.preventDefault()}>
|
|
220
|
+
${items.map((o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
|
|
221
|
+
aria-selected=${o.value === this.value ? 'true' : 'false'} aria-disabled=${o.disabled ? 'true' : nothing}
|
|
222
|
+
@pointerenter=${() => !o.disabled && (this._active = i)} @click=${() => __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_commit).call(this, i)}>${o.label}</li>`)}
|
|
223
|
+
</ul>
|
|
224
|
+
</div>
|
|
225
|
+
${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
|
|
226
|
+
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
227
|
+
<slot></slot>
|
|
228
|
+
</div>`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
_CmSelect_internals = new WeakMap(), _CmSelect_id = new WeakMap(), _CmSelect_defaultValue = new WeakMap(), _CmSelect_typed = new WeakMap(), _CmSelect_typedAt = new WeakMap(), _CmSelect_observer = new WeakMap(), _CmSelect_onKeyDown = new WeakMap(), _CmSelect_onOutside = new WeakMap(), _CmSelect_onBoxClick = new WeakMap(), _CmSelect_focusBox = new WeakMap(), _CmSelect_instances = new WeakSet(), _CmSelect_readChildren = function _CmSelect_readChildren() {
|
|
232
|
+
const opts = [...this.querySelectorAll('option')];
|
|
233
|
+
this._slotted = opts.map((o) => ({ value: o.value, label: o.label || o.textContent.trim(), disabled: o.disabled }));
|
|
234
|
+
if (!this.hasUpdated && !this.value) {
|
|
235
|
+
this.value = opts.find((o) => o.hasAttribute('selected'))?.value ?? '';
|
|
236
|
+
__classPrivateFieldSet(this, _CmSelect_defaultValue, this.value, "f");
|
|
237
|
+
}
|
|
238
|
+
}, _CmSelect_enabledIndexes = function _CmSelect_enabledIndexes() { return this.items.flatMap((o, i) => (o.disabled ? [] : [i])); }, _CmSelect_show = function _CmSelect_show(active) {
|
|
239
|
+
if (this.disabled)
|
|
240
|
+
return;
|
|
241
|
+
const sel = this.items.findIndex((o) => o.value === this.value);
|
|
242
|
+
this.open = true;
|
|
243
|
+
this._active = active ?? (sel >= 0 ? sel : __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_enabledIndexes).call(this)[0] ?? -1);
|
|
244
|
+
}, _CmSelect_hide = function _CmSelect_hide() { this.open = false; }, _CmSelect_commit = function _CmSelect_commit(i) {
|
|
245
|
+
const o = this.items[i];
|
|
246
|
+
if (!o || o.disabled)
|
|
247
|
+
return;
|
|
248
|
+
__classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this);
|
|
249
|
+
if (o.value === this.value)
|
|
250
|
+
return;
|
|
251
|
+
this.value = o.value;
|
|
252
|
+
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
253
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
254
|
+
}, _CmSelect_move = function _CmSelect_move(step) {
|
|
255
|
+
const en = __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_enabledIndexes).call(this);
|
|
256
|
+
if (!en.length)
|
|
257
|
+
return;
|
|
258
|
+
if (step === 'first')
|
|
259
|
+
return void (this._active = en[0]);
|
|
260
|
+
if (step === 'last')
|
|
261
|
+
return void (this._active = en[en.length - 1]);
|
|
262
|
+
const pos = en.indexOf(this._active);
|
|
263
|
+
this._active = pos < 0 ? en[0] : en[Math.min(en.length - 1, Math.max(0, pos + step))];
|
|
264
|
+
}, _CmSelect_typeahead = function _CmSelect_typeahead(ch) {
|
|
265
|
+
const now = Date.now();
|
|
266
|
+
__classPrivateFieldSet(this, _CmSelect_typed, now - __classPrivateFieldGet(this, _CmSelect_typedAt, "f") > 500 ? ch : __classPrivateFieldGet(this, _CmSelect_typed, "f") + ch, "f");
|
|
267
|
+
__classPrivateFieldSet(this, _CmSelect_typedAt, now, "f");
|
|
268
|
+
const items = this.items;
|
|
269
|
+
const start = this._active < 0 ? 0 : this._active;
|
|
270
|
+
// A repeated letter cycles through matches; a longer string matches from the current option.
|
|
271
|
+
const same = __classPrivateFieldGet(this, _CmSelect_typed, "f").split('').every((c) => c === __classPrivateFieldGet(this, _CmSelect_typed, "f")[0]);
|
|
272
|
+
const q = same ? __classPrivateFieldGet(this, _CmSelect_typed, "f")[0] : __classPrivateFieldGet(this, _CmSelect_typed, "f");
|
|
273
|
+
const from = same || __classPrivateFieldGet(this, _CmSelect_typed, "f").length === 1 ? start + 1 : start;
|
|
274
|
+
for (let k = 0; k < items.length; k++) {
|
|
275
|
+
const i = (from + k) % items.length;
|
|
276
|
+
if (!items[i].disabled && items[i].label.toLowerCase().startsWith(q.toLowerCase()))
|
|
277
|
+
return i;
|
|
278
|
+
}
|
|
279
|
+
return -1;
|
|
280
|
+
};
|
|
281
|
+
CmSelect.formAssociated = true;
|
|
282
|
+
CmSelect.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
283
|
+
CmSelect.properties = {
|
|
284
|
+
label: {},
|
|
285
|
+
helpText: { attribute: 'help-text' },
|
|
286
|
+
error: { reflect: true },
|
|
287
|
+
name: { reflect: true },
|
|
288
|
+
value: {},
|
|
289
|
+
placeholder: {},
|
|
290
|
+
options: { type: Array },
|
|
291
|
+
required: { type: Boolean, reflect: true },
|
|
292
|
+
disabled: { type: Boolean, reflect: true },
|
|
293
|
+
open: { type: Boolean, reflect: true },
|
|
294
|
+
_active: { state: true },
|
|
295
|
+
_slotted: { state: true },
|
|
296
|
+
};
|
|
297
|
+
CmSelect.styles = [
|
|
298
|
+
base,
|
|
299
|
+
css `
|
|
300
|
+
:host { display: block; position: relative; }
|
|
301
|
+
.field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
302
|
+
.label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); cursor: default; }
|
|
303
|
+
.req { color: var(--cm-text-critical); margin-left: 2px; }
|
|
304
|
+
.wrap { position: relative; }
|
|
305
|
+
.box {
|
|
306
|
+
display: flex; align-items: center; gap: var(--cm-space-10); width: 100%; height: 42px; padding: 0 var(--cm-space-10);
|
|
307
|
+
font-size: 16px; color: var(--cm-text-default); background: var(--cm-bg-surface); cursor: pointer;
|
|
308
|
+
border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm); outline: none; user-select: none;
|
|
309
|
+
}
|
|
310
|
+
.box:focus-visible, :host([open]) .box { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
|
|
311
|
+
.text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
312
|
+
.placeholder { color: var(--cm-text-tertiary); }
|
|
313
|
+
.chev { flex: none; color: var(--cm-icon-selected); transition: transform .15s; }
|
|
314
|
+
:host([open]) .chev { transform: rotate(180deg); }
|
|
315
|
+
:host([error]:not([error=''])) .box { border-color: var(--cm-border-critical); }
|
|
316
|
+
:host([disabled]) .box { background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-default); cursor: not-allowed; }
|
|
317
|
+
[role='listbox'] {
|
|
318
|
+
position: absolute; z-index: 20; top: calc(100% + var(--cm-space-10)); left: 0; right: 0;
|
|
319
|
+
max-height: 242px; overflow-y: auto; margin: 0; padding: var(--cm-space-10) 0; list-style: none;
|
|
320
|
+
background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-default);
|
|
321
|
+
border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-100);
|
|
322
|
+
}
|
|
323
|
+
[role='option'] {
|
|
324
|
+
display: flex; align-items: center; min-height: 40px; padding: 6px var(--cm-space-20);
|
|
325
|
+
font-size: 16px; color: var(--cm-text-default); cursor: pointer;
|
|
326
|
+
}
|
|
327
|
+
[role='option'].active { background: var(--cm-bg-hover); }
|
|
328
|
+
[role='option'][aria-selected='true'] { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
|
|
329
|
+
[role='option'][aria-selected='true'].active { background: var(--cm-action-primary-hover); }
|
|
330
|
+
[role='option'][aria-disabled='true'] { color: var(--cm-text-secondary); cursor: not-allowed; }
|
|
331
|
+
.help, .error { margin: 0; font-size: 12px; color: var(--cm-text-tertiary); }
|
|
332
|
+
.error { color: var(--cm-text-critical); }
|
|
333
|
+
slot { display: none; }
|
|
334
|
+
@media (max-width: 640px) { [role='option'] { font-size: 14px; min-height: 30px; padding-inline: var(--cm-space-15); } }
|
|
335
|
+
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
|
|
336
|
+
`,
|
|
337
|
+
];
|
|
338
|
+
define('cm-select', CmSelect);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { type NavItem } from './nav-item.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
/**
|
|
5
|
+
* The admin's main menu: a black rounded panel down the left of the page, with an icon and a label per
|
|
6
|
+
* destination and sections that open to show their sub-items. For Commmerce products only, not for apps:
|
|
7
|
+
* apps are shown inside the admin, which already has this menu.
|
|
8
|
+
*
|
|
9
|
+
* Items come from `cm-nav-item` children or the `items` property, so every Commmerce product can use it.
|
|
10
|
+
* @element cm-side-navigation
|
|
11
|
+
* @slot - `cm-nav-item` elements (nest them for sub-items).
|
|
12
|
+
* @slot header - Optional content above the items, such as a store switcher on narrow layouts.
|
|
13
|
+
* @slot footer - Optional content below the items.
|
|
14
|
+
* @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.
|
|
15
|
+
* @fires cm-expand - When a section opens or closes. `detail: { item, expanded }`.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CmSideNavigation extends LitElement {
|
|
18
|
+
#private;
|
|
19
|
+
static properties: {
|
|
20
|
+
items: {
|
|
21
|
+
type: ArrayConstructor;
|
|
22
|
+
};
|
|
23
|
+
label: {};
|
|
24
|
+
_slotted: {
|
|
25
|
+
state: boolean;
|
|
26
|
+
};
|
|
27
|
+
_open: {
|
|
28
|
+
state: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Items as data. Used instead of `cm-nav-item` children when set. */
|
|
32
|
+
items: NavItem[];
|
|
33
|
+
/** Accessible name of the navigation landmark. */
|
|
34
|
+
label: string;
|
|
35
|
+
_slotted: NavItem[];
|
|
36
|
+
_open: Set<string>;
|
|
37
|
+
static styles: import("lit").CSSResult[];
|
|
38
|
+
connectedCallback(): void;
|
|
39
|
+
disconnectedCallback(): void;
|
|
40
|
+
/** The items in use. */
|
|
41
|
+
get navItems(): NavItem[];
|
|
42
|
+
willUpdate(): void;
|
|
43
|
+
/** Opens or closes the section at `index`. */
|
|
44
|
+
toggle(index: number, open?: boolean): void;
|
|
45
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
46
|
+
}
|
|
47
|
+
declare global {
|
|
48
|
+
interface HTMLElementTagNameMap {
|
|
49
|
+
'cm-side-navigation': CmSideNavigation;
|
|
50
|
+
}
|
|
51
|
+
}
|