@commmerce/ui 0.0.0-stage → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/README.md +41 -2
- package/dist/base.d.ts +7 -0
- package/dist/base.js +22 -0
- package/dist/cdn.js +1958 -0
- package/dist/components/accordion.d.ts +43 -0
- package/dist/components/accordion.js +83 -0
- package/dist/components/action-bar.d.ts +42 -0
- package/dist/components/action-bar.js +84 -0
- package/dist/components/action-menu.d.ts +89 -0
- package/dist/components/action-menu.js +283 -0
- package/dist/components/app-card.d.ts +57 -0
- package/dist/components/app-card.js +100 -0
- package/dist/components/avatar.d.ts +48 -0
- package/dist/components/avatar.js +82 -0
- package/dist/components/badge.d.ts +23 -0
- package/dist/components/badge.js +35 -0
- package/dist/components/banner.d.ts +36 -0
- package/dist/components/banner.js +88 -0
- package/dist/components/bottom-navigation.d.ts +48 -0
- package/dist/components/bottom-navigation.js +98 -0
- package/dist/components/bottom-sheet.d.ts +54 -0
- package/dist/components/bottom-sheet.js +133 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +101 -0
- package/dist/components/card.d.ts +37 -0
- package/dist/components/card.js +58 -0
- package/dist/components/checkbox.d.ts +68 -0
- package/dist/components/checkbox.js +114 -0
- package/dist/components/comment.d.ts +76 -0
- package/dist/components/comment.js +170 -0
- package/dist/components/data-table.d.ts +132 -0
- package/dist/components/data-table.js +331 -0
- package/dist/components/empty-state.d.ts +49 -0
- package/dist/components/empty-state.js +94 -0
- package/dist/components/file-upload.d.ts +102 -0
- package/dist/components/file-upload.js +243 -0
- package/dist/components/filter-panel.d.ts +86 -0
- package/dist/components/filter-panel.js +128 -0
- package/dist/components/flash-offer-bar.d.ts +34 -0
- package/dist/components/flash-offer-bar.js +73 -0
- package/dist/components/grid.d.ts +39 -0
- package/dist/components/grid.js +42 -0
- package/dist/components/header-bar.d.ts +48 -0
- package/dist/components/header-bar.js +121 -0
- package/dist/components/icon.d.ts +30 -0
- package/dist/components/icon.js +36 -0
- package/dist/components/info-panel.d.ts +63 -0
- package/dist/components/info-panel.js +108 -0
- package/dist/components/layout.d.ts +45 -0
- package/dist/components/layout.js +67 -0
- package/dist/components/link-tabs.d.ts +40 -0
- package/dist/components/link-tabs.js +85 -0
- package/dist/components/menu-item.d.ts +68 -0
- package/dist/components/menu-item.js +64 -0
- package/dist/components/mobile-menu.d.ts +69 -0
- package/dist/components/mobile-menu.js +184 -0
- package/dist/components/modal.d.ts +46 -0
- package/dist/components/modal.js +59 -0
- package/dist/components/nav-item.d.ts +98 -0
- package/dist/components/nav-item.js +84 -0
- package/dist/components/nested-list.d.ts +105 -0
- package/dist/components/nested-list.js +279 -0
- package/dist/components/notification-panel.d.ts +121 -0
- package/dist/components/notification-panel.js +174 -0
- package/dist/components/option-group.d.ts +74 -0
- package/dist/components/option-group.js +172 -0
- package/dist/components/page-header.d.ts +58 -0
- package/dist/components/page-header.js +121 -0
- package/dist/components/page.d.ts +34 -0
- package/dist/components/page.js +41 -0
- package/dist/components/pagination.d.ts +64 -0
- package/dist/components/pagination.js +160 -0
- package/dist/components/progress-bar.d.ts +45 -0
- package/dist/components/progress-bar.js +81 -0
- package/dist/components/radio.d.ts +131 -0
- package/dist/components/radio.js +252 -0
- package/dist/components/report-tile.d.ts +65 -0
- package/dist/components/report-tile.js +112 -0
- package/dist/components/resource-list.d.ts +143 -0
- package/dist/components/resource-list.js +335 -0
- package/dist/components/save-bar.d.ts +58 -0
- package/dist/components/save-bar.js +128 -0
- package/dist/components/search.d.ts +78 -0
- package/dist/components/search.js +144 -0
- package/dist/components/select.d.ts +106 -0
- package/dist/components/select.js +338 -0
- package/dist/components/side-navigation.d.ts +51 -0
- package/dist/components/side-navigation.js +194 -0
- package/dist/components/side-panel.d.ts +50 -0
- package/dist/components/side-panel.js +73 -0
- package/dist/components/skeleton-display.d.ts +32 -0
- package/dist/components/skeleton-display.js +70 -0
- package/dist/components/skeleton.d.ts +41 -0
- package/dist/components/skeleton.js +59 -0
- package/dist/components/smart-tip.d.ts +62 -0
- package/dist/components/smart-tip.js +128 -0
- package/dist/components/spinner.d.ts +27 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/stack.d.ts +45 -0
- package/dist/components/stack.js +49 -0
- package/dist/components/status-tabs.d.ts +65 -0
- package/dist/components/status-tabs.js +158 -0
- package/dist/components/table-header.d.ts +84 -0
- package/dist/components/table-header.js +151 -0
- package/dist/components/tag.d.ts +39 -0
- package/dist/components/tag.js +68 -0
- package/dist/components/text-field.d.ts +101 -0
- package/dist/components/text-field.js +162 -0
- package/dist/components/thumbnail.d.ts +40 -0
- package/dist/components/thumbnail.js +61 -0
- package/dist/components/toast.d.ts +108 -0
- package/dist/components/toast.js +268 -0
- package/dist/components/toggle.d.ts +60 -0
- package/dist/components/toggle.js +108 -0
- package/dist/components/tooltip.d.ts +56 -0
- package/dist/components/tooltip.js +267 -0
- package/dist/custom-elements.json +13222 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +56 -0
- package/dist/overlay.d.ts +57 -0
- package/dist/overlay.js +205 -0
- package/dist/spacing.d.ts +6 -0
- package/dist/spacing.js +7 -0
- package/package.json +59 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
import './button.js';
|
|
5
|
+
/**
|
|
6
|
+
* A short, linked tip that points merchants to a guide or setting ("Importing and exporting products").
|
|
7
|
+
* The whole card is one link. Group tips in `cm-smart-tips`.
|
|
8
|
+
* @element cm-smart-tip
|
|
9
|
+
* @slot - One or two lines that say what the merchant gets from the guide.
|
|
10
|
+
*/
|
|
11
|
+
export class CmSmartTip extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
/** Tip title, at most two short lines. */
|
|
15
|
+
this.heading = '';
|
|
16
|
+
/** Where the tip leads. */
|
|
17
|
+
this.href = '';
|
|
18
|
+
/** Link target. `_blank` adds `rel="noopener noreferrer"` and tells screen readers it opens a new tab. */
|
|
19
|
+
this.target = '';
|
|
20
|
+
}
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
super.connectedCallback();
|
|
23
|
+
if (!this.hasAttribute('role') && this.parentElement?.localName === 'cm-smart-tips')
|
|
24
|
+
this.setAttribute('role', 'listitem');
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
const blank = this.target === '_blank';
|
|
28
|
+
return html `<a part="tip" href=${this.href || nothing} target=${this.target || nothing} rel=${blank ? 'noopener noreferrer' : nothing}>
|
|
29
|
+
<span class="text">
|
|
30
|
+
<span class="title" part="heading">${this.heading}</span>
|
|
31
|
+
<span class="desc" part="description"><slot></slot></span>
|
|
32
|
+
${blank ? html `<span style="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)">(opens in a new tab)</span>` : nothing}
|
|
33
|
+
</span>
|
|
34
|
+
<span class="go" aria-hidden="true"><cm-icon name="arrow-up-right" size="16"></cm-icon></span>
|
|
35
|
+
</a>`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
CmSmartTip.properties = {
|
|
39
|
+
heading: {},
|
|
40
|
+
href: {},
|
|
41
|
+
target: {},
|
|
42
|
+
};
|
|
43
|
+
CmSmartTip.styles = [
|
|
44
|
+
base,
|
|
45
|
+
css `
|
|
46
|
+
:host { display: block; }
|
|
47
|
+
a {
|
|
48
|
+
display: flex; align-items: flex-start; gap: var(--cm-space-10); padding: var(--cm-space-20) var(--cm-space-10) var(--cm-space-20) var(--cm-space-10);
|
|
49
|
+
min-height: 104px; background: var(--cm-bg-surface); color: var(--cm-text-default); text-decoration: none;
|
|
50
|
+
border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-md);
|
|
51
|
+
}
|
|
52
|
+
a:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
53
|
+
.text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
|
|
54
|
+
.title { font-size: 16px; font-weight: 500; line-height: 17px; }
|
|
55
|
+
.desc { font-size: 14px; line-height: 16px; color: var(--cm-text-tertiary); }
|
|
56
|
+
.go {
|
|
57
|
+
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
|
|
58
|
+
margin-top: -10px; border-radius: var(--cm-radius-full); background: var(--cm-bg-icon); color: var(--cm-icon-selected);
|
|
59
|
+
}
|
|
60
|
+
a:hover .go, a:focus-visible .go { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
|
|
61
|
+
a:hover .title { text-decoration: underline; }
|
|
62
|
+
`,
|
|
63
|
+
];
|
|
64
|
+
define('cm-smart-tip', CmSmartTip);
|
|
65
|
+
/**
|
|
66
|
+
* The "Smart tips" card on the home page: an optional dark tour banner on top, then a list of `cm-smart-tip` links.
|
|
67
|
+
* @element cm-smart-tips
|
|
68
|
+
* @slot - `cm-smart-tip` elements.
|
|
69
|
+
* @fires cm-tour - When the tour banner's button is pressed.
|
|
70
|
+
*/
|
|
71
|
+
export class CmSmartTips extends LitElement {
|
|
72
|
+
constructor() {
|
|
73
|
+
super(...arguments);
|
|
74
|
+
/** Title above the tips, shown in capitals. */
|
|
75
|
+
this.heading = 'Smart tips';
|
|
76
|
+
/** Text of the dark tour banner ("Take a tour of Commmerce"). Leave empty for no banner. */
|
|
77
|
+
this.tourHeading = '';
|
|
78
|
+
/** Label of the tour banner's button. */
|
|
79
|
+
this.tourAction = 'Start';
|
|
80
|
+
/** Heading level of the title. Default 2. */
|
|
81
|
+
this.headingLevel = 2;
|
|
82
|
+
}
|
|
83
|
+
render() {
|
|
84
|
+
const level = Math.min(6, Math.max(2, this.headingLevel || 2));
|
|
85
|
+
return html `<div class="card" part="smart-tips">
|
|
86
|
+
${this.tourHeading
|
|
87
|
+
? html `<div class="tour" part="tour">
|
|
88
|
+
<span class="tour-icon" aria-hidden="true"><cm-icon name="rocket" size="18"></cm-icon></span>
|
|
89
|
+
<span class="tour-text">${this.tourHeading}</span>
|
|
90
|
+
<cm-button size="medium" @click=${() => this.dispatchEvent(new CustomEvent('cm-tour', { bubbles: true, composed: true }))}>${this.tourAction}</cm-button>
|
|
91
|
+
</div>`
|
|
92
|
+
: nothing}
|
|
93
|
+
<section class="panel" part="panel" aria-label=${this.heading}>
|
|
94
|
+
<div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
|
|
95
|
+
<div class="list" role="list"><slot></slot></div>
|
|
96
|
+
</section>
|
|
97
|
+
</div>`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
CmSmartTips.properties = {
|
|
101
|
+
heading: {},
|
|
102
|
+
tourHeading: { attribute: 'tour-heading' },
|
|
103
|
+
tourAction: { attribute: 'tour-action' },
|
|
104
|
+
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
105
|
+
};
|
|
106
|
+
CmSmartTips.styles = [
|
|
107
|
+
base,
|
|
108
|
+
css `
|
|
109
|
+
:host { display: block; }
|
|
110
|
+
.card { display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
111
|
+
.tour {
|
|
112
|
+
display: flex; align-items: center; gap: var(--cm-space-10); min-height: 60px; padding: var(--cm-space-12) 14px var(--cm-space-12) var(--cm-space-20);
|
|
113
|
+
border-radius: var(--cm-radius-md); background: var(--cm-bg-panel-header); color: var(--cm-text-on-dark);
|
|
114
|
+
}
|
|
115
|
+
.tour-icon {
|
|
116
|
+
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
|
|
117
|
+
border-radius: var(--cm-radius-full); background: var(--cm-nav-active); color: var(--cm-text-on-dark);
|
|
118
|
+
}
|
|
119
|
+
.tour-text { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; line-height: 14px; }
|
|
120
|
+
.panel { padding: var(--cm-space-10); border-radius: var(--cm-radius-md); background: var(--cm-bg-surface); }
|
|
121
|
+
.title {
|
|
122
|
+
margin: var(--cm-space-10) 0 var(--cm-space-20); text-align: center; font-size: 14px; font-weight: 500;
|
|
123
|
+
letter-spacing: var(--cm-tracking-caps); text-transform: uppercase;
|
|
124
|
+
}
|
|
125
|
+
.list { display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
126
|
+
`,
|
|
127
|
+
];
|
|
128
|
+
define('cm-smart-tips', CmSmartTips);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Shows that something is loading when the wait is short or its length unknown. Announced to screen readers
|
|
4
|
+
* through a status role with a text label.
|
|
5
|
+
* @element cm-spinner
|
|
6
|
+
*/
|
|
7
|
+
export declare class CmSpinner extends LitElement {
|
|
8
|
+
static properties: {
|
|
9
|
+
size: {
|
|
10
|
+
reflect: boolean;
|
|
11
|
+
};
|
|
12
|
+
accessibleLabel: {
|
|
13
|
+
attribute: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** `small` (20px) for inline use in buttons, rows and fields; `large` (44px) for a section or page. */
|
|
17
|
+
size: 'small' | 'large';
|
|
18
|
+
/** What screen readers announce. Name what is loading when it helps: "Loading orders". */
|
|
19
|
+
accessibleLabel: string;
|
|
20
|
+
static styles: import("lit").CSSResult[];
|
|
21
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
interface HTMLElementTagNameMap {
|
|
25
|
+
'cm-spinner': CmSpinner;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Shows that something is loading when the wait is short or its length unknown. Announced to screen readers
|
|
5
|
+
* through a status role with a text label.
|
|
6
|
+
* @element cm-spinner
|
|
7
|
+
*/
|
|
8
|
+
export class CmSpinner extends LitElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
/** `small` (20px) for inline use in buttons, rows and fields; `large` (44px) for a section or page. */
|
|
12
|
+
this.size = 'large';
|
|
13
|
+
/** What screen readers announce. Name what is loading when it helps: "Loading orders". */
|
|
14
|
+
this.accessibleLabel = 'Loading';
|
|
15
|
+
}
|
|
16
|
+
render() {
|
|
17
|
+
const sw = this.size === 'small' ? 2.5 : 3;
|
|
18
|
+
return html `<span class="spinner" part="spinner" role="status">
|
|
19
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
20
|
+
<circle class="track" cx="12" cy="12" r="10" fill="none" stroke-width=${sw}></circle>
|
|
21
|
+
<path class="arc" d="M12 2a10 10 0 0 1 10 10" fill="none" stroke-width=${sw} stroke-linecap="round"></path>
|
|
22
|
+
</svg>
|
|
23
|
+
<span class="vh">${this.accessibleLabel || 'Loading'}</span>
|
|
24
|
+
</span>`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
CmSpinner.properties = {
|
|
28
|
+
size: { reflect: true },
|
|
29
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
30
|
+
};
|
|
31
|
+
CmSpinner.styles = [
|
|
32
|
+
base,
|
|
33
|
+
css `
|
|
34
|
+
:host { display: inline-flex; vertical-align: middle; color: var(--cm-border-strong); }
|
|
35
|
+
.spinner { display: inline-flex; }
|
|
36
|
+
svg { inline-size: 44px; block-size: 44px; animation: spin 0.8s linear infinite; }
|
|
37
|
+
:host([size='small']) svg { inline-size: 20px; block-size: 20px; }
|
|
38
|
+
.track { stroke: var(--cm-border-default); }
|
|
39
|
+
.arc { stroke: currentColor; }
|
|
40
|
+
.vh {
|
|
41
|
+
position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; overflow: hidden;
|
|
42
|
+
clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
|
|
43
|
+
}
|
|
44
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
45
|
+
@media (prefers-reduced-motion: reduce) { svg { animation-duration: 2.4s; } }
|
|
46
|
+
`,
|
|
47
|
+
];
|
|
48
|
+
define('cm-spinner', CmSpinner);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { type SpaceStep } from '../spacing.js';
|
|
3
|
+
/**
|
|
4
|
+
* Lays out its children in a column (default) or a row, a spacing token apart. The children stay in your
|
|
5
|
+
* page (light DOM), so your own styles and form elements keep working.
|
|
6
|
+
* @element cm-stack
|
|
7
|
+
* @slot - The items to stack.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CmStack extends LitElement {
|
|
10
|
+
static properties: {
|
|
11
|
+
direction: {
|
|
12
|
+
reflect: boolean;
|
|
13
|
+
};
|
|
14
|
+
gap: {
|
|
15
|
+
reflect: boolean;
|
|
16
|
+
};
|
|
17
|
+
align: {
|
|
18
|
+
reflect: boolean;
|
|
19
|
+
};
|
|
20
|
+
justify: {
|
|
21
|
+
reflect: boolean;
|
|
22
|
+
};
|
|
23
|
+
wrap: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
reflect: boolean;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/** `block` stacks top to bottom; `inline` lays items out in a row (right to left in RTL pages). */
|
|
29
|
+
direction: 'block' | 'inline';
|
|
30
|
+
/** Space between items: a spacing step (`0`, `10`, `12`, `15`, `20`, `22`, `30`). Default `20`, the gap between cards. */
|
|
31
|
+
gap: SpaceStep;
|
|
32
|
+
/** Cross-axis alignment. Default `stretch` in a column and `center` in a row. */
|
|
33
|
+
align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
|
|
34
|
+
/** Main-axis distribution. `space-between` pushes the first and last items to the edges. */
|
|
35
|
+
justify?: 'start' | 'center' | 'end' | 'space-between';
|
|
36
|
+
/** Lets a row wrap onto more lines when it runs out of space. */
|
|
37
|
+
wrap: boolean;
|
|
38
|
+
static styles: import("lit").CSSResult[];
|
|
39
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
interface HTMLElementTagNameMap {
|
|
43
|
+
'cm-stack': CmStack;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
import { spaceRules } from '../spacing.js';
|
|
4
|
+
/**
|
|
5
|
+
* Lays out its children in a column (default) or a row, a spacing token apart. The children stay in your
|
|
6
|
+
* page (light DOM), so your own styles and form elements keep working.
|
|
7
|
+
* @element cm-stack
|
|
8
|
+
* @slot - The items to stack.
|
|
9
|
+
*/
|
|
10
|
+
export class CmStack extends LitElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/** `block` stacks top to bottom; `inline` lays items out in a row (right to left in RTL pages). */
|
|
14
|
+
this.direction = 'block';
|
|
15
|
+
/** Space between items: a spacing step (`0`, `10`, `12`, `15`, `20`, `22`, `30`). Default `20`, the gap between cards. */
|
|
16
|
+
this.gap = '20';
|
|
17
|
+
/** Lets a row wrap onto more lines when it runs out of space. */
|
|
18
|
+
this.wrap = false;
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
return html `<slot></slot>`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
CmStack.properties = {
|
|
25
|
+
direction: { reflect: true },
|
|
26
|
+
gap: { reflect: true },
|
|
27
|
+
align: { reflect: true },
|
|
28
|
+
justify: { reflect: true },
|
|
29
|
+
wrap: { type: Boolean, reflect: true },
|
|
30
|
+
};
|
|
31
|
+
CmStack.styles = [
|
|
32
|
+
base,
|
|
33
|
+
css `
|
|
34
|
+
:host { display: flex; flex-direction: column; gap: var(--cm-space-20); min-inline-size: 0; }
|
|
35
|
+
:host([direction='inline']) { flex-direction: row; align-items: center; }
|
|
36
|
+
:host([wrap]) { flex-wrap: wrap; }
|
|
37
|
+
:host([align='start']) { align-items: flex-start; }
|
|
38
|
+
:host([align='center']) { align-items: center; }
|
|
39
|
+
:host([align='end']) { align-items: flex-end; }
|
|
40
|
+
:host([align='stretch']) { align-items: stretch; }
|
|
41
|
+
:host([align='baseline']) { align-items: baseline; }
|
|
42
|
+
:host([justify='start']) { justify-content: flex-start; }
|
|
43
|
+
:host([justify='center']) { justify-content: center; }
|
|
44
|
+
:host([justify='end']) { justify-content: flex-end; }
|
|
45
|
+
:host([justify='space-between']) { justify-content: space-between; }
|
|
46
|
+
`,
|
|
47
|
+
spaceRules('gap', 'gap'),
|
|
48
|
+
];
|
|
49
|
+
define('cm-stack', CmStack);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/** One status tab. */
|
|
3
|
+
export interface StatusTab {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** Number shown in brackets after the label, e.g. `All ( 233 )`. */
|
|
7
|
+
count?: number;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A row of statuses that filters the list under it, such as All, Unprocessed, Processing, Fulfilled.
|
|
12
|
+
* The chosen status is black and underlined; the others are grey. Each label can carry a count.
|
|
13
|
+
* Works as ARIA tabs: one tab stop, arrow keys move and select, Home/End jump to the ends.
|
|
14
|
+
* Too many tabs for the width scroll sideways.
|
|
15
|
+
*
|
|
16
|
+
* Tabs come from `<option>` children (`count` attribute for the number) or the `tabs` property.
|
|
17
|
+
* @element cm-status-tabs
|
|
18
|
+
* @slot - `<option value="…" count="23">Label</option>` elements. `disabled` and `selected` are honoured.
|
|
19
|
+
* @fires change - When the merchant picks another status. Read `value`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CmStatusTabs extends LitElement {
|
|
22
|
+
#private;
|
|
23
|
+
static properties: {
|
|
24
|
+
value: {
|
|
25
|
+
reflect: boolean;
|
|
26
|
+
};
|
|
27
|
+
tabs: {
|
|
28
|
+
type: ArrayConstructor;
|
|
29
|
+
};
|
|
30
|
+
controls: {};
|
|
31
|
+
size: {
|
|
32
|
+
reflect: boolean;
|
|
33
|
+
};
|
|
34
|
+
_slotted: {
|
|
35
|
+
state: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** Value of the chosen tab. Defaults to the first tab. */
|
|
39
|
+
value: string;
|
|
40
|
+
/** Tabs as strings or `{ value, label, count, disabled }`. Used instead of `<option>` children when set. */
|
|
41
|
+
tabs: Array<string | StatusTab>;
|
|
42
|
+
/**
|
|
43
|
+
* Id of the list or panel the tabs filter (in the same document or shadow root as the tabs). Each tab is linked to it
|
|
44
|
+
* with ARIA element reflection (`ariaControlsElements`), since an `aria-controls` id cannot point out of a shadow root.
|
|
45
|
+
* Browsers without element reflection skip the link.
|
|
46
|
+
*/
|
|
47
|
+
controls: string;
|
|
48
|
+
/** `large` (18px, page-level order statuses) or `small` (14px, inside a card, e.g. review sorting). */
|
|
49
|
+
size: 'large' | 'small';
|
|
50
|
+
_slotted: StatusTab[];
|
|
51
|
+
static styles: import("lit").CSSResult[];
|
|
52
|
+
connectedCallback(): void;
|
|
53
|
+
disconnectedCallback(): void;
|
|
54
|
+
/** The tabs in use, normalised. */
|
|
55
|
+
get items(): StatusTab[];
|
|
56
|
+
/** Focuses the selected tab. */
|
|
57
|
+
focus(options?: FocusOptions): void;
|
|
58
|
+
updated(): void;
|
|
59
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
60
|
+
}
|
|
61
|
+
declare global {
|
|
62
|
+
interface HTMLElementTagNameMap {
|
|
63
|
+
'cm-status-tabs': CmStatusTabs;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 _CmStatusTabs_instances, _CmStatusTabs_observer, _CmStatusTabs_readChildren, _CmStatusTabs_current, _CmStatusTabs_select, _CmStatusTabs_onKeyDown;
|
|
7
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
8
|
+
import { base, define } from '../base.js';
|
|
9
|
+
/**
|
|
10
|
+
* A row of statuses that filters the list under it, such as All, Unprocessed, Processing, Fulfilled.
|
|
11
|
+
* The chosen status is black and underlined; the others are grey. Each label can carry a count.
|
|
12
|
+
* Works as ARIA tabs: one tab stop, arrow keys move and select, Home/End jump to the ends.
|
|
13
|
+
* Too many tabs for the width scroll sideways.
|
|
14
|
+
*
|
|
15
|
+
* Tabs come from `<option>` children (`count` attribute for the number) or the `tabs` property.
|
|
16
|
+
* @element cm-status-tabs
|
|
17
|
+
* @slot - `<option value="…" count="23">Label</option>` elements. `disabled` and `selected` are honoured.
|
|
18
|
+
* @fires change - When the merchant picks another status. Read `value`.
|
|
19
|
+
*/
|
|
20
|
+
export class CmStatusTabs extends LitElement {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
_CmStatusTabs_instances.add(this);
|
|
24
|
+
/** Value of the chosen tab. Defaults to the first tab. */
|
|
25
|
+
this.value = '';
|
|
26
|
+
/** Tabs as strings or `{ value, label, count, disabled }`. Used instead of `<option>` children when set. */
|
|
27
|
+
this.tabs = [];
|
|
28
|
+
/**
|
|
29
|
+
* Id of the list or panel the tabs filter (in the same document or shadow root as the tabs). Each tab is linked to it
|
|
30
|
+
* with ARIA element reflection (`ariaControlsElements`), since an `aria-controls` id cannot point out of a shadow root.
|
|
31
|
+
* Browsers without element reflection skip the link.
|
|
32
|
+
*/
|
|
33
|
+
this.controls = '';
|
|
34
|
+
/** `large` (18px, page-level order statuses) or `small` (14px, inside a card, e.g. review sorting). */
|
|
35
|
+
this.size = 'large';
|
|
36
|
+
this._slotted = [];
|
|
37
|
+
_CmStatusTabs_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_readChildren).call(this)));
|
|
38
|
+
}
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
super.connectedCallback();
|
|
41
|
+
__classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_readChildren).call(this);
|
|
42
|
+
__classPrivateFieldGet(this, _CmStatusTabs_observer, "f").observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['value', 'label', 'count', 'disabled', 'selected'] });
|
|
43
|
+
}
|
|
44
|
+
disconnectedCallback() {
|
|
45
|
+
super.disconnectedCallback();
|
|
46
|
+
__classPrivateFieldGet(this, _CmStatusTabs_observer, "f").disconnect();
|
|
47
|
+
}
|
|
48
|
+
/** The tabs in use, normalised. */
|
|
49
|
+
get items() {
|
|
50
|
+
if (!this.tabs.length)
|
|
51
|
+
return this._slotted;
|
|
52
|
+
return this.tabs.map((t) => (typeof t === 'string' ? { value: t, label: t } : t));
|
|
53
|
+
}
|
|
54
|
+
/** Focuses the selected tab. */
|
|
55
|
+
focus(options) {
|
|
56
|
+
this.renderRoot.querySelector('button[tabindex="0"]')?.focus(options);
|
|
57
|
+
}
|
|
58
|
+
updated() {
|
|
59
|
+
if (!('ariaControlsElements' in Element.prototype))
|
|
60
|
+
return;
|
|
61
|
+
const root = this.getRootNode();
|
|
62
|
+
const target = this.controls ? root.getElementById?.(this.controls) : null;
|
|
63
|
+
for (const b of this.renderRoot.querySelectorAll('button'))
|
|
64
|
+
b.ariaControlsElements = target ? [target] : null;
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
const items = this.items;
|
|
68
|
+
const cur = __classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_current).call(this, items);
|
|
69
|
+
return html `
|
|
70
|
+
<div class="tabs" part="tabs" role="tablist" aria-label=${this.getAttribute('aria-label') || 'Status'}>
|
|
71
|
+
${items.map((t, i) => html `<button type="button" role="tab" part="tab" aria-selected=${i === cur ? 'true' : 'false'}
|
|
72
|
+
tabindex=${i === cur ? '0' : '-1'} ?disabled=${!!t.disabled}
|
|
73
|
+
@click=${() => __classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_select).call(this, i)} @keydown=${(e) => __classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_onKeyDown).call(this, e, i)}>${t.label}${t.count !== undefined && !Number.isNaN(t.count)
|
|
74
|
+
? html ` <span class="count">(</span> ${t.count.toLocaleString()} <span class="count">)</span>`
|
|
75
|
+
: nothing}</button>`)}
|
|
76
|
+
</div>
|
|
77
|
+
<slot></slot>
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
_CmStatusTabs_observer = new WeakMap(), _CmStatusTabs_instances = new WeakSet(), _CmStatusTabs_readChildren = function _CmStatusTabs_readChildren() {
|
|
82
|
+
const opts = [...this.querySelectorAll('option')];
|
|
83
|
+
this._slotted = opts.map((o) => {
|
|
84
|
+
const c = o.getAttribute('count');
|
|
85
|
+
return { value: o.value, label: o.label || o.textContent.trim(), count: c === null || c === '' ? undefined : Number(c), disabled: o.disabled };
|
|
86
|
+
});
|
|
87
|
+
if (!this.hasUpdated && !this.value)
|
|
88
|
+
this.value = opts.find((o) => o.hasAttribute('selected'))?.value ?? '';
|
|
89
|
+
}, _CmStatusTabs_current = function _CmStatusTabs_current(items) {
|
|
90
|
+
const i = items.findIndex((t) => t.value === this.value && !t.disabled);
|
|
91
|
+
return i >= 0 ? i : items.findIndex((t) => !t.disabled);
|
|
92
|
+
}, _CmStatusTabs_select = function _CmStatusTabs_select(i) {
|
|
93
|
+
const t = this.items[i];
|
|
94
|
+
if (!t || t.disabled)
|
|
95
|
+
return;
|
|
96
|
+
this.updateComplete.then(() => {
|
|
97
|
+
const b = this.renderRoot.querySelectorAll('button')[i];
|
|
98
|
+
b?.focus();
|
|
99
|
+
b?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
|
|
100
|
+
});
|
|
101
|
+
if (t.value === this.value)
|
|
102
|
+
return;
|
|
103
|
+
this.value = t.value;
|
|
104
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
105
|
+
}, _CmStatusTabs_onKeyDown = function _CmStatusTabs_onKeyDown(e, i) {
|
|
106
|
+
const en = this.items.flatMap((t, j) => (t.disabled ? [] : [j]));
|
|
107
|
+
const pos = en.indexOf(i);
|
|
108
|
+
let next;
|
|
109
|
+
if (e.key === 'ArrowRight')
|
|
110
|
+
next = en[(pos + 1) % en.length];
|
|
111
|
+
else if (e.key === 'ArrowLeft')
|
|
112
|
+
next = en[(pos - 1 + en.length) % en.length];
|
|
113
|
+
else if (e.key === 'Home')
|
|
114
|
+
next = en[0];
|
|
115
|
+
else if (e.key === 'End')
|
|
116
|
+
next = en[en.length - 1];
|
|
117
|
+
else
|
|
118
|
+
return;
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
if (next !== undefined)
|
|
121
|
+
__classPrivateFieldGet(this, _CmStatusTabs_instances, "m", _CmStatusTabs_select).call(this, next);
|
|
122
|
+
};
|
|
123
|
+
CmStatusTabs.properties = {
|
|
124
|
+
value: { reflect: true },
|
|
125
|
+
tabs: { type: Array },
|
|
126
|
+
controls: {},
|
|
127
|
+
size: { reflect: true },
|
|
128
|
+
_slotted: { state: true },
|
|
129
|
+
};
|
|
130
|
+
CmStatusTabs.styles = [
|
|
131
|
+
base,
|
|
132
|
+
css `
|
|
133
|
+
:host { display: block; }
|
|
134
|
+
.tabs {
|
|
135
|
+
display: flex; gap: 28px; overflow-x: auto; scrollbar-width: thin; padding: 2px 2px 0;
|
|
136
|
+
font-size: 18px; font-weight: 500; white-space: nowrap;
|
|
137
|
+
}
|
|
138
|
+
button {
|
|
139
|
+
position: relative; flex: none; padding: 0 0 12px; font: inherit; color: var(--cm-text-tertiary);
|
|
140
|
+
background: none; border: 0; cursor: pointer;
|
|
141
|
+
}
|
|
142
|
+
button::after {
|
|
143
|
+
content: ''; position: absolute; left: 0; right: 0; bottom: 4px; height: 2px; border-radius: 1px; background: transparent;
|
|
144
|
+
}
|
|
145
|
+
button:hover:not(:disabled) { color: var(--cm-text-default); }
|
|
146
|
+
button[aria-selected='true'] { color: var(--cm-text-default); }
|
|
147
|
+
button[aria-selected='true']::after { background: var(--cm-border-strong); }
|
|
148
|
+
button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; border-radius: var(--cm-radius-xs); }
|
|
149
|
+
button:disabled { color: var(--cm-text-secondary); cursor: not-allowed; }
|
|
150
|
+
.count { font-size: 0.89em; }
|
|
151
|
+
:host([size='small']) .tabs { gap: 18px; font-size: 14px; }
|
|
152
|
+
slot { display: none; }
|
|
153
|
+
@media (max-width: 640px) {
|
|
154
|
+
.tabs { gap: 18px; font-size: 14px; }
|
|
155
|
+
}
|
|
156
|
+
`,
|
|
157
|
+
];
|
|
158
|
+
define('cm-status-tabs', CmStatusTabs);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
/** One column of a table header. */
|
|
4
|
+
export interface TableColumn {
|
|
5
|
+
/** Identifies the column in `cm-sort`. Defaults to the label. */
|
|
6
|
+
key: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** Sortable columns become buttons. */
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
align?: 'start' | 'center' | 'end';
|
|
11
|
+
/** Shown to screen readers only, e.g. for an actions column with no visible label. */
|
|
12
|
+
hidden?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The grey 34px label bar at the top of a table or resource list: column names in 12px type,
|
|
16
|
+
* optional sort buttons and an optional "select all" checkbox.
|
|
17
|
+
*
|
|
18
|
+
* Columns come from `<option>` children or the `columns` property. Lay out the rows with the same
|
|
19
|
+
* grid: set `--cm-table-columns` (a `grid-template-columns` value) on a shared parent.
|
|
20
|
+
* Inside an element with `role="table"` or `role="grid"` it renders a real header row
|
|
21
|
+
* (`row` and `columnheader` roles); elsewhere it is a plain bar whose sort buttons say their state.
|
|
22
|
+
* @element cm-table-header
|
|
23
|
+
* @slot - `<option value="key" sortable align="end">Label</option>` elements.
|
|
24
|
+
* @fires cm-sort - `detail: { key, direction }` when a sortable column is clicked. Set `sort` and `direction` yourself.
|
|
25
|
+
* @fires cm-select-all - `detail: { checked }` when the select-all box is toggled.
|
|
26
|
+
* @cssprop --cm-table-columns - Column widths, e.g. `2fr 1fr 1fr 120px`. Default: equal columns.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CmTableHeader extends LitElement {
|
|
29
|
+
#private;
|
|
30
|
+
static properties: {
|
|
31
|
+
columns: {
|
|
32
|
+
type: ArrayConstructor;
|
|
33
|
+
};
|
|
34
|
+
sort: {
|
|
35
|
+
reflect: boolean;
|
|
36
|
+
};
|
|
37
|
+
direction: {
|
|
38
|
+
reflect: boolean;
|
|
39
|
+
};
|
|
40
|
+
selectable: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
reflect: boolean;
|
|
43
|
+
};
|
|
44
|
+
checked: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
reflect: boolean;
|
|
47
|
+
};
|
|
48
|
+
indeterminate: {
|
|
49
|
+
type: BooleanConstructor;
|
|
50
|
+
reflect: boolean;
|
|
51
|
+
};
|
|
52
|
+
_slotted: {
|
|
53
|
+
state: boolean;
|
|
54
|
+
};
|
|
55
|
+
_inTable: {
|
|
56
|
+
state: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Columns as strings or `{ key, label, sortable, align, hidden }`. Used instead of `<option>` children when set. */
|
|
60
|
+
columns: Array<string | TableColumn>;
|
|
61
|
+
/** Key of the sorted column. */
|
|
62
|
+
sort: string;
|
|
63
|
+
/** Sort direction of the `sort` column. */
|
|
64
|
+
direction: 'ascending' | 'descending';
|
|
65
|
+
/** Adds a leading "select all" checkbox column (50px, as in Figma). */
|
|
66
|
+
selectable: boolean;
|
|
67
|
+
/** Select-all box is ticked. */
|
|
68
|
+
checked: boolean;
|
|
69
|
+
/** Select-all box shows a dash: some rows are selected. */
|
|
70
|
+
indeterminate: boolean;
|
|
71
|
+
_slotted: TableColumn[];
|
|
72
|
+
_inTable: boolean;
|
|
73
|
+
static styles: import("lit").CSSResult[];
|
|
74
|
+
connectedCallback(): void;
|
|
75
|
+
disconnectedCallback(): void;
|
|
76
|
+
/** The columns in use, normalised. */
|
|
77
|
+
get items(): TableColumn[];
|
|
78
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
79
|
+
}
|
|
80
|
+
declare global {
|
|
81
|
+
interface HTMLElementTagNameMap {
|
|
82
|
+
'cm-table-header': CmTableHeader;
|
|
83
|
+
}
|
|
84
|
+
}
|