@commmerce/ui 1.1.0 → 1.2.0
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/dist/calendar.d.ts +38 -0
- package/dist/calendar.js +109 -0
- package/dist/cdn.js +682 -453
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +25 -0
- package/dist/components/card.d.ts +5 -0
- package/dist/components/card.js +44 -5
- package/dist/components/date-picker.d.ts +49 -5
- package/dist/components/date-picker.js +211 -48
- package/dist/components/empty-state.d.ts +19 -4
- package/dist/components/empty-state.js +59 -5
- package/dist/components/header-bar.js +4 -2
- package/dist/components/metric.d.ts +97 -0
- package/dist/components/metric.js +168 -0
- package/dist/components/page-header.js +3 -2
- package/dist/components/resource-list.d.ts +14 -2
- package/dist/components/resource-list.js +48 -6
- package/dist/components/table-header.d.ts +14 -0
- package/dist/components/table-header.js +21 -0
- package/dist/components/text-field.d.ts +36 -2
- package/dist/components/text-field.js +86 -14
- package/dist/components/timeline.d.ts +210 -0
- package/dist/components/timeline.js +380 -0
- package/dist/custom-elements.json +5102 -3386
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/package.json +3 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
import './skeleton.js';
|
|
4
|
+
declare const strings: {
|
|
5
|
+
/** Read for a rising change. `{change}` is the `change` text, e.g. "+12%". */
|
|
6
|
+
up: string;
|
|
7
|
+
/** Read for a falling change. */
|
|
8
|
+
down: string;
|
|
9
|
+
/** Read for a change that is level. */
|
|
10
|
+
flat: string;
|
|
11
|
+
/** Added when the change is good news (`trend-sentiment`). `{trend}` is the text above. */
|
|
12
|
+
good: string;
|
|
13
|
+
/** Added when the change is bad news. */
|
|
14
|
+
bad: string;
|
|
15
|
+
/** Announced (politely) while the figure loads. */
|
|
16
|
+
loadingValue: string;
|
|
17
|
+
};
|
|
18
|
+
declare module '../localize.js' {
|
|
19
|
+
interface CmStrings {
|
|
20
|
+
metric: typeof strings;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export type MetricTrend = 'up' | 'down' | 'flat';
|
|
24
|
+
export type MetricSentiment = 'auto' | 'positive' | 'negative' | 'neutral';
|
|
25
|
+
/**
|
|
26
|
+
* One number with its name, for totals and KPIs: "SMB leads 1,240". A large figure in tabular numerals, an optional
|
|
27
|
+
* hint line ("2 past demos need a result") and an optional change ("+12%" with an arrow, coloured by whether it is
|
|
28
|
+
* good news). With `href` the whole tile is one link, e.g. to the list behind the number. Put a row of them in
|
|
29
|
+
* `cm-grid`.
|
|
30
|
+
* @element cm-metric
|
|
31
|
+
* @slot hint - A hint with markup (e.g. a bold count), used instead of `hint`. No links or buttons: with `href` the whole tile is already one link.
|
|
32
|
+
*/
|
|
33
|
+
export declare class CmMetric extends CmLocalizedElement {
|
|
34
|
+
static properties: {
|
|
35
|
+
label: {};
|
|
36
|
+
value: {
|
|
37
|
+
converter: {
|
|
38
|
+
fromAttribute: (v: string | null) => string | number;
|
|
39
|
+
toAttribute: (v: unknown) => string | null | undefined;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
hint: {};
|
|
43
|
+
change: {};
|
|
44
|
+
trend: {
|
|
45
|
+
reflect: boolean;
|
|
46
|
+
};
|
|
47
|
+
trendSentiment: {
|
|
48
|
+
attribute: string;
|
|
49
|
+
reflect: boolean;
|
|
50
|
+
};
|
|
51
|
+
href: {};
|
|
52
|
+
loading: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
reflect: boolean;
|
|
55
|
+
};
|
|
56
|
+
_hasHint: {
|
|
57
|
+
state: boolean;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** What is counted, e.g. "SMB leads". Two to four words. */
|
|
61
|
+
label: string;
|
|
62
|
+
/**
|
|
63
|
+
* The figure. A number (or a plain number in the attribute, `value="1240"`) is formatted for the locale:
|
|
64
|
+
* "1,240", and lakh grouping "12,40,000" in `en-IN`. Any other text ("Rs. 2.4 L", "3 of 5") is shown as given.
|
|
65
|
+
*/
|
|
66
|
+
value: number | string;
|
|
67
|
+
/** One line under the figure in a quieter colour, e.g. "2 past demos need a result". */
|
|
68
|
+
hint: string;
|
|
69
|
+
/** The change to show, written as you want it read, e.g. "+12%" or "-3 vs last week". */
|
|
70
|
+
change: string;
|
|
71
|
+
/** Direction of `change`: `up`, `down` or `flat`. Adds an arrow and says the direction to screen readers. */
|
|
72
|
+
trend?: MetricTrend;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the change is good news. `auto` (default): up is positive (green), down is negative (red), flat is
|
|
75
|
+
* neutral. Set `negative` when up is bad (more refunds, more overdue tasks), `positive` when down is good.
|
|
76
|
+
*/
|
|
77
|
+
trendSentiment: MetricSentiment;
|
|
78
|
+
/** Makes the whole tile one link, named by the label and figure, e.g. to the list behind the number. */
|
|
79
|
+
href: string;
|
|
80
|
+
/** Shows a placeholder instead of the figure and announces "Loading <label>" politely. */
|
|
81
|
+
loading: boolean;
|
|
82
|
+
private _hasHint;
|
|
83
|
+
static styles: import("lit").CSSResult[];
|
|
84
|
+
connectedCallback(): void;
|
|
85
|
+
/** The figure as shown: a number formatted for the locale, any other text as given. */
|
|
86
|
+
private figure;
|
|
87
|
+
private sentiment;
|
|
88
|
+
private renderChange;
|
|
89
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
90
|
+
private onHintSlot;
|
|
91
|
+
}
|
|
92
|
+
declare global {
|
|
93
|
+
interface HTMLElementTagNameMap {
|
|
94
|
+
'cm-metric': CmMetric;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { html, css, nothing } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
4
|
+
import './icon.js';
|
|
5
|
+
import './skeleton.js';
|
|
6
|
+
const strings = defineStrings('metric', {
|
|
7
|
+
/** Read for a rising change. `{change}` is the `change` text, e.g. "+12%". */
|
|
8
|
+
up: 'Up {change}',
|
|
9
|
+
/** Read for a falling change. */
|
|
10
|
+
down: 'Down {change}',
|
|
11
|
+
/** Read for a change that is level. */
|
|
12
|
+
flat: 'No change {change}',
|
|
13
|
+
/** Added when the change is good news (`trend-sentiment`). `{trend}` is the text above. */
|
|
14
|
+
good: '{trend}, good',
|
|
15
|
+
/** Added when the change is bad news. */
|
|
16
|
+
bad: '{trend}, bad',
|
|
17
|
+
/** Announced (politely) while the figure loads. */
|
|
18
|
+
loadingValue: 'Loading {label}',
|
|
19
|
+
});
|
|
20
|
+
/** A plain number written as text ("1240", "-3.5"): formatted like a number. Anything else is shown as given. */
|
|
21
|
+
const PLAIN_NUMBER = /^\s*-?\d+(\.\d+)?\s*$/;
|
|
22
|
+
/**
|
|
23
|
+
* One number with its name, for totals and KPIs: "SMB leads 1,240". A large figure in tabular numerals, an optional
|
|
24
|
+
* hint line ("2 past demos need a result") and an optional change ("+12%" with an arrow, coloured by whether it is
|
|
25
|
+
* good news). With `href` the whole tile is one link, e.g. to the list behind the number. Put a row of them in
|
|
26
|
+
* `cm-grid`.
|
|
27
|
+
* @element cm-metric
|
|
28
|
+
* @slot hint - A hint with markup (e.g. a bold count), used instead of `hint`. No links or buttons: with `href` the whole tile is already one link.
|
|
29
|
+
*/
|
|
30
|
+
export class CmMetric extends CmLocalizedElement {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
/** What is counted, e.g. "SMB leads". Two to four words. */
|
|
34
|
+
this.label = '';
|
|
35
|
+
/**
|
|
36
|
+
* The figure. A number (or a plain number in the attribute, `value="1240"`) is formatted for the locale:
|
|
37
|
+
* "1,240", and lakh grouping "12,40,000" in `en-IN`. Any other text ("Rs. 2.4 L", "3 of 5") is shown as given.
|
|
38
|
+
*/
|
|
39
|
+
this.value = '';
|
|
40
|
+
/** One line under the figure in a quieter colour, e.g. "2 past demos need a result". */
|
|
41
|
+
this.hint = '';
|
|
42
|
+
/** The change to show, written as you want it read, e.g. "+12%" or "-3 vs last week". */
|
|
43
|
+
this.change = '';
|
|
44
|
+
/**
|
|
45
|
+
* Whether the change is good news. `auto` (default): up is positive (green), down is negative (red), flat is
|
|
46
|
+
* neutral. Set `negative` when up is bad (more refunds, more overdue tasks), `positive` when down is good.
|
|
47
|
+
*/
|
|
48
|
+
this.trendSentiment = 'auto';
|
|
49
|
+
/** Makes the whole tile one link, named by the label and figure, e.g. to the list behind the number. */
|
|
50
|
+
this.href = '';
|
|
51
|
+
/** Shows a placeholder instead of the figure and announces "Loading <label>" politely. */
|
|
52
|
+
this.loading = false;
|
|
53
|
+
this._hasHint = false;
|
|
54
|
+
this.onHintSlot = (e) => {
|
|
55
|
+
this._hasHint = e.target.assignedNodes({ flatten: false }).some((n) => n.nodeType === 1 || n.textContent?.trim());
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
connectedCallback() {
|
|
59
|
+
super.connectedCallback();
|
|
60
|
+
this._hasHint = !!this.querySelector(':scope > [slot="hint"]');
|
|
61
|
+
}
|
|
62
|
+
/** The figure as shown: a number formatted for the locale, any other text as given. */
|
|
63
|
+
figure() {
|
|
64
|
+
const v = this.value;
|
|
65
|
+
if (v === '' || v === null || v === undefined)
|
|
66
|
+
return '';
|
|
67
|
+
const n = typeof v === 'number' ? v : PLAIN_NUMBER.test(String(v)) ? Number(v) : NaN;
|
|
68
|
+
return Number.isNaN(n) ? String(v) : this.formatNumber(n);
|
|
69
|
+
}
|
|
70
|
+
sentiment() {
|
|
71
|
+
const s = this.trendSentiment;
|
|
72
|
+
if (s === 'positive' || s === 'negative' || s === 'neutral')
|
|
73
|
+
return s;
|
|
74
|
+
return this.trend === 'up' ? 'positive' : this.trend === 'down' ? 'negative' : 'neutral';
|
|
75
|
+
}
|
|
76
|
+
renderChange() {
|
|
77
|
+
const trend = this.trend && ['up', 'down', 'flat'].includes(this.trend) ? this.trend : undefined;
|
|
78
|
+
if (!this.change && !trend)
|
|
79
|
+
return nothing;
|
|
80
|
+
if (!trend)
|
|
81
|
+
return html `<span class="change neutral" part="change">${this.change}</span>`;
|
|
82
|
+
const sentiment = this.sentiment();
|
|
83
|
+
const said = this.t(trend, { change: this.change }).trim();
|
|
84
|
+
const spoken = sentiment === 'positive' ? this.t('good', { trend: said }) : sentiment === 'negative' ? this.t('bad', { trend: said }) : said;
|
|
85
|
+
// up: the arrow drawn up-and-forward; down: turned a quarter clockwise (mirrored first in RTL, so turned the other way);
|
|
86
|
+
// flat: arrow-left turned half round, which points forward in either direction.
|
|
87
|
+
const icon = trend === 'flat' ? 'arrow-left' : 'arrow-up-right';
|
|
88
|
+
return html `<span class="change ${trend} ${sentiment}" part="change">
|
|
89
|
+
<cm-icon name=${icon} size="16"></cm-icon><span aria-hidden="true">${this.change}</span><span class="sr">${spoken}</span>
|
|
90
|
+
</span>`;
|
|
91
|
+
}
|
|
92
|
+
render() {
|
|
93
|
+
const showHint = this._hasHint || !!this.hint;
|
|
94
|
+
const value = this.loading ? html `<cm-skeleton variant="block"></cm-skeleton>` : this.figure();
|
|
95
|
+
const change = this.renderChange();
|
|
96
|
+
const hasFoot = change !== nothing || showHint;
|
|
97
|
+
const body = html `
|
|
98
|
+
<span class="label" id="label" part="label">${this.label}</span>
|
|
99
|
+
<span class="value" id="value" part="value">${value}</span>
|
|
100
|
+
<span class="foot ${hasFoot ? 'on' : ''}" id="foot" part="footer">
|
|
101
|
+
${change}
|
|
102
|
+
<span class="hint ${showHint ? 'on' : ''}" part="hint"><slot name="hint" @slotchange=${this.onHintSlot}>${this.hint}</slot></span>
|
|
103
|
+
</span>
|
|
104
|
+
`;
|
|
105
|
+
const status = html `<span class="sr" role="status">${this.loading ? this.t('loadingValue', { label: this.label }) : ''}</span>`;
|
|
106
|
+
const busy = this.loading ? 'true' : nothing;
|
|
107
|
+
return this.href
|
|
108
|
+
? html `<a class="tile" part="tile" href=${this.href} aria-labelledby="label value" aria-describedby=${hasFoot ? 'foot' : nothing} aria-busy=${busy}>${body}</a>${status}`
|
|
109
|
+
: html `<div class="tile" part="tile" aria-busy=${busy}>${body}</div>${status}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
CmMetric.properties = {
|
|
113
|
+
label: {},
|
|
114
|
+
value: {
|
|
115
|
+
converter: {
|
|
116
|
+
fromAttribute: (v) => (v !== null && PLAIN_NUMBER.test(v) ? Number(v) : v ?? ''),
|
|
117
|
+
toAttribute: (v) => (v === null || v === undefined ? v : String(v)),
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
hint: {},
|
|
121
|
+
change: {},
|
|
122
|
+
trend: { reflect: true },
|
|
123
|
+
trendSentiment: { attribute: 'trend-sentiment', reflect: true },
|
|
124
|
+
href: {},
|
|
125
|
+
loading: { type: Boolean, reflect: true },
|
|
126
|
+
_hasHint: { state: true },
|
|
127
|
+
};
|
|
128
|
+
CmMetric.styles = [
|
|
129
|
+
base,
|
|
130
|
+
css `
|
|
131
|
+
:host { display: block; align-self: stretch; min-inline-size: 0; }
|
|
132
|
+
.tile {
|
|
133
|
+
display: flex; flex-direction: column; gap: 4px; block-size: 100%; min-inline-size: 0;
|
|
134
|
+
padding: var(--cm-space-20); color: var(--cm-text-default); text-decoration: none; text-align: start;
|
|
135
|
+
background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-card); border-radius: var(--cm-radius-md);
|
|
136
|
+
}
|
|
137
|
+
a.tile { cursor: pointer; }
|
|
138
|
+
a.tile:hover { border-color: var(--cm-border-strong); }
|
|
139
|
+
a.tile:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
140
|
+
.label { font-size: var(--cm-type-body-md-size); font-weight: 500; line-height: var(--cm-type-body-md-line-height); overflow-wrap: anywhere; }
|
|
141
|
+
.value {
|
|
142
|
+
font-size: var(--cm-type-heading-lg-size); font-weight: var(--cm-type-heading-lg-weight); line-height: 1.25;
|
|
143
|
+
font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-block-size: 1.25em;
|
|
144
|
+
}
|
|
145
|
+
.value cm-skeleton { inline-size: 6ch; max-inline-size: 100%; --cm-skeleton-height: 0.9em; margin-block: 0.175em; }
|
|
146
|
+
.foot { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--cm-space-10); row-gap: 2px; }
|
|
147
|
+
.foot:not(.on) { display: none; }
|
|
148
|
+
.change {
|
|
149
|
+
display: inline-flex; align-items: center; gap: 2px; font-size: var(--cm-type-body-sm-size); font-weight: 500;
|
|
150
|
+
font-variant-numeric: tabular-nums; color: var(--cm-text-tertiary);
|
|
151
|
+
}
|
|
152
|
+
.change.positive { color: var(--cm-text-success); }
|
|
153
|
+
.change.negative { color: var(--cm-text-critical); }
|
|
154
|
+
.change cm-icon { align-self: center; }
|
|
155
|
+
.change.down cm-icon { transform: rotate(90deg); }
|
|
156
|
+
:host(:dir(rtl)) .change.down cm-icon { transform: rotate(-90deg); }
|
|
157
|
+
.change.flat cm-icon { transform: rotate(180deg); }
|
|
158
|
+
.hint { font-size: var(--cm-type-body-sm-size); line-height: var(--cm-type-body-sm-line-height); color: var(--cm-text-tertiary); overflow-wrap: anywhere; }
|
|
159
|
+
.hint:not(.on) { display: none; }
|
|
160
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
|
|
161
|
+
@media (max-width: 640px) {
|
|
162
|
+
.tile { padding: var(--cm-space-15); }
|
|
163
|
+
.value { font-size: var(--cm-type-heading-lg-resp-size); }
|
|
164
|
+
}
|
|
165
|
+
@media (forced-colors: active) { .change { color: CanvasText; } }
|
|
166
|
+
`,
|
|
167
|
+
];
|
|
168
|
+
define('cm-metric', CmMetric);
|
|
@@ -105,10 +105,11 @@ CmPageHeader.styles = [
|
|
|
105
105
|
nav a:focus-visible, .back:focus-visible, .arrow:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
106
106
|
nav [aria-current] { color: var(--cm-text-default); }
|
|
107
107
|
h1 {
|
|
108
|
-
display: flex; align-items: center; gap: var(--cm-space-10); margin: 0; min-width: 0;
|
|
108
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--cm-space-10); margin: 0; min-width: 0;
|
|
109
109
|
font-size: 26px; font-weight: 500; line-height: 1.2;
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
/* The title keeps at least about 12 characters; badges in title-adornment wrap below it instead of pushing the page wider. */
|
|
112
|
+
.text { flex: 0 1 auto; min-width: min(12ch, 100%); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
112
113
|
.actions { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--cm-space-20); margin-inline-start: auto; }
|
|
113
114
|
.arrows { display: flex; gap: var(--cm-space-10); }
|
|
114
115
|
.arrow, .back {
|
|
@@ -34,7 +34,7 @@ declare module '../localize.js' {
|
|
|
34
34
|
* A row in a `cm-resource-list`: a checkbox when the list is selectable, an optional thumbnail and
|
|
35
35
|
* any content. With `href` the whole row is a link; otherwise clicking a selectable row ticks it.
|
|
36
36
|
* @element cm-resource-item
|
|
37
|
-
* @slot - Row content: name, details, badges.
|
|
37
|
+
* @slot - Row content: name, details, badges. To line up with a `cm-table-header`, set `columns` and give one element per column.
|
|
38
38
|
* @slot media - A 50px thumbnail (34px on phones): a `cm-thumbnail` (recommended; `alt=""` when the row names the product) or an `<img>`.
|
|
39
39
|
* @slot actions - Buttons at the end of the row. They do not toggle selection.
|
|
40
40
|
* @fires cm-resource-select - `detail: { value, selected }` when the merchant ticks or unticks the row. The list handles it.
|
|
@@ -59,6 +59,10 @@ export declare class CmResourceItem extends CmLocalizedElement {
|
|
|
59
59
|
type: BooleanConstructor;
|
|
60
60
|
reflect: boolean;
|
|
61
61
|
};
|
|
62
|
+
columns: {
|
|
63
|
+
type: BooleanConstructor;
|
|
64
|
+
reflect: boolean;
|
|
65
|
+
};
|
|
62
66
|
};
|
|
63
67
|
/** Identifies the row in the list's `selected` array. */
|
|
64
68
|
value: string;
|
|
@@ -72,6 +76,11 @@ export declare class CmResourceItem extends CmLocalizedElement {
|
|
|
72
76
|
label: string;
|
|
73
77
|
/** Shows the checkbox. Set by the parent list from its own `selectable`. */
|
|
74
78
|
selectable: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Lays the row's content out on the `--cm-table-columns` grid (set it on the list), one child element per column,
|
|
81
|
+
* `space-20` apart: the same grid as a `cm-table-header` in the list's `header` slot, so cells sit under their headings.
|
|
82
|
+
*/
|
|
83
|
+
columns: boolean;
|
|
75
84
|
constructor();
|
|
76
85
|
connectedCallback(): void;
|
|
77
86
|
static styles: import("lit").CSSResult[];
|
|
@@ -86,9 +95,12 @@ export declare class CmResourceItem extends CmLocalizedElement {
|
|
|
86
95
|
* When `selectable`, a toolbar shows a select-all box with a menu (this page, all matching, none), bulk actions once something is selected,
|
|
87
96
|
* "2 products selected" and, when there are more results than rows, a button to select all of them.
|
|
88
97
|
* Put a `cm-table-header` in the `header` slot for column names and `cm-pagination` under the list.
|
|
98
|
+
* The list lines a slotted `cm-table-header` up with its rows (it sets the header's `resource-rows`): lay each row's
|
|
99
|
+
* content out as a grid with `grid-template-columns: var(--cm-table-columns)` and `column-gap: var(--cm-space-20)`,
|
|
100
|
+
* and set `--cm-table-columns` on the list.
|
|
89
101
|
* @element cm-resource-list
|
|
90
102
|
* @slot - `cm-resource-item` rows.
|
|
91
|
-
* @slot header - A `cm-table-header` (or anything) between the toolbar and the rows.
|
|
103
|
+
* @slot header - A `cm-table-header` (or anything) between the toolbar and the rows. A `cm-table-header` here is lined up with the rows, checkbox column included.
|
|
92
104
|
* @slot bulk-actions - Buttons that act on the selection, e.g. "Bulk orders". Shown once a row is selected.
|
|
93
105
|
* @slot actions - Buttons at the end of the toolbar, e.g. "Customise columns".
|
|
94
106
|
* @slot empty - Shown instead of the rows when there are none, e.g. a `cm-empty-state`.
|
|
@@ -3,7 +3,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
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
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
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");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _CmResourceItem_instances, _CmResourceItem_internals, _CmResourceItem_onRowClick, _CmResourceList_instances, _CmResourceList_id, _CmResourceList_headers, _CmResourceList_plural, _CmResourceList_syncHeaders, _CmResourceList_onHeaderSlot, _CmResourceList_sync, _CmResourceList_emit, _CmResourceList_menuSelect;
|
|
7
13
|
import { html, css, nothing } from 'lit';
|
|
8
14
|
import { base, define, nextId } from '../base.js';
|
|
9
15
|
import { CmLocalizedElement, defineStrings, pluralCategory } from '../localize.js';
|
|
@@ -49,7 +55,7 @@ const checkboxStyles = css `
|
|
|
49
55
|
* A row in a `cm-resource-list`: a checkbox when the list is selectable, an optional thumbnail and
|
|
50
56
|
* any content. With `href` the whole row is a link; otherwise clicking a selectable row ticks it.
|
|
51
57
|
* @element cm-resource-item
|
|
52
|
-
* @slot - Row content: name, details, badges.
|
|
58
|
+
* @slot - Row content: name, details, badges. To line up with a `cm-table-header`, set `columns` and give one element per column.
|
|
53
59
|
* @slot media - A 50px thumbnail (34px on phones): a `cm-thumbnail` (recommended; `alt=""` when the row names the product) or an `<img>`.
|
|
54
60
|
* @slot actions - Buttons at the end of the row. They do not toggle selection.
|
|
55
61
|
* @fires cm-resource-select - `detail: { value, selected }` when the merchant ticks or unticks the row. The list handles it.
|
|
@@ -70,6 +76,11 @@ export class CmResourceItem extends CmLocalizedElement {
|
|
|
70
76
|
this.label = '';
|
|
71
77
|
/** Shows the checkbox. Set by the parent list from its own `selectable`. */
|
|
72
78
|
this.selectable = false;
|
|
79
|
+
/**
|
|
80
|
+
* Lays the row's content out on the `--cm-table-columns` grid (set it on the list), one child element per column,
|
|
81
|
+
* `space-20` apart: the same grid as a `cm-table-header` in the list's `header` slot, so cells sit under their headings.
|
|
82
|
+
*/
|
|
83
|
+
this.columns = false;
|
|
73
84
|
_CmResourceItem_internals.set(this, this.attachInternals());
|
|
74
85
|
__classPrivateFieldGet(this, _CmResourceItem_internals, "f").role = 'listitem';
|
|
75
86
|
}
|
|
@@ -126,6 +137,7 @@ CmResourceItem.properties = {
|
|
|
126
137
|
href: {},
|
|
127
138
|
label: {},
|
|
128
139
|
selectable: { type: Boolean, reflect: true },
|
|
140
|
+
columns: { type: Boolean, reflect: true },
|
|
129
141
|
};
|
|
130
142
|
CmResourceItem.styles = [
|
|
131
143
|
base,
|
|
@@ -146,6 +158,10 @@ CmResourceItem.styles = [
|
|
|
146
158
|
}
|
|
147
159
|
::slotted(cm-thumbnail[slot='media']) { --cm-thumbnail-size: 50px; background: none; }
|
|
148
160
|
.content { flex: 1; min-width: 0; }
|
|
161
|
+
:host([columns]) .content {
|
|
162
|
+
display: grid; grid-template-columns: var(--cm-table-columns, minmax(0, 1fr)); column-gap: var(--cm-space-20); align-items: center;
|
|
163
|
+
}
|
|
164
|
+
:host([columns]) ::slotted(*) { min-width: 0; overflow-wrap: anywhere; }
|
|
149
165
|
a { position: absolute; inset: 0; z-index: 0; border-radius: var(--cm-radius-xs); }
|
|
150
166
|
a:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: -2px; }
|
|
151
167
|
.check, .actions { position: relative; z-index: 1; }
|
|
@@ -165,9 +181,12 @@ define('cm-resource-item', CmResourceItem);
|
|
|
165
181
|
* When `selectable`, a toolbar shows a select-all box with a menu (this page, all matching, none), bulk actions once something is selected,
|
|
166
182
|
* "2 products selected" and, when there are more results than rows, a button to select all of them.
|
|
167
183
|
* Put a `cm-table-header` in the `header` slot for column names and `cm-pagination` under the list.
|
|
184
|
+
* The list lines a slotted `cm-table-header` up with its rows (it sets the header's `resource-rows`): lay each row's
|
|
185
|
+
* content out as a grid with `grid-template-columns: var(--cm-table-columns)` and `column-gap: var(--cm-space-20)`,
|
|
186
|
+
* and set `--cm-table-columns` on the list.
|
|
168
187
|
* @element cm-resource-list
|
|
169
188
|
* @slot - `cm-resource-item` rows.
|
|
170
|
-
* @slot header - A `cm-table-header` (or anything) between the toolbar and the rows.
|
|
189
|
+
* @slot header - A `cm-table-header` (or anything) between the toolbar and the rows. A `cm-table-header` here is lined up with the rows, checkbox column included.
|
|
171
190
|
* @slot bulk-actions - Buttons that act on the selection, e.g. "Bulk orders". Shown once a row is selected.
|
|
172
191
|
* @slot actions - Buttons at the end of the toolbar, e.g. "Customise columns".
|
|
173
192
|
* @slot empty - Shown instead of the rows when there are none, e.g. a `cm-empty-state`.
|
|
@@ -194,6 +213,12 @@ export class CmResourceList extends CmLocalizedElement {
|
|
|
194
213
|
this._count = 0;
|
|
195
214
|
this._rows = 0;
|
|
196
215
|
_CmResourceList_id.set(this, nextId('cm-rl'));
|
|
216
|
+
_CmResourceList_headers.set(this, new Set());
|
|
217
|
+
_CmResourceList_onHeaderSlot.set(this, (e) => {
|
|
218
|
+
const slot = e.target;
|
|
219
|
+
slot.parentElement.classList.toggle('has', slot.assignedElements().length > 0);
|
|
220
|
+
__classPrivateFieldGet(this, _CmResourceList_instances, "m", _CmResourceList_syncHeaders).call(this, slot);
|
|
221
|
+
});
|
|
197
222
|
_CmResourceList_menuSelect.set(this, (e) => {
|
|
198
223
|
e.stopPropagation(); // the list's own menu: don't leak its cm-select to the page
|
|
199
224
|
const v = e.detail.value;
|
|
@@ -240,8 +265,10 @@ export class CmResourceList extends CmLocalizedElement {
|
|
|
240
265
|
/** Clears the selection. */
|
|
241
266
|
clearSelection() { this.selectPage(false); }
|
|
242
267
|
updated(changed) {
|
|
243
|
-
if (changed.has('selectable'))
|
|
268
|
+
if (changed.has('selectable')) {
|
|
244
269
|
__classPrivateFieldGet(this, _CmResourceList_instances, "m", _CmResourceList_sync).call(this);
|
|
270
|
+
__classPrivateFieldGet(this, _CmResourceList_instances, "m", _CmResourceList_syncHeaders).call(this);
|
|
271
|
+
}
|
|
245
272
|
}
|
|
246
273
|
render() {
|
|
247
274
|
const n = this._count;
|
|
@@ -279,7 +306,7 @@ export class CmResourceList extends CmLocalizedElement {
|
|
|
279
306
|
<span class="actions"><slot name="actions"></slot></span>
|
|
280
307
|
</div>`
|
|
281
308
|
: nothing}
|
|
282
|
-
<div class="header"><slot name="header" @slotchange=${(
|
|
309
|
+
<div class="header"><slot name="header" @slotchange=${__classPrivateFieldGet(this, _CmResourceList_onHeaderSlot, "f")}></slot></div>
|
|
283
310
|
<div class="body">
|
|
284
311
|
<div class="list" part="list" role="list" aria-label=${this.label || plural.replace(/^./, (c) => c.toUpperCase())} aria-busy=${this.loading ? 'true' : 'false'}>
|
|
285
312
|
<slot @slotchange=${() => __classPrivateFieldGet(this, _CmResourceList_instances, "m", _CmResourceList_sync).call(this)}></slot>
|
|
@@ -290,12 +317,27 @@ export class CmResourceList extends CmLocalizedElement {
|
|
|
290
317
|
`;
|
|
291
318
|
}
|
|
292
319
|
}
|
|
293
|
-
_CmResourceList_id = new WeakMap(), _CmResourceList_menuSelect = new WeakMap(), _CmResourceList_instances = new WeakSet(), _CmResourceList_plural = function _CmResourceList_plural() {
|
|
320
|
+
_CmResourceList_id = new WeakMap(), _CmResourceList_headers = new WeakMap(), _CmResourceList_onHeaderSlot = new WeakMap(), _CmResourceList_menuSelect = new WeakMap(), _CmResourceList_instances = new WeakSet(), _CmResourceList_plural = function _CmResourceList_plural() {
|
|
294
321
|
if (this.resourceNamePlural)
|
|
295
322
|
return this.resourceNamePlural;
|
|
296
323
|
const own = this.resourceName;
|
|
297
324
|
// A custom singular keeps the old rule (plus "s"); the built-in noun has its own plural.
|
|
298
325
|
return own !== this.t('resourceName') ? `${own}s` : this.t('resourceNamePlural');
|
|
326
|
+
}, _CmResourceList_syncHeaders = function _CmResourceList_syncHeaders(slot = this.renderRoot?.querySelector('slot[name="header"]')) {
|
|
327
|
+
if (!slot)
|
|
328
|
+
return;
|
|
329
|
+
const found = new Set();
|
|
330
|
+
for (const el of slot.assignedElements()) {
|
|
331
|
+
if (el.localName === 'cm-table-header')
|
|
332
|
+
found.add(el);
|
|
333
|
+
el.querySelectorAll('cm-table-header').forEach((h) => found.add(h));
|
|
334
|
+
}
|
|
335
|
+
for (const h of __classPrivateFieldGet(this, _CmResourceList_headers, "f"))
|
|
336
|
+
if (!found.has(h))
|
|
337
|
+
h.removeAttribute('resource-rows');
|
|
338
|
+
for (const h of found)
|
|
339
|
+
h.setAttribute('resource-rows', this.selectable ? 'selectable' : 'plain');
|
|
340
|
+
__classPrivateFieldSet(this, _CmResourceList_headers, found, "f");
|
|
299
341
|
}, _CmResourceList_sync = function _CmResourceList_sync() {
|
|
300
342
|
const items = this.items;
|
|
301
343
|
items.forEach((i) => (i.selectable = this.selectable));
|
|
@@ -31,6 +31,10 @@ export interface TableColumn {
|
|
|
31
31
|
* grid: set `--cm-table-columns` (a `grid-template-columns` value) on a shared parent.
|
|
32
32
|
* Inside an element with `role="table"` or `role="grid"` it renders a real header row
|
|
33
33
|
* (`row` and `columnheader` roles); elsewhere it is a plain bar whose sort buttons say their state.
|
|
34
|
+
*
|
|
35
|
+
* In the `header` slot of a `cm-resource-list`, the list sets `resource-rows` so the column names line up with the
|
|
36
|
+
* cells of its `cm-resource-item` rows (including the rows' checkbox column when the list is `selectable`). The
|
|
37
|
+
* list's toolbar has the select-all box there: don't also set `selectable` on the header.
|
|
34
38
|
* @element cm-table-header
|
|
35
39
|
* @slot - `<option value="key" sortable align="end">Label</option>` elements.
|
|
36
40
|
* @fires cm-sort - `detail: { key, direction }` when a sortable column is clicked. Set `sort` and `direction` yourself.
|
|
@@ -61,6 +65,10 @@ export declare class CmTableHeader extends CmLocalizedElement {
|
|
|
61
65
|
type: BooleanConstructor;
|
|
62
66
|
reflect: boolean;
|
|
63
67
|
};
|
|
68
|
+
resourceRows: {
|
|
69
|
+
attribute: string;
|
|
70
|
+
reflect: boolean;
|
|
71
|
+
};
|
|
64
72
|
_slotted: {
|
|
65
73
|
state: boolean;
|
|
66
74
|
};
|
|
@@ -80,6 +88,12 @@ export declare class CmTableHeader extends CmLocalizedElement {
|
|
|
80
88
|
checked: boolean;
|
|
81
89
|
/** Select-all box shows a dash: some rows are selected. */
|
|
82
90
|
indeterminate: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Lines the columns up with `cm-resource-item` rows: `plain` matches the rows' padding, `selectable` also leaves
|
|
93
|
+
* room for the rows' checkboxes. Set by `cm-resource-list` on a header in its `header` slot (from its own
|
|
94
|
+
* `selectable`); you don't need to set it. Unset (the default) is the standalone bar.
|
|
95
|
+
*/
|
|
96
|
+
resourceRows?: 'plain' | 'selectable';
|
|
83
97
|
_slotted: TableColumn[];
|
|
84
98
|
_inTable: boolean;
|
|
85
99
|
static styles: import("lit").CSSResult[];
|
|
@@ -23,6 +23,10 @@ const strings = defineStrings('tableHeader', {
|
|
|
23
23
|
* grid: set `--cm-table-columns` (a `grid-template-columns` value) on a shared parent.
|
|
24
24
|
* Inside an element with `role="table"` or `role="grid"` it renders a real header row
|
|
25
25
|
* (`row` and `columnheader` roles); elsewhere it is a plain bar whose sort buttons say their state.
|
|
26
|
+
*
|
|
27
|
+
* In the `header` slot of a `cm-resource-list`, the list sets `resource-rows` so the column names line up with the
|
|
28
|
+
* cells of its `cm-resource-item` rows (including the rows' checkbox column when the list is `selectable`). The
|
|
29
|
+
* list's toolbar has the select-all box there: don't also set `selectable` on the header.
|
|
26
30
|
* @element cm-table-header
|
|
27
31
|
* @slot - `<option value="key" sortable align="end">Label</option>` elements.
|
|
28
32
|
* @fires cm-sort - `detail: { key, direction }` when a sortable column is clicked. Set `sort` and `direction` yourself.
|
|
@@ -119,6 +123,7 @@ CmTableHeader.properties = {
|
|
|
119
123
|
selectable: { type: Boolean, reflect: true },
|
|
120
124
|
checked: { type: Boolean, reflect: true },
|
|
121
125
|
indeterminate: { type: Boolean, reflect: true },
|
|
126
|
+
resourceRows: { attribute: 'resource-rows', reflect: true },
|
|
122
127
|
_slotted: { state: true },
|
|
123
128
|
_inTable: { state: true },
|
|
124
129
|
};
|
|
@@ -154,6 +159,22 @@ CmTableHeader.styles = [
|
|
|
154
159
|
.dash { width: 10px; height: 2px; background: var(--cm-icon-selected); }
|
|
155
160
|
input:focus-visible + .box { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
156
161
|
slot { display: none; }
|
|
162
|
+
/* In a cm-resource-list (resource-rows): the bar's content box matches a row's content box, so the same
|
|
163
|
+
--cm-table-columns grid (with column-gap space-20) lands on the same x positions. Rows are padded space-10
|
|
164
|
+
inline, start with a 20px checkbox and a space-20 gap when selectable, and end with the gap before their
|
|
165
|
+
(possibly empty) actions; on phones: no padding, an 18px checkbox, space-10 gaps.
|
|
166
|
+
The bar reaches out to the list's edges; its border is drawn inside so it takes no room. */
|
|
167
|
+
:host([resource-rows]) .bar {
|
|
168
|
+
margin-inline: calc(-1 * var(--cm-space-10)); padding-inline: var(--cm-space-20) calc(2 * var(--cm-space-20));
|
|
169
|
+
border: 0; box-shadow: inset 0 0 0 var(--cm-border-1) var(--cm-border-subtle);
|
|
170
|
+
}
|
|
171
|
+
:host([resource-rows='selectable']) .bar:not(.sel) { padding-inline-start: calc(var(--cm-space-20) + 20px + var(--cm-space-20)); }
|
|
172
|
+
:host([resource-rows]) .bar.sel > .cell:first-child { overflow: visible; }
|
|
173
|
+
@media (max-width: 640px) {
|
|
174
|
+
:host([resource-rows]) .bar { padding-inline: var(--cm-space-10) calc(2 * var(--cm-space-10)); }
|
|
175
|
+
:host([resource-rows='selectable']) .bar:not(.sel) { padding-inline-start: calc(var(--cm-space-10) + 18px + var(--cm-space-10)); }
|
|
176
|
+
:host([resource-rows]) .bar.sel { grid-template-columns: calc(18px + var(--cm-space-10) - var(--cm-space-20)) var(--cm-table-columns, var(--_cols)); }
|
|
177
|
+
}
|
|
157
178
|
`,
|
|
158
179
|
];
|
|
159
180
|
define('cm-table-header', CmTableHeader);
|
|
@@ -2,6 +2,20 @@ import { CmLocalizedElement } from '../localize.js';
|
|
|
2
2
|
declare const strings: {
|
|
3
3
|
/** Validation message when `required` and empty. */
|
|
4
4
|
required: string;
|
|
5
|
+
/** Validation: a date or time before `min`. `{min}` is the min in the page language, e.g. "16 Nov 2026, 3:30 pm". */
|
|
6
|
+
rangeUnderflow: string;
|
|
7
|
+
/** Validation: a date or time after `max`. */
|
|
8
|
+
rangeOverflow: string;
|
|
9
|
+
/** Validation: a number below `min`. */
|
|
10
|
+
numberUnderflow: string;
|
|
11
|
+
/** Validation: a number above `max`. */
|
|
12
|
+
numberOverflow: string;
|
|
13
|
+
/** Validation: a value off the `step`. `{lower}` and `{upper}` are the nearest allowed values. */
|
|
14
|
+
stepMismatch: string;
|
|
15
|
+
/** Validation, `type="time"`: the time is only partly filled in. */
|
|
16
|
+
badTime: string;
|
|
17
|
+
/** Validation, `type="datetime-local"`: the date and time are only partly filled in. */
|
|
18
|
+
badDateTime: string;
|
|
5
19
|
};
|
|
6
20
|
declare module '../localize.js' {
|
|
7
21
|
interface CmStrings {
|
|
@@ -10,6 +24,8 @@ declare module '../localize.js' {
|
|
|
10
24
|
}
|
|
11
25
|
/**
|
|
12
26
|
* Labelled single- or multi-line input. Participates in native forms.
|
|
27
|
+
* `type="date"`, `"time"` and `"datetime-local"` use the browser's own picker; their values are ISO and local
|
|
28
|
+
* (`yyyy-mm-dd`, `hh:mm`, `yyyy-mm-ddThh:mm`), with no time zone.
|
|
13
29
|
* @element cm-text-field
|
|
14
30
|
* @fires input - On every keystroke (bubbles, composed).
|
|
15
31
|
* @fires change - When the value is committed.
|
|
@@ -60,6 +76,9 @@ export declare class CmTextField extends CmLocalizedElement {
|
|
|
60
76
|
size: {
|
|
61
77
|
reflect: boolean;
|
|
62
78
|
};
|
|
79
|
+
min: {};
|
|
80
|
+
max: {};
|
|
81
|
+
step: {};
|
|
63
82
|
};
|
|
64
83
|
/** Visible label above the box. Required for accessibility unless the field has an aria-label. */
|
|
65
84
|
label: string;
|
|
@@ -75,8 +94,11 @@ export declare class CmTextField extends CmLocalizedElement {
|
|
|
75
94
|
value: string;
|
|
76
95
|
/** Example input, shown in text-tertiary. Never a substitute for the label. */
|
|
77
96
|
placeholder: string;
|
|
78
|
-
/**
|
|
79
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Native input type. Ignored when `multiline`. `time` and `datetime-local` (since 1.2) give the browser's time and
|
|
99
|
+
* date-and-time pickers; their value is local time without a time zone, `hh:mm` and `yyyy-mm-ddThh:mm`.
|
|
100
|
+
*/
|
|
101
|
+
type: 'text' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'url' | 'date' | 'time' | 'datetime-local';
|
|
80
102
|
/** Renders a resizable textarea. */
|
|
81
103
|
multiline: boolean;
|
|
82
104
|
/** Visible rows when `multiline`. */
|
|
@@ -91,6 +113,18 @@ export declare class CmTextField extends CmLocalizedElement {
|
|
|
91
113
|
autocomplete?: string;
|
|
92
114
|
/** `small`: 12px label, 14px value (filter panels). */
|
|
93
115
|
size: 'default' | 'small';
|
|
116
|
+
/**
|
|
117
|
+
* Lowest allowed value for `number`, `date`, `time` and `datetime-local`, in the value's format (`2026-11-16T15:30`
|
|
118
|
+
* for `datetime-local`). The browser's picker doesn't offer earlier dates; an earlier value makes the field invalid.
|
|
119
|
+
*/
|
|
120
|
+
min?: string;
|
|
121
|
+
/** Highest allowed value for `number`, `date`, `time` and `datetime-local`, in the value's format. */
|
|
122
|
+
max?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Allowed steps from `min`, as on a native input: a number for `number`, days for `date`, seconds for `time` and
|
|
125
|
+
* `datetime-local` (`900` = 15 minutes; under 60 shows seconds). `any` allows every value.
|
|
126
|
+
*/
|
|
127
|
+
step?: string;
|
|
94
128
|
static styles: import("lit").CSSResult[];
|
|
95
129
|
connectedCallback(): void;
|
|
96
130
|
get form(): HTMLFormElement | null;
|