@commmerce/ui 0.0.0-stage → 1.0.0-rc.4
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,252 @@
|
|
|
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 _CmRadio_id, _CmRadioGroup_instances, _CmRadioGroup_internals, _CmRadioGroup_id, _CmRadioGroup_defaultValue, _CmRadioGroup_pristine, _CmRadioGroup_rendered, _CmRadioGroup_adopting, _CmRadioGroup_adoptInitial, _CmRadioGroup_onSlotChange, _CmRadioGroup_radios, _CmRadioGroup_enabled, _CmRadioGroup_sync, _CmRadioGroup_select, _CmRadioGroup_onClick, _CmRadioGroup_onKeyDown, _CmRadioGroup_hasLabel;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { base, define, nextId } from '../base.js';
|
|
15
|
+
/**
|
|
16
|
+
* One option in a `<cm-radio-group>`. On its own it does nothing: the group owns
|
|
17
|
+
* the value, the keyboard behaviour and the form submission.
|
|
18
|
+
* @element cm-radio
|
|
19
|
+
* @slot - Rich label content, used instead of `label`.
|
|
20
|
+
*/
|
|
21
|
+
export class CmRadio extends LitElement {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
/** Visible label. Write it in sentence case. */
|
|
25
|
+
this.label = '';
|
|
26
|
+
/** Help text under the label, linked for screen readers. */
|
|
27
|
+
this.description = '';
|
|
28
|
+
/** The group's value when this option is selected. */
|
|
29
|
+
this.value = '';
|
|
30
|
+
/** Selected. Set by the group; set it in markup to choose the initial option. */
|
|
31
|
+
this.checked = false;
|
|
32
|
+
/** This option can't be chosen. Arrow keys skip it. */
|
|
33
|
+
this.disabled = false;
|
|
34
|
+
/** @internal Set by a disabled group. */
|
|
35
|
+
this.groupDisabled = false;
|
|
36
|
+
/** @internal Roving tab stop, managed by the group. */
|
|
37
|
+
this._tabbable = false;
|
|
38
|
+
_CmRadio_id.set(this, nextId('cm-radio'));
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
const desc = this.description ? `${__classPrivateFieldGet(this, _CmRadio_id, "f")}-d` : null;
|
|
42
|
+
return html `<div class="radio" part="radio" role="radio" id=${__classPrivateFieldGet(this, _CmRadio_id, "f")}
|
|
43
|
+
aria-checked=${this.checked ? 'true' : 'false'} aria-disabled=${this.disabled || this.groupDisabled ? 'true' : nothing}
|
|
44
|
+
aria-describedby=${desc ?? nothing} tabindex=${this._tabbable && !this.disabled && !this.groupDisabled ? '0' : '-1'}>
|
|
45
|
+
<span class="dot" part="dot"></span>
|
|
46
|
+
<span class="text"><span class="label">${this.label}<slot></slot></span>${desc ? html `<span class="desc" id=${desc}>${this.description}</span>` : nothing}</span>
|
|
47
|
+
</div>`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_CmRadio_id = new WeakMap();
|
|
51
|
+
CmRadio.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
52
|
+
CmRadio.properties = {
|
|
53
|
+
label: {},
|
|
54
|
+
description: {},
|
|
55
|
+
value: { reflect: true },
|
|
56
|
+
checked: { type: Boolean, reflect: true },
|
|
57
|
+
disabled: { type: Boolean, reflect: true },
|
|
58
|
+
groupDisabled: { type: Boolean, reflect: true, attribute: 'group-disabled' },
|
|
59
|
+
_tabbable: { state: true },
|
|
60
|
+
};
|
|
61
|
+
CmRadio.styles = [
|
|
62
|
+
base,
|
|
63
|
+
css `
|
|
64
|
+
:host { display: inline-flex; }
|
|
65
|
+
.radio { display: inline-flex; align-items: flex-start; gap: var(--cm-space-10); cursor: pointer; outline: none; }
|
|
66
|
+
.dot {
|
|
67
|
+
position: relative; flex: none; width: 20px; height: 20px; border-radius: var(--cm-radius-full);
|
|
68
|
+
border: var(--cm-border-1) solid var(--cm-border-strong); background: var(--cm-bg-surface);
|
|
69
|
+
}
|
|
70
|
+
:host([checked]) .dot { background: var(--cm-border-strong); }
|
|
71
|
+
:host([checked]) .dot::after {
|
|
72
|
+
content: ''; position: absolute; inset: 0; margin: auto; width: 8px; height: 8px;
|
|
73
|
+
border-radius: var(--cm-radius-full); background: var(--cm-bg-surface);
|
|
74
|
+
}
|
|
75
|
+
.radio:focus-visible .dot { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
76
|
+
.text { display: flex; flex-direction: column; gap: 6px; padding-top: 1px; }
|
|
77
|
+
.label { font-size: 16px; }
|
|
78
|
+
.desc { font-size: 12px; color: var(--cm-text-tertiary); }
|
|
79
|
+
:host([disabled]) .radio, :host([group-disabled]) .radio { cursor: not-allowed; }
|
|
80
|
+
:host([disabled]) .dot, :host([group-disabled]) .dot { background: var(--cm-bg-input-filled); border-color: var(--cm-border-default); }
|
|
81
|
+
:host([disabled][checked]) .dot, :host([group-disabled][checked]) .dot { background: var(--cm-border-default); }
|
|
82
|
+
:host([disabled]) .label, :host([group-disabled]) .label { color: var(--cm-text-secondary); }
|
|
83
|
+
`,
|
|
84
|
+
];
|
|
85
|
+
define('cm-radio', CmRadio);
|
|
86
|
+
/**
|
|
87
|
+
* A set of `<cm-radio>` options where exactly one can be chosen. Behaves like a native radio group:
|
|
88
|
+
* one tab stop, arrow keys move and select, and the form receives the selected value.
|
|
89
|
+
* @element cm-radio-group
|
|
90
|
+
* @slot - The `<cm-radio>` options.
|
|
91
|
+
* @slot label - Rich label content, used instead of `label`.
|
|
92
|
+
* @fires change - When the merchant picks a different option.
|
|
93
|
+
* @fires input - Same moment as `change`, for frameworks that listen to `input`.
|
|
94
|
+
*/
|
|
95
|
+
export class CmRadioGroup extends LitElement {
|
|
96
|
+
constructor() {
|
|
97
|
+
super();
|
|
98
|
+
_CmRadioGroup_instances.add(this);
|
|
99
|
+
/** Question above the options. Required for accessibility unless the group has an aria-label. */
|
|
100
|
+
this.label = '';
|
|
101
|
+
/** One sentence under the label in text-tertiary. */
|
|
102
|
+
this.helpText = '';
|
|
103
|
+
/** Error message; announced and linked to the group. */
|
|
104
|
+
this.error = '';
|
|
105
|
+
/** Form field name. */
|
|
106
|
+
this.name = '';
|
|
107
|
+
/** Value of the selected option; empty when nothing is selected. */
|
|
108
|
+
this.value = '';
|
|
109
|
+
/** `vertical` stacks options `space-20` apart; `horizontal` puts them in a row `space-30` apart. */
|
|
110
|
+
this.orientation = 'vertical';
|
|
111
|
+
/** The form will not submit until an option is chosen. */
|
|
112
|
+
this.required = false;
|
|
113
|
+
/** Blocks every option. Also set by a disabled `<fieldset>`. */
|
|
114
|
+
this.disabled = false;
|
|
115
|
+
_CmRadioGroup_internals.set(this, this.attachInternals());
|
|
116
|
+
_CmRadioGroup_id.set(this, nextId('cm-rg'));
|
|
117
|
+
_CmRadioGroup_defaultValue.set(this, '');
|
|
118
|
+
// Options may be parsed or upgraded after the group, so the initial value is taken from a
|
|
119
|
+
// `checked` option whenever options arrive, until the value has been set some other way.
|
|
120
|
+
_CmRadioGroup_pristine.set(this, true);
|
|
121
|
+
_CmRadioGroup_rendered.set(this, false);
|
|
122
|
+
_CmRadioGroup_adopting.set(this, false);
|
|
123
|
+
_CmRadioGroup_onSlotChange.set(this, () => { __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_adoptInitial).call(this); __classPrivateFieldGet(this, _CmRadioGroup_sync, "f").call(this); });
|
|
124
|
+
_CmRadioGroup_sync.set(this, () => {
|
|
125
|
+
const radios = __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this);
|
|
126
|
+
let found = false;
|
|
127
|
+
for (const r of radios) {
|
|
128
|
+
r.checked = !!this.value && r.value === this.value && !found;
|
|
129
|
+
if (r.checked)
|
|
130
|
+
found = true;
|
|
131
|
+
r.groupDisabled = this.disabled;
|
|
132
|
+
}
|
|
133
|
+
const stop = radios.find((r) => r.checked && !r.disabled) ?? __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_enabled).call(this)[0];
|
|
134
|
+
for (const r of radios)
|
|
135
|
+
r._tabbable = r === stop && !this.disabled;
|
|
136
|
+
});
|
|
137
|
+
_CmRadioGroup_onClick.set(this, (e) => {
|
|
138
|
+
const r = e.target.closest?.('cm-radio');
|
|
139
|
+
if (!r || r.disabled || this.disabled || !this.contains(r))
|
|
140
|
+
return;
|
|
141
|
+
__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_select).call(this, r, true);
|
|
142
|
+
});
|
|
143
|
+
_CmRadioGroup_onKeyDown.set(this, (e) => {
|
|
144
|
+
const r = e.target.closest?.('cm-radio');
|
|
145
|
+
if (!r || this.disabled)
|
|
146
|
+
return;
|
|
147
|
+
const list = __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_enabled).call(this);
|
|
148
|
+
const i = list.indexOf(r);
|
|
149
|
+
let next;
|
|
150
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowRight')
|
|
151
|
+
next = list[(i + 1) % list.length];
|
|
152
|
+
else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft')
|
|
153
|
+
next = list[(i - 1 + list.length) % list.length];
|
|
154
|
+
else if (e.key === ' ')
|
|
155
|
+
next = r.disabled ? undefined : r;
|
|
156
|
+
else
|
|
157
|
+
return;
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
if (next)
|
|
160
|
+
__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_select).call(this, next, true);
|
|
161
|
+
});
|
|
162
|
+
this.addEventListener('keydown', __classPrivateFieldGet(this, _CmRadioGroup_onKeyDown, "f"));
|
|
163
|
+
this.addEventListener('click', __classPrivateFieldGet(this, _CmRadioGroup_onClick, "f"));
|
|
164
|
+
}
|
|
165
|
+
connectedCallback() {
|
|
166
|
+
super.connectedCallback();
|
|
167
|
+
__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_adoptInitial).call(this);
|
|
168
|
+
}
|
|
169
|
+
get form() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").form; }
|
|
170
|
+
get validity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").validity; }
|
|
171
|
+
get validationMessage() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").validationMessage; }
|
|
172
|
+
checkValidity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").checkValidity(); }
|
|
173
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").reportValidity(); }
|
|
174
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmRadioGroup_defaultValue, "f"); }
|
|
175
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
176
|
+
formStateRestoreCallback(state) { this.value = state; }
|
|
177
|
+
/** Focuses the selected option, or the first one. */
|
|
178
|
+
focus(options) {
|
|
179
|
+
(__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this).find((r) => r._tabbable) ?? __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this)[0])?.focus(options);
|
|
180
|
+
}
|
|
181
|
+
updated(changed) {
|
|
182
|
+
if (changed.has('value') && __classPrivateFieldGet(this, _CmRadioGroup_rendered, "f") && !__classPrivateFieldGet(this, _CmRadioGroup_adopting, "f"))
|
|
183
|
+
__classPrivateFieldSet(this, _CmRadioGroup_pristine, false, "f");
|
|
184
|
+
__classPrivateFieldSet(this, _CmRadioGroup_rendered, true, "f");
|
|
185
|
+
__classPrivateFieldGet(this, _CmRadioGroup_sync, "f").call(this);
|
|
186
|
+
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setFormValue(this.value || null, this.value);
|
|
187
|
+
const anchor = __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this)[0];
|
|
188
|
+
if (this.error)
|
|
189
|
+
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setValidity({ customError: true }, this.error, anchor);
|
|
190
|
+
else if (this.required && !this.value)
|
|
191
|
+
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setValidity({ valueMissing: true }, 'Please select one of these options.', anchor);
|
|
192
|
+
else
|
|
193
|
+
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setValidity({});
|
|
194
|
+
}
|
|
195
|
+
render() {
|
|
196
|
+
const described = [this.error && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-help`].filter(Boolean).join(' ');
|
|
197
|
+
return html `<div class="group" role="radiogroup" part="group"
|
|
198
|
+
aria-labelledby=${__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this) ? `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-l` : nothing} aria-label=${__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this) ? nothing : this.getAttribute('aria-label') ?? nothing}
|
|
199
|
+
aria-describedby=${described || nothing}
|
|
200
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${this.error ? 'true' : nothing}
|
|
201
|
+
aria-disabled=${this.disabled ? 'true' : nothing}>
|
|
202
|
+
<span class="label" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-l" part="label" ?hidden=${!__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this)}>${this.label}<slot name="label"></slot>${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>
|
|
203
|
+
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
204
|
+
${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
|
|
205
|
+
<div class="options" part="options"><slot @slotchange=${__classPrivateFieldGet(this, _CmRadioGroup_onSlotChange, "f")}></slot></div>
|
|
206
|
+
</div>`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
_CmRadioGroup_internals = new WeakMap(), _CmRadioGroup_id = new WeakMap(), _CmRadioGroup_defaultValue = new WeakMap(), _CmRadioGroup_pristine = new WeakMap(), _CmRadioGroup_rendered = new WeakMap(), _CmRadioGroup_adopting = new WeakMap(), _CmRadioGroup_onSlotChange = new WeakMap(), _CmRadioGroup_sync = new WeakMap(), _CmRadioGroup_onClick = new WeakMap(), _CmRadioGroup_onKeyDown = new WeakMap(), _CmRadioGroup_instances = new WeakSet(), _CmRadioGroup_adoptInitial = function _CmRadioGroup_adoptInitial() {
|
|
210
|
+
if (!__classPrivateFieldGet(this, _CmRadioGroup_pristine, "f"))
|
|
211
|
+
return;
|
|
212
|
+
if (!this.value) {
|
|
213
|
+
__classPrivateFieldSet(this, _CmRadioGroup_adopting, true, "f");
|
|
214
|
+
this.value = __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this).find((r) => r.hasAttribute('checked'))?.getAttribute('value') ?? '';
|
|
215
|
+
this.updateComplete.then(() => (__classPrivateFieldSet(this, _CmRadioGroup_adopting, false, "f")));
|
|
216
|
+
}
|
|
217
|
+
__classPrivateFieldSet(this, _CmRadioGroup_defaultValue, this.value, "f");
|
|
218
|
+
}, _CmRadioGroup_radios = function _CmRadioGroup_radios() { return [...this.querySelectorAll('cm-radio')]; }, _CmRadioGroup_enabled = function _CmRadioGroup_enabled() { return __classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_radios).call(this).filter((r) => !r.disabled && !this.disabled); }, _CmRadioGroup_select = function _CmRadioGroup_select(r, focus) {
|
|
219
|
+
if (focus)
|
|
220
|
+
r.focus();
|
|
221
|
+
if (r.value === this.value)
|
|
222
|
+
return;
|
|
223
|
+
this.value = r.value;
|
|
224
|
+
__classPrivateFieldGet(this, _CmRadioGroup_sync, "f").call(this);
|
|
225
|
+
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
226
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
227
|
+
}, _CmRadioGroup_hasLabel = function _CmRadioGroup_hasLabel() { return !!this.label || !!this.querySelector('[slot=label]'); };
|
|
228
|
+
CmRadioGroup.formAssociated = true;
|
|
229
|
+
CmRadioGroup.properties = {
|
|
230
|
+
label: {},
|
|
231
|
+
helpText: { attribute: 'help-text' },
|
|
232
|
+
error: { reflect: true },
|
|
233
|
+
name: { reflect: true },
|
|
234
|
+
value: { reflect: true },
|
|
235
|
+
orientation: { reflect: true },
|
|
236
|
+
required: { type: Boolean, reflect: true },
|
|
237
|
+
disabled: { type: Boolean, reflect: true },
|
|
238
|
+
};
|
|
239
|
+
CmRadioGroup.styles = [
|
|
240
|
+
base,
|
|
241
|
+
css `
|
|
242
|
+
:host { display: block; }
|
|
243
|
+
.group { display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
244
|
+
.label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); }
|
|
245
|
+
.req { color: var(--cm-text-critical); margin-left: 2px; }
|
|
246
|
+
.help, .error { margin: 0; font-size: 12px; color: var(--cm-text-tertiary); }
|
|
247
|
+
.error { color: var(--cm-text-critical); }
|
|
248
|
+
.options { display: flex; flex-direction: column; align-items: flex-start; gap: var(--cm-space-20); padding-top: var(--cm-space-10); }
|
|
249
|
+
:host([orientation='horizontal']) .options { flex-direction: row; flex-wrap: wrap; column-gap: var(--cm-space-30); }
|
|
250
|
+
`,
|
|
251
|
+
];
|
|
252
|
+
define('cm-radio-group', CmRadioGroup);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import type { IconName } from '@commmerce/icons';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
/**
|
|
5
|
+
* A square tile that opens one report: a large icon over a short name, e.g. "Hourly sales".
|
|
6
|
+
* A pinned tile shows a pin in its corner. With `href` the tile is a link; without, a button.
|
|
7
|
+
* @element cm-report-tile
|
|
8
|
+
* @slot icon - Your own 58px illustration, used instead of `icon`.
|
|
9
|
+
* @fires click - When a tile without `href` is chosen.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CmReportTile extends LitElement {
|
|
12
|
+
static properties: {
|
|
13
|
+
label: {};
|
|
14
|
+
icon: {};
|
|
15
|
+
href: {};
|
|
16
|
+
pinned: {
|
|
17
|
+
type: BooleanConstructor;
|
|
18
|
+
reflect: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** Report name, two or three words. */
|
|
22
|
+
label: string;
|
|
23
|
+
/** System icon shown above the name. */
|
|
24
|
+
icon: IconName;
|
|
25
|
+
/** Opens the report page. */
|
|
26
|
+
href: string;
|
|
27
|
+
/** Shows a pin: the report is pinned to the dashboard. */
|
|
28
|
+
pinned: boolean;
|
|
29
|
+
static shadowRootOptions: {
|
|
30
|
+
delegatesFocus: boolean;
|
|
31
|
+
mode: ShadowRootMode;
|
|
32
|
+
serializable?: boolean;
|
|
33
|
+
slotAssignment?: SlotAssignmentMode;
|
|
34
|
+
};
|
|
35
|
+
static styles: import("lit").CSSResult[];
|
|
36
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A titled group of report tiles, e.g. "Sales". Tiles are 146px wide, 15px apart, and wrap;
|
|
40
|
+
* on phones three fit a row.
|
|
41
|
+
* @element cm-report-tiles
|
|
42
|
+
* @slot - `cm-report-tile` elements.
|
|
43
|
+
*/
|
|
44
|
+
export declare class CmReportTiles extends LitElement {
|
|
45
|
+
static properties: {
|
|
46
|
+
heading: {};
|
|
47
|
+
headingLevel: {
|
|
48
|
+
type: NumberConstructor;
|
|
49
|
+
attribute: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** Group title, e.g. "Sales". */
|
|
53
|
+
heading: string;
|
|
54
|
+
/** Heading level for the title (1–6). */
|
|
55
|
+
headingLevel: number;
|
|
56
|
+
static styles: import("lit").CSSResult[];
|
|
57
|
+
firstUpdated(): void;
|
|
58
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
59
|
+
}
|
|
60
|
+
declare global {
|
|
61
|
+
interface HTMLElementTagNameMap {
|
|
62
|
+
'cm-report-tile': CmReportTile;
|
|
63
|
+
'cm-report-tiles': CmReportTiles;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
/**
|
|
5
|
+
* A square tile that opens one report: a large icon over a short name, e.g. "Hourly sales".
|
|
6
|
+
* A pinned tile shows a pin in its corner. With `href` the tile is a link; without, a button.
|
|
7
|
+
* @element cm-report-tile
|
|
8
|
+
* @slot icon - Your own 58px illustration, used instead of `icon`.
|
|
9
|
+
* @fires click - When a tile without `href` is chosen.
|
|
10
|
+
*/
|
|
11
|
+
export class CmReportTile extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
/** Report name, two or three words. */
|
|
15
|
+
this.label = '';
|
|
16
|
+
/** System icon shown above the name. */
|
|
17
|
+
this.icon = 'chart';
|
|
18
|
+
/** Opens the report page. */
|
|
19
|
+
this.href = '';
|
|
20
|
+
/** Shows a pin: the report is pinned to the dashboard. */
|
|
21
|
+
this.pinned = false;
|
|
22
|
+
}
|
|
23
|
+
render() {
|
|
24
|
+
const inner = html `
|
|
25
|
+
<span class="icon" aria-hidden="true"><slot name="icon"><cm-icon name=${this.icon} size="58"></cm-icon></slot></span>
|
|
26
|
+
<span class="label">${this.label}</span>
|
|
27
|
+
${this.pinned ? html `<span class="pin" part="pin"><cm-icon name="pin" size="18"></cm-icon><span class="sr">, pinned</span></span>` : nothing}
|
|
28
|
+
`;
|
|
29
|
+
return this.href
|
|
30
|
+
? html `<a class="tile" part="tile" href=${this.href}>${inner}</a>`
|
|
31
|
+
: html `<button class="tile" part="tile" type="button">${inner}</button>`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
CmReportTile.properties = {
|
|
35
|
+
label: {},
|
|
36
|
+
icon: {},
|
|
37
|
+
href: {},
|
|
38
|
+
pinned: { type: Boolean, reflect: true },
|
|
39
|
+
};
|
|
40
|
+
CmReportTile.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
41
|
+
CmReportTile.styles = [
|
|
42
|
+
base,
|
|
43
|
+
css `
|
|
44
|
+
:host { display: block; }
|
|
45
|
+
.tile {
|
|
46
|
+
position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--cm-space-20);
|
|
47
|
+
width: 100%; height: 150px; padding: var(--cm-space-10); font: inherit; font-size: 14px; font-weight: 500; text-align: center;
|
|
48
|
+
color: var(--cm-text-default); text-decoration: none; background: var(--cm-bg-surface); cursor: pointer;
|
|
49
|
+
border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-md);
|
|
50
|
+
}
|
|
51
|
+
.tile:hover { border-color: var(--cm-border-strong); }
|
|
52
|
+
.tile:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
53
|
+
.icon { display: inline-flex; color: var(--cm-icon-selected); }
|
|
54
|
+
::slotted([slot='icon']) { width: 58px; height: 58px; }
|
|
55
|
+
.pin { position: absolute; top: 10px; right: 10px; color: var(--cm-icon-selected); }
|
|
56
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
57
|
+
@media (max-width: 640px) {
|
|
58
|
+
.tile { height: 118px; gap: var(--cm-space-10); font-size: 12px; }
|
|
59
|
+
.icon cm-icon::part(svg) { width: 38px; height: 38px; }
|
|
60
|
+
::slotted([slot='icon']) { width: 38px; height: 38px; }
|
|
61
|
+
.pin { top: 8px; right: 8px; }
|
|
62
|
+
}
|
|
63
|
+
`,
|
|
64
|
+
];
|
|
65
|
+
define('cm-report-tile', CmReportTile);
|
|
66
|
+
/**
|
|
67
|
+
* A titled group of report tiles, e.g. "Sales". Tiles are 146px wide, 15px apart, and wrap;
|
|
68
|
+
* on phones three fit a row.
|
|
69
|
+
* @element cm-report-tiles
|
|
70
|
+
* @slot - `cm-report-tile` elements.
|
|
71
|
+
*/
|
|
72
|
+
export class CmReportTiles extends LitElement {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(...arguments);
|
|
75
|
+
/** Group title, e.g. "Sales". */
|
|
76
|
+
this.heading = '';
|
|
77
|
+
/** Heading level for the title (1–6). */
|
|
78
|
+
this.headingLevel = 2;
|
|
79
|
+
}
|
|
80
|
+
firstUpdated() {
|
|
81
|
+
// Tiles become list items of the grid.
|
|
82
|
+
for (const t of this.querySelectorAll(':scope > cm-report-tile'))
|
|
83
|
+
if (!t.hasAttribute('role'))
|
|
84
|
+
t.setAttribute('role', 'listitem');
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const level = Math.min(6, Math.max(1, this.headingLevel || 2));
|
|
88
|
+
return html `
|
|
89
|
+
${this.heading ? html `<div class="title" part="heading" role="heading" aria-level=${level} id="h">${this.heading}</div>` : nothing}
|
|
90
|
+
<div class="grid" part="grid" role="list" aria-labelledby=${this.heading ? 'h' : nothing}><slot @slotchange=${() => this.firstUpdated()}></slot></div>
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
CmReportTiles.properties = {
|
|
95
|
+
heading: {},
|
|
96
|
+
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
97
|
+
};
|
|
98
|
+
CmReportTiles.styles = [
|
|
99
|
+
base,
|
|
100
|
+
css `
|
|
101
|
+
:host { display: block; padding: var(--cm-space-20); background: var(--cm-bg-surface); border-radius: var(--cm-radius-md); }
|
|
102
|
+
.title { margin: 0 0 var(--cm-space-20); font-size: 16px; font-weight: 500; }
|
|
103
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: var(--cm-space-15); }
|
|
104
|
+
@media (min-width: 641px) { .grid { grid-template-columns: repeat(auto-fill, 146px); } }
|
|
105
|
+
@media (max-width: 640px) {
|
|
106
|
+
:host { padding: var(--cm-space-10); }
|
|
107
|
+
.title { margin-bottom: var(--cm-space-10); font-size: 14px; }
|
|
108
|
+
.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--cm-space-10); }
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
];
|
|
112
|
+
define('cm-report-tiles', CmReportTiles);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
import './action-menu.js';
|
|
4
|
+
/**
|
|
5
|
+
* A row in a `cm-resource-list`: a checkbox when the list is selectable, an optional thumbnail and
|
|
6
|
+
* any content. With `href` the whole row is a link; otherwise clicking a selectable row ticks it.
|
|
7
|
+
* @element cm-resource-item
|
|
8
|
+
* @slot - Row content: name, details, badges. Lay columns out with `--cm-table-columns` to line up with a table header.
|
|
9
|
+
* @slot media - A 50px thumbnail (34px on phones): a `cm-thumbnail` (recommended; `alt=""` when the row names the product) or an `<img>`.
|
|
10
|
+
* @slot actions - Buttons at the end of the row. They do not toggle selection.
|
|
11
|
+
* @fires cm-resource-select - `detail: { value, selected }` when the merchant ticks or unticks the row. The list handles it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CmResourceItem extends LitElement {
|
|
14
|
+
#private;
|
|
15
|
+
static properties: {
|
|
16
|
+
value: {
|
|
17
|
+
reflect: boolean;
|
|
18
|
+
};
|
|
19
|
+
selected: {
|
|
20
|
+
type: BooleanConstructor;
|
|
21
|
+
reflect: boolean;
|
|
22
|
+
};
|
|
23
|
+
disabled: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
reflect: boolean;
|
|
26
|
+
};
|
|
27
|
+
href: {};
|
|
28
|
+
label: {};
|
|
29
|
+
selectable: {
|
|
30
|
+
type: BooleanConstructor;
|
|
31
|
+
reflect: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** Identifies the row in the list's `selected` array. */
|
|
35
|
+
value: string;
|
|
36
|
+
/** The row is ticked. */
|
|
37
|
+
selected: boolean;
|
|
38
|
+
/** The row cannot be selected or opened. */
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
/** Makes the row a link to the resource's page. */
|
|
41
|
+
href: string;
|
|
42
|
+
/** Name for the checkbox and link, e.g. the product name. Defaults to the row's text. */
|
|
43
|
+
label: string;
|
|
44
|
+
/** Shows the checkbox. Set by the parent list from its own `selectable`. */
|
|
45
|
+
selectable: boolean;
|
|
46
|
+
constructor();
|
|
47
|
+
connectedCallback(): void;
|
|
48
|
+
static styles: import("lit").CSSResult[];
|
|
49
|
+
/** Accessible name: `label` or the row's text. */
|
|
50
|
+
get name(): string;
|
|
51
|
+
/** Ticks or unticks the row and fires `cm-resource-select`. */
|
|
52
|
+
toggle(force?: boolean): void;
|
|
53
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A list of products, orders, customers or other resources, with optional bulk selection.
|
|
57
|
+
* When `selectable`, a toolbar shows a select-all box with a menu (this page, all matching, none), bulk actions once something is selected,
|
|
58
|
+
* "2 products selected" and, when there are more results than rows, a button to select all of them.
|
|
59
|
+
* Put a `cm-table-header` in the `header` slot for column names and `cm-pagination` under the list.
|
|
60
|
+
* @element cm-resource-list
|
|
61
|
+
* @slot - `cm-resource-item` rows.
|
|
62
|
+
* @slot header - A `cm-table-header` (or anything) between the toolbar and the rows.
|
|
63
|
+
* @slot bulk-actions - Buttons that act on the selection, e.g. "Bulk orders". Shown once a row is selected.
|
|
64
|
+
* @slot actions - Buttons at the end of the toolbar, e.g. "Customise columns".
|
|
65
|
+
* @slot empty - Shown instead of the rows when there are none, e.g. a `cm-empty-state`.
|
|
66
|
+
* @fires cm-selection-change - `detail: { selected, all }`: values of the selected rows, and whether every matching resource (all `total`) is selected.
|
|
67
|
+
*/
|
|
68
|
+
export declare class CmResourceList extends LitElement {
|
|
69
|
+
#private;
|
|
70
|
+
static properties: {
|
|
71
|
+
selectable: {
|
|
72
|
+
type: BooleanConstructor;
|
|
73
|
+
reflect: boolean;
|
|
74
|
+
};
|
|
75
|
+
total: {
|
|
76
|
+
type: NumberConstructor;
|
|
77
|
+
};
|
|
78
|
+
resourceName: {
|
|
79
|
+
attribute: string;
|
|
80
|
+
};
|
|
81
|
+
resourceNamePlural: {
|
|
82
|
+
attribute: string;
|
|
83
|
+
};
|
|
84
|
+
loading: {
|
|
85
|
+
type: BooleanConstructor;
|
|
86
|
+
reflect: boolean;
|
|
87
|
+
};
|
|
88
|
+
allSelected: {
|
|
89
|
+
type: BooleanConstructor;
|
|
90
|
+
attribute: string;
|
|
91
|
+
reflect: boolean;
|
|
92
|
+
};
|
|
93
|
+
hideSelectMenu: {
|
|
94
|
+
type: BooleanConstructor;
|
|
95
|
+
attribute: string;
|
|
96
|
+
};
|
|
97
|
+
label: {};
|
|
98
|
+
_count: {
|
|
99
|
+
state: boolean;
|
|
100
|
+
};
|
|
101
|
+
_rows: {
|
|
102
|
+
state: boolean;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
/** Rows get checkboxes and the selection toolbar appears. */
|
|
106
|
+
selectable: boolean;
|
|
107
|
+
/** Number of resources matching the current filter across all pages. When higher than the rows shown, offers "Select all". */
|
|
108
|
+
total: number;
|
|
109
|
+
/** Singular noun, e.g. "product". */
|
|
110
|
+
resourceName: string;
|
|
111
|
+
/** Plural noun. Defaults to the singular plus "s". */
|
|
112
|
+
resourceNamePlural: string;
|
|
113
|
+
/** Dims the rows and shows a spinner while results load. */
|
|
114
|
+
loading: boolean;
|
|
115
|
+
/** Every matching resource is selected, not just the rows on this page. */
|
|
116
|
+
allSelected: boolean;
|
|
117
|
+
/** Hides the menu next to the select box (select this page, select all matching, select none). */
|
|
118
|
+
hideSelectMenu: boolean;
|
|
119
|
+
/** Accessible name of the list, e.g. "Products". Defaults to the plural noun. */
|
|
120
|
+
label: string;
|
|
121
|
+
_count: number;
|
|
122
|
+
_rows: number;
|
|
123
|
+
static styles: import("lit").CSSResult[];
|
|
124
|
+
constructor();
|
|
125
|
+
/** The `cm-resource-item` rows. */
|
|
126
|
+
get items(): CmResourceItem[];
|
|
127
|
+
/** Values of the selected rows on this page. */
|
|
128
|
+
get selected(): string[];
|
|
129
|
+
/** Ticks or unticks every enabled row on this page. */
|
|
130
|
+
selectPage(select?: boolean): void;
|
|
131
|
+
/** Selects every matching resource (`total`), including rows on other pages. */
|
|
132
|
+
selectAll(): void;
|
|
133
|
+
/** Clears the selection. */
|
|
134
|
+
clearSelection(): void;
|
|
135
|
+
updated(changed: Map<string, unknown>): void;
|
|
136
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
137
|
+
}
|
|
138
|
+
declare global {
|
|
139
|
+
interface HTMLElementTagNameMap {
|
|
140
|
+
'cm-resource-list': CmResourceList;
|
|
141
|
+
'cm-resource-item': CmResourceItem;
|
|
142
|
+
}
|
|
143
|
+
}
|