@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,108 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ export type ToastTone = 'default' | 'critical';
4
+ export type ToastDismissReason = 'timeout' | 'close' | 'action';
5
+ /**
6
+ * A short confirmation that appears at the bottom of the screen and goes away on its own ("Product saved").
7
+ * Usually shown with `showToast()`, which puts it in the page's toast region so screen readers announce it.
8
+ * Hovering or focusing it pauses the timer.
9
+ * @element cm-toast
10
+ * @slot - The message, if not given with `message`.
11
+ * @fires cm-action - The action button was pressed (cancelable; by default the toast then closes).
12
+ * @fires cm-dismiss - The toast is closing: `detail.reason` is `timeout`, `close` or `action` (cancelable; keeps it open).
13
+ */
14
+ export declare class CmToast extends LitElement {
15
+ #private;
16
+ static properties: {
17
+ message: {};
18
+ tone: {
19
+ reflect: boolean;
20
+ };
21
+ duration: {
22
+ type: NumberConstructor;
23
+ };
24
+ actionLabel: {
25
+ attribute: string;
26
+ };
27
+ open: {
28
+ type: BooleanConstructor;
29
+ reflect: boolean;
30
+ };
31
+ _inRegion: {
32
+ state: boolean;
33
+ };
34
+ _primed: {
35
+ state: boolean;
36
+ };
37
+ };
38
+ /** The text: one short sentence, up to about 50 characters. */
39
+ message: string;
40
+ /** `critical` for failures. Never the only place an error is shown: also say it next to what failed. */
41
+ tone: ToastTone;
42
+ /** How long it stays, in ms: 2000–10000. Default 5000, or 10000 when it has an action. */
43
+ duration?: number;
44
+ /** Label of one optional action ("Undo", "View"). The toast stays 10 seconds when it has one. */
45
+ actionLabel: string;
46
+ /** Whether it is showing. Set it to show the toast again; it is cleared when the toast closes. */
47
+ open: boolean;
48
+ /** @internal */
49
+ _inRegion: boolean;
50
+ /** Alone, the toast's live region must exist before its text, or screen readers skip the first message. */
51
+ _primed: boolean;
52
+ static styles: import("lit").CSSResult[];
53
+ /** The time the toast stays, clamped to 2000–10000 ms. */
54
+ get effectiveDuration(): number;
55
+ connectedCallback(): void;
56
+ disconnectedCallback(): void;
57
+ updated(changed: Map<string, unknown>): void;
58
+ /** Shows the toast again and restarts its timer. */
59
+ show(): void;
60
+ /** Closes the toast, as if the close button were pressed. Returns false if a listener kept it open. */
61
+ dismiss(reason?: ToastDismissReason): boolean;
62
+ render(): import("lit-html").TemplateResult<1>;
63
+ }
64
+ /**
65
+ * The page's toast area: bottom centre, above everything, a polite live region so new toasts are announced.
66
+ * `showToast()` creates one when needed; add it yourself only to change where toasts appear.
67
+ * @element cm-toast-region
68
+ * @slot - `cm-toast` elements. Closed toasts are removed.
69
+ */
70
+ export declare class CmToastRegion extends LitElement {
71
+ #private;
72
+ static properties: {
73
+ max: {
74
+ type: NumberConstructor;
75
+ };
76
+ };
77
+ /** Most toasts shown at once. When a new one would exceed it, the oldest is removed. Default 3. */
78
+ max: number;
79
+ static styles: import("lit").CSSResult[];
80
+ connectedCallback(): void;
81
+ disconnectedCallback(): void;
82
+ /** Adds a toast, removing the oldest ones above `max`. */
83
+ add(toast: CmToast): CmToast;
84
+ render(): import("lit-html").TemplateResult<1>;
85
+ }
86
+ export interface ShowToastOptions {
87
+ tone?: ToastTone;
88
+ /** ms, 2000–10000. */
89
+ duration?: number;
90
+ /** One action: its label and what it does. */
91
+ action?: {
92
+ label: string;
93
+ onAction: () => void;
94
+ };
95
+ /** Where to put the toast region. Default `document.body`. */
96
+ root?: HTMLElement;
97
+ }
98
+ /**
99
+ * Shows a toast in the page's toast region (created on first use) and returns it. The message is text, never HTML.
100
+ * @example showToast('Product saved'); showToast('Order archived', { action: { label: 'Undo', onAction: undo } });
101
+ */
102
+ export declare function showToast(message: string, options?: ShowToastOptions): CmToast;
103
+ declare global {
104
+ interface HTMLElementTagNameMap {
105
+ 'cm-toast': CmToast;
106
+ 'cm-toast-region': CmToastRegion;
107
+ }
108
+ }
@@ -0,0 +1,268 @@
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 _CmToast_instances, _CmToast_primeTimer, _CmToast_timer, _CmToast_remaining, _CmToast_startedAt, _CmToast_hovered, _CmToast_focused, _CmToast_paused_get, _CmToast_resume, _CmToast_pause, _CmToast_onEnter, _CmToast_onLeave, _CmToast_onFocusIn, _CmToast_onFocusOut, _CmToast_action, _CmToastRegion_onDismiss;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { base, define } from '../base.js';
15
+ import './icon.js';
16
+ const MIN = 2000;
17
+ const MAX = 10000;
18
+ /** How long a new live region gets before its first message, so screen readers register it (ms). */
19
+ const LIVE_REGION_DELAY = 150;
20
+ /**
21
+ * A short confirmation that appears at the bottom of the screen and goes away on its own ("Product saved").
22
+ * Usually shown with `showToast()`, which puts it in the page's toast region so screen readers announce it.
23
+ * Hovering or focusing it pauses the timer.
24
+ * @element cm-toast
25
+ * @slot - The message, if not given with `message`.
26
+ * @fires cm-action - The action button was pressed (cancelable; by default the toast then closes).
27
+ * @fires cm-dismiss - The toast is closing: `detail.reason` is `timeout`, `close` or `action` (cancelable; keeps it open).
28
+ */
29
+ export class CmToast extends LitElement {
30
+ constructor() {
31
+ super(...arguments);
32
+ _CmToast_instances.add(this);
33
+ /** The text: one short sentence, up to about 50 characters. */
34
+ this.message = '';
35
+ /** `critical` for failures. Never the only place an error is shown: also say it next to what failed. */
36
+ this.tone = 'default';
37
+ /** Label of one optional action ("Undo", "View"). The toast stays 10 seconds when it has one. */
38
+ this.actionLabel = '';
39
+ /** Whether it is showing. Set it to show the toast again; it is cleared when the toast closes. */
40
+ this.open = true;
41
+ /** @internal */
42
+ this._inRegion = false;
43
+ /** Alone, the toast's live region must exist before its text, or screen readers skip the first message. */
44
+ this._primed = false;
45
+ _CmToast_primeTimer.set(this, void 0);
46
+ _CmToast_timer.set(this, void 0);
47
+ _CmToast_remaining.set(this, 0);
48
+ _CmToast_startedAt.set(this, 0);
49
+ _CmToast_hovered.set(this, false);
50
+ _CmToast_focused.set(this, false);
51
+ _CmToast_onEnter.set(this, () => { __classPrivateFieldSet(this, _CmToast_hovered, true, "f"); __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_pause).call(this); });
52
+ _CmToast_onLeave.set(this, () => { __classPrivateFieldSet(this, _CmToast_hovered, false, "f"); __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_resume).call(this); });
53
+ _CmToast_onFocusIn.set(this, () => { __classPrivateFieldSet(this, _CmToast_focused, true, "f"); __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_pause).call(this); });
54
+ _CmToast_onFocusOut.set(this, (e) => {
55
+ if (e.relatedTarget instanceof Node && this.contains(e.relatedTarget))
56
+ return;
57
+ if (e.relatedTarget instanceof Node && this.shadowRoot?.contains(e.relatedTarget))
58
+ return;
59
+ __classPrivateFieldSet(this, _CmToast_focused, false, "f");
60
+ __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_resume).call(this);
61
+ });
62
+ }
63
+ /** The time the toast stays, clamped to 2000–10000 ms. */
64
+ get effectiveDuration() {
65
+ const d = this.duration ?? (this.actionLabel ? MAX : 5000);
66
+ return Math.min(MAX, Math.max(MIN, Number(d) || 5000));
67
+ }
68
+ connectedCallback() {
69
+ super.connectedCallback();
70
+ this._inRegion = !!this.parentElement?.closest('cm-toast-region');
71
+ if (!this._inRegion && !this._primed)
72
+ __classPrivateFieldSet(this, _CmToast_primeTimer, setTimeout(() => { this._primed = true; }, LIVE_REGION_DELAY), "f");
73
+ this.addEventListener('pointerenter', __classPrivateFieldGet(this, _CmToast_onEnter, "f"));
74
+ this.addEventListener('pointerleave', __classPrivateFieldGet(this, _CmToast_onLeave, "f"));
75
+ this.addEventListener('focusin', __classPrivateFieldGet(this, _CmToast_onFocusIn, "f"));
76
+ this.addEventListener('focusout', __classPrivateFieldGet(this, _CmToast_onFocusOut, "f"));
77
+ }
78
+ disconnectedCallback() {
79
+ super.disconnectedCallback();
80
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_timer, "f"));
81
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_primeTimer, "f"));
82
+ this.removeEventListener('pointerenter', __classPrivateFieldGet(this, _CmToast_onEnter, "f"));
83
+ this.removeEventListener('pointerleave', __classPrivateFieldGet(this, _CmToast_onLeave, "f"));
84
+ this.removeEventListener('focusin', __classPrivateFieldGet(this, _CmToast_onFocusIn, "f"));
85
+ this.removeEventListener('focusout', __classPrivateFieldGet(this, _CmToast_onFocusOut, "f"));
86
+ }
87
+ updated(changed) {
88
+ if (changed.has('open') || changed.has('duration') || changed.has('actionLabel') || changed.has('_primed') || changed.has('_inRegion')) {
89
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_timer, "f"));
90
+ // The time on screen starts when the message is shown.
91
+ if (this.open && (this._inRegion || this._primed)) {
92
+ __classPrivateFieldSet(this, _CmToast_remaining, this.effectiveDuration, "f");
93
+ __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_resume).call(this);
94
+ }
95
+ }
96
+ }
97
+ /** Shows the toast again and restarts its timer. */
98
+ show() { if (this.open) {
99
+ __classPrivateFieldSet(this, _CmToast_remaining, this.effectiveDuration, "f");
100
+ __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_resume).call(this);
101
+ }
102
+ else
103
+ this.open = true; }
104
+ /** Closes the toast, as if the close button were pressed. Returns false if a listener kept it open. */
105
+ dismiss(reason = 'close') {
106
+ const ev = new CustomEvent('cm-dismiss', { bubbles: true, composed: true, cancelable: true, detail: { reason } });
107
+ if (!this.dispatchEvent(ev)) {
108
+ if (reason === 'timeout') {
109
+ __classPrivateFieldSet(this, _CmToast_remaining, this.effectiveDuration, "f");
110
+ __classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_resume).call(this);
111
+ }
112
+ return false;
113
+ }
114
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_timer, "f"));
115
+ this.open = false;
116
+ return true;
117
+ }
118
+ render() {
119
+ const body = html `<div class="toast" part="toast">
120
+ ${this.tone === 'critical' ? html `<cm-icon class="icon" name="alert" size="20"></cm-icon>` : nothing}
121
+ <div class="message" part="message">${this.message}<slot></slot></div>
122
+ ${this.actionLabel ? html `<button class="action" part="action" @click=${__classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_action)}>${this.actionLabel}</button>` : nothing}
123
+ <button class="close" part="close" aria-label="Dismiss" @click=${() => this.dismiss('close')}>
124
+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="m4 4 8 8M12 4l-8 8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
125
+ </button>
126
+ </div>`;
127
+ // Inside a toast region the region is the live region; alone, the toast carries its own.
128
+ return this._inRegion ? body : html `<div role="status" aria-live="polite" aria-atomic="false">${this.open && this._primed ? body : nothing}</div>`;
129
+ }
130
+ }
131
+ _CmToast_primeTimer = new WeakMap(), _CmToast_timer = new WeakMap(), _CmToast_remaining = new WeakMap(), _CmToast_startedAt = new WeakMap(), _CmToast_hovered = new WeakMap(), _CmToast_focused = new WeakMap(), _CmToast_onEnter = new WeakMap(), _CmToast_onLeave = new WeakMap(), _CmToast_onFocusIn = new WeakMap(), _CmToast_onFocusOut = new WeakMap(), _CmToast_instances = new WeakSet(), _CmToast_paused_get = function _CmToast_paused_get() { return __classPrivateFieldGet(this, _CmToast_hovered, "f") || __classPrivateFieldGet(this, _CmToast_focused, "f"); }, _CmToast_resume = function _CmToast_resume() {
132
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_timer, "f"));
133
+ if (!this.open || __classPrivateFieldGet(this, _CmToast_instances, "a", _CmToast_paused_get))
134
+ return;
135
+ __classPrivateFieldSet(this, _CmToast_startedAt, Date.now(), "f");
136
+ __classPrivateFieldSet(this, _CmToast_timer, setTimeout(() => this.dismiss('timeout'), __classPrivateFieldGet(this, _CmToast_remaining, "f")), "f");
137
+ }, _CmToast_pause = function _CmToast_pause() {
138
+ if (__classPrivateFieldGet(this, _CmToast_timer, "f") === undefined)
139
+ return;
140
+ clearTimeout(__classPrivateFieldGet(this, _CmToast_timer, "f"));
141
+ __classPrivateFieldSet(this, _CmToast_timer, undefined, "f");
142
+ __classPrivateFieldSet(this, _CmToast_remaining, Math.max(1000, __classPrivateFieldGet(this, _CmToast_remaining, "f") - (Date.now() - __classPrivateFieldGet(this, _CmToast_startedAt, "f"))), "f");
143
+ }, _CmToast_action = function _CmToast_action() {
144
+ const ev = new CustomEvent('cm-action', { bubbles: true, composed: true, cancelable: true });
145
+ if (this.dispatchEvent(ev))
146
+ this.dismiss('action');
147
+ };
148
+ CmToast.properties = {
149
+ message: {},
150
+ tone: { reflect: true },
151
+ duration: { type: Number },
152
+ actionLabel: { attribute: 'action-label' },
153
+ open: { type: Boolean, reflect: true },
154
+ _inRegion: { state: true },
155
+ _primed: { state: true },
156
+ };
157
+ CmToast.styles = [
158
+ base,
159
+ css `
160
+ :host { display: block; pointer-events: auto; }
161
+ :host(:not([open])) { display: none; }
162
+ .toast {
163
+ display: flex; align-items: center; gap: var(--cm-space-15);
164
+ min-block-size: 48px; max-inline-size: min(480px, calc(100vw - 32px));
165
+ padding: var(--cm-space-10) var(--cm-space-10) var(--cm-space-10) var(--cm-space-20);
166
+ border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-100);
167
+ background: var(--cm-bg-dashboard); color: var(--cm-text-on-dark);
168
+ outline: 1px solid var(--cm-nav-divider); font-size: 14px; line-height: 20px;
169
+ }
170
+ :host([tone='critical']) .toast { background: var(--cm-bg-error-bar); color: var(--cm-text-default); outline-color: var(--cm-border-critical); }
171
+ .icon { flex: none; color: var(--cm-icon-critical); }
172
+ .message { flex: 1; min-inline-size: 0; padding-block: 4px; }
173
+ button {
174
+ flex: none; display: inline-flex; align-items: center; justify-content: center; min-block-size: 32px;
175
+ padding: 0 var(--cm-space-10); border: 0; border-radius: var(--cm-radius-sm); background: none;
176
+ color: inherit; font: inherit; font-weight: 600; cursor: pointer;
177
+ }
178
+ .action { text-decoration: underline; text-underline-offset: 3px; }
179
+ .close { inline-size: 32px; padding: 0; }
180
+ button:hover { background: color-mix(in srgb, var(--cm-text-on-dark) 14%, transparent); }
181
+ :host([tone='critical']) button:hover { background: var(--cm-bg-hover); }
182
+ button:focus-visible { outline: 2px solid var(--cm-text-on-dark); outline-offset: 1px; }
183
+ :host([tone='critical']) button:focus-visible { outline-color: var(--cm-border-strong); }
184
+ `,
185
+ ];
186
+ define('cm-toast', CmToast);
187
+ /**
188
+ * The page's toast area: bottom centre, above everything, a polite live region so new toasts are announced.
189
+ * `showToast()` creates one when needed; add it yourself only to change where toasts appear.
190
+ * @element cm-toast-region
191
+ * @slot - `cm-toast` elements. Closed toasts are removed.
192
+ */
193
+ export class CmToastRegion extends LitElement {
194
+ constructor() {
195
+ super(...arguments);
196
+ /** Most toasts shown at once. When a new one would exceed it, the oldest is removed. Default 3. */
197
+ this.max = 3;
198
+ _CmToastRegion_onDismiss.set(this, (e) => {
199
+ const t = e.target;
200
+ // Remove after the toast has handled the event (and only if nobody cancelled it).
201
+ queueMicrotask(() => { if (t.localName === 'cm-toast' && !t.open)
202
+ t.remove(); });
203
+ });
204
+ }
205
+ connectedCallback() {
206
+ super.connectedCallback();
207
+ this.setAttribute('role', 'status');
208
+ this.setAttribute('aria-live', 'polite');
209
+ // Read each new toast on its own, not every toast still on screen.
210
+ this.setAttribute('aria-atomic', 'false');
211
+ if (!this.hasAttribute('aria-label'))
212
+ this.setAttribute('aria-label', 'Notifications');
213
+ this.addEventListener('cm-dismiss', __classPrivateFieldGet(this, _CmToastRegion_onDismiss, "f"));
214
+ }
215
+ disconnectedCallback() { super.disconnectedCallback(); this.removeEventListener('cm-dismiss', __classPrivateFieldGet(this, _CmToastRegion_onDismiss, "f")); }
216
+ /** Adds a toast, removing the oldest ones above `max`. */
217
+ add(toast) {
218
+ this.append(toast);
219
+ const all = [...this.querySelectorAll(':scope > cm-toast')];
220
+ all.slice(0, Math.max(0, all.length - Math.max(1, this.max))).forEach((t) => t.remove());
221
+ return toast;
222
+ }
223
+ render() { return html `<slot></slot>`; }
224
+ }
225
+ _CmToastRegion_onDismiss = new WeakMap();
226
+ CmToastRegion.properties = { max: { type: Number } };
227
+ CmToastRegion.styles = [
228
+ base,
229
+ css `
230
+ :host {
231
+ position: fixed; inset-block-end: var(--cm-space-20); inset-inline: 0; z-index: 1000;
232
+ display: flex; flex-direction: column; align-items: center; gap: var(--cm-space-10);
233
+ padding-inline: var(--cm-space-15); pointer-events: none;
234
+ }
235
+ `,
236
+ ];
237
+ define('cm-toast-region', CmToastRegion);
238
+ /**
239
+ * Shows a toast in the page's toast region (created on first use) and returns it. The message is text, never HTML.
240
+ * @example showToast('Product saved'); showToast('Order archived', { action: { label: 'Undo', onAction: undo } });
241
+ */
242
+ export function showToast(message, options = {}) {
243
+ const root = options.root ?? document.body;
244
+ let region = root.querySelector(':scope > cm-toast-region');
245
+ const fresh = !region;
246
+ if (!region) {
247
+ region = document.createElement('cm-toast-region');
248
+ root.append(region);
249
+ }
250
+ const toast = document.createElement('cm-toast');
251
+ toast.message = String(message);
252
+ if (options.tone)
253
+ toast.tone = options.tone;
254
+ if (options.duration !== undefined)
255
+ toast.duration = options.duration;
256
+ if (options.action) {
257
+ toast.actionLabel = options.action.label;
258
+ const run = options.action.onAction;
259
+ toast.addEventListener('cm-action', () => run());
260
+ }
261
+ // A live region added in the same moment as its text is not announced: give a new region time to register.
262
+ if (fresh) {
263
+ const r = region;
264
+ setTimeout(() => r.add(toast), LIVE_REGION_DELAY);
265
+ return toast;
266
+ }
267
+ return region.add(toast);
268
+ }
@@ -0,0 +1,60 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * On/off switch for settings that apply straight away, such as showing a product on the store.
4
+ * Participates in native forms like a checkbox.
5
+ * @element cm-toggle
6
+ * @slot - Rich label content, used instead of `label`.
7
+ * @fires change - When switched by the user.
8
+ */
9
+ export declare class CmToggle extends LitElement {
10
+ #private;
11
+ static formAssociated: boolean;
12
+ static shadowRootOptions: {
13
+ delegatesFocus: boolean;
14
+ mode: ShadowRootMode;
15
+ serializable?: boolean;
16
+ slotAssignment?: SlotAssignmentMode;
17
+ };
18
+ static properties: {
19
+ label: {};
20
+ description: {};
21
+ name: {
22
+ reflect: boolean;
23
+ };
24
+ value: {};
25
+ checked: {
26
+ type: BooleanConstructor;
27
+ reflect: boolean;
28
+ };
29
+ disabled: {
30
+ type: BooleanConstructor;
31
+ reflect: boolean;
32
+ };
33
+ };
34
+ /** Visible label after the switch. Without one, give the element an `aria-label`. */
35
+ label: string;
36
+ /** Help text under the label, linked for screen readers. */
37
+ description: string;
38
+ /** Form field name. */
39
+ name: string;
40
+ /** Submitted value when on. */
41
+ value: string;
42
+ /** Whether the switch is on. Reflects to the attribute. */
43
+ checked: boolean;
44
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
45
+ disabled: boolean;
46
+ static styles: import("lit").CSSResult[];
47
+ connectedCallback(): void;
48
+ get form(): HTMLFormElement | null;
49
+ checkValidity(): boolean;
50
+ formResetCallback(): void;
51
+ formDisabledCallback(d: boolean): void;
52
+ formStateRestoreCallback(state: string | null): void;
53
+ updated(): void;
54
+ render(): import("lit-html").TemplateResult<1>;
55
+ }
56
+ declare global {
57
+ interface HTMLElementTagNameMap {
58
+ 'cm-toggle': CmToggle;
59
+ }
60
+ }
@@ -0,0 +1,108 @@
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 _CmToggle_instances, _CmToggle_internals, _CmToggle_id, _CmToggle_defaultChecked, _CmToggle_onChange;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { base, define, nextId } from '../base.js';
15
+ /**
16
+ * On/off switch for settings that apply straight away, such as showing a product on the store.
17
+ * Participates in native forms like a checkbox.
18
+ * @element cm-toggle
19
+ * @slot - Rich label content, used instead of `label`.
20
+ * @fires change - When switched by the user.
21
+ */
22
+ export class CmToggle extends LitElement {
23
+ constructor() {
24
+ super(...arguments);
25
+ _CmToggle_instances.add(this);
26
+ /** Visible label after the switch. Without one, give the element an `aria-label`. */
27
+ this.label = '';
28
+ /** Help text under the label, linked for screen readers. */
29
+ this.description = '';
30
+ /** Form field name. */
31
+ this.name = '';
32
+ /** Submitted value when on. */
33
+ this.value = 'on';
34
+ /** Whether the switch is on. Reflects to the attribute. */
35
+ this.checked = false;
36
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
37
+ this.disabled = false;
38
+ _CmToggle_internals.set(this, this.attachInternals());
39
+ _CmToggle_id.set(this, nextId('cm-tg'));
40
+ _CmToggle_defaultChecked.set(this, false);
41
+ }
42
+ connectedCallback() {
43
+ super.connectedCallback();
44
+ __classPrivateFieldSet(this, _CmToggle_defaultChecked, this.checked, "f");
45
+ }
46
+ get form() { return __classPrivateFieldGet(this, _CmToggle_internals, "f").form; }
47
+ checkValidity() { return __classPrivateFieldGet(this, _CmToggle_internals, "f").checkValidity(); }
48
+ formResetCallback() { this.checked = __classPrivateFieldGet(this, _CmToggle_defaultChecked, "f"); }
49
+ formDisabledCallback(d) { this.disabled = d; }
50
+ formStateRestoreCallback(state) { this.checked = state != null; }
51
+ updated() {
52
+ __classPrivateFieldGet(this, _CmToggle_internals, "f").setFormValue(this.checked ? this.value : null);
53
+ }
54
+ render() {
55
+ const hasText = this.label || this.description || this.textContent?.trim();
56
+ return html `<label for=${__classPrivateFieldGet(this, _CmToggle_id, "f")}>
57
+ <input type="checkbox" role="switch" id=${__classPrivateFieldGet(this, _CmToggle_id, "f")} .checked=${this.checked} ?disabled=${this.disabled}
58
+ aria-label=${hasText ? nothing : this.getAttribute('aria-label') ?? nothing}
59
+ aria-describedby=${this.description ? `${__classPrivateFieldGet(this, _CmToggle_id, "f")}-d` : nothing} @change=${__classPrivateFieldGet(this, _CmToggle_instances, "m", _CmToggle_onChange)} />
60
+ <span class="track" part="track"><span class="thumb" part="thumb"></span></span>
61
+ ${hasText
62
+ ? html `<span class="text"><span class="label">${this.label}<slot></slot></span>${this.description ? html `<span class="desc" id="${__classPrivateFieldGet(this, _CmToggle_id, "f")}-d">${this.description}</span>` : nothing}</span>`
63
+ : nothing}
64
+ </label>`;
65
+ }
66
+ }
67
+ _CmToggle_internals = new WeakMap(), _CmToggle_id = new WeakMap(), _CmToggle_defaultChecked = new WeakMap(), _CmToggle_instances = new WeakSet(), _CmToggle_onChange = function _CmToggle_onChange(e) {
68
+ this.checked = e.target.checked;
69
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
70
+ };
71
+ CmToggle.formAssociated = true;
72
+ CmToggle.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
73
+ CmToggle.properties = {
74
+ label: {},
75
+ description: {},
76
+ name: { reflect: true },
77
+ value: {},
78
+ checked: { type: Boolean, reflect: true },
79
+ disabled: { type: Boolean, reflect: true },
80
+ };
81
+ CmToggle.styles = [
82
+ base,
83
+ css `
84
+ :host { display: inline-flex; }
85
+ label { position: relative; display: inline-flex; align-items: flex-start; gap: var(--cm-space-10); cursor: pointer; }
86
+ input { position: absolute; opacity: 0; width: 38px; height: 20px; margin: 0; cursor: inherit; }
87
+ .track {
88
+ flex: none; display: inline-flex; align-items: center; width: 38px; height: 20px; padding: 2px;
89
+ border-radius: var(--cm-radius-full); background: var(--cm-toggle-off);
90
+ border: var(--cm-border-1) solid var(--cm-border-input); transition: background-color .15s;
91
+ }
92
+ .thumb {
93
+ width: 14px; height: 14px; border-radius: var(--cm-radius-full); background: var(--cm-bg-surface);
94
+ border: var(--cm-border-1) solid var(--cm-border-input); transition: transform .15s;
95
+ }
96
+ input:checked + .track { background: var(--cm-toggle-on); }
97
+ input:checked + .track .thumb { transform: translateX(18px); }
98
+ input:focus-visible + .track { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
99
+ .text { display: flex; flex-direction: column; gap: 4px; padding-top: 1px; }
100
+ .label { font-size: 14px; }
101
+ .desc { font-size: 12px; color: var(--cm-text-tertiary); }
102
+ :host([disabled]) label { cursor: not-allowed; }
103
+ :host([disabled]) .track { opacity: .5; }
104
+ :host([disabled]) .label { color: var(--cm-text-secondary); }
105
+ @media (prefers-reduced-motion: reduce) { .track, .thumb { transition: none; } }
106
+ `,
107
+ ];
108
+ define('cm-toggle', CmToggle);
@@ -0,0 +1,56 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * Short text that names or explains a control, shown on hover and keyboard focus.
4
+ * Wrap exactly one focusable element. The text becomes that element's accessible description, so screen readers
5
+ * hear it too. It stays open while the pointer is over the control or the tooltip, and Esc closes it
6
+ * (WCAG 1.4.13). Text only: never put links or buttons in a tooltip.
7
+ *
8
+ * An icon-only button still needs its own accessible name (visually hidden text or `aria-label`): the tooltip
9
+ * describes, it does not name.
10
+ * @element cm-tooltip
11
+ * @slot - The one focusable element the tooltip belongs to (a `cm-button`, a link, an input…).
12
+ * @fires cm-show - When the tooltip appears.
13
+ * @fires cm-hide - When the tooltip disappears.
14
+ */
15
+ export declare class CmTooltip extends LitElement {
16
+ #private;
17
+ static properties: {
18
+ content: {};
19
+ placement: {
20
+ reflect: boolean;
21
+ };
22
+ delay: {
23
+ type: NumberConstructor;
24
+ };
25
+ open: {
26
+ type: BooleanConstructor;
27
+ reflect: boolean;
28
+ };
29
+ _side: {
30
+ state: boolean;
31
+ };
32
+ };
33
+ /** The tooltip text. Plain text, ideally under 80 characters. */
34
+ content: string;
35
+ /** Preferred side. It flips to the opposite side when there is no room. */
36
+ placement: 'top' | 'bottom' | 'start' | 'end';
37
+ /** Wait before showing on hover, in ms. Keyboard focus shows it at once. */
38
+ delay: number;
39
+ /** True while the tooltip is shown. Read it; use `show()` / `hide()` to change it. */
40
+ open: boolean;
41
+ _side: 'top' | 'bottom' | 'start' | 'end';
42
+ static styles: import("lit").CSSResult[];
43
+ connectedCallback(): void;
44
+ disconnectedCallback(): void;
45
+ /** Shows the tooltip now. */
46
+ show(): void;
47
+ /** Hides the tooltip now. */
48
+ hide(): void;
49
+ updated(changed: Map<string, unknown>): void;
50
+ render(): import("lit-html").TemplateResult<1>;
51
+ }
52
+ declare global {
53
+ interface HTMLElementTagNameMap {
54
+ 'cm-tooltip': CmTooltip;
55
+ }
56
+ }