@commmerce/ui 1.5.1 → 1.6.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.js +2 -0
- package/dist/cdn.js +1018 -659
- package/dist/components/action-menu.d.ts +28 -1
- package/dist/components/action-menu.js +86 -17
- package/dist/components/badge.d.ts +3 -2
- package/dist/components/badge.js +4 -3
- package/dist/components/bottom-sheet.js +1 -1
- package/dist/components/button.d.ts +5 -1
- package/dist/components/button.js +18 -6
- package/dist/components/calendar.d.ts +6 -1
- package/dist/components/calendar.js +15 -1
- package/dist/components/card.d.ts +38 -0
- package/dist/components/card.js +77 -12
- package/dist/components/checkbox.js +7 -2
- package/dist/components/color-field.js +2 -0
- package/dist/components/combobox.d.ts +27 -2
- package/dist/components/combobox.js +109 -15
- package/dist/components/data-table.d.ts +127 -9
- package/dist/components/data-table.js +577 -67
- package/dist/components/date-picker.d.ts +1 -1
- package/dist/components/date-picker.js +1 -1
- package/dist/components/date-range-picker.d.ts +1 -1
- package/dist/components/date-range-picker.js +2 -2
- package/dist/components/empty-state.d.ts +8 -6
- package/dist/components/empty-state.js +26 -17
- package/dist/components/file-upload.d.ts +49 -4
- package/dist/components/file-upload.js +136 -29
- package/dist/components/layout.d.ts +2 -2
- package/dist/components/layout.js +5 -5
- package/dist/components/menu-item.d.ts +18 -0
- package/dist/components/menu-item.js +8 -0
- package/dist/components/page-header.d.ts +6 -0
- package/dist/components/page-header.js +22 -5
- package/dist/components/pagination.d.ts +3 -2
- package/dist/components/pagination.js +13 -10
- package/dist/components/radio.js +4 -2
- package/dist/components/resource-list.d.ts +28 -3
- package/dist/components/resource-list.js +47 -15
- package/dist/components/search.d.ts +2 -2
- package/dist/components/search.js +4 -2
- package/dist/components/segmented-control.js +1 -1
- package/dist/components/select.d.ts +11 -1
- package/dist/components/select.js +17 -4
- package/dist/components/side-navigation.d.ts +1 -1
- package/dist/components/side-navigation.js +5 -3
- package/dist/components/signature-field.js +2 -2
- package/dist/components/status-tabs.d.ts +24 -4
- package/dist/components/status-tabs.js +82 -9
- package/dist/components/table-header.d.ts +1 -1
- package/dist/components/table-header.js +3 -3
- package/dist/components/tag.d.ts +7 -0
- package/dist/components/tag.js +6 -3
- package/dist/components/text-field.d.ts +1 -1
- package/dist/components/text-field.js +3 -1
- package/dist/components/toggle.js +3 -1
- package/dist/components/tooltip.d.ts +5 -2
- package/dist/components/tooltip.js +14 -9
- package/dist/custom-elements.json +1599 -129
- package/dist/density.d.ts +21 -0
- package/dist/density.js +46 -0
- package/dist/field.d.ts +9 -5
- package/dist/field.js +16 -10
- package/dist/index.d.ts +1 -1
- package/dist/popover.js +1 -1
- package/package.json +3 -3
|
@@ -179,7 +179,7 @@ export declare class CmDatePicker extends CmLocalizedElement {
|
|
|
179
179
|
disabled: boolean;
|
|
180
180
|
/** Whether the calendar is showing. */
|
|
181
181
|
open: boolean;
|
|
182
|
-
/** `small`:
|
|
182
|
+
/** `small`: a 32px box with a 13px label (filter rows and panels). Default: a 40px box (since 1.6; was 36px). On touch screens both are 44px. */
|
|
183
183
|
size: 'default' | 'small';
|
|
184
184
|
/**
|
|
185
185
|
* Adds a time box next to the date box, so the field holds a date and a time. Times are typed (`3:30 pm`, `15:30`)
|
|
@@ -107,7 +107,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
107
107
|
this.disabled = false;
|
|
108
108
|
/** Whether the calendar is showing. */
|
|
109
109
|
this.open = false;
|
|
110
|
-
/** `small`:
|
|
110
|
+
/** `small`: a 32px box with a 13px label (filter rows and panels). Default: a 40px box (since 1.6; was 36px). On touch screens both are 44px. */
|
|
111
111
|
this.size = 'default';
|
|
112
112
|
/**
|
|
113
113
|
* Adds a time box next to the date box, so the field holds a date and a time. Times are typed (`3:30 pm`, `15:30`)
|
|
@@ -214,7 +214,7 @@ export declare class CmDateRangePicker extends CmLocalizedElement {
|
|
|
214
214
|
disabled: boolean;
|
|
215
215
|
/** Whether the calendar is showing. */
|
|
216
216
|
open: boolean;
|
|
217
|
-
/** `small`:
|
|
217
|
+
/** `small`: a 32px box with a 13px label (filter rows and panels). Default: a 40px box (since 1.6; was 36px). On touch screens both are 44px. */
|
|
218
218
|
size: 'default' | 'small';
|
|
219
219
|
_startText: string;
|
|
220
220
|
_endText: string;
|
|
@@ -131,7 +131,7 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
131
131
|
this.disabled = false;
|
|
132
132
|
/** Whether the calendar is showing. */
|
|
133
133
|
this.open = false;
|
|
134
|
-
/** `small`:
|
|
134
|
+
/** `small`: a 32px box with a 13px label (filter rows and panels). Default: a 40px box (since 1.6; was 36px). On touch screens both are 44px. */
|
|
135
135
|
this.size = 'default';
|
|
136
136
|
this._startText = '';
|
|
137
137
|
this._endText = '';
|
|
@@ -472,7 +472,7 @@ CmDateRangePicker.styles = [
|
|
|
472
472
|
}
|
|
473
473
|
.preset:hover { background: var(--cm-bg-hover); }
|
|
474
474
|
.preset[aria-pressed='true'] { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
|
|
475
|
-
.status { margin: var(--cm-space-8) 0 0; font-size: var(--cm-type-body-
|
|
475
|
+
.status { margin: var(--cm-space-8) 0 0; font-size: var(--cm-type-body-xs-size); line-height: var(--cm-type-body-xs-line-height); color: var(--cm-text-tertiary); }
|
|
476
476
|
@media (max-width: 640px) {
|
|
477
477
|
.body { flex-direction: column; }
|
|
478
478
|
.presets { flex-direction: row; flex-wrap: wrap; min-width: 0; padding: 0 0 var(--cm-space-8); border-inline-end: 0; border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); }
|
|
@@ -3,12 +3,13 @@ import type { IconName } from '@commmerce/icons';
|
|
|
3
3
|
import './icon.js';
|
|
4
4
|
/**
|
|
5
5
|
* Shown in place of a list or page when there is nothing to show yet, with the next step to take.
|
|
6
|
-
*
|
|
6
|
+
* Owner standard (1.6): by default a 48px icon tile (a 24px system icon or a small image), a 16px heading, 13px text
|
|
7
|
+
* and a 36px action, 8-12px apart. `size="large"` keeps the big 160px illustration circle of earlier versions.
|
|
7
8
|
* `size="inline"` is the compact form for an empty list inside a card or table: one or two left-aligned lines,
|
|
8
9
|
* an optional small icon and an optional text action, with no circle.
|
|
9
10
|
* @element cm-empty-state
|
|
10
11
|
* @slot - Optional supporting text under the heading (inline: after it, on the same line).
|
|
11
|
-
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`. Inline: 20px.
|
|
12
|
+
* @slot image - Your own illustration or icon, drawn inside the tile (or the circle with `size="large"`/`"small"`). Decorative: give it `alt=""`. Inline: 20px.
|
|
12
13
|
* @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
|
|
13
14
|
* @fires cm-action - The text action (`action`) was pressed. Not fired when it has `action-href` (it is then a link).
|
|
14
15
|
*/
|
|
@@ -39,11 +40,12 @@ export declare class CmEmptyState extends LitElement {
|
|
|
39
40
|
/** Heading level, so the page outline stays correct. Default 2. */
|
|
40
41
|
headingLevel: 2 | 3 | 4 | 5 | 6;
|
|
41
42
|
/**
|
|
42
|
-
* `
|
|
43
|
-
* (
|
|
44
|
-
*
|
|
43
|
+
* `default` (since 1.6, owner standard: a 48px icon tile, 16px heading, 13px text; for pages, cards and lists),
|
|
44
|
+
* `large` (the 160px illustration circle, 120px on phones: a first-run page with a real illustration; the default
|
|
45
|
+
* before 1.6), `small` (a 120px circle) or `inline` (since 1.2: no tile, a 20px icon, heading and text on one or two
|
|
46
|
+
* left-aligned lines; for an empty list inside a card, panel or table). Inline shows the `icon` (default `box`); set `icon=""` for text only.
|
|
45
47
|
*/
|
|
46
|
-
size: 'large' | 'small' | 'inline';
|
|
48
|
+
size: 'default' | 'large' | 'small' | 'inline';
|
|
47
49
|
/** Text of one action drawn as a text button ("Add task", "View all"), after the text. Meant for `size="inline"`; larger sizes put a `cm-button` in the `actions` slot. Fires `cm-action`. Since 1.2. */
|
|
48
50
|
action: string;
|
|
49
51
|
/** Makes the text action a link to this URL instead of a button. Since 1.2. */
|
|
@@ -9,12 +9,13 @@ import { base, define } from '../base.js';
|
|
|
9
9
|
import './icon.js';
|
|
10
10
|
/**
|
|
11
11
|
* Shown in place of a list or page when there is nothing to show yet, with the next step to take.
|
|
12
|
-
*
|
|
12
|
+
* Owner standard (1.6): by default a 48px icon tile (a 24px system icon or a small image), a 16px heading, 13px text
|
|
13
|
+
* and a 36px action, 8-12px apart. `size="large"` keeps the big 160px illustration circle of earlier versions.
|
|
13
14
|
* `size="inline"` is the compact form for an empty list inside a card or table: one or two left-aligned lines,
|
|
14
15
|
* an optional small icon and an optional text action, with no circle.
|
|
15
16
|
* @element cm-empty-state
|
|
16
17
|
* @slot - Optional supporting text under the heading (inline: after it, on the same line).
|
|
17
|
-
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`. Inline: 20px.
|
|
18
|
+
* @slot image - Your own illustration or icon, drawn inside the tile (or the circle with `size="large"`/`"small"`). Decorative: give it `alt=""`. Inline: 20px.
|
|
18
19
|
* @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
|
|
19
20
|
* @fires cm-action - The text action (`action`) was pressed. Not fired when it has `action-href` (it is then a link).
|
|
20
21
|
*/
|
|
@@ -31,11 +32,12 @@ export class CmEmptyState extends LitElement {
|
|
|
31
32
|
/** Heading level, so the page outline stays correct. Default 2. */
|
|
32
33
|
this.headingLevel = 2;
|
|
33
34
|
/**
|
|
34
|
-
* `
|
|
35
|
-
* (
|
|
36
|
-
*
|
|
35
|
+
* `default` (since 1.6, owner standard: a 48px icon tile, 16px heading, 13px text; for pages, cards and lists),
|
|
36
|
+
* `large` (the 160px illustration circle, 120px on phones: a first-run page with a real illustration; the default
|
|
37
|
+
* before 1.6), `small` (a 120px circle) or `inline` (since 1.2: no tile, a 20px icon, heading and text on one or two
|
|
38
|
+
* left-aligned lines; for an empty list inside a card, panel or table). Inline shows the `icon` (default `box`); set `icon=""` for text only.
|
|
37
39
|
*/
|
|
38
|
-
this.size = '
|
|
40
|
+
this.size = 'default';
|
|
39
41
|
/** Text of one action drawn as a text button ("Add task", "View all"), after the text. Meant for `size="inline"`; larger sizes put a `cm-button` in the `actions` slot. Fires `cm-action`. Since 1.2. */
|
|
40
42
|
this.action = '';
|
|
41
43
|
/** Makes the text action a link to this URL instead of a button. Since 1.2. */
|
|
@@ -53,8 +55,7 @@ export class CmEmptyState extends LitElement {
|
|
|
53
55
|
return __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_renderInline).call(this, level);
|
|
54
56
|
const fallback = this.image
|
|
55
57
|
? html `<img src=${this.image} alt="" part="image">`
|
|
56
|
-
: this.icon ? html `<cm-icon name=${this.icon} size
|
|
57
|
-
` : nothing;
|
|
58
|
+
: this.icon ? html `<cm-icon name=${this.icon} size=${this.size === 'large' || this.size === 'small' ? '48' : '24'}></cm-icon>` : nothing;
|
|
58
59
|
return html `<div class="wrap" part="empty-state">
|
|
59
60
|
<div class="circle" part="circle" aria-hidden=${this.hasImage ? nothing : 'true'}>
|
|
60
61
|
<slot name="image" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasImage')}>${fallback}</slot>
|
|
@@ -104,20 +105,28 @@ CmEmptyState.styles = [
|
|
|
104
105
|
base,
|
|
105
106
|
css `
|
|
106
107
|
:host { display: block; }
|
|
108
|
+
/* Default (1.6): a 48px tile with a 24px icon, then 12px to a 16/24 heading, 4px to 13/18 text, 12px to the actions. */
|
|
107
109
|
.wrap {
|
|
108
110
|
display: flex; flex-direction: column; align-items: center; text-align: center;
|
|
109
|
-
padding: var(--cm-space-32) var(--cm-space-
|
|
111
|
+
padding: var(--cm-space-32) var(--cm-space-16);
|
|
110
112
|
}
|
|
111
113
|
.circle {
|
|
112
|
-
display: flex; align-items: center; justify-content: center; overflow: hidden;
|
|
113
|
-
width:
|
|
114
|
-
background: var(--cm-bg-
|
|
114
|
+
display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none;
|
|
115
|
+
width: 48px; height: 48px; border-radius: var(--cm-radius-md);
|
|
116
|
+
background: var(--cm-bg-tag); color: var(--cm-icon-selected);
|
|
115
117
|
}
|
|
116
118
|
.circle img, ::slotted([slot='image']) { max-width: 66%; max-height: 66%; object-fit: contain; }
|
|
117
|
-
.title { margin: var(--cm-space-
|
|
118
|
-
.text { margin-top: var(--cm-space-4); max-width: 46ch; font-size: var(--cm-
|
|
119
|
+
.title { margin: var(--cm-space-12) 0 0; font-size: var(--cm-type-heading-sm-size); line-height: var(--cm-type-heading-sm-line-height); font-weight: 600; }
|
|
120
|
+
.text { margin-top: var(--cm-space-4); max-width: 46ch; font-size: var(--cm-type-body-sm-size); line-height: var(--cm-type-body-sm-line-height); color: var(--cm-text-tertiary); }
|
|
119
121
|
.text[hidden], .actions[hidden] { display: none; }
|
|
120
|
-
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--cm-space-8); margin-top: var(--cm-space-
|
|
122
|
+
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--cm-space-8); margin-top: var(--cm-space-12); }
|
|
123
|
+
/* Large and small: the illustration circle of 1.0-1.5. */
|
|
124
|
+
:host([size='large']) .circle, :host([size='small']) .circle { border-radius: var(--cm-radius-full); background: var(--cm-bg-input-filled); }
|
|
125
|
+
:host([size='large']) .wrap { padding: var(--cm-space-32) var(--cm-space-20); }
|
|
126
|
+
:host([size='large']) .circle { width: 160px; height: 160px; }
|
|
127
|
+
:host([size='large']) .title { margin-top: var(--cm-space-24); }
|
|
128
|
+
:host([size='large']) .text { font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); }
|
|
129
|
+
:host([size='large']) .actions { margin-top: var(--cm-space-16); }
|
|
121
130
|
:host([size='small']) .wrap { padding: var(--cm-space-24) var(--cm-space-16); }
|
|
122
131
|
:host([size='small']) .circle { width: 120px; height: 120px; }
|
|
123
132
|
:host([size='small']) .title { margin-top: var(--cm-space-16); font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); }
|
|
@@ -140,8 +149,8 @@ CmEmptyState.styles = [
|
|
|
140
149
|
.text-action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
141
150
|
.inline .text-action { display: inline; min-height: 0; vertical-align: baseline; margin: 0; margin-inline-start: var(--cm-space-8); padding-block: 2px; }
|
|
142
151
|
@media (max-width: 640px) {
|
|
143
|
-
.circle { width: 120px; height: 120px; }
|
|
144
|
-
.title { margin-top: var(--cm-space-16); }
|
|
152
|
+
:host([size='large']) .circle { width: 120px; height: 120px; }
|
|
153
|
+
:host([size='large']) .title { margin-top: var(--cm-space-16); }
|
|
145
154
|
}
|
|
146
155
|
`,
|
|
147
156
|
];
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { CmLocalizedElement } from '../localize.js';
|
|
2
2
|
import './icon.js';
|
|
3
3
|
declare const strings: {
|
|
4
|
-
/** Text inside the empty zone. */
|
|
4
|
+
/** Text inside the empty zone. `{browse}` is where the `browse` word goes, drawn like a link. */
|
|
5
5
|
prompt: string;
|
|
6
|
+
/** The link-like word in the prompt. */
|
|
7
|
+
browse: string;
|
|
8
|
+
/** The prompt while files are dragged over the zone. */
|
|
9
|
+
drop: string;
|
|
10
|
+
/** Accessible name of a file's progress bar while it uploads (`setProgress`). */
|
|
11
|
+
uploading: string;
|
|
12
|
+
/** Accessible name of the button that cancels a file's upload. */
|
|
13
|
+
cancel: string;
|
|
14
|
+
/** `variant="photo"`: visible text of the Cancel button while the photo uploads. */
|
|
15
|
+
cancelShort: string;
|
|
6
16
|
/** Text of the tile that adds more files. */
|
|
7
17
|
addMore: string;
|
|
8
18
|
/** Accessible name of the list of chosen files. */
|
|
@@ -38,12 +48,21 @@ declare module '../localize.js' {
|
|
|
38
48
|
* Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
|
|
39
49
|
* Participates in native forms (submit with `enctype="multipart/form-data"`).
|
|
40
50
|
*
|
|
51
|
+
* Empty, it is one compact row (72px: an icon, "Drag files here or Browse" and the `hint` in 12px), with hover,
|
|
52
|
+
* drag-over, focus, pressed and disabled states (owner standard, 1.6; it was a 160px box). Upload the chosen files
|
|
53
|
+
* yourself: report progress with `setProgress(file, percent)` (a bar and a Cancel button on that file's tile; Cancel
|
|
54
|
+
* fires `cm-cancel`) and a failed file with `setFileError(file, message)`.
|
|
55
|
+
*
|
|
41
56
|
* `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
|
|
42
57
|
* is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
|
|
43
58
|
* back camera directly on phones.
|
|
44
59
|
* @element cm-file-upload
|
|
45
60
|
* @fires change - When files are added or removed. Read `files`.
|
|
46
61
|
* @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
|
|
62
|
+
* @fires cm-cancel - When the merchant cancels a file's upload, with `detail: { file }`: stop the upload. The file is then removed; `preventDefault()` keeps it. Since 1.6.
|
|
63
|
+
* @csspart zone - The drop zone (the compact row, the "Add more" tile, or the empty photo tile).
|
|
64
|
+
* @csspart files - The list of chosen files.
|
|
65
|
+
* @csspart progress - A file's progress bar while it uploads.
|
|
47
66
|
*/
|
|
48
67
|
export declare class CmFileUpload extends CmLocalizedElement {
|
|
49
68
|
#private;
|
|
@@ -98,12 +117,27 @@ export declare class CmFileUpload extends CmLocalizedElement {
|
|
|
98
117
|
_rejected: {
|
|
99
118
|
state: boolean;
|
|
100
119
|
};
|
|
120
|
+
_progress: {
|
|
121
|
+
state: boolean;
|
|
122
|
+
};
|
|
123
|
+
_fileErrors: {
|
|
124
|
+
state: boolean;
|
|
125
|
+
};
|
|
126
|
+
_over: {
|
|
127
|
+
state: boolean;
|
|
128
|
+
};
|
|
101
129
|
};
|
|
102
130
|
/** Heading above the zone, e.g. "Add product images". */
|
|
103
131
|
label: string;
|
|
104
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Accepted types and size in 12px grey, e.g. "PNG or JPG, up to 2 MB". Shown in the empty zone's row (since 1.6),
|
|
134
|
+
* next to the label once files are chosen, and under the label in the photo tile.
|
|
135
|
+
*/
|
|
105
136
|
hint: string;
|
|
106
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Text inside the zone; `{browse}` in it becomes the link-like "Browse". Default: the built-in string `prompt`
|
|
139
|
+
* ("Drag files here or {browse}"; "Click here to upload" before 1.6).
|
|
140
|
+
*/
|
|
107
141
|
prompt: string;
|
|
108
142
|
/** Form field name. */
|
|
109
143
|
name: string;
|
|
@@ -127,7 +161,8 @@ export declare class CmFileUpload extends CmLocalizedElement {
|
|
|
127
161
|
* `photo` (since 1.3): a single-photo tile for phones. It shows a camera icon and the `label` (or the prompt
|
|
128
162
|
* "Take a photo" without one); after a photo is taken it fills the tile, with Retake and Remove buttons under it.
|
|
129
163
|
* One file only (`multiple` is ignored); `accept` defaults to `image/*`. Size the tile with CSS on the element;
|
|
130
|
-
* it is 4:3 (change it with `::part(photo)`, e.g. `aspect-ratio: 16 / 10` for a visiting card).
|
|
164
|
+
* it is 4:3 (change it with `::part(photo)`, e.g. `aspect-ratio: 16 / 10` for a visiting card). Empty, the tile is
|
|
165
|
+
* at most 120px tall (since 1.6; 4:3 when it is narrower than 160px).
|
|
131
166
|
*/
|
|
132
167
|
variant?: 'photo';
|
|
133
168
|
/**
|
|
@@ -137,6 +172,9 @@ export declare class CmFileUpload extends CmLocalizedElement {
|
|
|
137
172
|
*/
|
|
138
173
|
capture?: 'environment' | 'user';
|
|
139
174
|
_rejected: string;
|
|
175
|
+
_progress: Map<File, number>;
|
|
176
|
+
_fileErrors: Map<File, string>;
|
|
177
|
+
_over: boolean;
|
|
140
178
|
static styles: import("lit").CSSResult[];
|
|
141
179
|
get form(): HTMLFormElement | null;
|
|
142
180
|
get validity(): ValidityState;
|
|
@@ -149,6 +187,13 @@ export declare class CmFileUpload extends CmLocalizedElement {
|
|
|
149
187
|
updated(changed: Map<string, unknown>): void;
|
|
150
188
|
/** Adds files as if the merchant had chosen them: filters by type, size and count, then fires events. */
|
|
151
189
|
addFiles(list: Iterable<File>): void;
|
|
190
|
+
/**
|
|
191
|
+
* Shows a chosen file uploading (since 1.6): a progress bar from 0 to 100 on its tile, with a Cancel button in place
|
|
192
|
+
* of Remove. `null` ends it (the upload finished, or failed: then call `setFileError`).
|
|
193
|
+
*/
|
|
194
|
+
setProgress(file: File, percent: number | null): void;
|
|
195
|
+
/** Marks one chosen file as failed (since 1.6): its tile turns red with `message` under it. `''` clears it. */
|
|
196
|
+
setFileError(file: File, message: string): void;
|
|
152
197
|
/** Removes one chosen file and fires `change`. */
|
|
153
198
|
removeFile(file: File): void;
|
|
154
199
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -3,14 +3,24 @@ 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 _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone, _CmFileUpload_retake, _CmFileUpload_renderPhoto;
|
|
6
|
+
var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_busy, _CmFileUpload_cancel, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_prompt, _CmFileUpload_file, _CmFileUpload_zone, _CmFileUpload_retake, _CmFileUpload_renderPhoto;
|
|
7
7
|
import { LitElement, html, css, nothing } from 'lit';
|
|
8
8
|
import { base, define, nextId } from '../base.js';
|
|
9
9
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
10
10
|
import './icon.js';
|
|
11
11
|
const strings = defineStrings('fileUpload', {
|
|
12
|
-
/** Text inside the empty zone. */
|
|
13
|
-
prompt: '
|
|
12
|
+
/** Text inside the empty zone. `{browse}` is where the `browse` word goes, drawn like a link. */
|
|
13
|
+
prompt: 'Drag files here or {browse}',
|
|
14
|
+
/** The link-like word in the prompt. */
|
|
15
|
+
browse: 'Browse',
|
|
16
|
+
/** The prompt while files are dragged over the zone. */
|
|
17
|
+
drop: 'Drop files to upload',
|
|
18
|
+
/** Accessible name of a file's progress bar while it uploads (`setProgress`). */
|
|
19
|
+
uploading: 'Uploading {name}',
|
|
20
|
+
/** Accessible name of the button that cancels a file's upload. */
|
|
21
|
+
cancel: 'Cancel uploading {name}',
|
|
22
|
+
/** `variant="photo"`: visible text of the Cancel button while the photo uploads. */
|
|
23
|
+
cancelShort: 'Cancel',
|
|
14
24
|
/** Text of the tile that adds more files. */
|
|
15
25
|
addMore: 'Add more',
|
|
16
26
|
/** Accessible name of the list of chosen files. */
|
|
@@ -48,12 +58,21 @@ function accepts(file, accept) {
|
|
|
48
58
|
* Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
|
|
49
59
|
* Participates in native forms (submit with `enctype="multipart/form-data"`).
|
|
50
60
|
*
|
|
61
|
+
* Empty, it is one compact row (72px: an icon, "Drag files here or Browse" and the `hint` in 12px), with hover,
|
|
62
|
+
* drag-over, focus, pressed and disabled states (owner standard, 1.6; it was a 160px box). Upload the chosen files
|
|
63
|
+
* yourself: report progress with `setProgress(file, percent)` (a bar and a Cancel button on that file's tile; Cancel
|
|
64
|
+
* fires `cm-cancel`) and a failed file with `setFileError(file, message)`.
|
|
65
|
+
*
|
|
51
66
|
* `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
|
|
52
67
|
* is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
|
|
53
68
|
* back camera directly on phones.
|
|
54
69
|
* @element cm-file-upload
|
|
55
70
|
* @fires change - When files are added or removed. Read `files`.
|
|
56
71
|
* @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
|
|
72
|
+
* @fires cm-cancel - When the merchant cancels a file's upload, with `detail: { file }`: stop the upload. The file is then removed; `preventDefault()` keeps it. Since 1.6.
|
|
73
|
+
* @csspart zone - The drop zone (the compact row, the "Add more" tile, or the empty photo tile).
|
|
74
|
+
* @csspart files - The list of chosen files.
|
|
75
|
+
* @csspart progress - A file's progress bar while it uploads.
|
|
57
76
|
*/
|
|
58
77
|
export class CmFileUpload extends CmLocalizedElement {
|
|
59
78
|
constructor() {
|
|
@@ -61,7 +80,10 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
61
80
|
_CmFileUpload_instances.add(this);
|
|
62
81
|
/** Heading above the zone, e.g. "Add product images". */
|
|
63
82
|
this.label = '';
|
|
64
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Accepted types and size in 12px grey, e.g. "PNG or JPG, up to 2 MB". Shown in the empty zone's row (since 1.6),
|
|
85
|
+
* next to the label once files are chosen, and under the label in the photo tile.
|
|
86
|
+
*/
|
|
65
87
|
this.hint = '';
|
|
66
88
|
/** Form field name. */
|
|
67
89
|
this.name = '';
|
|
@@ -82,6 +104,9 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
82
104
|
/** The chosen files. Set it to `[]` to clear. */
|
|
83
105
|
this.files = [];
|
|
84
106
|
this._rejected = '';
|
|
107
|
+
this._progress = new Map();
|
|
108
|
+
this._fileErrors = new Map();
|
|
109
|
+
this._over = false;
|
|
85
110
|
_CmFileUpload_internals.set(this, this.attachInternals());
|
|
86
111
|
_CmFileUpload_id.set(this, nextId('cm-fu'));
|
|
87
112
|
_CmFileUpload_urls.set(this, new Map());
|
|
@@ -91,7 +116,7 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
91
116
|
get validationMessage() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").validationMessage; }
|
|
92
117
|
checkValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").checkValidity(); }
|
|
93
118
|
reportValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").reportValidity(); }
|
|
94
|
-
formResetCallback() { this.files = []; this._rejected = ''; }
|
|
119
|
+
formResetCallback() { this.files = []; this._rejected = ''; this._progress = new Map(); this._fileErrors = new Map(); }
|
|
95
120
|
formDisabledCallback(d) { this.disabled = d; }
|
|
96
121
|
disconnectedCallback() {
|
|
97
122
|
super.disconnectedCallback();
|
|
@@ -153,12 +178,37 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
153
178
|
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
154
179
|
}
|
|
155
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Shows a chosen file uploading (since 1.6): a progress bar from 0 to 100 on its tile, with a Cancel button in place
|
|
183
|
+
* of Remove. `null` ends it (the upload finished, or failed: then call `setFileError`).
|
|
184
|
+
*/
|
|
185
|
+
setProgress(file, percent) {
|
|
186
|
+
const next = new Map(this._progress);
|
|
187
|
+
if (percent === null || percent === undefined)
|
|
188
|
+
next.delete(file);
|
|
189
|
+
else
|
|
190
|
+
next.set(file, Math.min(100, Math.max(0, Number(percent) || 0)));
|
|
191
|
+
this._progress = next;
|
|
192
|
+
}
|
|
193
|
+
/** Marks one chosen file as failed (since 1.6): its tile turns red with `message` under it. `''` clears it. */
|
|
194
|
+
setFileError(file, message) {
|
|
195
|
+
const next = new Map(this._fileErrors);
|
|
196
|
+
if (message)
|
|
197
|
+
next.set(file, message);
|
|
198
|
+
else
|
|
199
|
+
next.delete(file);
|
|
200
|
+
this._fileErrors = next;
|
|
201
|
+
}
|
|
156
202
|
/** Removes one chosen file and fires `change`. */
|
|
157
203
|
removeFile(file) {
|
|
158
204
|
if (!this.files.includes(file))
|
|
159
205
|
return;
|
|
160
206
|
this.files = this.files.filter((f) => f !== file);
|
|
161
207
|
this._rejected = '';
|
|
208
|
+
if (this._progress.has(file))
|
|
209
|
+
this.setProgress(file, null);
|
|
210
|
+
if (this._fileErrors.has(file))
|
|
211
|
+
this.setFileError(file, '');
|
|
162
212
|
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
163
213
|
this.updateComplete.then(() => this.renderRoot.querySelector('input')?.focus());
|
|
164
214
|
}
|
|
@@ -169,20 +219,15 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
169
219
|
const showZone = !this.files.length || this.multiple;
|
|
170
220
|
const tile = this.files.length > 0;
|
|
171
221
|
return html `
|
|
172
|
-
${this.label || this.hint
|
|
222
|
+
${this.label || (this.hint && tile)
|
|
173
223
|
? html `<div class="head">
|
|
174
224
|
${this.label ? html `<span class="label" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>` : nothing}
|
|
175
|
-
${this.hint ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing}
|
|
225
|
+
${this.hint && tile ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing}
|
|
176
226
|
</div>`
|
|
177
227
|
: nothing}
|
|
178
228
|
${tile
|
|
179
229
|
? html `<ul class="grid" part="files" role="list" style="list-style:none;margin:0;padding:0" aria-label=${this.t('files')}>
|
|
180
|
-
${this.files.map((f) =>
|
|
181
|
-
${f.type.startsWith('image/')
|
|
182
|
-
? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${f.name} />`
|
|
183
|
-
: html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_size).call(this, f.size)}</span></div>`}
|
|
184
|
-
${this.disabled ? nothing : html `<button type="button" class="remove" aria-label=${this.t('remove', { name: f.name })} @click=${() => this.removeFile(f)}><cm-icon name="close" size="12"></cm-icon></button>`}
|
|
185
|
-
</li>`)}
|
|
230
|
+
${this.files.map((f) => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_file).call(this, f))}
|
|
186
231
|
${showZone ? html `<li>${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_zone).call(this, true)}</li>` : nothing}
|
|
187
232
|
</ul>`
|
|
188
233
|
: __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_zone).call(this, false)}
|
|
@@ -201,27 +246,56 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
|
|
|
201
246
|
__classPrivateFieldGet(this, _CmFileUpload_urls, "f").set(f, u);
|
|
202
247
|
}
|
|
203
248
|
return u;
|
|
249
|
+
}, _CmFileUpload_busy = function _CmFileUpload_busy(f) { return this._progress.has(f); }, _CmFileUpload_cancel = function _CmFileUpload_cancel(f) {
|
|
250
|
+
const ok = this.dispatchEvent(new CustomEvent('cm-cancel', { detail: { file: f }, bubbles: true, composed: true, cancelable: true }));
|
|
251
|
+
this.setProgress(f, null);
|
|
252
|
+
if (ok)
|
|
253
|
+
this.removeFile(f);
|
|
204
254
|
}, _CmFileUpload_onInputChange = function _CmFileUpload_onInputChange(e) {
|
|
205
255
|
e.stopPropagation();
|
|
206
256
|
const input = e.target;
|
|
207
257
|
this.addFiles(input.files ?? []);
|
|
208
258
|
input.value = '';
|
|
209
|
-
}, _CmFileUpload_setOver = function _CmFileUpload_setOver(on) { this.toggleAttribute('data-over', on); },
|
|
259
|
+
}, _CmFileUpload_setOver = function _CmFileUpload_setOver(on) { this.toggleAttribute('data-over', on); this._over = on; }, _CmFileUpload_prompt = function _CmFileUpload_prompt() {
|
|
260
|
+
if (this._over)
|
|
261
|
+
return this.t('drop');
|
|
262
|
+
const [before, after] = this.prompt.split('{browse}');
|
|
263
|
+
return after === undefined ? before : html `${before}<span class="browse">${this.t('browse')}</span>${after}`;
|
|
264
|
+
}, _CmFileUpload_file = function _CmFileUpload_file(f) {
|
|
265
|
+
const busy = __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_busy).call(this, f), err = this._fileErrors.get(f) ?? '';
|
|
266
|
+
const errId = `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-e${this.files.indexOf(f)}`;
|
|
267
|
+
const pct = this._progress.get(f) ?? 0;
|
|
268
|
+
return html `<li class="item"><div class="file ${busy ? 'busy' : ''} ${err ? 'invalid' : ''}">
|
|
269
|
+
${f.type.startsWith('image/')
|
|
270
|
+
? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${f.name} />`
|
|
271
|
+
: html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_size).call(this, f.size)}</span></div>`}
|
|
272
|
+
${busy ? html `<div class="bar" part="progress" role="progressbar" aria-label=${this.t('uploading', { name: f.name })}
|
|
273
|
+
aria-valuemin="0" aria-valuemax="100" aria-valuenow=${Math.round(pct)}><span style="inline-size:${pct}%"></span></div>` : nothing}
|
|
274
|
+
${this.disabled ? nothing : busy
|
|
275
|
+
? html `<button type="button" class="remove" aria-label=${this.t('cancel', { name: f.name })} @click=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_cancel).call(this, f)}><cm-icon name="close" size="12"></cm-icon></button>`
|
|
276
|
+
: html `<button type="button" class="remove" aria-label=${this.t('remove', { name: f.name })} aria-describedby=${err ? errId : nothing}
|
|
277
|
+
@click=${() => this.removeFile(f)}><cm-icon name="close" size="12"></cm-icon></button>`}
|
|
278
|
+
</div>${err ? html `<p class="ferr" id=${errId} role="alert">${err}</p>` : nothing}</li>`;
|
|
279
|
+
}, _CmFileUpload_zone = function _CmFileUpload_zone(tile) {
|
|
210
280
|
const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, (this.error || this._rejected) && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
|
|
211
|
-
|
|
281
|
+
const msg = this.error || this._rejected;
|
|
282
|
+
return html `<label class="zone ${tile ? 'tile' : 'row'} ${msg && !tile ? 'invalid' : ''}" part="zone"
|
|
212
283
|
@dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
|
|
213
284
|
<input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} capture=${this.capture || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
|
|
214
285
|
?required=${this.required && !this.files.length}
|
|
215
286
|
aria-labelledby=${[this.label && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l`, `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`].filter(Boolean).join(' ')}
|
|
216
287
|
aria-describedby=${described || nothing} aria-invalid=${this.error || this._rejected ? 'true' : nothing}
|
|
217
288
|
@change=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_onInputChange)} @cancel=${(e) => e.stopPropagation()} />
|
|
218
|
-
|
|
219
|
-
></cm-icon
|
|
220
|
-
|
|
289
|
+
${tile
|
|
290
|
+
? html `<cm-icon name="plus" size="24"></cm-icon><span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${this.t('addMore')}</span>`
|
|
291
|
+
: html `<span class="ico"><cm-icon name="upload" size="20"></cm-icon></span>
|
|
292
|
+
<span class="words"><span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_prompt).call(this)}</span>${this.hint
|
|
293
|
+
? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing}</span>`}
|
|
221
294
|
</label>`;
|
|
222
295
|
}, _CmFileUpload_retake = function _CmFileUpload_retake() { this.renderRoot.querySelector('input[type=file]')?.click(); }, _CmFileUpload_renderPhoto = function _CmFileUpload_renderPhoto() {
|
|
223
|
-
const msg = this.error || this._rejected;
|
|
224
296
|
const f = this.files[0];
|
|
297
|
+
const msg = this.error || this._rejected || (f && this._fileErrors.get(f)) || '';
|
|
298
|
+
const busy = !!f && __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_busy).call(this, f);
|
|
225
299
|
const name = this.label || this.t('photo');
|
|
226
300
|
const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, msg && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
|
|
227
301
|
const input = (hidden) => html `<input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_accept_get)} capture=${this.capture || nothing}
|
|
@@ -231,21 +305,25 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
|
|
|
231
305
|
const hint = this.hint ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing;
|
|
232
306
|
return html `
|
|
233
307
|
${f
|
|
234
|
-
? html `<div class="shot" part="photo">
|
|
308
|
+
? html `<div class="shot ${busy ? 'busy' : ''}" part="photo">
|
|
235
309
|
${f.type.startsWith('image/')
|
|
236
310
|
? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${name} />`
|
|
237
311
|
: html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_size).call(this, f.size)}</span></div>`}
|
|
312
|
+
${busy ? html `<div class="bar" part="progress" role="progressbar" aria-label=${this.t('uploading', { name: f.name })}
|
|
313
|
+
aria-valuemin="0" aria-valuemax="100" aria-valuenow=${Math.round(this._progress.get(f) ?? 0)}><span style="inline-size:${this._progress.get(f) ?? 0}%"></span></div>` : nothing}
|
|
238
314
|
</div>
|
|
239
315
|
<p class="caption" aria-hidden="true">${this.label}</p>
|
|
240
316
|
${input(true)}
|
|
241
|
-
${this.disabled ? nothing : html `<div class="actions" part="actions">
|
|
317
|
+
${this.disabled ? nothing : busy ? html `<div class="actions" part="actions">
|
|
318
|
+
<button type="button" class="action" aria-label=${this.t('cancel', { name })} @click=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_cancel).call(this, f)}><cm-icon name="close" size="16"></cm-icon>${this.t('cancelShort')}</button>
|
|
319
|
+
</div>` : html `<div class="actions" part="actions">
|
|
242
320
|
<button type="button" class="action retake" aria-label=${this.t('retakeName', { name })} aria-describedby=${msg ? `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg` : nothing} @click=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_retake)}><cm-icon name="camera" size="16"></cm-icon>${this.t('retake')}</button>
|
|
243
321
|
<button type="button" class="action" aria-label=${this.t('removeName', { name })} @click=${() => this.removeFile(f)}><cm-icon name="trash" size="16"></cm-icon>${this.t('removePhoto')}</button>
|
|
244
322
|
</div>`}`
|
|
245
323
|
: html `<label class="zone photo ${msg ? 'invalid' : ''}" part="zone photo"
|
|
246
324
|
@dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
|
|
247
325
|
${input(false)}
|
|
248
|
-
<cm-icon name="camera" size="
|
|
326
|
+
<cm-icon name="camera" size="24"></cm-icon>
|
|
249
327
|
<span class="photo-label" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p" part="label">${this.label || this.t('takePhoto')}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>
|
|
250
328
|
${hint}
|
|
251
329
|
</label>`}
|
|
@@ -270,6 +348,9 @@ CmFileUpload.properties = {
|
|
|
270
348
|
variant: { reflect: true },
|
|
271
349
|
capture: { reflect: true },
|
|
272
350
|
_rejected: { state: true },
|
|
351
|
+
_progress: { state: true },
|
|
352
|
+
_fileErrors: { state: true },
|
|
353
|
+
_over: { state: true },
|
|
273
354
|
};
|
|
274
355
|
CmFileUpload.styles = [
|
|
275
356
|
base,
|
|
@@ -279,16 +360,38 @@ CmFileUpload.styles = [
|
|
|
279
360
|
.label { font-size: var(--cm-type-heading-sm-size); line-height: var(--cm-type-heading-sm-line-height); font-weight: 600; }
|
|
280
361
|
.req { color: var(--cm-text-critical); margin-inline-start: 2px; }
|
|
281
362
|
.hint { font-size: 12px; color: var(--cm-text-tertiary); }
|
|
282
|
-
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(
|
|
363
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 140px)); gap: var(--cm-space-16); }
|
|
283
364
|
.zone {
|
|
284
365
|
position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--cm-space-8);
|
|
285
|
-
|
|
286
|
-
background: var(--cm-bg-surface); border: var(--cm-border-1) dashed var(--cm-border-
|
|
366
|
+
padding: var(--cm-space-12); text-align: center; font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); color: var(--cm-text-default);
|
|
367
|
+
background: var(--cm-bg-surface); border: var(--cm-border-1) dashed var(--cm-border-input); border-radius: var(--cm-radius-md); cursor: pointer;
|
|
368
|
+
transition: background-color var(--cm-duration-fast) var(--cm-easing-standard), border-color var(--cm-duration-fast) var(--cm-easing-standard);
|
|
287
369
|
}
|
|
288
|
-
|
|
289
|
-
.zone.
|
|
370
|
+
/* The empty zone (1.6): one compact row, 72px tall. */
|
|
371
|
+
.zone.row { flex-direction: row; justify-content: flex-start; gap: var(--cm-space-12); min-height: 72px; padding: var(--cm-space-12) var(--cm-space-16); text-align: start; }
|
|
372
|
+
.ico {
|
|
373
|
+
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
|
|
374
|
+
border-radius: var(--cm-radius-md); background: var(--cm-bg-inset); color: var(--cm-icon-selected);
|
|
375
|
+
}
|
|
376
|
+
.words { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
377
|
+
.browse { font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
|
|
378
|
+
.zone .hint { overflow-wrap: anywhere; }
|
|
379
|
+
.zone:hover { background: var(--cm-bg-hover); border-color: var(--cm-border-strong); }
|
|
380
|
+
.zone:active { background: color-mix(in srgb, var(--cm-bg-hover), var(--cm-text-default) 8%); }
|
|
381
|
+
:host([data-over]) .zone { background: var(--cm-bg-hover); border-color: var(--cm-border-strong); border-style: solid; box-shadow: inset 0 0 0 1px var(--cm-border-strong); }
|
|
382
|
+
.zone.tile { min-height: 0; aspect-ratio: 1; font-size: 14px; }
|
|
290
383
|
.zone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: inherit; font-size: 0; }
|
|
291
384
|
.zone:focus-within { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
385
|
+
.zone.invalid { border-color: var(--cm-border-critical); }
|
|
386
|
+
.item { display: flex; flex-direction: column; gap: var(--cm-space-4); min-width: 0; }
|
|
387
|
+
.ferr { margin: 0; font-size: var(--cm-type-body-xs-size); line-height: var(--cm-type-body-xs-line-height); color: var(--cm-text-critical); overflow-wrap: anywhere; }
|
|
388
|
+
.file.invalid { border-color: var(--cm-border-critical); }
|
|
389
|
+
.file.busy img { opacity: 0.6; } /* text stays full strength (contrast) */
|
|
390
|
+
.bar {
|
|
391
|
+
position: absolute; inset-inline: var(--cm-space-8); inset-block-end: var(--cm-space-8); height: 4px; overflow: hidden;
|
|
392
|
+
border-radius: var(--cm-radius-full); background: var(--cm-bg-inset); box-shadow: 0 0 0 1px var(--cm-bg-surface);
|
|
393
|
+
}
|
|
394
|
+
.bar span { display: block; height: 100%; background: var(--cm-action-primary); border-radius: inherit; transition: inline-size var(--cm-duration-base) var(--cm-easing-standard); }
|
|
292
395
|
.file {
|
|
293
396
|
position: relative; aspect-ratio: 1; border-radius: var(--cm-radius-md); background: var(--cm-bg-inset);
|
|
294
397
|
border: var(--cm-border-1) solid var(--cm-border-subtle);
|
|
@@ -307,7 +410,11 @@ CmFileUpload.styles = [
|
|
|
307
410
|
:host([disabled]) .zone { cursor: not-allowed; background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-subtle); }
|
|
308
411
|
:host([disabled]) .remove { display: none; }
|
|
309
412
|
/* variant="photo" (1.3) */
|
|
310
|
-
|
|
413
|
+
/* Empty, the tile is 4:3 up to 120px tall (1.6): a 160px-wide tile, or a full-width strip in a wider column. */
|
|
414
|
+
.zone.photo { min-height: 0; aspect-ratio: 4 / 3; max-height: 120px; gap: var(--cm-space-4); font-size: 14px; }
|
|
415
|
+
.zone.photo .hint { font-size: 12px; }
|
|
416
|
+
.shot { position: relative; }
|
|
417
|
+
.shot.busy img { opacity: 0.6; }
|
|
311
418
|
.zone.photo.invalid { border-color: var(--cm-border-critical); }
|
|
312
419
|
.photo-label { font-weight: 500; overflow-wrap: anywhere; }
|
|
313
420
|
.shot {
|
|
@@ -327,8 +434,8 @@ CmFileUpload.styles = [
|
|
|
327
434
|
.action:hover { background: var(--cm-bg-surface); }
|
|
328
435
|
.action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
329
436
|
@media (pointer: coarse) { .action { min-height: var(--cm-control-height-touch); } }
|
|
437
|
+
@media (prefers-reduced-motion: reduce) { .zone, .bar span { transition: none; } }
|
|
330
438
|
@media (max-width: 640px) {
|
|
331
|
-
.zone:not(.tile):not(.photo) { min-height: 100px; }
|
|
332
439
|
.label { font-size: var(--cm-type-heading-sm-resp-size); }
|
|
333
440
|
}
|
|
334
441
|
`,
|
|
@@ -13,13 +13,13 @@ export declare class CmLayout extends LitElement {
|
|
|
13
13
|
reflect: boolean;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
/** Space between sections, across and down: a spacing step on the 4px grid (`0`, `4`, `8`, `12`, `16`, `20`, `24`, `32`, `40`, `48`, `64`; the pre-1.5 steps `10`, `15`, `22` and `30` still work and draw as 8, 16, 24 and 32). Default `20
|
|
16
|
+
/** Space between sections, across and down: a spacing step on the 4px grid (`0`, `4`, `8`, `12`, `16`, `20`, `24`, `32`, `40`, `48`, `64`; the pre-1.5 steps `10`, `15`, `22` and `30` still work and draw as 8, 16, 24 and 32). Default `24` (owner standard, 1.6: 24px between page sections; was 20). */
|
|
17
17
|
gap: SpaceStep;
|
|
18
18
|
static styles: import("lit").CSSResult[];
|
|
19
19
|
render(): import("lit-html").TemplateResult<1>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* One column of a `cm-layout`. Its children are stacked `space-
|
|
22
|
+
* One column of a `cm-layout`. Its children are stacked `space-24` apart (cards on the page; since 1.6, was `space-20`).
|
|
23
23
|
* @element cm-layout-section
|
|
24
24
|
* @slot - The section's content, usually cards.
|
|
25
25
|
*/
|