@commmerce/ui 1.0.0-rc.4 → 1.0.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/LICENSE.md +152 -17
- package/README.md +2 -3
- package/THIRD_PARTY_NOTICES.txt +175 -0
- package/dist/base.d.ts +5 -0
- package/dist/base.js +10 -0
- package/dist/calendar.d.ts +95 -0
- package/dist/calendar.js +280 -0
- package/dist/cdn.js +721 -477
- package/dist/components/accordion.js +2 -2
- package/dist/components/action-bar.d.ts +12 -2
- package/dist/components/action-bar.js +10 -5
- package/dist/components/action-menu.d.ts +17 -4
- package/dist/components/action-menu.js +8 -5
- package/dist/components/app-card.d.ts +24 -2
- package/dist/components/app-card.js +25 -10
- package/dist/components/banner.d.ts +2 -2
- package/dist/components/banner.js +4 -3
- package/dist/components/bottom-navigation.d.ts +16 -4
- package/dist/components/bottom-navigation.js +10 -7
- package/dist/components/bottom-sheet.d.ts +4 -1
- package/dist/components/bottom-sheet.js +2 -2
- package/dist/components/checkbox.d.ts +12 -2
- package/dist/components/checkbox.js +7 -2
- package/dist/components/combobox.d.ts +186 -0
- package/dist/components/combobox.js +521 -0
- package/dist/components/comment.d.ts +27 -9
- package/dist/components/comment.js +14 -13
- package/dist/components/data-table.d.ts +14 -2
- package/dist/components/data-table.js +31 -10
- package/dist/components/date-picker.d.ts +179 -0
- package/dist/components/date-picker.js +336 -0
- package/dist/components/date-range-picker.d.ts +251 -0
- package/dist/components/date-range-picker.js +484 -0
- package/dist/components/file-upload.d.ts +30 -4
- package/dist/components/file-upload.js +37 -17
- package/dist/components/filter-panel.d.ts +29 -6
- package/dist/components/filter-panel.js +16 -14
- package/dist/components/flash-offer-bar.d.ts +18 -4
- package/dist/components/flash-offer-bar.js +13 -8
- package/dist/components/header-bar.d.ts +20 -4
- package/dist/components/header-bar.js +20 -13
- package/dist/components/icon.d.ts +7 -0
- package/dist/components/icon.js +9 -1
- package/dist/components/link-tabs.d.ts +16 -4
- package/dist/components/link-tabs.js +10 -7
- package/dist/components/mobile-menu.d.ts +19 -4
- package/dist/components/mobile-menu.js +16 -10
- package/dist/components/modal.d.ts +4 -1
- package/dist/components/nested-list.d.ts +22 -3
- package/dist/components/nested-list.js +25 -12
- package/dist/components/notification-panel.d.ts +26 -5
- package/dist/components/notification-panel.js +17 -11
- package/dist/components/option-group.d.ts +12 -2
- package/dist/components/option-group.js +13 -7
- package/dist/components/page-header.d.ts +18 -2
- package/dist/components/page-header.js +23 -10
- package/dist/components/pagination.d.ts +27 -4
- package/dist/components/pagination.js +28 -16
- package/dist/components/progress-bar.d.ts +12 -2
- package/dist/components/progress-bar.js +9 -4
- package/dist/components/radio.d.ts +12 -1
- package/dist/components/radio.js +12 -6
- package/dist/components/report-tile.d.ts +12 -1
- package/dist/components/report-tile.js +9 -4
- package/dist/components/resource-list.d.ts +36 -5
- package/dist/components/resource-list.js +50 -23
- package/dist/components/save-bar.d.ts +23 -6
- package/dist/components/save-bar.js +14 -12
- package/dist/components/search.d.ts +28 -7
- package/dist/components/search.js +18 -13
- package/dist/components/select.d.ts +12 -2
- package/dist/components/select.js +9 -4
- package/dist/components/side-navigation.d.ts +16 -4
- package/dist/components/side-navigation.js +16 -12
- package/dist/components/side-panel.d.ts +5 -2
- package/dist/components/side-panel.js +5 -3
- package/dist/components/skeleton-display.d.ts +6 -4
- package/dist/components/skeleton-display.js +4 -5
- package/dist/components/smart-tip.d.ts +25 -6
- package/dist/components/smart-tip.js +18 -12
- package/dist/components/spinner.d.ts +4 -3
- package/dist/components/spinner.js +5 -6
- package/dist/components/status-tabs.d.ts +12 -2
- package/dist/components/status-tabs.js +14 -8
- package/dist/components/table-header.d.ts +15 -2
- package/dist/components/table-header.js +13 -5
- package/dist/components/tag.d.ts +12 -2
- package/dist/components/tag.js +9 -4
- package/dist/components/text-field.d.ts +12 -2
- package/dist/components/text-field.js +9 -4
- package/dist/components/thumbnail.d.ts +12 -2
- package/dist/components/thumbnail.js +8 -3
- package/dist/components/toast.d.ts +14 -3
- package/dist/components/toast.js +20 -9
- package/dist/components/toggle.js +2 -0
- package/dist/custom-elements.json +16477 -6434
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -1
- package/dist/localize.d.ts +130 -0
- package/dist/localize.js +232 -0
- package/dist/overlay.d.ts +8 -4
- package/dist/overlay.js +9 -12
- package/package.json +5 -4
|
@@ -4,9 +4,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _CmTableHeader_instances, _CmTableHeader_id, _CmTableHeader_observer, _CmTableHeader_readChildren, _CmTableHeader_onSort, _CmTableHeader_onSelectAll;
|
|
7
|
-
import {
|
|
7
|
+
import { html, css, nothing } from 'lit';
|
|
8
8
|
import { base, define, nextId } from '../base.js';
|
|
9
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
9
10
|
import './icon.js';
|
|
11
|
+
const strings = defineStrings('tableHeader', {
|
|
12
|
+
/** Accessible name of the select-all box. */
|
|
13
|
+
selectAll: 'Select all',
|
|
14
|
+
/** Read after a sortable column's name (outside a table). `{direction}` is the common `ascending` or `descending`. */
|
|
15
|
+
sorted: ', sorted {direction}',
|
|
16
|
+
sortable: ', sortable',
|
|
17
|
+
});
|
|
10
18
|
/**
|
|
11
19
|
* The grey 34px label bar at the top of a table or resource list: column names in 12px type,
|
|
12
20
|
* optional sort buttons and an optional "select all" checkbox.
|
|
@@ -21,7 +29,7 @@ import './icon.js';
|
|
|
21
29
|
* @fires cm-select-all - `detail: { checked }` when the select-all box is toggled.
|
|
22
30
|
* @cssprop --cm-table-columns - Column widths, e.g. `2fr 1fr 1fr 120px`. Default: equal columns.
|
|
23
31
|
*/
|
|
24
|
-
export class CmTableHeader extends
|
|
32
|
+
export class CmTableHeader extends CmLocalizedElement {
|
|
25
33
|
constructor() {
|
|
26
34
|
super(...arguments);
|
|
27
35
|
_CmTableHeader_instances.add(this);
|
|
@@ -66,7 +74,7 @@ export class CmTableHeader extends LitElement {
|
|
|
66
74
|
style="--_cols: repeat(${Math.max(1, items.length)}, minmax(0, 1fr))">
|
|
67
75
|
${this.selectable
|
|
68
76
|
? html `<span class="cell" role=${t ? 'columnheader' : nothing}><span class="check">
|
|
69
|
-
<input id="${__classPrivateFieldGet(this, _CmTableHeader_id, "f")}-all" type="checkbox" aria-label
|
|
77
|
+
<input id="${__classPrivateFieldGet(this, _CmTableHeader_id, "f")}-all" type="checkbox" aria-label=${this.t('selectAll')} .checked=${this.checked} .indeterminate=${this.indeterminate}
|
|
70
78
|
@change=${__classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_onSelectAll)} />
|
|
71
79
|
<span class="box" aria-hidden="true">${this.indeterminate ? html `<span class="dash"></span>` : this.checked ? html `<cm-icon name="check" size="14"></cm-icon>` : nothing}</span>
|
|
72
80
|
</span></span>`
|
|
@@ -78,7 +86,7 @@ export class CmTableHeader extends LitElement {
|
|
|
78
86
|
return html `<span class="cell" part="cell" data-align=${c.align ?? 'start'} role=${t ? 'columnheader' : nothing}
|
|
79
87
|
aria-sort=${t && c.sortable ? state : nothing}>${c.sortable
|
|
80
88
|
? html `<button type="button" class=${on ? 'on' : ''} @click=${() => __classPrivateFieldGet(this, _CmTableHeader_instances, "m", _CmTableHeader_onSort).call(this, c)}>${label}${!t
|
|
81
|
-
? html `<span class="sr">${on ?
|
|
89
|
+
? html `<span class="sr">${on ? this.t('sorted', { direction: this.t(state) }) : this.t('sortable')}</span>` : nothing}<cm-icon
|
|
82
90
|
name=${on && this.direction === 'descending' ? 'chevron-down' : 'chevron-up'} size="12"></cm-icon></button>`
|
|
83
91
|
: label}</span>`;
|
|
84
92
|
})}
|
|
@@ -125,7 +133,7 @@ CmTableHeader.styles = [
|
|
|
125
133
|
background: var(--cm-bg-hover); border: var(--cm-border-1) solid var(--cm-border-subtle);
|
|
126
134
|
border-radius: var(--cm-radius-md) var(--cm-radius-md) 0 0;
|
|
127
135
|
}
|
|
128
|
-
.bar.sel { grid-template-columns: 20px var(--cm-table-columns, var(--_cols)); padding-
|
|
136
|
+
.bar.sel { grid-template-columns: 20px var(--cm-table-columns, var(--_cols)); padding-inline-start: var(--cm-space-10); }
|
|
129
137
|
.cell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
130
138
|
.cell[data-align='center'] { text-align: center; }
|
|
131
139
|
.cell[data-align='end'] { text-align: end; }
|
package/dist/components/tag.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
2
|
import './icon.js';
|
|
3
|
+
declare const strings: {
|
|
4
|
+
/** Accessible name of the remove button. `{label}` is the tag's text. */
|
|
5
|
+
remove: string;
|
|
6
|
+
};
|
|
7
|
+
declare module '../localize.js' {
|
|
8
|
+
interface CmStrings {
|
|
9
|
+
tag: typeof strings;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Pill for a product tag or an applied filter value, optionally with a remove button.
|
|
5
14
|
* Removing is up to you: listen for `cm-remove` and take the tag out of your list,
|
|
@@ -8,7 +17,7 @@ import './icon.js';
|
|
|
8
17
|
* @slot - The tag text.
|
|
9
18
|
* @fires cm-remove - When the remove button is pressed.
|
|
10
19
|
*/
|
|
11
|
-
export declare class CmTag extends
|
|
20
|
+
export declare class CmTag extends CmLocalizedElement {
|
|
12
21
|
#private;
|
|
13
22
|
static properties: {
|
|
14
23
|
removable: {
|
|
@@ -37,3 +46,4 @@ declare global {
|
|
|
37
46
|
'cm-tag': CmTag;
|
|
38
47
|
}
|
|
39
48
|
}
|
|
49
|
+
export {};
|
package/dist/components/tag.js
CHANGED
|
@@ -4,9 +4,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _CmTag_instances, _CmTag_remove;
|
|
7
|
-
import {
|
|
7
|
+
import { html, css, nothing } from 'lit';
|
|
8
8
|
import { base, define } from '../base.js';
|
|
9
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
9
10
|
import './icon.js';
|
|
11
|
+
const strings = defineStrings('tag', {
|
|
12
|
+
/** Accessible name of the remove button. `{label}` is the tag's text. */
|
|
13
|
+
remove: 'Remove {label}',
|
|
14
|
+
});
|
|
10
15
|
/**
|
|
11
16
|
* Pill for a product tag or an applied filter value, optionally with a remove button.
|
|
12
17
|
* Removing is up to you: listen for `cm-remove` and take the tag out of your list,
|
|
@@ -15,7 +20,7 @@ import './icon.js';
|
|
|
15
20
|
* @slot - The tag text.
|
|
16
21
|
* @fires cm-remove - When the remove button is pressed.
|
|
17
22
|
*/
|
|
18
|
-
export class CmTag extends
|
|
23
|
+
export class CmTag extends CmLocalizedElement {
|
|
19
24
|
constructor() {
|
|
20
25
|
super(...arguments);
|
|
21
26
|
_CmTag_instances.add(this);
|
|
@@ -27,7 +32,7 @@ export class CmTag extends LitElement {
|
|
|
27
32
|
this.disabled = false;
|
|
28
33
|
}
|
|
29
34
|
render() {
|
|
30
|
-
const name = this.removeLabel ||
|
|
35
|
+
const name = this.removeLabel || this.t('remove', { label: this.textContent?.trim() ?? '' }).trim();
|
|
31
36
|
return html `<span class="tag" part="tag"><span class="text"><slot @slotchange=${() => this.requestUpdate()}></slot></span>${this.removable
|
|
32
37
|
? html `<button type="button" part="remove" aria-label=${name} ?disabled=${this.disabled} @click=${__classPrivateFieldGet(this, _CmTag_instances, "m", _CmTag_remove)}><cm-icon name="x-circle" size="14"></cm-icon></button>`
|
|
33
38
|
: nothing}</span>`;
|
|
@@ -52,7 +57,7 @@ CmTag.styles = [
|
|
|
52
57
|
font-size: 12px; color: var(--cm-text-default); background: var(--cm-bg-tag);
|
|
53
58
|
border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full);
|
|
54
59
|
}
|
|
55
|
-
:host([removable]) .tag { padding-
|
|
60
|
+
:host([removable]) .tag { padding-inline-end: 4px; }
|
|
56
61
|
.text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
57
62
|
button {
|
|
58
63
|
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
|
+
declare const strings: {
|
|
3
|
+
/** Validation message when `required` and empty. */
|
|
4
|
+
required: string;
|
|
5
|
+
};
|
|
6
|
+
declare module '../localize.js' {
|
|
7
|
+
interface CmStrings {
|
|
8
|
+
textField: typeof strings;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Labelled single- or multi-line input. Participates in native forms.
|
|
4
13
|
* @element cm-text-field
|
|
5
14
|
* @fires input - On every keystroke (bubbles, composed).
|
|
6
15
|
* @fires change - When the value is committed.
|
|
7
16
|
*/
|
|
8
|
-
export declare class CmTextField extends
|
|
17
|
+
export declare class CmTextField extends CmLocalizedElement {
|
|
9
18
|
#private;
|
|
10
19
|
static formAssociated: boolean;
|
|
11
20
|
static shadowRootOptions: {
|
|
@@ -99,3 +108,4 @@ declare global {
|
|
|
99
108
|
'cm-text-field': CmTextField;
|
|
100
109
|
}
|
|
101
110
|
}
|
|
111
|
+
export {};
|
|
@@ -13,13 +13,18 @@ var _CmTextField_instances, _CmTextField_internals, _CmTextField_id, _CmTextFiel
|
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { base, define, nextId } from '../base.js';
|
|
16
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
const strings = defineStrings('textField', {
|
|
18
|
+
/** Validation message when `required` and empty. */
|
|
19
|
+
required: 'Please fill in this field.',
|
|
20
|
+
});
|
|
16
21
|
/**
|
|
17
22
|
* Labelled single- or multi-line input. Participates in native forms.
|
|
18
23
|
* @element cm-text-field
|
|
19
24
|
* @fires input - On every keystroke (bubbles, composed).
|
|
20
25
|
* @fires change - When the value is committed.
|
|
21
26
|
*/
|
|
22
|
-
export class CmTextField extends
|
|
27
|
+
export class CmTextField extends CmLocalizedElement {
|
|
23
28
|
constructor() {
|
|
24
29
|
super(...arguments);
|
|
25
30
|
_CmTextField_instances.add(this);
|
|
@@ -75,7 +80,7 @@ export class CmTextField extends LitElement {
|
|
|
75
80
|
if (this.error)
|
|
76
81
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ customError: true }, this.error, control ?? undefined);
|
|
77
82
|
else if (this.required && !this.value)
|
|
78
|
-
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ valueMissing: true },
|
|
83
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ valueMissing: true }, this.t('required'), control ?? undefined);
|
|
79
84
|
else
|
|
80
85
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({});
|
|
81
86
|
}
|
|
@@ -138,8 +143,8 @@ CmTextField.styles = [
|
|
|
138
143
|
:host { display: block; }
|
|
139
144
|
.field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
140
145
|
label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); }
|
|
141
|
-
.req { color: var(--cm-text-critical); margin-
|
|
142
|
-
.hint { margin-
|
|
146
|
+
.req { color: var(--cm-text-critical); margin-inline-start: 2px; }
|
|
147
|
+
.hint { margin-inline-start: var(--cm-space-10); font-size: 12px; color: var(--cm-text-tertiary); text-transform: lowercase; }
|
|
143
148
|
.input {
|
|
144
149
|
width: 100%; height: 42px; padding: 0 var(--cm-space-10);
|
|
145
150
|
font: inherit; font-size: 16px; color: var(--cm-text-default);
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
2
|
import './icon.js';
|
|
3
|
+
declare const strings: {
|
|
4
|
+
/** Accessible name of the placeholder when there is no image. */
|
|
5
|
+
noImage: string;
|
|
6
|
+
};
|
|
7
|
+
declare module '../localize.js' {
|
|
8
|
+
interface CmStrings {
|
|
9
|
+
thumbnail: typeof strings;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* A small product or file image in a fixed square box, shown whole (never cropped) on a grey backdrop.
|
|
5
14
|
* Without an image, or when it fails to load, it shows a placeholder icon.
|
|
6
15
|
* @element cm-thumbnail
|
|
7
16
|
*/
|
|
8
|
-
export declare class CmThumbnail extends
|
|
17
|
+
export declare class CmThumbnail extends CmLocalizedElement {
|
|
9
18
|
static properties: {
|
|
10
19
|
src: {};
|
|
11
20
|
alt: {};
|
|
@@ -38,3 +47,4 @@ declare global {
|
|
|
38
47
|
'cm-thumbnail': CmThumbnail;
|
|
39
48
|
}
|
|
40
49
|
}
|
|
50
|
+
export {};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { html, css, nothing } from 'lit';
|
|
2
2
|
import { base, define } from '../base.js';
|
|
3
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
3
4
|
import './icon.js';
|
|
5
|
+
const strings = defineStrings('thumbnail', {
|
|
6
|
+
/** Accessible name of the placeholder when there is no image. */
|
|
7
|
+
noImage: '{alt} (no image)',
|
|
8
|
+
});
|
|
4
9
|
/**
|
|
5
10
|
* A small product or file image in a fixed square box, shown whole (never cropped) on a grey backdrop.
|
|
6
11
|
* Without an image, or when it fails to load, it shows a placeholder icon.
|
|
7
12
|
* @element cm-thumbnail
|
|
8
13
|
*/
|
|
9
|
-
export class CmThumbnail extends
|
|
14
|
+
export class CmThumbnail extends CmLocalizedElement {
|
|
10
15
|
constructor() {
|
|
11
16
|
super(...arguments);
|
|
12
17
|
/** Image URL. */
|
|
@@ -33,7 +38,7 @@ export class CmThumbnail extends LitElement {
|
|
|
33
38
|
}
|
|
34
39
|
const size = this.size === 'small' ? 18 : this.size === 'large' ? 32 : 24;
|
|
35
40
|
return html `<span class="box" part="thumbnail" role=${this.alt ? 'img' : nothing}
|
|
36
|
-
aria-label=${this.alt ?
|
|
41
|
+
aria-label=${this.alt ? this.t('noImage', { alt: this.alt }) : nothing} aria-hidden=${this.alt ? nothing : 'true'}>
|
|
37
42
|
<cm-icon name="box" size=${size}></cm-icon></span>`;
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
2
|
import './icon.js';
|
|
3
3
|
export type ToastTone = 'default' | 'critical';
|
|
4
4
|
export type ToastDismissReason = 'timeout' | 'close' | 'action';
|
|
5
|
+
declare const regionStrings: {
|
|
6
|
+
/** Accessible name of the toast region (a live region). */
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
declare module '../localize.js' {
|
|
10
|
+
interface CmStrings {
|
|
11
|
+
toastRegion: typeof regionStrings;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* A short confirmation that appears at the bottom of the screen and goes away on its own ("Product saved").
|
|
7
16
|
* Usually shown with `showToast()`, which puts it in the page's toast region so screen readers announce it.
|
|
@@ -11,7 +20,7 @@ export type ToastDismissReason = 'timeout' | 'close' | 'action';
|
|
|
11
20
|
* @fires cm-action - The action button was pressed (cancelable; by default the toast then closes).
|
|
12
21
|
* @fires cm-dismiss - The toast is closing: `detail.reason` is `timeout`, `close` or `action` (cancelable; keeps it open).
|
|
13
22
|
*/
|
|
14
|
-
export declare class CmToast extends
|
|
23
|
+
export declare class CmToast extends CmLocalizedElement {
|
|
15
24
|
#private;
|
|
16
25
|
static properties: {
|
|
17
26
|
message: {};
|
|
@@ -67,7 +76,7 @@ export declare class CmToast extends LitElement {
|
|
|
67
76
|
* @element cm-toast-region
|
|
68
77
|
* @slot - `cm-toast` elements. Closed toasts are removed.
|
|
69
78
|
*/
|
|
70
|
-
export declare class CmToastRegion extends
|
|
79
|
+
export declare class CmToastRegion extends CmLocalizedElement {
|
|
71
80
|
#private;
|
|
72
81
|
static properties: {
|
|
73
82
|
max: {
|
|
@@ -79,6 +88,7 @@ export declare class CmToastRegion extends LitElement {
|
|
|
79
88
|
static styles: import("lit").CSSResult[];
|
|
80
89
|
connectedCallback(): void;
|
|
81
90
|
disconnectedCallback(): void;
|
|
91
|
+
updated(): void;
|
|
82
92
|
/** Adds a toast, removing the oldest ones above `max`. */
|
|
83
93
|
add(toast: CmToast): CmToast;
|
|
84
94
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -106,3 +116,4 @@ declare global {
|
|
|
106
116
|
'cm-toast-region': CmToastRegion;
|
|
107
117
|
}
|
|
108
118
|
}
|
|
119
|
+
export {};
|
package/dist/components/toast.js
CHANGED
|
@@ -9,10 +9,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CmToast_instances, _CmToast_primeTimer, _CmToast_timer, _CmToast_remaining, _CmToast_startedAt, _CmToast_hovered, _CmToast_focused, _CmToast_paused_get, _CmToast_resume, _CmToast_pause, _CmToast_onEnter, _CmToast_onLeave, _CmToast_onFocusIn, _CmToast_onFocusOut, _CmToast_action, _CmToastRegion_onDismiss;
|
|
13
|
-
import {
|
|
12
|
+
var _CmToast_instances, _CmToast_primeTimer, _CmToast_timer, _CmToast_remaining, _CmToast_startedAt, _CmToast_hovered, _CmToast_focused, _CmToast_paused_get, _CmToast_resume, _CmToast_pause, _CmToast_onEnter, _CmToast_onLeave, _CmToast_onFocusIn, _CmToast_onFocusOut, _CmToast_action, _CmToastRegion_ownLabel, _CmToastRegion_onDismiss;
|
|
13
|
+
import { html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define } from '../base.js';
|
|
15
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
15
16
|
import './icon.js';
|
|
17
|
+
const regionStrings = defineStrings('toastRegion', {
|
|
18
|
+
/** Accessible name of the toast region (a live region). */
|
|
19
|
+
label: 'Notifications',
|
|
20
|
+
});
|
|
16
21
|
const MIN = 2000;
|
|
17
22
|
const MAX = 10000;
|
|
18
23
|
/** How long a new live region gets before its first message, so screen readers register it (ms). */
|
|
@@ -26,7 +31,7 @@ const LIVE_REGION_DELAY = 150;
|
|
|
26
31
|
* @fires cm-action - The action button was pressed (cancelable; by default the toast then closes).
|
|
27
32
|
* @fires cm-dismiss - The toast is closing: `detail.reason` is `timeout`, `close` or `action` (cancelable; keeps it open).
|
|
28
33
|
*/
|
|
29
|
-
export class CmToast extends
|
|
34
|
+
export class CmToast extends CmLocalizedElement {
|
|
30
35
|
constructor() {
|
|
31
36
|
super(...arguments);
|
|
32
37
|
_CmToast_instances.add(this);
|
|
@@ -120,7 +125,7 @@ export class CmToast extends LitElement {
|
|
|
120
125
|
${this.tone === 'critical' ? html `<cm-icon class="icon" name="alert" size="20"></cm-icon>` : nothing}
|
|
121
126
|
<div class="message" part="message">${this.message}<slot></slot></div>
|
|
122
127
|
${this.actionLabel ? html `<button class="action" part="action" @click=${__classPrivateFieldGet(this, _CmToast_instances, "m", _CmToast_action)}>${this.actionLabel}</button>` : nothing}
|
|
123
|
-
<button class="close" part="close" aria-label
|
|
128
|
+
<button class="close" part="close" aria-label=${this.t('dismiss')} @click=${() => this.dismiss('close')}>
|
|
124
129
|
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="m4 4 8 8M12 4l-8 8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
|
|
125
130
|
</button>
|
|
126
131
|
</div>`;
|
|
@@ -162,7 +167,7 @@ CmToast.styles = [
|
|
|
162
167
|
.toast {
|
|
163
168
|
display: flex; align-items: center; gap: var(--cm-space-15);
|
|
164
169
|
min-block-size: 48px; max-inline-size: min(480px, calc(100vw - 32px));
|
|
165
|
-
padding: var(--cm-space-10)
|
|
170
|
+
padding-block: var(--cm-space-10); padding-inline: var(--cm-space-20) var(--cm-space-10);
|
|
166
171
|
border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-100);
|
|
167
172
|
background: var(--cm-bg-dashboard); color: var(--cm-text-on-dark);
|
|
168
173
|
outline: 1px solid var(--cm-nav-divider); font-size: 14px; line-height: 20px;
|
|
@@ -190,11 +195,13 @@ define('cm-toast', CmToast);
|
|
|
190
195
|
* @element cm-toast-region
|
|
191
196
|
* @slot - `cm-toast` elements. Closed toasts are removed.
|
|
192
197
|
*/
|
|
193
|
-
export class CmToastRegion extends
|
|
198
|
+
export class CmToastRegion extends CmLocalizedElement {
|
|
194
199
|
constructor() {
|
|
195
200
|
super(...arguments);
|
|
196
201
|
/** Most toasts shown at once. When a new one would exceed it, the oldest is removed. Default 3. */
|
|
197
202
|
this.max = 3;
|
|
203
|
+
/** The region names itself (unless the page set `aria-label`): keep that name in the current language. */
|
|
204
|
+
_CmToastRegion_ownLabel.set(this, false);
|
|
198
205
|
_CmToastRegion_onDismiss.set(this, (e) => {
|
|
199
206
|
const t = e.target;
|
|
200
207
|
// Remove after the toast has handled the event (and only if nobody cancelled it).
|
|
@@ -208,11 +215,15 @@ export class CmToastRegion extends LitElement {
|
|
|
208
215
|
this.setAttribute('aria-live', 'polite');
|
|
209
216
|
// Read each new toast on its own, not every toast still on screen.
|
|
210
217
|
this.setAttribute('aria-atomic', 'false');
|
|
211
|
-
if (!this.hasAttribute('aria-label'))
|
|
212
|
-
this.setAttribute('aria-label', '
|
|
218
|
+
if (!this.hasAttribute('aria-label')) {
|
|
219
|
+
this.setAttribute('aria-label', this.t('label'));
|
|
220
|
+
__classPrivateFieldSet(this, _CmToastRegion_ownLabel, true, "f");
|
|
221
|
+
}
|
|
213
222
|
this.addEventListener('cm-dismiss', __classPrivateFieldGet(this, _CmToastRegion_onDismiss, "f"));
|
|
214
223
|
}
|
|
215
224
|
disconnectedCallback() { super.disconnectedCallback(); this.removeEventListener('cm-dismiss', __classPrivateFieldGet(this, _CmToastRegion_onDismiss, "f")); }
|
|
225
|
+
updated() { if (__classPrivateFieldGet(this, _CmToastRegion_ownLabel, "f"))
|
|
226
|
+
this.setAttribute('aria-label', this.t('label')); }
|
|
216
227
|
/** Adds a toast, removing the oldest ones above `max`. */
|
|
217
228
|
add(toast) {
|
|
218
229
|
this.append(toast);
|
|
@@ -222,7 +233,7 @@ export class CmToastRegion extends LitElement {
|
|
|
222
233
|
}
|
|
223
234
|
render() { return html `<slot></slot>`; }
|
|
224
235
|
}
|
|
225
|
-
_CmToastRegion_onDismiss = new WeakMap();
|
|
236
|
+
_CmToastRegion_ownLabel = new WeakMap(), _CmToastRegion_onDismiss = new WeakMap();
|
|
226
237
|
CmToastRegion.properties = { max: { type: Number } };
|
|
227
238
|
CmToastRegion.styles = [
|
|
228
239
|
base,
|
|
@@ -95,6 +95,8 @@ CmToggle.styles = [
|
|
|
95
95
|
}
|
|
96
96
|
input:checked + .track { background: var(--cm-toggle-on); }
|
|
97
97
|
input:checked + .track .thumb { transform: translateX(18px); }
|
|
98
|
+
/* On is the end side: the left in right-to-left text. */
|
|
99
|
+
:host(:dir(rtl)) input:checked + .track .thumb { transform: translateX(-18px); }
|
|
98
100
|
input:focus-visible + .track { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
99
101
|
.text { display: flex; flex-direction: column; gap: 4px; padding-top: 1px; }
|
|
100
102
|
.label { font-size: 14px; }
|