@commmerce/ui 1.1.1 → 1.3.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 +1010 -533
- package/dist/components/board.d.ts +338 -0
- package/dist/components/board.js +1017 -0
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +25 -0
- package/dist/components/card.d.ts +7 -1
- package/dist/components/card.js +58 -7
- package/dist/components/color-field.d.ts +153 -0
- package/dist/components/color-field.js +369 -0
- package/dist/components/combobox.d.ts +17 -4
- package/dist/components/combobox.js +55 -23
- 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/file-upload.d.ts +33 -0
- package/dist/components/file-upload.js +80 -9
- package/dist/components/global-search.js +2 -7
- package/dist/components/metric.d.ts +97 -0
- package/dist/components/metric.js +168 -0
- package/dist/components/nested-list.d.ts +33 -1
- package/dist/components/nested-list.js +197 -18
- package/dist/components/option-group.d.ts +15 -6
- package/dist/components/option-group.js +25 -6
- 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/select.d.ts +20 -3
- package/dist/components/select.js +35 -11
- 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 +9371 -4963
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/move-model.d.ts +93 -0
- package/dist/move-model.js +169 -0
- package/dist/popover.d.ts +24 -0
- package/dist/popover.js +59 -0
- package/package.json +3 -3
|
@@ -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);
|
|
@@ -4,8 +4,12 @@ declare const itemStrings: {
|
|
|
4
4
|
/** Accessible name of the drag handle, and the keyboard hint read with it. */
|
|
5
5
|
reorder: string;
|
|
6
6
|
hint: string;
|
|
7
|
+
/** The keyboard hint in a list with a `group`: the arrows also cross into the list before or after. */
|
|
8
|
+
hintGroup: string;
|
|
7
9
|
/** Announced after a move. */
|
|
8
10
|
moved: string;
|
|
11
|
+
/** Announced after a move into another list (`group`). */
|
|
12
|
+
movedTo: string;
|
|
9
13
|
};
|
|
10
14
|
declare const listStrings: {
|
|
11
15
|
/** Accessible name of the show/hide button. */
|
|
@@ -25,6 +29,7 @@ declare module '../localize.js' {
|
|
|
25
29
|
* @slot - Child `cm-nested-item`s.
|
|
26
30
|
* @slot actions - Controls at the end of the row: a badge, a toggle, edit and delete buttons.
|
|
27
31
|
* @fires cm-reorder - Bubbles from the moved item: `detail: { item, from, to }` (positions among its siblings). Cancelable.
|
|
32
|
+
* @fires cm-move - Bubbles from the item before it moves into another list with the same `group` (since 1.3): `detail: { item, from, to, fromList, toList }`, where `from` is its position in `fromList` and `to` its position in `toList` after the move. Cancelable: the component moves the element unless you call `preventDefault()`.
|
|
28
33
|
*/
|
|
29
34
|
export declare class CmNestedItem extends CmLocalizedElement {
|
|
30
35
|
#private;
|
|
@@ -51,6 +56,14 @@ export declare class CmNestedItem extends CmLocalizedElement {
|
|
|
51
56
|
constructor();
|
|
52
57
|
connectedCallback(): void;
|
|
53
58
|
static styles: import("lit").CSSResult[];
|
|
59
|
+
/** The `cm-nested-list` this item is a top-level row of, or null when it is nested in another item. */
|
|
60
|
+
get list(): CmNestedList | null;
|
|
61
|
+
/**
|
|
62
|
+
* Moves this top-level row into another `cm-nested-list` with the same `group`, at position `to` (default: the
|
|
63
|
+
* end), firing a cancelable `cm-move` first. With its own list it is the same as `moveTo(to)`. Use it for a
|
|
64
|
+
* "Move to…" menu. Returns false if nothing moved. Since 1.3.
|
|
65
|
+
*/
|
|
66
|
+
moveToList(list: CmNestedList, to?: number): boolean;
|
|
54
67
|
/** Sibling `cm-nested-item`s, including this one. */
|
|
55
68
|
get siblings(): CmNestedItem[];
|
|
56
69
|
/**
|
|
@@ -67,11 +80,13 @@ export declare class CmNestedItem extends CmLocalizedElement {
|
|
|
67
80
|
* sub-links, or categories and sub-categories. The heading sits in a 90px grey bar with its own
|
|
68
81
|
* actions; rows below are indented one step per level. With `sortable`, each row gets a drag
|
|
69
82
|
* handle that also works from the keyboard (↑/↓, Home/End). With `collapsible`, the bar gets a
|
|
70
|
-
* round button that shows and hides the rows.
|
|
83
|
+
* round button that shows and hides the rows. Give sortable lists the same `group` to let top-level rows move
|
|
84
|
+
* between them, by drag and drop or from the keyboard (since 1.3).
|
|
71
85
|
* @element cm-nested-list
|
|
72
86
|
* @slot - `cm-nested-item` rows.
|
|
73
87
|
* @slot actions - Controls in the heading bar, e.g. an "Add links" button or a toggle.
|
|
74
88
|
* @fires cm-reorder - When a row is moved. See `cm-nested-item`.
|
|
89
|
+
* @fires cm-move - When a row moves into another list with the same `group`. Fired on the row before it moves, so it bubbles through the list it leaves. See `cm-nested-item`.
|
|
75
90
|
* @fires cm-toggle - `detail: { open }` when a collapsible list is shown or hidden.
|
|
76
91
|
*/
|
|
77
92
|
export declare class CmNestedList extends CmLocalizedElement {
|
|
@@ -94,9 +109,15 @@ export declare class CmNestedList extends CmLocalizedElement {
|
|
|
94
109
|
type: BooleanConstructor;
|
|
95
110
|
reflect: boolean;
|
|
96
111
|
};
|
|
112
|
+
group: {
|
|
113
|
+
reflect: boolean;
|
|
114
|
+
};
|
|
97
115
|
_msg: {
|
|
98
116
|
state: boolean;
|
|
99
117
|
};
|
|
118
|
+
_empty: {
|
|
119
|
+
state: boolean;
|
|
120
|
+
};
|
|
100
121
|
};
|
|
101
122
|
/** Title in the grey bar, e.g. "Header" or "Clothing & accessories". */
|
|
102
123
|
heading: string;
|
|
@@ -108,10 +129,21 @@ export declare class CmNestedList extends CmLocalizedElement {
|
|
|
108
129
|
collapsible: boolean;
|
|
109
130
|
/** Whether the rows are shown when `collapsible`. */
|
|
110
131
|
open: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Name shared by sortable lists that accept each other's top-level rows (since 1.3), e.g. every section of a
|
|
134
|
+
* form layout. Rows then move between them by drag and drop (mouse or touch) and from the keyboard: ↑ on the
|
|
135
|
+
* first row or ↓ on the last moves it into the list before or after. The component moves the element and fires
|
|
136
|
+
* a cancelable `cm-move`. An empty list in a group shows a drop area.
|
|
137
|
+
*/
|
|
138
|
+
group: string;
|
|
111
139
|
_msg: string;
|
|
140
|
+
_empty: boolean;
|
|
112
141
|
static styles: import("lit").CSSResult[];
|
|
142
|
+
/** The top-level `cm-nested-item` rows, in order. */
|
|
143
|
+
get items(): CmNestedItem[];
|
|
113
144
|
/** Reads a message to screen readers, e.g. after a move. */
|
|
114
145
|
announce(msg: string): void;
|
|
146
|
+
willUpdate(): void;
|
|
115
147
|
updated(changed: Map<string, unknown>): void;
|
|
116
148
|
render(): import("lit-html").TemplateResult<1>;
|
|
117
149
|
}
|
|
@@ -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 _CmNestedItem_instances, _a, _CmNestedItem_internals, _CmNestedItem_peerLists_get, _CmNestedItem_refocus, _CmNestedItem_onHandleKey, _CmNestedItem_onDragStart, _CmNestedItem_pointerDrag, _CmNestedItem_onPointerDown, _CmNestedItem_targetAt, _CmNestedItem_onDragOver, _CmNestedItem_clearDrop, _CmNestedItem_onDrop, _CmNestedList_instances, _CmNestedList_id, _CmNestedList_toggle, _CmNestedList_syncSortable, _CmNestedList_accepts, _CmNestedList_onDragOver, _CmNestedList_onDrop;
|
|
7
13
|
import { html, css, nothing } from 'lit';
|
|
8
14
|
import { base, define, nextId } from '../base.js';
|
|
9
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
@@ -12,8 +18,12 @@ const itemStrings = defineStrings('nestedItem', {
|
|
|
12
18
|
/** Accessible name of the drag handle, and the keyboard hint read with it. */
|
|
13
19
|
reorder: 'Reorder {label}',
|
|
14
20
|
hint: 'Press up or down arrow to move.',
|
|
21
|
+
/** The keyboard hint in a list with a `group`: the arrows also cross into the list before or after. */
|
|
22
|
+
hintGroup: 'Press up or down arrow to move. At either end of the list, the arrow moves it into the list before or after.',
|
|
15
23
|
/** Announced after a move. */
|
|
16
24
|
moved: '{label} moved to position {position} of {total}.',
|
|
25
|
+
/** Announced after a move into another list (`group`). */
|
|
26
|
+
movedTo: '{label} moved to {list}, position {position} of {total}.',
|
|
17
27
|
});
|
|
18
28
|
const listStrings = defineStrings('nestedList', {
|
|
19
29
|
/** Accessible name of the show/hide button. */
|
|
@@ -27,6 +37,7 @@ const listStrings = defineStrings('nestedList', {
|
|
|
27
37
|
* @slot - Child `cm-nested-item`s.
|
|
28
38
|
* @slot actions - Controls at the end of the row: a badge, a toggle, edit and delete buttons.
|
|
29
39
|
* @fires cm-reorder - Bubbles from the moved item: `detail: { item, from, to }` (positions among its siblings). Cancelable.
|
|
40
|
+
* @fires cm-move - Bubbles from the item before it moves into another list with the same `group` (since 1.3): `detail: { item, from, to, fromList, toList }`, where `from` is its position in `fromList` and `to` its position in `toList` after the move. Cancelable: the component moves the element unless you call `preventDefault()`.
|
|
30
41
|
*/
|
|
31
42
|
export class CmNestedItem extends CmLocalizedElement {
|
|
32
43
|
constructor() {
|
|
@@ -40,6 +51,7 @@ export class CmNestedItem extends CmLocalizedElement {
|
|
|
40
51
|
this.sortable = false;
|
|
41
52
|
this._hasChildren = false;
|
|
42
53
|
_CmNestedItem_internals.set(this, this.attachInternals());
|
|
54
|
+
_CmNestedItem_pointerDrag.set(this, false);
|
|
43
55
|
__classPrivateFieldGet(this, _CmNestedItem_internals, "f").role = 'listitem';
|
|
44
56
|
}
|
|
45
57
|
connectedCallback() {
|
|
@@ -48,6 +60,33 @@ export class CmNestedItem extends CmLocalizedElement {
|
|
|
48
60
|
if (!this.hasAttribute('role'))
|
|
49
61
|
this.setAttribute('role', 'listitem');
|
|
50
62
|
}
|
|
63
|
+
/** The `cm-nested-list` this item is a top-level row of, or null when it is nested in another item. */
|
|
64
|
+
get list() {
|
|
65
|
+
const p = this.parentElement;
|
|
66
|
+
return p?.localName === 'cm-nested-list' ? p : null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Moves this top-level row into another `cm-nested-list` with the same `group`, at position `to` (default: the
|
|
70
|
+
* end), firing a cancelable `cm-move` first. With its own list it is the same as `moveTo(to)`. Use it for a
|
|
71
|
+
* "Move to…" menu. Returns false if nothing moved. Since 1.3.
|
|
72
|
+
*/
|
|
73
|
+
moveToList(list, to) {
|
|
74
|
+
const from = this.list;
|
|
75
|
+
if (!from || !list)
|
|
76
|
+
return false;
|
|
77
|
+
if (list === from)
|
|
78
|
+
return to === undefined ? false : this.moveTo(to);
|
|
79
|
+
if (!from.group || list.group !== from.group)
|
|
80
|
+
return false;
|
|
81
|
+
const targets = list.items;
|
|
82
|
+
const index = Math.max(0, Math.min(targets.length, to ?? targets.length));
|
|
83
|
+
const detail = { item: this, from: from.items.indexOf(this), to: index, fromList: from, toList: list };
|
|
84
|
+
if (!this.dispatchEvent(new CustomEvent('cm-move', { detail, bubbles: true, composed: true, cancelable: true })))
|
|
85
|
+
return false;
|
|
86
|
+
list.insertBefore(this, targets[index] ?? null);
|
|
87
|
+
list.announce(this.t('movedTo', { label: this.label, list: list.heading, position: index + 1, total: targets.length + 1 }));
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
51
90
|
/** Sibling `cm-nested-item`s, including this one. */
|
|
52
91
|
get siblings() {
|
|
53
92
|
return [...this.parentElement.children].filter((c) => c.localName === 'cm-nested-item');
|
|
@@ -76,10 +115,10 @@ export class CmNestedItem extends CmLocalizedElement {
|
|
|
76
115
|
${this.sortable
|
|
77
116
|
? html `<button class="handle" type="button" part="handle" draggable="true" aria-label=${this.t('reorder', { label: this.label })}
|
|
78
117
|
aria-describedby="hint"
|
|
79
|
-
@keydown=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onHandleKey)} @dragstart=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onDragStart)}
|
|
80
|
-
@dragend=${() => { this.classList.remove('dragging'); _a.dragged = null; }}><cm-icon name="drag" size="18"></cm-icon></button>`
|
|
118
|
+
@keydown=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onHandleKey)} @dragstart=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onDragStart)} @pointerdown=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onPointerDown)}
|
|
119
|
+
@dragend=${() => { this.classList.remove('dragging'); _a.dragged = null; markDrop(this, null); }}><cm-icon name="drag" size="18"></cm-icon></button>`
|
|
81
120
|
: nothing}
|
|
82
|
-
${this.sortable ? html `<span class="sr" id="hint">${this.t('hint')}</span>` : nothing}
|
|
121
|
+
${this.sortable ? html `<span class="sr" id="hint">${this.t(this.list?.group ? 'hintGroup' : 'hint')}</span>` : nothing}
|
|
83
122
|
<span class="label" part="label">${this.label}</span>
|
|
84
123
|
<span class="actions" part="actions"><slot name="actions"></slot></span>
|
|
85
124
|
</div>
|
|
@@ -99,8 +138,33 @@ export class CmNestedItem extends CmLocalizedElement {
|
|
|
99
138
|
}
|
|
100
139
|
}
|
|
101
140
|
}
|
|
102
|
-
_a = CmNestedItem, _CmNestedItem_internals = new WeakMap(), _CmNestedItem_instances = new WeakSet(),
|
|
141
|
+
_a = CmNestedItem, _CmNestedItem_internals = new WeakMap(), _CmNestedItem_pointerDrag = new WeakMap(), _CmNestedItem_instances = new WeakSet(), _CmNestedItem_peerLists_get = function _CmNestedItem_peerLists_get() {
|
|
142
|
+
const own = this.list;
|
|
143
|
+
if (!own?.group)
|
|
144
|
+
return [];
|
|
145
|
+
const root = own.getRootNode();
|
|
146
|
+
return [...root.querySelectorAll('cm-nested-list')]
|
|
147
|
+
.filter((l) => l === own || (l.group === own.group && l.sortable && (!l.collapsible || l.open)));
|
|
148
|
+
}, _CmNestedItem_refocus = function _CmNestedItem_refocus() {
|
|
149
|
+
// Moving the row re-inserts it, which drops focus. Restore it at once so a quick second key
|
|
150
|
+
// press (e.g. ↓ then End) still reaches the handle, and again after render as a fallback.
|
|
151
|
+
const refocus = () => this.renderRoot.querySelector('.handle')?.focus();
|
|
152
|
+
refocus();
|
|
153
|
+
requestAnimationFrame(refocus);
|
|
154
|
+
}, _CmNestedItem_onHandleKey = function _CmNestedItem_onHandleKey(e) {
|
|
103
155
|
const i = this.siblings.indexOf(this);
|
|
156
|
+
// In a list with a `group`, ↑ on the first row and ↓ on the last cross into the list before or after.
|
|
157
|
+
const up = e.key === 'ArrowUp', down = e.key === 'ArrowDown';
|
|
158
|
+
if ((up && i === 0) || (down && i === this.siblings.length - 1)) {
|
|
159
|
+
const lists = __classPrivateFieldGet(this, _CmNestedItem_instances, "a", _CmNestedItem_peerLists_get);
|
|
160
|
+
const next = lists[lists.indexOf(this.list) + (up ? -1 : 1)];
|
|
161
|
+
if (next) {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
if (this.moveToList(next, up ? next.items.length : 0))
|
|
164
|
+
__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_refocus).call(this);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
104
168
|
let to;
|
|
105
169
|
if (e.key === 'ArrowUp')
|
|
106
170
|
to = i - 1;
|
|
@@ -113,20 +177,68 @@ _a = CmNestedItem, _CmNestedItem_internals = new WeakMap(), _CmNestedItem_instan
|
|
|
113
177
|
else
|
|
114
178
|
return;
|
|
115
179
|
e.preventDefault();
|
|
116
|
-
if (this.moveTo(to))
|
|
117
|
-
|
|
118
|
-
// press (e.g. ↓ then End) still reaches the handle, and again after render as a fallback.
|
|
119
|
-
const refocus = () => this.renderRoot.querySelector('.handle')?.focus();
|
|
120
|
-
refocus();
|
|
121
|
-
requestAnimationFrame(refocus);
|
|
122
|
-
}
|
|
180
|
+
if (this.moveTo(to))
|
|
181
|
+
__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_refocus).call(this);
|
|
123
182
|
}, _CmNestedItem_onDragStart = function _CmNestedItem_onDragStart(e) {
|
|
124
183
|
e.stopPropagation();
|
|
184
|
+
if (__classPrivateFieldGet(this, _CmNestedItem_pointerDrag, "f")) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
return;
|
|
187
|
+
} // a touch drag is already moving the row
|
|
125
188
|
_a.dragged = this;
|
|
126
189
|
this.classList.add('dragging');
|
|
127
190
|
e.dataTransfer?.setData('text/plain', this.label);
|
|
128
191
|
if (e.dataTransfer)
|
|
129
192
|
e.dataTransfer.effectAllowed = 'move';
|
|
193
|
+
}, _CmNestedItem_onPointerDown = function _CmNestedItem_onPointerDown(e) {
|
|
194
|
+
if (e.pointerType === 'mouse' || !e.isPrimary)
|
|
195
|
+
return;
|
|
196
|
+
const startY = e.clientY;
|
|
197
|
+
let target = null;
|
|
198
|
+
const move = (ev) => {
|
|
199
|
+
if (ev.pointerId !== e.pointerId)
|
|
200
|
+
return;
|
|
201
|
+
if (!__classPrivateFieldGet(this, _CmNestedItem_pointerDrag, "f")) {
|
|
202
|
+
if (Math.abs(ev.clientY - startY) < 6)
|
|
203
|
+
return;
|
|
204
|
+
__classPrivateFieldSet(this, _CmNestedItem_pointerDrag, true, "f");
|
|
205
|
+
_a.dragged = this;
|
|
206
|
+
this.classList.add('dragging');
|
|
207
|
+
}
|
|
208
|
+
ev.preventDefault();
|
|
209
|
+
target = __classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_targetAt).call(this, ev.clientX, ev.clientY);
|
|
210
|
+
markDrop(this, target);
|
|
211
|
+
};
|
|
212
|
+
const end = (ev) => {
|
|
213
|
+
if (ev.pointerId !== e.pointerId)
|
|
214
|
+
return;
|
|
215
|
+
document.removeEventListener('pointermove', move, true);
|
|
216
|
+
document.removeEventListener('pointerup', end, true);
|
|
217
|
+
document.removeEventListener('pointercancel', end, true);
|
|
218
|
+
const dragged = __classPrivateFieldGet(this, _CmNestedItem_pointerDrag, "f");
|
|
219
|
+
__classPrivateFieldSet(this, _CmNestedItem_pointerDrag, false, "f");
|
|
220
|
+
_a.dragged = null;
|
|
221
|
+
this.classList.remove('dragging');
|
|
222
|
+
markDrop(this, null);
|
|
223
|
+
if (!dragged || ev.type === 'pointercancel' || !target)
|
|
224
|
+
return;
|
|
225
|
+
if (target.list)
|
|
226
|
+
this.moveToList(target.list, target.index);
|
|
227
|
+
else
|
|
228
|
+
this.moveTo(target.index);
|
|
229
|
+
};
|
|
230
|
+
document.addEventListener('pointermove', move, true);
|
|
231
|
+
document.addEventListener('pointerup', end, true);
|
|
232
|
+
document.addEventListener('pointercancel', end, true);
|
|
233
|
+
}, _CmNestedItem_targetAt = function _CmNestedItem_targetAt(x, y) {
|
|
234
|
+
for (const l of __classPrivateFieldGet(this, _CmNestedItem_instances, "a", _CmNestedItem_peerLists_get)) {
|
|
235
|
+
if (l === this.list)
|
|
236
|
+
continue;
|
|
237
|
+
const r = l.getBoundingClientRect();
|
|
238
|
+
if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom)
|
|
239
|
+
return { list: l, index: indexAt(l.items, this, y) };
|
|
240
|
+
}
|
|
241
|
+
return { index: indexAt(this.siblings, this, y) };
|
|
130
242
|
}, _CmNestedItem_onDragOver = function _CmNestedItem_onDragOver(e) {
|
|
131
243
|
const d = _a.dragged;
|
|
132
244
|
if (!d || d === this || d.parentElement !== this.parentElement)
|
|
@@ -177,6 +289,8 @@ CmNestedItem.styles = [
|
|
|
177
289
|
color: var(--cm-icon-selected); background: none; border: 0; border-radius: var(--cm-radius-xs); cursor: grab;
|
|
178
290
|
}
|
|
179
291
|
.handle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
292
|
+
/* Touch: a drag that starts on the handle moves the row instead of scrolling the page. */
|
|
293
|
+
.handle { touch-action: none; }
|
|
180
294
|
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
181
295
|
.children { margin-block: var(--cm-space-10) 0; margin-inline: 50px 0; display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
182
296
|
.children:not(.has) { display: none; }
|
|
@@ -189,16 +303,42 @@ CmNestedItem.styles = [
|
|
|
189
303
|
];
|
|
190
304
|
CmNestedItem.dragged = null;
|
|
191
305
|
define('cm-nested-item', CmNestedItem);
|
|
306
|
+
/** Position a dragged row would take among `rows` (it is left out) for a pointer at `y`: rows whose middle is above it. */
|
|
307
|
+
function indexAt(rows, dragged, y) {
|
|
308
|
+
return rows.filter((r) => {
|
|
309
|
+
if (r === dragged)
|
|
310
|
+
return false;
|
|
311
|
+
const b = r.getBoundingClientRect();
|
|
312
|
+
return b.top + b.height / 2 < y;
|
|
313
|
+
}).length;
|
|
314
|
+
}
|
|
315
|
+
/** Shows where a dragged row will land (a line before or after a row, or an outline on an empty list); null clears. */
|
|
316
|
+
function markDrop(dragged, target) {
|
|
317
|
+
const root = (dragged.list ?? dragged).getRootNode();
|
|
318
|
+
root.querySelectorAll('cm-nested-item.drop-before, cm-nested-item.drop-after, cm-nested-list.drop-target')
|
|
319
|
+
.forEach((el) => el.classList.remove('drop-before', 'drop-after', 'drop-target'));
|
|
320
|
+
if (!target)
|
|
321
|
+
return;
|
|
322
|
+
const rows = (target.list ? target.list.items : dragged.siblings).filter((r) => r !== dragged);
|
|
323
|
+
if (!rows.length)
|
|
324
|
+
target.list?.classList.add('drop-target');
|
|
325
|
+
else if (target.index < rows.length)
|
|
326
|
+
rows[target.index].classList.add('drop-before');
|
|
327
|
+
else
|
|
328
|
+
rows[rows.length - 1].classList.add('drop-after');
|
|
329
|
+
}
|
|
192
330
|
/**
|
|
193
331
|
* A titled group of rows that nest inside each other, such as a navigation menu with links and
|
|
194
332
|
* sub-links, or categories and sub-categories. The heading sits in a 90px grey bar with its own
|
|
195
333
|
* actions; rows below are indented one step per level. With `sortable`, each row gets a drag
|
|
196
334
|
* handle that also works from the keyboard (↑/↓, Home/End). With `collapsible`, the bar gets a
|
|
197
|
-
* round button that shows and hides the rows.
|
|
335
|
+
* round button that shows and hides the rows. Give sortable lists the same `group` to let top-level rows move
|
|
336
|
+
* between them, by drag and drop or from the keyboard (since 1.3).
|
|
198
337
|
* @element cm-nested-list
|
|
199
338
|
* @slot - `cm-nested-item` rows.
|
|
200
339
|
* @slot actions - Controls in the heading bar, e.g. an "Add links" button or a toggle.
|
|
201
340
|
* @fires cm-reorder - When a row is moved. See `cm-nested-item`.
|
|
341
|
+
* @fires cm-move - When a row moves into another list with the same `group`. Fired on the row before it moves, so it bubbles through the list it leaves. See `cm-nested-item`.
|
|
202
342
|
* @fires cm-toggle - `detail: { open }` when a collapsible list is shown or hidden.
|
|
203
343
|
*/
|
|
204
344
|
export class CmNestedList extends CmLocalizedElement {
|
|
@@ -215,16 +355,33 @@ export class CmNestedList extends CmLocalizedElement {
|
|
|
215
355
|
this.collapsible = false;
|
|
216
356
|
/** Whether the rows are shown when `collapsible`. */
|
|
217
357
|
this.open = true;
|
|
358
|
+
/**
|
|
359
|
+
* Name shared by sortable lists that accept each other's top-level rows (since 1.3), e.g. every section of a
|
|
360
|
+
* form layout. Rows then move between them by drag and drop (mouse or touch) and from the keyboard: ↑ on the
|
|
361
|
+
* first row or ↓ on the last moves it into the list before or after. The component moves the element and fires
|
|
362
|
+
* a cancelable `cm-move`. An empty list in a group shows a drop area.
|
|
363
|
+
*/
|
|
364
|
+
this.group = '';
|
|
218
365
|
this._msg = '';
|
|
366
|
+
this._empty = false;
|
|
219
367
|
_CmNestedList_id.set(this, nextId('cm-nl'));
|
|
220
368
|
}
|
|
369
|
+
/** The top-level `cm-nested-item` rows, in order. */
|
|
370
|
+
get items() {
|
|
371
|
+
return [...this.children].filter((c) => c.localName === 'cm-nested-item');
|
|
372
|
+
}
|
|
221
373
|
/** Reads a message to screen readers, e.g. after a move. */
|
|
222
374
|
announce(msg) {
|
|
223
375
|
this._msg = '';
|
|
224
376
|
requestAnimationFrame(() => (this._msg = msg));
|
|
225
377
|
}
|
|
378
|
+
willUpdate() {
|
|
379
|
+
// A list with no rows gets no slotchange, so count them before the first render.
|
|
380
|
+
if (!this.hasUpdated)
|
|
381
|
+
this._empty = !this.items.length;
|
|
382
|
+
}
|
|
226
383
|
updated(changed) {
|
|
227
|
-
if (changed.has('sortable'))
|
|
384
|
+
if (changed.has('sortable') || changed.has('group'))
|
|
228
385
|
__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_syncSortable).call(this);
|
|
229
386
|
}
|
|
230
387
|
render() {
|
|
@@ -240,8 +397,9 @@ export class CmNestedList extends CmLocalizedElement {
|
|
|
240
397
|
<cm-icon name=${shown ? 'chevron-up' : 'chevron-down'} size="14"></cm-icon></button>`
|
|
241
398
|
: nothing}
|
|
242
399
|
</div>
|
|
243
|
-
<div class="rows" id="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-rows" role="list" aria-labelledby="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-h" ?hidden=${!shown}
|
|
244
|
-
|
|
400
|
+
<div class="rows ${this.group && this._empty ? 'empty' : ''}" id="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-rows" role="list" aria-labelledby="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-h" ?hidden=${!shown}
|
|
401
|
+
@dragover=${__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_onDragOver)} @drop=${__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_onDrop)}>
|
|
402
|
+
<slot @slotchange=${() => { __classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_syncSortable).call(this); this._empty = !this.items.length; }}></slot>
|
|
245
403
|
</div>
|
|
246
404
|
<span class="sr" role="status">${this._msg}</span>
|
|
247
405
|
`;
|
|
@@ -251,8 +409,25 @@ _CmNestedList_id = new WeakMap(), _CmNestedList_instances = new WeakSet(), _CmNe
|
|
|
251
409
|
this.open = !this.open;
|
|
252
410
|
this.dispatchEvent(new CustomEvent('cm-toggle', { detail: { open: this.open }, bubbles: true, composed: true }));
|
|
253
411
|
}, _CmNestedList_syncSortable = function _CmNestedList_syncSortable() {
|
|
254
|
-
|
|
255
|
-
|
|
412
|
+
const rows = this.items;
|
|
413
|
+
rows.forEach((k) => { k.sortable = this.sortable; k.requestUpdate(); });
|
|
414
|
+
}, _CmNestedList_accepts = function _CmNestedList_accepts(d) {
|
|
415
|
+
const from = d?.list;
|
|
416
|
+
return !!d && !!from && from !== this && !!this.group && from.group === this.group && this.sortable && (!this.collapsible || this.open);
|
|
417
|
+
}, _CmNestedList_onDragOver = function _CmNestedList_onDragOver(e) {
|
|
418
|
+
const d = CmNestedItem.dragged;
|
|
419
|
+
if (!__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_accepts).call(this, d))
|
|
420
|
+
return;
|
|
421
|
+
e.preventDefault();
|
|
422
|
+
markDrop(d, { list: this, index: indexAt(this.items, d, e.clientY) });
|
|
423
|
+
}, _CmNestedList_onDrop = function _CmNestedList_onDrop(e) {
|
|
424
|
+
const d = CmNestedItem.dragged;
|
|
425
|
+
if (!__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_accepts).call(this, d))
|
|
426
|
+
return;
|
|
427
|
+
e.preventDefault();
|
|
428
|
+
const index = indexAt(this.items, d, e.clientY);
|
|
429
|
+
markDrop(d, null);
|
|
430
|
+
d.moveToList(this, index);
|
|
256
431
|
};
|
|
257
432
|
CmNestedList.properties = {
|
|
258
433
|
heading: {},
|
|
@@ -260,7 +435,9 @@ CmNestedList.properties = {
|
|
|
260
435
|
sortable: { type: Boolean, reflect: true },
|
|
261
436
|
collapsible: { type: Boolean, reflect: true },
|
|
262
437
|
open: { type: Boolean, reflect: true },
|
|
438
|
+
group: { reflect: true },
|
|
263
439
|
_msg: { state: true },
|
|
440
|
+
_empty: { state: true },
|
|
264
441
|
};
|
|
265
442
|
CmNestedList.styles = [
|
|
266
443
|
base,
|
|
@@ -280,6 +457,8 @@ CmNestedList.styles = [
|
|
|
280
457
|
.toggle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
281
458
|
.rows { display: flex; flex-direction: column; gap: var(--cm-space-10); margin-block: var(--cm-space-15) 0; margin-inline: 50px 0; }
|
|
282
459
|
.rows[hidden] { display: none; }
|
|
460
|
+
.rows.empty { min-height: 60px; border: var(--cm-border-1) dashed var(--cm-border-default); border-radius: var(--cm-radius-md); }
|
|
461
|
+
:host(.drop-target) .rows.empty { border: 2px solid var(--cm-border-strong); }
|
|
283
462
|
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
284
463
|
@media (max-width: 640px) {
|
|
285
464
|
.bar { min-height: 60px; padding: 0 var(--cm-space-10); gap: var(--cm-space-10); }
|
|
@@ -9,14 +9,23 @@ declare module '../localize.js' {
|
|
|
9
9
|
optionGroup: typeof strings;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
/** An option of `cm-option-group`. */
|
|
13
|
+
export interface OptionGroupOption extends SelectOption {
|
|
14
|
+
/**
|
|
15
|
+
* Colours the option by the outcome it records, as `cm-button`'s `tone`: `success` (green, "Signed up") or
|
|
16
|
+
* `critical` (red, "Not interested"). The label still carries the meaning. Since 1.3.
|
|
17
|
+
*/
|
|
18
|
+
tone?: 'critical' | 'success';
|
|
19
|
+
}
|
|
12
20
|
/**
|
|
13
21
|
* A row of outlined buttons where exactly one is selected (black), used to switch a form between
|
|
14
22
|
* types, such as offer types. Behaves like a native radio group: one tab stop, arrow keys move and
|
|
15
23
|
* select, and the form receives the selected value.
|
|
16
24
|
*
|
|
17
|
-
* Options come from `<option>` children or the `options` property.
|
|
25
|
+
* Options come from `<option>` children or the `options` property. A `tone` on an option (`<option tone="success">`
|
|
26
|
+
* or `{ tone }`, since 1.3) colours it by the outcome it records: outlined in the tone, filled in it when selected.
|
|
18
27
|
* @element cm-option-group
|
|
19
|
-
* @slot - `<option value="…">Label</option>` elements. `disabled` and `
|
|
28
|
+
* @slot - `<option value="…">Label</option>` elements. `disabled`, `selected` and `tone` (`success`, `critical`) are honoured.
|
|
20
29
|
* @fires change - When the merchant picks a different option.
|
|
21
30
|
* @fires input - Same moment as `change`.
|
|
22
31
|
*/
|
|
@@ -50,13 +59,13 @@ export declare class CmOptionGroup extends CmLocalizedElement {
|
|
|
50
59
|
name: string;
|
|
51
60
|
/** Value of the selected option; empty when nothing is selected. */
|
|
52
61
|
value: string;
|
|
53
|
-
/** Options as strings or `{ value, label, disabled }`. Used instead of `<option>` children when set. */
|
|
54
|
-
options: Array<string |
|
|
62
|
+
/** Options as strings or `{ value, label, disabled, tone }`. Used instead of `<option>` children when set. */
|
|
63
|
+
options: Array<string | OptionGroupOption>;
|
|
55
64
|
/** The form will not submit until an option is chosen. */
|
|
56
65
|
required: boolean;
|
|
57
66
|
/** Blocks every option. Also set by a disabled `<fieldset>`. */
|
|
58
67
|
disabled: boolean;
|
|
59
|
-
_slotted:
|
|
68
|
+
_slotted: OptionGroupOption[];
|
|
60
69
|
static styles: import("lit").CSSResult[];
|
|
61
70
|
connectedCallback(): void;
|
|
62
71
|
disconnectedCallback(): void;
|
|
@@ -71,7 +80,7 @@ export declare class CmOptionGroup extends CmLocalizedElement {
|
|
|
71
80
|
/** Focuses the selected option, or the first one. */
|
|
72
81
|
focus(options?: FocusOptions): void;
|
|
73
82
|
/** The options in use, normalised. */
|
|
74
|
-
get items():
|
|
83
|
+
get items(): OptionGroupOption[];
|
|
75
84
|
firstUpdated(): void;
|
|
76
85
|
updated(): void;
|
|
77
86
|
render(): import("lit-html").TemplateResult<1>;
|