@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.
Files changed (125) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +41 -2
  3. package/dist/base.d.ts +7 -0
  4. package/dist/base.js +22 -0
  5. package/dist/cdn.js +1958 -0
  6. package/dist/components/accordion.d.ts +43 -0
  7. package/dist/components/accordion.js +83 -0
  8. package/dist/components/action-bar.d.ts +42 -0
  9. package/dist/components/action-bar.js +84 -0
  10. package/dist/components/action-menu.d.ts +89 -0
  11. package/dist/components/action-menu.js +283 -0
  12. package/dist/components/app-card.d.ts +57 -0
  13. package/dist/components/app-card.js +100 -0
  14. package/dist/components/avatar.d.ts +48 -0
  15. package/dist/components/avatar.js +82 -0
  16. package/dist/components/badge.d.ts +23 -0
  17. package/dist/components/badge.js +35 -0
  18. package/dist/components/banner.d.ts +36 -0
  19. package/dist/components/banner.js +88 -0
  20. package/dist/components/bottom-navigation.d.ts +48 -0
  21. package/dist/components/bottom-navigation.js +98 -0
  22. package/dist/components/bottom-sheet.d.ts +54 -0
  23. package/dist/components/bottom-sheet.js +133 -0
  24. package/dist/components/button.d.ts +53 -0
  25. package/dist/components/button.js +101 -0
  26. package/dist/components/card.d.ts +37 -0
  27. package/dist/components/card.js +58 -0
  28. package/dist/components/checkbox.d.ts +68 -0
  29. package/dist/components/checkbox.js +114 -0
  30. package/dist/components/comment.d.ts +76 -0
  31. package/dist/components/comment.js +170 -0
  32. package/dist/components/data-table.d.ts +132 -0
  33. package/dist/components/data-table.js +331 -0
  34. package/dist/components/empty-state.d.ts +49 -0
  35. package/dist/components/empty-state.js +94 -0
  36. package/dist/components/file-upload.d.ts +102 -0
  37. package/dist/components/file-upload.js +243 -0
  38. package/dist/components/filter-panel.d.ts +86 -0
  39. package/dist/components/filter-panel.js +128 -0
  40. package/dist/components/flash-offer-bar.d.ts +34 -0
  41. package/dist/components/flash-offer-bar.js +73 -0
  42. package/dist/components/grid.d.ts +39 -0
  43. package/dist/components/grid.js +42 -0
  44. package/dist/components/header-bar.d.ts +48 -0
  45. package/dist/components/header-bar.js +121 -0
  46. package/dist/components/icon.d.ts +30 -0
  47. package/dist/components/icon.js +36 -0
  48. package/dist/components/info-panel.d.ts +63 -0
  49. package/dist/components/info-panel.js +108 -0
  50. package/dist/components/layout.d.ts +45 -0
  51. package/dist/components/layout.js +67 -0
  52. package/dist/components/link-tabs.d.ts +40 -0
  53. package/dist/components/link-tabs.js +85 -0
  54. package/dist/components/menu-item.d.ts +68 -0
  55. package/dist/components/menu-item.js +64 -0
  56. package/dist/components/mobile-menu.d.ts +69 -0
  57. package/dist/components/mobile-menu.js +184 -0
  58. package/dist/components/modal.d.ts +46 -0
  59. package/dist/components/modal.js +59 -0
  60. package/dist/components/nav-item.d.ts +98 -0
  61. package/dist/components/nav-item.js +84 -0
  62. package/dist/components/nested-list.d.ts +105 -0
  63. package/dist/components/nested-list.js +279 -0
  64. package/dist/components/notification-panel.d.ts +121 -0
  65. package/dist/components/notification-panel.js +174 -0
  66. package/dist/components/option-group.d.ts +74 -0
  67. package/dist/components/option-group.js +172 -0
  68. package/dist/components/page-header.d.ts +58 -0
  69. package/dist/components/page-header.js +121 -0
  70. package/dist/components/page.d.ts +34 -0
  71. package/dist/components/page.js +41 -0
  72. package/dist/components/pagination.d.ts +64 -0
  73. package/dist/components/pagination.js +160 -0
  74. package/dist/components/progress-bar.d.ts +45 -0
  75. package/dist/components/progress-bar.js +81 -0
  76. package/dist/components/radio.d.ts +131 -0
  77. package/dist/components/radio.js +252 -0
  78. package/dist/components/report-tile.d.ts +65 -0
  79. package/dist/components/report-tile.js +112 -0
  80. package/dist/components/resource-list.d.ts +143 -0
  81. package/dist/components/resource-list.js +335 -0
  82. package/dist/components/save-bar.d.ts +58 -0
  83. package/dist/components/save-bar.js +128 -0
  84. package/dist/components/search.d.ts +78 -0
  85. package/dist/components/search.js +144 -0
  86. package/dist/components/select.d.ts +106 -0
  87. package/dist/components/select.js +338 -0
  88. package/dist/components/side-navigation.d.ts +51 -0
  89. package/dist/components/side-navigation.js +194 -0
  90. package/dist/components/side-panel.d.ts +50 -0
  91. package/dist/components/side-panel.js +73 -0
  92. package/dist/components/skeleton-display.d.ts +32 -0
  93. package/dist/components/skeleton-display.js +70 -0
  94. package/dist/components/skeleton.d.ts +41 -0
  95. package/dist/components/skeleton.js +59 -0
  96. package/dist/components/smart-tip.d.ts +62 -0
  97. package/dist/components/smart-tip.js +128 -0
  98. package/dist/components/spinner.d.ts +27 -0
  99. package/dist/components/spinner.js +48 -0
  100. package/dist/components/stack.d.ts +45 -0
  101. package/dist/components/stack.js +49 -0
  102. package/dist/components/status-tabs.d.ts +65 -0
  103. package/dist/components/status-tabs.js +158 -0
  104. package/dist/components/table-header.d.ts +84 -0
  105. package/dist/components/table-header.js +151 -0
  106. package/dist/components/tag.d.ts +39 -0
  107. package/dist/components/tag.js +68 -0
  108. package/dist/components/text-field.d.ts +101 -0
  109. package/dist/components/text-field.js +162 -0
  110. package/dist/components/thumbnail.d.ts +40 -0
  111. package/dist/components/thumbnail.js +61 -0
  112. package/dist/components/toast.d.ts +108 -0
  113. package/dist/components/toast.js +268 -0
  114. package/dist/components/toggle.d.ts +60 -0
  115. package/dist/components/toggle.js +108 -0
  116. package/dist/components/tooltip.d.ts +56 -0
  117. package/dist/components/tooltip.js +267 -0
  118. package/dist/custom-elements.json +13222 -0
  119. package/dist/index.d.ts +70 -0
  120. package/dist/index.js +56 -0
  121. package/dist/overlay.d.ts +57 -0
  122. package/dist/overlay.js +205 -0
  123. package/dist/spacing.d.ts +6 -0
  124. package/dist/spacing.js +7 -0
  125. package/package.json +59 -4
