@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.
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,76 @@
1
+ import { LitElement } from 'lit';
2
+ import './button.js';
3
+ /**
4
+ * One entry in an order or customer timeline: when it was written, what it says and who wrote it.
5
+ * Stack several inside any container, `space-10` apart; put a `cm-comment-box` above or below to add new ones.
6
+ * @element cm-comment
7
+ * @slot - The comment text.
8
+ */
9
+ export declare class CmComment extends LitElement {
10
+ #private;
11
+ static properties: {
12
+ author: {};
13
+ datetime: {};
14
+ time: {};
15
+ };
16
+ /** Who wrote it (a staff name, "System" or an app name). */
17
+ author: string;
18
+ /** When it was written, as an ISO date-time (`2023-02-09T17:07`). Used for `<time datetime>`. */
19
+ datetime: string;
20
+ /** The date as shown. Leave empty to format `datetime` in the viewer's locale. */
21
+ time: string;
22
+ static styles: import("lit").CSSResult[];
23
+ connectedCallback(): void;
24
+ render(): import("lit-html").TemplateResult<1>;
25
+ }
26
+ /**
27
+ * Writes a new comment: a heading, a text box and a Post button. Ctrl/⌘ + Enter also posts.
28
+ * Put your `cm-comment` elements in the default slot to show the timeline under the box.
29
+ * @element cm-comment-box
30
+ * @slot - Existing `cm-comment` elements, shown as a list under the box.
31
+ * @fires cm-submit - When Post is pressed with text; `detail.value` is the trimmed text. Cancelable: the default clears the box.
32
+ */
33
+ export declare class CmCommentBox extends LitElement {
34
+ #private;
35
+ static properties: {
36
+ heading: {};
37
+ label: {};
38
+ placeholder: {};
39
+ action: {};
40
+ value: {};
41
+ disabled: {
42
+ type: BooleanConstructor;
43
+ reflect: boolean;
44
+ };
45
+ headingLevel: {
46
+ type: NumberConstructor;
47
+ attribute: string;
48
+ };
49
+ };
50
+ /** Section title above the box. */
51
+ heading: string;
52
+ /** Accessible name of the text box. */
53
+ label: string;
54
+ /** Placeholder in the empty box. */
55
+ placeholder: string;
56
+ /** Text of the post button. */
57
+ action: string;
58
+ /** Current text in the box. */
59
+ value: string;
60
+ /** Blocks typing and posting (for example while the comment saves). */
61
+ disabled: boolean;
62
+ /** Heading level of the title. Default 2. */
63
+ headingLevel: 2 | 3 | 4 | 5 | 6;
64
+ static styles: import("lit").CSSResult[];
65
+ /** @internal */
66
+ hasComments: boolean;
67
+ /** Posts the current text, as if Post was pressed. */
68
+ submit(): void;
69
+ render(): import("lit-html").TemplateResult<1>;
70
+ }
71
+ declare global {
72
+ interface HTMLElementTagNameMap {
73
+ 'cm-comment': CmComment;
74
+ 'cm-comment-box': CmCommentBox;
75
+ }
76
+ }
@@ -0,0 +1,170 @@
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 _CmComment_instances, _CmComment_shown, _CmCommentBox_instances, _CmCommentBox_id, _CmCommentBox_key;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define, nextId } from '../base.js';
9
+ import './button.js';
10
+ /**
11
+ * One entry in an order or customer timeline: when it was written, what it says and who wrote it.
12
+ * Stack several inside any container, `space-10` apart; put a `cm-comment-box` above or below to add new ones.
13
+ * @element cm-comment
14
+ * @slot - The comment text.
15
+ */
16
+ export class CmComment extends LitElement {
17
+ constructor() {
18
+ super(...arguments);
19
+ _CmComment_instances.add(this);
20
+ /** Who wrote it (a staff name, "System" or an app name). */
21
+ this.author = '';
22
+ /** When it was written, as an ISO date-time (`2023-02-09T17:07`). Used for `<time datetime>`. */
23
+ this.datetime = '';
24
+ /** The date as shown. Leave empty to format `datetime` in the viewer's locale. */
25
+ this.time = '';
26
+ }
27
+ connectedCallback() {
28
+ super.connectedCallback();
29
+ // A list item only inside a comment box, which provides the list.
30
+ if (!this.hasAttribute('role') && this.parentElement?.localName === 'cm-comment-box')
31
+ this.setAttribute('role', 'listitem');
32
+ }
33
+ render() {
34
+ const shown = __classPrivateFieldGet(this, _CmComment_instances, "m", _CmComment_shown).call(this);
35
+ return html `<article part="comment">
36
+ ${shown ? html `<time class="meta" part="time" datetime=${this.datetime || nothing}>${shown}</time>` : nothing}
37
+ <div class="body" part="body"><slot></slot></div>
38
+ ${this.author ? html `<div class="meta" part="author">– ${this.author}</div>` : nothing}
39
+ </article>`;
40
+ }
41
+ }
42
+ _CmComment_instances = new WeakSet(), _CmComment_shown = function _CmComment_shown() {
43
+ if (this.time)
44
+ return this.time;
45
+ if (!this.datetime)
46
+ return '';
47
+ const d = new Date(this.datetime);
48
+ if (Number.isNaN(d.getTime()))
49
+ return this.datetime;
50
+ return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(d);
51
+ };
52
+ CmComment.properties = {
53
+ author: {},
54
+ datetime: {},
55
+ time: {},
56
+ };
57
+ CmComment.styles = [
58
+ base,
59
+ css `
60
+ :host { display: block; }
61
+ article {
62
+ display: flex; flex-direction: column; gap: 6px; padding: var(--cm-space-10);
63
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-sm);
64
+ }
65
+ .meta { font-size: 12px; color: var(--cm-text-tertiary); }
66
+ .body { font-size: 14px; line-height: 16px; overflow-wrap: anywhere; }
67
+ `,
68
+ ];
69
+ define('cm-comment', CmComment);
70
+ /**
71
+ * Writes a new comment: a heading, a text box and a Post button. Ctrl/⌘ + Enter also posts.
72
+ * Put your `cm-comment` elements in the default slot to show the timeline under the box.
73
+ * @element cm-comment-box
74
+ * @slot - Existing `cm-comment` elements, shown as a list under the box.
75
+ * @fires cm-submit - When Post is pressed with text; `detail.value` is the trimmed text. Cancelable: the default clears the box.
76
+ */
77
+ export class CmCommentBox extends LitElement {
78
+ constructor() {
79
+ super(...arguments);
80
+ _CmCommentBox_instances.add(this);
81
+ /** Section title above the box. */
82
+ this.heading = 'Comments';
83
+ /** Accessible name of the text box. */
84
+ this.label = 'Add a comment';
85
+ /** Placeholder in the empty box. */
86
+ this.placeholder = '';
87
+ /** Text of the post button. */
88
+ this.action = 'Post comment';
89
+ /** Current text in the box. */
90
+ this.value = '';
91
+ /** Blocks typing and posting (for example while the comment saves). */
92
+ this.disabled = false;
93
+ /** Heading level of the title. Default 2. */
94
+ this.headingLevel = 2;
95
+ _CmCommentBox_id.set(this, nextId('cm-comment-box'));
96
+ /** @internal */
97
+ this.hasComments = false;
98
+ }
99
+ /** Posts the current text, as if Post was pressed. */
100
+ submit() {
101
+ const ta = this.renderRoot.querySelector('textarea');
102
+ const text = (ta?.value ?? this.value).trim();
103
+ if (this.disabled)
104
+ return;
105
+ if (!text) {
106
+ ta?.focus();
107
+ return;
108
+ }
109
+ const ev = new CustomEvent('cm-submit', { bubbles: true, composed: true, cancelable: true, detail: { value: text } });
110
+ if (this.dispatchEvent(ev)) {
111
+ this.value = '';
112
+ if (ta)
113
+ ta.value = '';
114
+ }
115
+ }
116
+ render() {
117
+ const level = Math.min(6, Math.max(2, this.headingLevel || 2));
118
+ return html `<section part="comment-box" aria-labelledby="${__classPrivateFieldGet(this, _CmCommentBox_id, "f")}-h">
119
+ <div class="title" id="${__classPrivateFieldGet(this, _CmCommentBox_id, "f")}-h" role="heading" aria-level=${level} part="heading">${this.heading}</div>
120
+ <textarea part="input" aria-label=${this.label} placeholder=${this.placeholder || nothing} .value=${this.value}
121
+ ?disabled=${this.disabled} @input=${(e) => { this.value = e.target.value; }}
122
+ @keydown=${__classPrivateFieldGet(this, _CmCommentBox_instances, "m", _CmCommentBox_key)}></textarea>
123
+ <div class="actions"><cm-button variant="primary" size="large" ?disabled=${this.disabled} @click=${() => this.submit()}>${this.action}</cm-button></div>
124
+ <div class="list" role="list" ?hidden=${!this.hasComments}>
125
+ <slot @slotchange=${(e) => { this.hasComments = e.target.assignedElements().length > 0; this.requestUpdate(); }}></slot>
126
+ </div>
127
+ </section>`;
128
+ }
129
+ }
130
+ _CmCommentBox_id = new WeakMap(), _CmCommentBox_instances = new WeakSet(), _CmCommentBox_key = function _CmCommentBox_key(e) {
131
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
132
+ e.preventDefault();
133
+ this.submit();
134
+ }
135
+ };
136
+ CmCommentBox.properties = {
137
+ heading: {},
138
+ label: {},
139
+ placeholder: {},
140
+ action: {},
141
+ value: {},
142
+ disabled: { type: Boolean, reflect: true },
143
+ headingLevel: { type: Number, attribute: 'heading-level' },
144
+ };
145
+ CmCommentBox.styles = [
146
+ base,
147
+ css `
148
+ :host { display: block; }
149
+ section { display: flex; flex-direction: column; gap: var(--cm-space-20); }
150
+ .title { margin: 0; font-size: 20px; font-weight: 600; }
151
+ textarea {
152
+ display: block; width: 100%; min-height: 128px; padding: var(--cm-space-10); resize: vertical;
153
+ border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
154
+ background: var(--cm-bg-surface); color: var(--cm-text-default); font: inherit; font-size: 14px;
155
+ }
156
+ textarea::placeholder { color: var(--cm-text-tertiary); }
157
+ textarea:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; border-color: var(--cm-border-strong); }
158
+ textarea:disabled { background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); }
159
+ .actions { display: flex; }
160
+ .list { display: flex; flex-direction: column; gap: var(--cm-space-10); }
161
+ .list[hidden] { display: none; }
162
+ @media (max-width: 640px) {
163
+ section { gap: var(--cm-space-10); }
164
+ .title { font-size: 16px; }
165
+ textarea { min-height: 100px; }
166
+ .actions { justify-content: flex-end; }
167
+ }
168
+ `,
169
+ ];
170
+ define('cm-comment-box', CmCommentBox);
@@ -0,0 +1,132 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ import './skeleton.js';
4
+ /** One column of a data table. */
5
+ export interface DataTableColumn {
6
+ /** The property of each row shown in this column, and the key in `cm-sort`. */
7
+ key: string;
8
+ /** Column heading. */
9
+ label: string;
10
+ /** Text alignment. Default: `end` for `numeric` and `money`, otherwise `start`. */
11
+ align?: 'start' | 'end';
12
+ /** Lets the merchant sort by this column. */
13
+ sortable?: boolean;
14
+ /**
15
+ * How values are compared and laid out. `numeric` and `money` are right-aligned with tabular figures;
16
+ * `date` sorts by date (ISO strings, timestamps or `Date` objects).
17
+ */
18
+ type?: 'text' | 'numeric' | 'money' | 'date';
19
+ /** Heading for screen readers only, e.g. for an actions column. */
20
+ hidden?: boolean;
21
+ }
22
+ /** A row: column keys to cell values. Values are shown as text, never as HTML. */
23
+ export type DataTableRow = Record<string, unknown>;
24
+ export type SortDirection = 'ascending' | 'descending';
25
+ /**
26
+ * A data table for reports and read-only lists: sales by day, stock by location, order lines.
27
+ * A real `<table>` with column headings, sortable columns, a totals row, a sticky header and first column,
28
+ * loading rows and an empty state. For lists merchants select and act on, use Resource list.
29
+ *
30
+ * Give it `columns` and `rows`, or write a native `<table>` inside it (for server-rendered pages): that
31
+ * table is styled to match. Mark a heading `<th data-sort="text|numeric|money|date">` to make its column sortable
32
+ * in the browser too (a cell's `data-value` is compared instead of its text when present; `data-key` names the
33
+ * column in `cm-sort`). Every sort is announced to screen readers ("Sorted by Net sales, descending").
34
+ * @element cm-data-table
35
+ * @slot - Optional: a native `<table>` to style instead of `columns`/`rows`.
36
+ * @slot empty - Shown instead of the rows when `rows` is empty, e.g. a `cm-empty-state`.
37
+ * @fires cm-sort - `detail: { key, direction }` when a sortable heading is clicked. Cancelable: call
38
+ * `preventDefault()` to stop the table sorting itself. With `sort-mode="manual"` it never sorts itself.
39
+ * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`.
40
+ */
41
+ export declare class CmDataTable extends LitElement {
42
+ #private;
43
+ static properties: {
44
+ columns: {
45
+ type: ArrayConstructor;
46
+ };
47
+ rows: {
48
+ type: ArrayConstructor;
49
+ };
50
+ totals: {
51
+ type: ObjectConstructor;
52
+ };
53
+ caption: {};
54
+ captionHidden: {
55
+ type: BooleanConstructor;
56
+ attribute: string;
57
+ reflect: boolean;
58
+ };
59
+ sort: {
60
+ reflect: boolean;
61
+ };
62
+ direction: {
63
+ reflect: boolean;
64
+ };
65
+ sortMode: {
66
+ attribute: string;
67
+ reflect: boolean;
68
+ };
69
+ stickyHeader: {
70
+ type: BooleanConstructor;
71
+ attribute: string;
72
+ reflect: boolean;
73
+ };
74
+ stickyFirstColumn: {
75
+ type: BooleanConstructor;
76
+ attribute: string;
77
+ reflect: boolean;
78
+ };
79
+ loading: {
80
+ type: BooleanConstructor;
81
+ reflect: boolean;
82
+ };
83
+ loadingRows: {
84
+ type: NumberConstructor;
85
+ attribute: string;
86
+ };
87
+ _light: {
88
+ state: boolean;
89
+ };
90
+ _announce: {
91
+ state: boolean;
92
+ };
93
+ };
94
+ /** The columns, in order. */
95
+ columns: DataTableColumn[];
96
+ /** The rows: objects keyed by column `key`. Values are shown as text. */
97
+ rows: DataTableRow[];
98
+ /** A totals row shown at the bottom (`<tfoot>`), keyed like a row. Leave a key out for an empty cell. */
99
+ totals: DataTableRow | null;
100
+ /** What the table shows, e.g. "Sales by day". Every table needs one; it names the table for screen readers. */
101
+ caption: string;
102
+ /** Keeps the caption for screen readers but hides it, when a card or page heading already says it. */
103
+ captionHidden: boolean;
104
+ /** Key of the sorted column. Empty: rows stay in the order given. */
105
+ sort: string;
106
+ /** Direction of the sorted column. */
107
+ direction: SortDirection;
108
+ /** `auto`: the table sorts its own rows. `manual`: it only fires `cm-sort` (sort on your server, then set `rows`). */
109
+ sortMode: 'auto' | 'manual';
110
+ /** Keeps the heading row visible while the table scrolls inside `--cm-data-table-max-height`. */
111
+ stickyHeader: boolean;
112
+ /** Keeps the first column visible while the table scrolls sideways (on narrow screens). */
113
+ stickyFirstColumn: boolean;
114
+ /** Shows placeholder rows and marks the table busy. */
115
+ loading: boolean;
116
+ /** How many placeholder rows `loading` shows. */
117
+ loadingRows: number;
118
+ _light: boolean;
119
+ _announce: string;
120
+ static styles: import("lit").CSSResult[];
121
+ connectedCallback(): void;
122
+ disconnectedCallback(): void;
123
+ /** The rows in display order: sorted when `sort` is set and `sort-mode` is `auto`. */
124
+ get sortedRows(): DataTableRow[];
125
+ updated(changed: Map<string, unknown>): void;
126
+ render(): import("lit-html").TemplateResult<1>;
127
+ }
128
+ declare global {
129
+ interface HTMLElementTagNameMap {
130
+ 'cm-data-table': CmDataTable;
131
+ }
132
+ }