@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,151 @@
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 _CmTableHeader_instances, _CmTableHeader_id, _CmTableHeader_observer, _CmTableHeader_readChildren, _CmTableHeader_onSort, _CmTableHeader_onSelectAll;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define, nextId } from '../base.js';
9
+ import './icon.js';
10
+ /**
11
+ * The grey 34px label bar at the top of a table or resource list: column names in 12px type,
12
+ * optional sort buttons and an optional "select all" checkbox.
13
+ *
14
+ * Columns come from `<option>` children or the `columns` property. Lay out the rows with the same
15
+ * grid: set `--cm-table-columns` (a `grid-template-columns` value) on a shared parent.
16
+ * Inside an element with `role="table"` or `role="grid"` it renders a real header row
17
+ * (`row` and `columnheader` roles); elsewhere it is a plain bar whose sort buttons say their state.
18
+ * @element cm-table-header
19
+ * @slot - `<option value="key" sortable align="end">Label</option>` elements.
20
+ * @fires cm-sort - `detail: { key, direction }` when a sortable column is clicked. Set `sort` and `direction` yourself.
21
+ * @fires cm-select-all - `detail: { checked }` when the select-all box is toggled.
22
+ * @cssprop --cm-table-columns - Column widths, e.g. `2fr 1fr 1fr 120px`. Default: equal columns.
23
+ */
24
+ export class CmTableHeader extends LitElement {
25
+ constructor() {
26
+ super(...arguments);
27
+ _CmTableHeader_instances.add(this);
28
+ /** Columns as strings or `{ key, label, sortable, align, hidden }`. Used instead of `<option>` children when set. */
29
+ this.columns = [];
30
+ /** Key of the sorted column. */
31
+ this.sort = '';
32
+ /** Sort direction of the `sort` column. */
33
+ this.direction = 'ascending';
34
+ /** Adds a leading "select all" checkbox column (50px, as in Figma). */
35
+ this.selectable = false;
36
+ /** Select-all box is ticked. */
37
+ this.checked = false;
38
+ /** Select-all box shows a dash: some rows are selected. */
39
+ this.indeterminate = false;
40
+ this._slotted = [];
41
+ this._inTable = false;
42
+ _CmTableHeader_id.set(this, nextId('cm-th'));
43
+ _CmTableHeader_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_readChildren).call(this)));
44
+ }
45
+ connectedCallback() {
46
+ super.connectedCallback();
47
+ this._inTable = !!this.parentElement?.closest('table, [role="table"], [role="grid"], [role="treegrid"]');
48
+ __classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_readChildren).call(this);
49
+ __classPrivateFieldGet(this, _CmTableHeader_observer, "f").observe(this, { childList: true, subtree: true, characterData: true, attributes: true });
50
+ }
51
+ disconnectedCallback() {
52
+ super.disconnectedCallback();
53
+ __classPrivateFieldGet(this, _CmTableHeader_observer, "f").disconnect();
54
+ }
55
+ /** The columns in use, normalised. */
56
+ get items() {
57
+ if (!this.columns.length)
58
+ return this._slotted;
59
+ return this.columns.map((c) => (typeof c === 'string' ? { key: c, label: c } : { ...c, key: c.key ?? c.label }));
60
+ }
61
+ render() {
62
+ const t = this._inTable;
63
+ const items = this.items;
64
+ return html `
65
+ <div class="bar ${this.selectable ? 'sel' : ''}" part="bar" role=${t ? 'row' : nothing}
66
+ style="--_cols: repeat(${Math.max(1, items.length)}, minmax(0, 1fr))">
67
+ ${this.selectable
68
+ ? html `<span class="cell" role=${t ? 'columnheader' : nothing}><span class="check">
69
+ <input id="${__classPrivateFieldGet(this, _CmTableHeader_id, "f")}-all" type="checkbox" aria-label="Select all" .checked=${this.checked} .indeterminate=${this.indeterminate}
70
+ @change=${__classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_onSelectAll)} />
71
+ <span class="box" aria-hidden="true">${this.indeterminate ? html `<span class="dash"></span>` : this.checked ? html `<cm-icon name="check" size="14"></cm-icon>` : nothing}</span>
72
+ </span></span>`
73
+ : nothing}
74
+ ${items.map((c) => {
75
+ const on = this.sort === c.key;
76
+ const state = on ? (this.direction === 'descending' ? 'descending' : 'ascending') : 'none';
77
+ const label = c.hidden ? html `<span class="sr">${c.label}</span>` : c.label;
78
+ return html `<span class="cell" part="cell" data-align=${c.align ?? 'start'} role=${t ? 'columnheader' : nothing}
79
+ aria-sort=${t && c.sortable ? state : nothing}>${c.sortable
80
+ ? html `<button type="button" class=${on ? 'on' : ''} @click=${() => __classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_onSort).call(this, c)}>${label}${!t
81
+ ? html `<span class="sr">${on ? `, sorted ${state}` : ', sortable'}</span>` : nothing}<cm-icon
82
+ name=${on && this.direction === 'descending' ? 'chevron-down' : 'chevron-up'} size="12"></cm-icon></button>`
83
+ : label}</span>`;
84
+ })}
85
+ </div>
86
+ <slot></slot>
87
+ `;
88
+ }
89
+ }
90
+ _CmTableHeader_id = new WeakMap(), _CmTableHeader_observer = new WeakMap(), _CmTableHeader_instances = new WeakSet(), _CmTableHeader_readChildren = function _CmTableHeader_readChildren() {
91
+ this._slotted = [...this.querySelectorAll('option')].map((o) => {
92
+ const label = o.label || o.textContent.trim();
93
+ return {
94
+ key: o.getAttribute('value') ?? label, label, sortable: o.hasAttribute('sortable'), hidden: o.hasAttribute('hidden'),
95
+ align: o.getAttribute('align') ?? 'start',
96
+ };
97
+ });
98
+ }, _CmTableHeader_onSort = function _CmTableHeader_onSort(c) {
99
+ const direction = this.sort === c.key && this.direction === 'ascending' ? 'descending' : 'ascending';
100
+ this.dispatchEvent(new CustomEvent('cm-sort', { detail: { key: c.key, direction }, bubbles: true, composed: true }));
101
+ }, _CmTableHeader_onSelectAll = function _CmTableHeader_onSelectAll(e) {
102
+ const checked = e.target.checked;
103
+ this.checked = checked;
104
+ this.indeterminate = false;
105
+ this.dispatchEvent(new CustomEvent('cm-select-all', { detail: { checked }, bubbles: true, composed: true }));
106
+ };
107
+ CmTableHeader.properties = {
108
+ columns: { type: Array },
109
+ sort: { reflect: true },
110
+ direction: { reflect: true },
111
+ selectable: { type: Boolean, reflect: true },
112
+ checked: { type: Boolean, reflect: true },
113
+ indeterminate: { type: Boolean, reflect: true },
114
+ _slotted: { state: true },
115
+ _inTable: { state: true },
116
+ };
117
+ CmTableHeader.styles = [
118
+ base,
119
+ css `
120
+ :host { display: block; }
121
+ slot { display: none; } /* <option> children are column data, not content */
122
+ .bar {
123
+ display: grid; grid-template-columns: var(--cm-table-columns, var(--_cols)); align-items: center; column-gap: var(--cm-space-20);
124
+ min-height: 34px; padding: 0 var(--cm-space-20); font-size: 12px; line-height: 1.5; color: var(--cm-text-default);
125
+ background: var(--cm-bg-hover); border: var(--cm-border-1) solid var(--cm-border-subtle);
126
+ border-radius: var(--cm-radius-md) var(--cm-radius-md) 0 0;
127
+ }
128
+ .bar.sel { grid-template-columns: 20px var(--cm-table-columns, var(--_cols)); padding-left: var(--cm-space-10); }
129
+ .cell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
130
+ .cell[data-align='center'] { text-align: center; }
131
+ .cell[data-align='end'] { text-align: end; }
132
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
133
+ button {
134
+ display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 0; font: inherit; color: inherit;
135
+ background: none; border: 0; cursor: pointer;
136
+ }
137
+ button cm-icon { color: var(--cm-icon-selected); opacity: 0; }
138
+ button:hover cm-icon, button.on cm-icon { opacity: 1; }
139
+ button:focus-visible, input:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
140
+ .check { display: inline-flex; position: relative; width: 20px; height: 20px; }
141
+ input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
142
+ .box {
143
+ width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; pointer-events: none;
144
+ border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-xs); background: var(--cm-bg-surface);
145
+ }
146
+ .dash { width: 10px; height: 2px; background: var(--cm-icon-selected); }
147
+ input:focus-visible + .box { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
148
+ slot { display: none; }
149
+ `,
150
+ ];
151
+ define('cm-table-header', CmTableHeader);
@@ -0,0 +1,39 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ /**
4
+ * Pill for a product tag or an applied filter value, optionally with a remove button.
5
+ * Removing is up to you: listen for `cm-remove` and take the tag out of your list,
6
+ * then move focus to the next tag or the field that adds tags.
7
+ * @element cm-tag
8
+ * @slot - The tag text.
9
+ * @fires cm-remove - When the remove button is pressed.
10
+ */
11
+ export declare class CmTag extends LitElement {
12
+ #private;
13
+ static properties: {
14
+ removable: {
15
+ type: BooleanConstructor;
16
+ reflect: boolean;
17
+ };
18
+ removeLabel: {
19
+ attribute: string;
20
+ };
21
+ disabled: {
22
+ type: BooleanConstructor;
23
+ reflect: boolean;
24
+ };
25
+ };
26
+ /** Shows the remove button. */
27
+ removable: boolean;
28
+ /** Accessible name of the remove button. Defaults to "Remove" plus the tag text. */
29
+ removeLabel: string;
30
+ /** Hides the remove button's action and dims the tag. */
31
+ disabled: boolean;
32
+ static styles: import("lit").CSSResult[];
33
+ render(): import("lit-html").TemplateResult<1>;
34
+ }
35
+ declare global {
36
+ interface HTMLElementTagNameMap {
37
+ 'cm-tag': CmTag;
38
+ }
39
+ }
@@ -0,0 +1,68 @@
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 _CmTag_instances, _CmTag_remove;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define } from '../base.js';
9
+ import './icon.js';
10
+ /**
11
+ * Pill for a product tag or an applied filter value, optionally with a remove button.
12
+ * Removing is up to you: listen for `cm-remove` and take the tag out of your list,
13
+ * then move focus to the next tag or the field that adds tags.
14
+ * @element cm-tag
15
+ * @slot - The tag text.
16
+ * @fires cm-remove - When the remove button is pressed.
17
+ */
18
+ export class CmTag extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ _CmTag_instances.add(this);
22
+ /** Shows the remove button. */
23
+ this.removable = false;
24
+ /** Accessible name of the remove button. Defaults to "Remove" plus the tag text. */
25
+ this.removeLabel = '';
26
+ /** Hides the remove button's action and dims the tag. */
27
+ this.disabled = false;
28
+ }
29
+ render() {
30
+ const name = this.removeLabel || `Remove ${this.textContent?.trim() ?? ''}`.trim();
31
+ return html `<span class="tag" part="tag"><span class="text"><slot @slotchange=${() => this.requestUpdate()}></slot></span>${this.removable
32
+ ? html `<button type="button" part="remove" aria-label=${name} ?disabled=${this.disabled} @click=${__classPrivateFieldGet(this, _CmTag_instances, "m", _CmTag_remove)}><cm-icon name="x-circle" size="14"></cm-icon></button>`
33
+ : nothing}</span>`;
34
+ }
35
+ }
36
+ _CmTag_instances = new WeakSet(), _CmTag_remove = function _CmTag_remove() {
37
+ if (this.disabled)
38
+ return;
39
+ this.dispatchEvent(new CustomEvent('cm-remove', { bubbles: true, composed: true }));
40
+ };
41
+ CmTag.properties = {
42
+ removable: { type: Boolean, reflect: true },
43
+ removeLabel: { attribute: 'remove-label' },
44
+ disabled: { type: Boolean, reflect: true },
45
+ };
46
+ CmTag.styles = [
47
+ base,
48
+ css `
49
+ :host { display: inline-flex; vertical-align: middle; max-width: 100%; }
50
+ .tag {
51
+ display: inline-flex; align-items: center; gap: 6px; min-width: 0; height: 26px; padding: 0 var(--cm-space-10);
52
+ font-size: 12px; color: var(--cm-text-default); background: var(--cm-bg-tag);
53
+ border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full);
54
+ }
55
+ :host([removable]) .tag { padding-right: 4px; }
56
+ .text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
57
+ button {
58
+ flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
59
+ padding: 0; border: 0; border-radius: var(--cm-radius-full); background: none; color: var(--cm-icon-selected); cursor: pointer;
60
+ }
61
+ button:hover { background: var(--cm-bg-hover); }
62
+ button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
63
+ :host([disabled]) .tag { color: var(--cm-text-secondary); border-color: var(--cm-border-default); }
64
+ :host([disabled]) button { cursor: not-allowed; color: var(--cm-text-secondary); }
65
+ @media (max-width: 640px) { .tag { height: 22px; } button { width: 18px; height: 18px; } }
66
+ `,
67
+ ];
68
+ define('cm-tag', CmTag);
@@ -0,0 +1,101 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * Labelled single- or multi-line input. Participates in native forms.
4
+ * @element cm-text-field
5
+ * @fires input - On every keystroke (bubbles, composed).
6
+ * @fires change - When the value is committed.
7
+ */
8
+ export declare class CmTextField extends LitElement {
9
+ #private;
10
+ static formAssociated: boolean;
11
+ static shadowRootOptions: {
12
+ delegatesFocus: boolean;
13
+ mode: ShadowRootMode;
14
+ serializable?: boolean;
15
+ slotAssignment?: SlotAssignmentMode;
16
+ };
17
+ static properties: {
18
+ label: {};
19
+ hint: {};
20
+ helpText: {
21
+ attribute: string;
22
+ };
23
+ error: {
24
+ reflect: boolean;
25
+ };
26
+ name: {
27
+ reflect: boolean;
28
+ };
29
+ value: {};
30
+ placeholder: {};
31
+ type: {};
32
+ multiline: {
33
+ type: BooleanConstructor;
34
+ };
35
+ rows: {
36
+ type: NumberConstructor;
37
+ };
38
+ required: {
39
+ type: BooleanConstructor;
40
+ reflect: boolean;
41
+ };
42
+ disabled: {
43
+ type: BooleanConstructor;
44
+ reflect: boolean;
45
+ };
46
+ readonly: {
47
+ type: BooleanConstructor;
48
+ reflect: boolean;
49
+ };
50
+ autocomplete: {};
51
+ size: {
52
+ reflect: boolean;
53
+ };
54
+ };
55
+ /** Visible label above the box. Required for accessibility unless the field has an aria-label. */
56
+ label: string;
57
+ /** Lowercase bracketed note after the label, e.g. "points earned per rupee spent". */
58
+ hint: string;
59
+ /** One sentence under the box in text-tertiary. */
60
+ helpText: string;
61
+ /** Error message; turns the border critical and sets aria-invalid. */
62
+ error: string;
63
+ /** Form field name. */
64
+ name: string;
65
+ /** Current value. Updated on every keystroke. */
66
+ value: string;
67
+ /** Example input, shown in text-tertiary. Never a substitute for the label. */
68
+ placeholder: string;
69
+ /** Native input type. Ignored when `multiline`. */
70
+ type: 'text' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'url' | 'date';
71
+ /** Renders a resizable textarea. */
72
+ multiline: boolean;
73
+ /** Visible rows when `multiline`. */
74
+ rows: number;
75
+ /** Shows a red asterisk and blocks form submission while empty. */
76
+ required: boolean;
77
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
78
+ disabled: boolean;
79
+ /** Shows the value on the filled background; the value is still submitted. */
80
+ readonly: boolean;
81
+ /** Native autocomplete hint, e.g. `email`, `postal-code`. */
82
+ autocomplete?: string;
83
+ /** `small`: 12px label, 14px value (filter panels). */
84
+ size: 'default' | 'small';
85
+ static styles: import("lit").CSSResult[];
86
+ connectedCallback(): void;
87
+ get form(): HTMLFormElement | null;
88
+ get validity(): ValidityState;
89
+ get validationMessage(): string;
90
+ checkValidity(): boolean;
91
+ reportValidity(): boolean;
92
+ formResetCallback(): void;
93
+ formDisabledCallback(disabled: boolean): void;
94
+ updated(): void;
95
+ render(): import("lit-html").TemplateResult<1>;
96
+ }
97
+ declare global {
98
+ interface HTMLElementTagNameMap {
99
+ 'cm-text-field': CmTextField;
100
+ }
101
+ }
@@ -0,0 +1,162 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CmTextField_instances, _CmTextField_internals, _CmTextField_id, _CmTextField_defaultValue, _CmTextField_onInput, _CmTextField_onChange;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { live } from 'lit/directives/live.js';
15
+ import { base, define, nextId } from '../base.js';
16
+ /**
17
+ * Labelled single- or multi-line input. Participates in native forms.
18
+ * @element cm-text-field
19
+ * @fires input - On every keystroke (bubbles, composed).
20
+ * @fires change - When the value is committed.
21
+ */
22
+ export class CmTextField extends LitElement {
23
+ constructor() {
24
+ super(...arguments);
25
+ _CmTextField_instances.add(this);
26
+ /** Visible label above the box. Required for accessibility unless the field has an aria-label. */
27
+ this.label = '';
28
+ /** Lowercase bracketed note after the label, e.g. "points earned per rupee spent". */
29
+ this.hint = '';
30
+ /** One sentence under the box in text-tertiary. */
31
+ this.helpText = '';
32
+ /** Error message; turns the border critical and sets aria-invalid. */
33
+ this.error = '';
34
+ /** Form field name. */
35
+ this.name = '';
36
+ /** Current value. Updated on every keystroke. */
37
+ this.value = '';
38
+ /** Example input, shown in text-tertiary. Never a substitute for the label. */
39
+ this.placeholder = '';
40
+ /** Native input type. Ignored when `multiline`. */
41
+ this.type = 'text';
42
+ /** Renders a resizable textarea. */
43
+ this.multiline = false;
44
+ /** Visible rows when `multiline`. */
45
+ this.rows = 4;
46
+ /** Shows a red asterisk and blocks form submission while empty. */
47
+ this.required = false;
48
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
49
+ this.disabled = false;
50
+ /** Shows the value on the filled background; the value is still submitted. */
51
+ this.readonly = false;
52
+ /** `small`: 12px label, 14px value (filter panels). */
53
+ this.size = 'default';
54
+ _CmTextField_internals.set(this, this.attachInternals());
55
+ _CmTextField_id.set(this, nextId('cm-tf'));
56
+ _CmTextField_defaultValue.set(this, '');
57
+ }
58
+ connectedCallback() {
59
+ super.connectedCallback();
60
+ __classPrivateFieldSet(this, _CmTextField_defaultValue, this.value, "f");
61
+ }
62
+ get form() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").form; }
63
+ get validity() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validity; }
64
+ get validationMessage() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validationMessage; }
65
+ checkValidity() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").checkValidity(); }
66
+ reportValidity() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").reportValidity(); }
67
+ formResetCallback() {
68
+ this.value = __classPrivateFieldGet(this, _CmTextField_defaultValue, "f");
69
+ this.error = '';
70
+ }
71
+ formDisabledCallback(disabled) { this.disabled = disabled; }
72
+ updated() {
73
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setFormValue(this.value);
74
+ const control = this.renderRoot.querySelector('.input');
75
+ if (this.error)
76
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ customError: true }, this.error, control ?? undefined);
77
+ else if (this.required && !this.value)
78
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ valueMissing: true }, 'Please fill in this field.', control ?? undefined);
79
+ else
80
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({});
81
+ }
82
+ render() {
83
+ const describedBy = [this.error && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help`].filter(Boolean).join(' ') || nothing;
84
+ const common = {
85
+ id: __classPrivateFieldGet(this, _CmTextField_id, "f"),
86
+ invalid: this.error ? 'true' : nothing,
87
+ };
88
+ const control = this.multiline
89
+ ? html `<textarea class="input" part="input" id=${common.id} rows=${this.rows}
90
+ .value=${live(this.value)} placeholder=${this.placeholder || nothing}
91
+ ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
92
+ aria-invalid=${common.invalid} aria-describedby=${describedBy}
93
+ @input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)}></textarea>`
94
+ : html `<input class="input" part="input" id=${common.id} type=${this.type}
95
+ .value=${live(this.value)} placeholder=${this.placeholder || nothing}
96
+ autocomplete=${this.autocomplete ?? nothing}
97
+ ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
98
+ aria-invalid=${common.invalid} aria-describedby=${describedBy}
99
+ @input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)} />`;
100
+ return html `<div class="field">
101
+ ${this.label
102
+ ? html `<label for=${__classPrivateFieldGet(this, _CmTextField_id, "f")} part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}${this.hint ? html `<span class="hint">[${this.hint}]</span>` : nothing}</label>`
103
+ : nothing}
104
+ ${control}
105
+ ${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
106
+ ${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help">${this.helpText}</p>` : nothing}
107
+ </div>`;
108
+ }
109
+ }
110
+ _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmTextField_defaultValue = new WeakMap(), _CmTextField_instances = new WeakSet(), _CmTextField_onInput = function _CmTextField_onInput(e) {
111
+ this.value = e.target.value;
112
+ }, _CmTextField_onChange = function _CmTextField_onChange() {
113
+ // native change does not cross the shadow boundary; re-dispatch it
114
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
115
+ };
116
+ CmTextField.formAssociated = true;
117
+ CmTextField.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
118
+ CmTextField.properties = {
119
+ label: {},
120
+ hint: {},
121
+ helpText: { attribute: 'help-text' },
122
+ error: { reflect: true },
123
+ name: { reflect: true },
124
+ value: {},
125
+ placeholder: {},
126
+ type: {},
127
+ multiline: { type: Boolean },
128
+ rows: { type: Number },
129
+ required: { type: Boolean, reflect: true },
130
+ disabled: { type: Boolean, reflect: true },
131
+ readonly: { type: Boolean, reflect: true },
132
+ autocomplete: {},
133
+ size: { reflect: true },
134
+ };
135
+ CmTextField.styles = [
136
+ base,
137
+ css `
138
+ :host { display: block; }
139
+ .field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
140
+ label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); }
141
+ .req { color: var(--cm-text-critical); margin-left: 2px; }
142
+ .hint { margin-left: var(--cm-space-10); font-size: 12px; color: var(--cm-text-tertiary); text-transform: lowercase; }
143
+ .input {
144
+ width: 100%; height: 42px; padding: 0 var(--cm-space-10);
145
+ font: inherit; font-size: 16px; color: var(--cm-text-default);
146
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input);
147
+ border-radius: var(--cm-radius-sm); outline: none;
148
+ }
149
+ textarea.input { height: auto; padding: var(--cm-space-10); resize: vertical; }
150
+ .input::placeholder { color: var(--cm-text-tertiary); }
151
+ .input:focus { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
152
+ .input:read-only, .input:disabled { background: var(--cm-bg-input-filled); }
153
+ .input:disabled { color: var(--cm-text-secondary); border-color: var(--cm-border-default); cursor: not-allowed; }
154
+ :host([error]:not([error=''])) .input { border-color: var(--cm-border-critical); }
155
+ .help { margin: 0; font-size: 12px; color: var(--cm-text-tertiary); }
156
+ .error { margin: 0; font-size: 12px; color: var(--cm-text-critical); }
157
+ :host([size='small']) .field { gap: 6px; }
158
+ :host([size='small']) label { font-size: 12px; }
159
+ :host([size='small']) .input { font-size: 14px; }
160
+ `,
161
+ ];
162
+ define('cm-text-field', CmTextField);
@@ -0,0 +1,40 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ /**
4
+ * A small product or file image in a fixed square box, shown whole (never cropped) on a grey backdrop.
5
+ * Without an image, or when it fails to load, it shows a placeholder icon.
6
+ * @element cm-thumbnail
7
+ */
8
+ export declare class CmThumbnail extends LitElement {
9
+ static properties: {
10
+ src: {};
11
+ alt: {};
12
+ size: {
13
+ reflect: boolean;
14
+ };
15
+ loading: {};
16
+ _failed: {
17
+ state: boolean;
18
+ };
19
+ };
20
+ /** Image URL. */
21
+ src: string;
22
+ /**
23
+ * What the image shows, e.g. "Blue cotton kurta, front". Leave empty when the product name is written next to
24
+ * the thumbnail: the image is then decorative.
25
+ */
26
+ alt: string;
27
+ /** `small` 40px, `medium` 60px, `large` 80px. Set `--cm-thumbnail-size` for any other size. */
28
+ size: 'small' | 'medium' | 'large';
29
+ /** `lazy` waits until the thumbnail is near the screen: use it in long lists. */
30
+ loading: 'eager' | 'lazy';
31
+ _failed: boolean;
32
+ static styles: import("lit").CSSResult[];
33
+ willUpdate(changed: Map<string, unknown>): void;
34
+ render(): import("lit-html").TemplateResult<1>;
35
+ }
36
+ declare global {
37
+ interface HTMLElementTagNameMap {
38
+ 'cm-thumbnail': CmThumbnail;
39
+ }
40
+ }
@@ -0,0 +1,61 @@
1
+ import { LitElement, html, css, nothing } from 'lit';
2
+ import { base, define } from '../base.js';
3
+ import './icon.js';
4
+ /**
5
+ * A small product or file image in a fixed square box, shown whole (never cropped) on a grey backdrop.
6
+ * Without an image, or when it fails to load, it shows a placeholder icon.
7
+ * @element cm-thumbnail
8
+ */
9
+ export class CmThumbnail extends LitElement {
10
+ constructor() {
11
+ super(...arguments);
12
+ /** Image URL. */
13
+ this.src = '';
14
+ /**
15
+ * What the image shows, e.g. "Blue cotton kurta, front". Leave empty when the product name is written next to
16
+ * the thumbnail: the image is then decorative.
17
+ */
18
+ this.alt = '';
19
+ /** `small` 40px, `medium` 60px, `large` 80px. Set `--cm-thumbnail-size` for any other size. */
20
+ this.size = 'medium';
21
+ /** `lazy` waits until the thumbnail is near the screen: use it in long lists. */
22
+ this.loading = 'eager';
23
+ this._failed = false;
24
+ }
25
+ willUpdate(changed) {
26
+ if (changed.has('src'))
27
+ this._failed = false;
28
+ }
29
+ render() {
30
+ if (this.src && !this._failed) {
31
+ return html `<span class="box" part="thumbnail"><img src=${this.src} alt=${this.alt} loading=${this.loading}
32
+ @error=${() => { this._failed = true; }}></span>`;
33
+ }
34
+ const size = this.size === 'small' ? 18 : this.size === 'large' ? 32 : 24;
35
+ return html `<span class="box" part="thumbnail" role=${this.alt ? 'img' : nothing}
36
+ aria-label=${this.alt ? `${this.alt} (no image)` : nothing} aria-hidden=${this.alt ? nothing : 'true'}>
37
+ <cm-icon name="box" size=${size}></cm-icon></span>`;
38
+ }
39
+ }
40
+ CmThumbnail.properties = {
41
+ src: {},
42
+ alt: {},
43
+ size: { reflect: true },
44
+ loading: {},
45
+ _failed: { state: true },
46
+ };
47
+ CmThumbnail.styles = [
48
+ base,
49
+ css `
50
+ :host { --_size: var(--cm-thumbnail-size, 60px); display: inline-flex; vertical-align: middle; flex: none; }
51
+ :host([size='small']) { --_size: var(--cm-thumbnail-size, 40px); }
52
+ :host([size='large']) { --_size: var(--cm-thumbnail-size, 80px); }
53
+ .box {
54
+ display: grid; place-items: center; overflow: hidden; inline-size: var(--_size); block-size: var(--_size);
55
+ border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-sm);
56
+ background: var(--cm-thumb-bg); color: var(--cm-icon-selected);
57
+ }
58
+ img { inline-size: 100%; block-size: 100%; object-fit: contain; display: block; }
59
+ `,
60
+ ];
61
+ define('cm-thumbnail', CmThumbnail);