@@ -0,0 +1,243 @@
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 _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define, nextId } from '../base.js';
9
+ import './icon.js';
10
+ const kb = (n) => (n >= 1024 * 1024 ? `${+(n / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} KB`);
11
+ /** Does `file` match an `accept` list such as `image/*,.pdf`? */
12
+ function accepts(file, accept) {
13
+ if (!accept.trim())
14
+ return true;
15
+ const name = file.name.toLowerCase(), type = file.type.toLowerCase();
16
+ return accept.split(',').map((a) => a.trim().toLowerCase()).filter(Boolean).some((a) => a.startsWith('.') ? name.endsWith(a) : a.endsWith('/*') ? type.startsWith(a.slice(0, -1)) : type === a);
17
+ }
18
+ /**
19
+ * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
20
+ * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
21
+ * Participates in native forms (submit with `enctype="multipart/form-data"`).
22
+ * @element cm-file-upload
23
+ * @fires change - When files are added or removed. Read `files`.
24
+ * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
25
+ */
26
+ export class CmFileUpload extends LitElement {
27
+ constructor() {
28
+ super(...arguments);
29
+ _CmFileUpload_instances.add(this);
30
+ /** Heading above the zone, e.g. "Add product images". */
31
+ this.label = '';
32
+ /** Rule shown next to the label in text-tertiary, e.g. "max. file size 300 KB". */
33
+ this.hint = '';
34
+ /** Text inside the zone. */
35
+ this.prompt = 'Click here to upload';
36
+ /** Form field name. */
37
+ this.name = '';
38
+ /** Allowed types, as for a native input: `image/*`, `.pdf,.csv`. Other files are refused. */
39
+ this.accept = '';
40
+ /** Allows more than one file. Chosen files are added to the list rather than replacing it. */
41
+ this.multiple = false;
42
+ /** Largest allowed file in bytes. Larger files are refused. */
43
+ this.maxSize = 0;
44
+ /** Most files allowed when `multiple`; 0 for no limit. */
45
+ this.maxFiles = 0;
46
+ /** The form will not submit without a file. */
47
+ this.required = false;
48
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
49
+ this.disabled = false;
50
+ /** Error message from your own validation; announced and linked to the input. */
51
+ this.error = '';
52
+ /** The chosen files. Set it to `[]` to clear. */
53
+ this.files = [];
54
+ this._rejected = '';
55
+ _CmFileUpload_internals.set(this, this.attachInternals());
56
+ _CmFileUpload_id.set(this, nextId('cm-fu'));
57
+ _CmFileUpload_urls.set(this, new Map());
58
+ }
59
+ get form() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").form; }
60
+ get validity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").validity; }
61
+ get validationMessage() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").validationMessage; }
62
+ checkValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").checkValidity(); }
63
+ reportValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").reportValidity(); }
64
+ formResetCallback() { this.files = []; this._rejected = ''; }
65
+ formDisabledCallback(d) { this.disabled = d; }
66
+ disconnectedCallback() {
67
+ super.disconnectedCallback();
68
+ for (const u of __classPrivateFieldGet(this, _CmFileUpload_urls, "f").values())
69
+ URL.revokeObjectURL(u);
70
+ __classPrivateFieldGet(this, _CmFileUpload_urls, "f").clear();
71
+ }
72
+ updated(changed) {
73
+ if (changed.has('files')) {
74
+ for (const [f, u] of __classPrivateFieldGet(this, _CmFileUpload_urls, "f"))
75
+ if (!this.files.includes(f)) {
76
+ URL.revokeObjectURL(u);
77
+ __classPrivateFieldGet(this, _CmFileUpload_urls, "f").delete(f);
78
+ }
79
+ }
80
+ const data = new FormData();
81
+ for (const f of this.files)
82
+ data.append(this.name || 'file', f);
83
+ __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setFormValue(this.files.length ? data : null);
84
+ const input = this.renderRoot.querySelector('input') ?? undefined;
85
+ const msg = this.error || this._rejected;
86
+ if (msg)
87
+ __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({ customError: true }, msg, input);
88
+ else if (this.required && !this.files.length)
89
+ __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({ valueMissing: true }, 'Please choose a file.', input);
90
+ else
91
+ __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({});
92
+ }
93
+ /** Adds files as if the merchant had chosen them: filters by type, size and count, then fires events. */
94
+ addFiles(list) {
95
+ const incoming = [...list];
96
+ const ok = [], refused = [], reasons = [];
97
+ for (const f of incoming) {
98
+ if (!accepts(f, this.accept)) {
99
+ refused.push(f);
100
+ reasons.push(`${f.name} is not an allowed file type`);
101
+ }
102
+ else if (this.maxSize && f.size > this.maxSize) {
103
+ refused.push(f);
104
+ reasons.push(`${f.name} is larger than ${kb(this.maxSize)}`);
105
+ }
106
+ else
107
+ ok.push(f);
108
+ }
109
+ let next = this.multiple ? [...this.files, ...ok] : ok.slice(-1);
110
+ if (!this.multiple && !ok.length)
111
+ next = this.files;
112
+ if (this.multiple && this.maxFiles && next.length > this.maxFiles) {
113
+ refused.push(...next.slice(this.maxFiles));
114
+ reasons.push(`You can add up to ${this.maxFiles} files`);
115
+ next = next.slice(0, this.maxFiles);
116
+ }
117
+ this._rejected = reasons.join('. ');
118
+ if (refused.length)
119
+ this.dispatchEvent(new CustomEvent('cm-reject', { bubbles: true, composed: true, detail: { files: refused } }));
120
+ if (next !== this.files && (next.length !== this.files.length || next.some((f, i) => f !== this.files[i]))) {
121
+ this.files = next;
122
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
123
+ }
124
+ }
125
+ /** Removes one chosen file and fires `change`. */
126
+ removeFile(file) {
127
+ if (!this.files.includes(file))
128
+ return;
129
+ this.files = this.files.filter((f) => f !== file);
130
+ this._rejected = '';
131
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
132
+ this.updateComplete.then(() => this.renderRoot.querySelector('input')?.focus());
133
+ }
134
+ render() {
135
+ const msg = this.error || this._rejected;
136
+ const showZone = !this.files.length || this.multiple;
137
+ const tile = this.files.length > 0;
138
+ return html `
139
+ ${this.label || this.hint
140
+ ? html `<div class="head">
141
+ ${this.label ? html `<span class="label" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>` : nothing}
142
+ ${this.hint ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing}
143
+ </div>`
144
+ : nothing}
145
+ ${tile
146
+ ? html `<ul class="grid" part="files" role="list" style="list-style:none;margin:0;padding:0" aria-label="Chosen files">
147
+ ${this.files.map((f) => html `<li class="file">
148
+ ${f.type.startsWith('image/')
149
+ ? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${f.name} />`
150
+ : html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${kb(f.size)}</span></div>`}
151
+ ${this.disabled ? nothing : html `<button type="button" class="remove" aria-label="Remove ${f.name}" @click=${() => this.removeFile(f)}><cm-icon name="close" size="12"></cm-icon></button>`}
152
+ </li>`)}
153
+ ${showZone ? html `<li>${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_zone).call(this, true)}</li>` : nothing}
154
+ </ul>`
155
+ : __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_zone).call(this, false)}
156
+ ${msg ? html `<p class="msg" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg" role="alert">${msg}</p>` : nothing}
157
+ `;
158
+ }
159
+ }
160
+ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFileUpload_urls = new WeakMap(), _CmFileUpload_instances = new WeakSet(), _CmFileUpload_url = function _CmFileUpload_url(f) {
161
+ let u = __classPrivateFieldGet(this, _CmFileUpload_urls, "f").get(f);
162
+ if (!u) {
163
+ u = URL.createObjectURL(f);
164
+ __classPrivateFieldGet(this, _CmFileUpload_urls, "f").set(f, u);
165
+ }
166
+ return u;
167
+ }, _CmFileUpload_onInputChange = function _CmFileUpload_onInputChange(e) {
168
+ e.stopPropagation();
169
+ const input = e.target;
170
+ this.addFiles(input.files ?? []);
171
+ input.value = '';
172
+ }, _CmFileUpload_setOver = function _CmFileUpload_setOver(on) { this.toggleAttribute('data-over', on); }, _CmFileUpload_zone = function _CmFileUpload_zone(tile) {
173
+ const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, (this.error || this._rejected) && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
174
+ return html `<label class="zone ${tile ? 'tile' : ''}" part="zone"
175
+ @dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
176
+ <input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
177
+ ?required=${this.required && !this.files.length}
178
+ aria-labelledby=${[this.label && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l`, `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`].filter(Boolean).join(' ')}
179
+ aria-describedby=${described || nothing} aria-invalid=${this.error || this._rejected ? 'true' : nothing}
180
+ @change=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_onInputChange)} @cancel=${(e) => e.stopPropagation()} />
181
+ <cm-icon name=${tile ? 'plus' : 'upload'} size=${tile ? 24 : 38}></cm-icon>
182
+ <span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${tile ? 'Add more' : this.prompt}</span>
183
+ </label>`;
184
+ };
185
+ CmFileUpload.formAssociated = true;
186
+ CmFileUpload.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
187
+ CmFileUpload.properties = {
188
+ label: {},
189
+ hint: {},
190
+ prompt: {},
191
+ name: { reflect: true },
192
+ accept: {},
193
+ multiple: { type: Boolean },
194
+ maxSize: { type: Number, attribute: 'max-size' },
195
+ maxFiles: { type: Number, attribute: 'max-files' },
196
+ required: { type: Boolean, reflect: true },
197
+ disabled: { type: Boolean, reflect: true },
198
+ error: { reflect: true },
199
+ files: { attribute: false },
200
+ _rejected: { state: true },
201
+ };
202
+ CmFileUpload.styles = [
203
+ base,
204
+ css `
205
+ :host { display: block; }
206
+ .head { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: var(--cm-space-10); margin-bottom: var(--cm-space-20); }
207
+ .label { font-size: var(--cm-type-heading-sm-size); font-weight: 600; }
208
+ .req { color: var(--cm-text-critical); margin-left: 2px; }
209
+ .hint { font-size: 12px; color: var(--cm-text-tertiary); }
210
+ .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 186px)); gap: var(--cm-space-30); }
211
+ .zone {
212
+ position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--cm-space-10);
213
+ min-height: 177px; padding: var(--cm-space-20); text-align: center; font-size: 16px; color: var(--cm-text-default);
214
+ background: var(--cm-bg-surface); border: var(--cm-border-1) dashed var(--cm-border-strong); cursor: pointer;
215
+ }
216
+ .zone:hover, :host([data-over]) .zone { background: var(--cm-bg-hover); }
217
+ .zone.tile { min-height: 0; aspect-ratio: 1; border-radius: var(--cm-radius-md); font-size: 14px; }
218
+ .zone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: inherit; font-size: 0; }
219
+ .zone:focus-within { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
220
+ .file {
221
+ position: relative; aspect-ratio: 1; border-radius: var(--cm-radius-md); background: var(--cm-bg-inset);
222
+ border: var(--cm-border-1) solid var(--cm-border-card);
223
+ }
224
+ .file img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
225
+ .doc { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 100%; padding: var(--cm-space-10); text-align: center; }
226
+ .doc .name { font-size: 12px; word-break: break-all; }
227
+ .doc .size, .tile .size { font-size: 12px; color: var(--cm-text-tertiary); }
228
+ .remove {
229
+ position: absolute; top: -10px; right: -10px; display: inline-flex; align-items: center; justify-content: center;
230
+ width: 24px; height: 24px; padding: 0; border-radius: var(--cm-radius-full); cursor: pointer;
231
+ background: var(--cm-bg-surface); color: var(--cm-icon-selected); border: var(--cm-border-1) solid var(--cm-border-input);
232
+ }
233
+ .remove:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
234
+ .msg { margin: var(--cm-space-10) 0 0; font-size: 12px; color: var(--cm-text-critical); }
235
+ :host([disabled]) .zone { cursor: not-allowed; background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-default); }
236
+ :host([disabled]) .remove { display: none; }
237
+ @media (max-width: 640px) {
238
+ .zone:not(.tile) { min-height: 100px; font-size: 14px; }
239
+ .label { font-size: var(--cm-type-heading-sm-resp-size); }
240
+ }
241
+ `,
242
+ ];
243
+ define('cm-file-upload', CmFileUpload);
@@ -0,0 +1,86 @@
1
+ import { CmSidePanel } from './side-panel.js';
2
+ import './search.js';
3
+ import './button.js';
4
+ /** Filter values: one entry per field name; a name used by several checked fields gives an array. */
5
+ export type FilterValues = Record<string, string | string[]>;
6
+ /**
7
+ * "Search and Filter": a Side panel holding a search field and the fields that narrow a list (status, type,
8
+ * category, date range, tags), with Reset and Search at the bottom. Put the fields in a `<form>` in the panel
9
+ * (any form controls with a `name`, including `cm-select`, `cm-text-field`, `cm-checkbox`); the panel reads
10
+ * and resets that form.
11
+ *
12
+ * A native modal `<dialog>`, like Side panel: Esc and the backdrop ask to close, scrolling is locked, focus
13
+ * returns to the opener (usually the filter button of `cm-search`).
14
+ * @element cm-filter-panel
15
+ * @slot - A `<form>` with the filter fields.
16
+ * @fires cm-filter-apply - When Search is pressed (or Enter in the search field). `detail: { values, query }`. Cancelable: call `preventDefault()` to keep the panel open (e.g. an invalid date range).
17
+ * @fires cm-filter-reset - When Reset is pressed, after the fields went back to their first values.
18
+ * @fires cm-open - After the panel opens.
19
+ * @fires cm-close - Before it closes from Esc, the backdrop or the close button. `detail: { reason }`. Cancelable.
20
+ * @fires cm-closed - After it has closed.
21
+ */
22
+ export declare class CmFilterPanel extends CmSidePanel {
23
+ #private;
24
+ static properties: {
25
+ search: {
26
+ type: BooleanConstructor;
27
+ };
28
+ query: {};
29
+ searchLabel: {
30
+ attribute: string;
31
+ };
32
+ searchPlaceholder: {
33
+ attribute: string;
34
+ };
35
+ applyLabel: {
36
+ attribute: string;
37
+ };
38
+ resetLabel: {
39
+ attribute: string;
40
+ };
41
+ size: {
42
+ reflect: boolean;
43
+ };
44
+ _hasFooter: {
45
+ state: boolean;
46
+ };
47
+ open: {
48
+ type: BooleanConstructor;
49
+ reflect: boolean;
50
+ };
51
+ heading: {};
52
+ label: {};
53
+ closeLabel: {
54
+ attribute: string;
55
+ };
56
+ };
57
+ /** Title in the header. */
58
+ heading: string;
59
+ /** Shows a search field above the filters. */
60
+ search: boolean;
61
+ /** Text in the search field. */
62
+ query: string;
63
+ /** Accessible name of the search field. */
64
+ searchLabel: string;
65
+ /** Placeholder of the search field. */
66
+ searchPlaceholder: string;
67
+ /** Text of the main button. */
68
+ applyLabel: string;
69
+ /** Text of the reset button. */
70
+ resetLabel: string;
71
+ static styles: import("lit").CSSResult[];
72
+ /** The `<form>` holding the fields: a direct child, or the first one inside the panel. */
73
+ get form(): HTMLFormElement | null;
74
+ /** The current filter values, keyed by field name. Empty values are left out. */
75
+ get values(): FilterValues;
76
+ /** Puts every field back to its first value and clears the search. */
77
+ reset(): void;
78
+ protected renderBody(): import("lit-html").TemplateResult<1>;
79
+ protected renderFooter(): import("lit-html").TemplateResult<1>;
80
+ protected get showFooter(): boolean;
81
+ }
82
+ declare global {
83
+ interface HTMLElementTagNameMap {
84
+ 'cm-filter-panel': CmFilterPanel;
85
+ }
86
+ }
@@ -0,0 +1,128 @@
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 _CmFilterPanel_apply, _CmFilterPanel_reset;
7
+ import { html, css, nothing } from 'lit';
8
+ import { define } from '../base.js';
9
+ import { CmSidePanel } from './side-panel.js';
10
+ import './search.js';
11
+ import './button.js';
12
+ /**
13
+ * "Search and Filter": a Side panel holding a search field and the fields that narrow a list (status, type,
14
+ * category, date range, tags), with Reset and Search at the bottom. Put the fields in a `<form>` in the panel
15
+ * (any form controls with a `name`, including `cm-select`, `cm-text-field`, `cm-checkbox`); the panel reads
16
+ * and resets that form.
17
+ *
18
+ * A native modal `<dialog>`, like Side panel: Esc and the backdrop ask to close, scrolling is locked, focus
19
+ * returns to the opener (usually the filter button of `cm-search`).
20
+ * @element cm-filter-panel
21
+ * @slot - A `<form>` with the filter fields.
22
+ * @fires cm-filter-apply - When Search is pressed (or Enter in the search field). `detail: { values, query }`. Cancelable: call `preventDefault()` to keep the panel open (e.g. an invalid date range).
23
+ * @fires cm-filter-reset - When Reset is pressed, after the fields went back to their first values.
24
+ * @fires cm-open - After the panel opens.
25
+ * @fires cm-close - Before it closes from Esc, the backdrop or the close button. `detail: { reason }`. Cancelable.
26
+ * @fires cm-closed - After it has closed.
27
+ */
28
+ export class CmFilterPanel extends CmSidePanel {
29
+ constructor() {
30
+ super(...arguments);
31
+ /** Title in the header. */
32
+ this.heading = 'Search and Filter';
33
+ /** Shows a search field above the filters. */
34
+ this.search = false;
35
+ /** Text in the search field. */
36
+ this.query = '';
37
+ /** Accessible name of the search field. */
38
+ this.searchLabel = 'Search';
39
+ /** Placeholder of the search field. */
40
+ this.searchPlaceholder = 'Search anything';
41
+ /** Text of the main button. */
42
+ this.applyLabel = 'Search';
43
+ /** Text of the reset button. */
44
+ this.resetLabel = 'Reset';
45
+ _CmFilterPanel_apply.set(this, () => {
46
+ const ok = this.dispatchEvent(new CustomEvent('cm-filter-apply', {
47
+ detail: { values: this.values, query: this.query }, bubbles: true, composed: true, cancelable: true,
48
+ }));
49
+ if (ok)
50
+ this.requestClose('action');
51
+ });
52
+ _CmFilterPanel_reset.set(this, () => {
53
+ this.reset();
54
+ this.dispatchEvent(new CustomEvent('cm-filter-reset', { bubbles: true, composed: true }));
55
+ });
56
+ }
57
+ /** The `<form>` holding the fields: a direct child, or the first one inside the panel. */
58
+ get form() {
59
+ return this.querySelector('form');
60
+ }
61
+ /** The current filter values, keyed by field name. Empty values are left out. */
62
+ get values() {
63
+ const out = {};
64
+ const add = (k, v) => {
65
+ if (v === '')
66
+ return;
67
+ const cur = out[k];
68
+ out[k] = cur === undefined ? v : Array.isArray(cur) ? [...cur, v] : [cur, v];
69
+ };
70
+ const form = this.form;
71
+ if (form) {
72
+ for (const [k, v] of new FormData(form))
73
+ if (typeof v === 'string')
74
+ add(k, v);
75
+ return out;
76
+ }
77
+ this.querySelectorAll('[name]').forEach((f) => {
78
+ const name = f.getAttribute('name');
79
+ if (('checked' in f) && (f.type === 'checkbox' || f.type === 'radio' || f.localName.match(/^cm-(checkbox|radio|toggle)$/))) {
80
+ if (f.checked)
81
+ add(name, f.value || 'on');
82
+ }
83
+ else if (typeof f.value === 'string')
84
+ add(name, f.value);
85
+ });
86
+ return out;
87
+ }
88
+ /** Puts every field back to its first value and clears the search. */
89
+ reset() {
90
+ const form = this.form;
91
+ if (form)
92
+ form.reset();
93
+ else
94
+ this.querySelectorAll('[name]').forEach((f) => f.formResetCallback?.());
95
+ this.query = '';
96
+ }
97
+ renderBody() {
98
+ return html `${this.search ? html `<cm-search class="search" part="search" .value=${this.query} label=${this.searchLabel}
99
+ placeholder=${this.searchPlaceholder}
100
+ @input=${(e) => { this.query = e.target.value; }}
101
+ @cm-search=${(e) => { e.stopPropagation(); __classPrivateFieldGet(this, _CmFilterPanel_apply, "f").call(this); }}></cm-search>` : nothing}
102
+ <slot @submit=${(e) => { e.preventDefault(); __classPrivateFieldGet(this, _CmFilterPanel_apply, "f").call(this); }}></slot>`;
103
+ }
104
+ renderFooter() {
105
+ return html `<cm-button part="reset" @click=${__classPrivateFieldGet(this, _CmFilterPanel_reset, "f")}>${this.resetLabel}</cm-button>
106
+ <cm-button part="apply" variant="primary" @click=${__classPrivateFieldGet(this, _CmFilterPanel_apply, "f")}>${this.applyLabel}</cm-button>`;
107
+ }
108
+ get showFooter() { return true; }
109
+ }
110
+ _CmFilterPanel_apply = new WeakMap(), _CmFilterPanel_reset = new WeakMap();
111
+ CmFilterPanel.properties = {
112
+ ...CmSidePanel.properties,
113
+ search: { type: Boolean },
114
+ query: {},
115
+ searchLabel: { attribute: 'search-label' },
116
+ searchPlaceholder: { attribute: 'search-placeholder' },
117
+ applyLabel: { attribute: 'apply-label' },
118
+ resetLabel: { attribute: 'reset-label' },
119
+ };
120
+ CmFilterPanel.styles = [
121
+ ...CmSidePanel.styles,
122
+ css `
123
+ .search { display: block; margin-bottom: var(--cm-space-20); }
124
+ .foot { justify-content: center; }
125
+ ::slotted(form) { display: grid; gap: var(--cm-space-15); }
126
+ `,
127
+ ];
128
+ define('cm-filter-panel', CmFilterPanel);
@@ -0,0 +1,34 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ /**
4
+ * A dark strip across the top of the page with one short offer or call to action, such as
5
+ * "Publish your store with a Commmerce plan - Click here to pick a plan". Links inside it are green.
6
+ * @element cm-flash-offer-bar
7
+ * @slot - The message. Put one `<a>` inside it for the action.
8
+ * @slot icon - Replaces the leading icon.
9
+ * @fires cm-dismiss - When the close button is pressed (with `dismissible`). The bar hides itself unless the event is cancelled.
10
+ */
11
+ export declare class CmFlashOfferBar extends LitElement {
12
+ #private;
13
+ static properties: {
14
+ icon: {};
15
+ dismissible: {
16
+ type: BooleanConstructor;
17
+ reflect: boolean;
18
+ };
19
+ label: {};
20
+ };
21
+ /** Leading icon from @commmerce/icons. Empty hides it. */
22
+ icon: string;
23
+ /** Shows a close button. */
24
+ dismissible: boolean;
25
+ /** Accessible name of the bar's region. */
26
+ label: string;
27
+ static styles: import("lit").CSSResult[];
28
+ render(): import("lit-html").TemplateResult<1>;
29
+ }
30
+ declare global {
31
+ interface HTMLElementTagNameMap {
32
+ 'cm-flash-offer-bar': CmFlashOfferBar;
33
+ }
34
+ }
@@ -0,0 +1,73 @@
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 _CmFlashOfferBar_instances, _CmFlashOfferBar_dismiss;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define } from '../base.js';
9
+ import './icon.js';
10
+ /**
11
+ * A dark strip across the top of the page with one short offer or call to action, such as
12
+ * "Publish your store with a Commmerce plan - Click here to pick a plan". Links inside it are green.
13
+ * @element cm-flash-offer-bar
14
+ * @slot - The message. Put one `<a>` inside it for the action.
15
+ * @slot icon - Replaces the leading icon.
16
+ * @fires cm-dismiss - When the close button is pressed (with `dismissible`). The bar hides itself unless the event is cancelled.
17
+ */
18
+ export class CmFlashOfferBar extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ _CmFlashOfferBar_instances.add(this);
22
+ /** Leading icon from @commmerce/icons. Empty hides it. */
23
+ this.icon = 'send';
24
+ /** Shows a close button. */
25
+ this.dismissible = false;
26
+ /** Accessible name of the bar's region. */
27
+ this.label = 'Offer';
28
+ }
29
+ render() {
30
+ return html `<div class="bar" part="bar" role="region" aria-label=${this.label || 'Offer'}>
31
+ <span class="icon" aria-hidden="true"><slot name="icon">${this.icon ? html `<cm-icon name=${this.icon} size="20"></cm-icon>` : nothing}</slot></span>
32
+ <span class="text"><slot></slot></span>
33
+ ${this.dismissible ? html `<button type="button" class="close" part="close" aria-label="Dismiss offer" @click=${__classPrivateFieldGet(this, _CmFlashOfferBar_instances, "m", _CmFlashOfferBar_dismiss)}><cm-icon name="close" size="18"></cm-icon></button>` : nothing}
34
+ </div>`;
35
+ }
36
+ }
37
+ _CmFlashOfferBar_instances = new WeakSet(), _CmFlashOfferBar_dismiss = function _CmFlashOfferBar_dismiss() {
38
+ const ok = this.dispatchEvent(new CustomEvent('cm-dismiss', { bubbles: true, composed: true, cancelable: true }));
39
+ if (ok)
40
+ this.hidden = true;
41
+ };
42
+ CmFlashOfferBar.properties = {
43
+ icon: {},
44
+ dismissible: { type: Boolean, reflect: true },
45
+ label: {},
46
+ };
47
+ CmFlashOfferBar.styles = [
48
+ base,
49
+ css `
50
+ :host { display: block; }
51
+ .bar {
52
+ position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 56px;
53
+ padding: 10px var(--cm-space-20); background: var(--cm-bg-flash-bar); color: var(--cm-text-on-dark);
54
+ font-size: 18px; text-align: center;
55
+ }
56
+ :host([dismissible]) .bar { padding-inline: 56px; }
57
+ .icon { display: inline-flex; color: var(--cm-text-speciality-on-dark); flex: none; }
58
+ /* !important: page link colours (usually blue) would otherwise win over ::slotted and fail contrast on the dark bar. */
59
+ ::slotted(a) { color: var(--cm-text-speciality-on-dark) !important; font-weight: 500; text-decoration: none; }
60
+ ::slotted(a:hover) { text-decoration: underline; }
61
+ ::slotted(a:focus-visible) { outline: 2px solid var(--cm-text-on-dark); outline-offset: 2px; border-radius: 2px; }
62
+ .close {
63
+ position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: grid; place-items: center;
64
+ width: 32px; height: 32px; padding: 0; color: var(--cm-text-on-dark); background: none; border: 0; border-radius: 50%; cursor: pointer;
65
+ }
66
+ .close:hover { background: var(--cm-nav-active); }
67
+ .close:focus-visible { outline: 2px solid var(--cm-text-on-dark); outline-offset: 0; }
68
+ @media (max-width: 640px) {
69
+ .bar { font-size: 14px; min-height: 44px; justify-content: flex-start; text-align: start; }
70
+ }
71
+ `,
72
+ ];
73
+ define('cm-flash-offer-bar', CmFlashOfferBar);
@@ -0,0 +1,39 @@
1
+ import { LitElement } from 'lit';
2
+ import { type SpaceStep } from '../spacing.js';
3
+ /**
4
+ * Equal-width columns, for tiles, cards and short fields side by side. Collapses to one column when the grid
5
+ * itself is 640px wide or less (a container query), so it also works inside a narrow side column.
6
+ * @element cm-grid
7
+ * @slot - The grid items, in reading order.
8
+ */
9
+ export declare class CmGrid extends LitElement {
10
+ static properties: {
11
+ columns: {
12
+ type: NumberConstructor;
13
+ reflect: boolean;
14
+ };
15
+ minColumnWidth: {
16
+ attribute: string;
17
+ reflect: boolean;
18
+ };
19
+ gap: {
20
+ reflect: boolean;
21
+ };
22
+ };
23
+ /** Number of columns. Default 2. Ignored when `min-column-width` is set. */
24
+ columns: number;
25
+ /**
26
+ * Fit as many columns as there is room for, each at least this wide (a CSS length such as `240px` or `15rem`).
27
+ * Never wider than the grid, so it reaches one column on its own on narrow screens.
28
+ */
29
+ minColumnWidth?: string;
30
+ /** Space between items: a spacing step (`0`, `10`, `12`, `15`, `20`, `22`, `30`). Default `20`. */
31
+ gap: SpaceStep;
32
+ static styles: import("lit").CSSResult[];
33
+ render(): import("lit-html").TemplateResult<1>;
34
+ }
35
+ declare global {
36
+ interface HTMLElementTagNameMap {
37
+ 'cm-grid': CmGrid;
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { styleMap } from 'lit/directives/style-map.js';
3
+ import { base, define } from '../base.js';
4
+ import { spaceRules } from '../spacing.js';
5
+ /**
6
+ * Equal-width columns, for tiles, cards and short fields side by side. Collapses to one column when the grid
7
+ * itself is 640px wide or less (a container query), so it also works inside a narrow side column.
8
+ * @element cm-grid
9
+ * @slot - The grid items, in reading order.
10
+ */
11
+ export class CmGrid extends LitElement {
12
+ constructor() {
13
+ super(...arguments);
14
+ /** Number of columns. Default 2. Ignored when `min-column-width` is set. */
15
+ this.columns = 2;
16
+ /** Space between items: a spacing step (`0`, `10`, `12`, `15`, `20`, `22`, `30`). Default `20`. */
17
+ this.gap = '20';
18
+ }
19
+ render() {
20
+ const n = Math.max(1, Math.floor(Number(this.columns) || 1));
21
+ const fit = this.minColumnWidth?.trim();
22
+ const cols = fit ? `repeat(auto-fit, minmax(min(100%, ${fit}), 1fr))` : `repeat(${n}, minmax(0, 1fr))`;
23
+ return html `<div class="grid ${fit ? 'fit' : 'fixed'}" part="grid" style=${styleMap({ gridTemplateColumns: cols })}><slot></slot></div>`;
24
+ }
25
+ }
26
+ CmGrid.properties = {
27
+ columns: { type: Number, reflect: true },
28
+ minColumnWidth: { attribute: 'min-column-width', reflect: true },
29
+ gap: { reflect: true },
30
+ };
31
+ CmGrid.styles = [
32
+ base,
33
+ css `
34
+ :host { display: block; container: cm-grid / inline-size; --_gap: var(--cm-space-20); }
35
+ .grid { display: grid; gap: var(--_gap); align-items: start; }
36
+ @container cm-grid (max-width: 640px) {
37
+ .grid.fixed { grid-template-columns: minmax(0, 1fr) !important; }
38
+ }
39
+ `,
40
+ spaceRules('gap', '--_gap'),
41
+ ];
42
+ define('cm-grid', CmGrid);