@commmerce/ui 1.0.0-rc.3 → 1.0.0-rc.5
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/README.md +1 -1
- 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 +4 -4
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __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 _CmDateRangePicker_instances, _CmDateRangePicker_localeProp, _CmDateRangePicker_internals, _CmDateRangePicker_id, _CmDateRangePicker_default, _CmDateRangePicker_keepText, _CmDateRangePicker_focusGrid, _CmDateRangePicker_locale_get, _CmDateRangePicker_fmt_get, _CmDateRangePicker_firstDay_get, _CmDateRangePicker_picking, _CmDateRangePicker_pattern_get, _CmDateRangePicker_format, _CmDateRangePicker_emit, _CmDateRangePicker_setRange, _CmDateRangePicker_commitText, _CmDateRangePicker_pick, _CmDateRangePicker_applyPreset, _CmDateRangePicker_focusTrigger, _CmDateRangePicker_toggle, _CmDateRangePicker_onInputKey, _CmDateRangePicker_onGridKey, _CmDateRangePicker_onPopKey, _CmDateRangePicker_onOutside, _CmDateRangePicker_mark;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { live } from 'lit/directives/live.js';
|
|
15
|
+
import { base, define, nextId, logicalKey } from '../base.js';
|
|
16
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
import { fromISO, toISO, addDays, addMonths, startOfMonth, endOfMonth, clamp, gridKey, renderGrid, calendarStyles, dateFormat, parseDate, resolveLocale, localeFirstDay, listConverter, asList, trapTab, dateFieldStyles, datePattern, } from '../calendar.js';
|
|
18
|
+
import './icon.js';
|
|
19
|
+
const strings = defineStrings('dateRangePicker', {
|
|
20
|
+
/** Calendar button while the range is not set. */
|
|
21
|
+
choose: 'Choose dates',
|
|
22
|
+
chooseFor: 'Choose dates for {label}',
|
|
23
|
+
/** Calendar button once set. `{start}` and `{end}` are full dates. */
|
|
24
|
+
change: 'Change dates, {start} to {end}',
|
|
25
|
+
changeFor: 'Change dates for {label}, {start} to {end}',
|
|
26
|
+
/** Accessible name of the calendar popup. */
|
|
27
|
+
dialog: 'Choose dates',
|
|
28
|
+
previousMonth: 'Previous month',
|
|
29
|
+
nextMonth: 'Next month',
|
|
30
|
+
/** Accessible names of the two inputs. */
|
|
31
|
+
start: 'Start date',
|
|
32
|
+
end: 'End date',
|
|
33
|
+
/** Accessible name of the list of preset ranges. */
|
|
34
|
+
presets: 'Preset ranges',
|
|
35
|
+
/** Line under the calendar while picking. */
|
|
36
|
+
chooseStart: 'Choose the start date.',
|
|
37
|
+
chooseEnd: 'Start date {date}. Choose the end date.',
|
|
38
|
+
/** Added to the start and end days' accessible names. */
|
|
39
|
+
startNote: 'start date',
|
|
40
|
+
endNote: 'end date',
|
|
41
|
+
patternDay: 'dd',
|
|
42
|
+
patternMonth: 'mm',
|
|
43
|
+
patternYear: 'yyyy',
|
|
44
|
+
badStart: 'Enter a start date like {pattern}.',
|
|
45
|
+
badEnd: 'Enter an end date like {pattern}.',
|
|
46
|
+
required: 'Enter or choose a start and end date.',
|
|
47
|
+
endBeforeStart: 'The end date is before the start date.',
|
|
48
|
+
rangeUnderflow: 'Choose {date} or later.',
|
|
49
|
+
rangeOverflow: 'Choose {date} or earlier.',
|
|
50
|
+
unavailable: 'A chosen date isn\'t available. Choose another date.',
|
|
51
|
+
/** Preset labels. */
|
|
52
|
+
today: 'Today',
|
|
53
|
+
yesterday: 'Yesterday',
|
|
54
|
+
last7Days: 'Last 7 days',
|
|
55
|
+
last30Days: 'Last 30 days',
|
|
56
|
+
last90Days: 'Last 90 days',
|
|
57
|
+
thisMonth: 'This month',
|
|
58
|
+
lastMonth: 'Last month',
|
|
59
|
+
});
|
|
60
|
+
const PRESETS = {
|
|
61
|
+
'today': ['Today', (t) => [t, t]],
|
|
62
|
+
'yesterday': ['Yesterday', (t) => [addDays(t, -1), addDays(t, -1)]],
|
|
63
|
+
'last-7-days': ['Last 7 days', (t) => [addDays(t, -6), t]],
|
|
64
|
+
'last-30-days': ['Last 30 days', (t) => [addDays(t, -29), t]],
|
|
65
|
+
'last-90-days': ['Last 90 days', (t) => [addDays(t, -89), t]],
|
|
66
|
+
'this-month': ['This month', (t) => [startOfMonth(t), t]],
|
|
67
|
+
'last-month': ['Last month', (t) => [startOfMonth(addMonths(t, -1)), endOfMonth(addMonths(t, -1))]],
|
|
68
|
+
};
|
|
69
|
+
const presetKey = (k) => k.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a preset key or object to a label and ISO dates (relative to today). Unknown keys return null.
|
|
72
|
+
* `label` translates a key's label (it gets the key in camelCase, e.g. `last7Days`); English otherwise.
|
|
73
|
+
*/
|
|
74
|
+
export function resolvePreset(p, today = new Date(), label) {
|
|
75
|
+
if (typeof p === 'object' && p)
|
|
76
|
+
return p;
|
|
77
|
+
const def = PRESETS[p];
|
|
78
|
+
if (!def)
|
|
79
|
+
return null;
|
|
80
|
+
const t = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
81
|
+
const [s, e] = def[1](t);
|
|
82
|
+
return { label: label?.(presetKey(p)) || def[0], start: toISO(s), end: toISO(e) };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Date range field for report and order filters: type a start and end date or pick them in a calendar, or choose
|
|
86
|
+
* a preset range such as "Last 7 days". The calendar is the same APG date picker grid as `cm-date-picker`: the first
|
|
87
|
+
* date picked is the start, the second the end. Participates in native forms: submits `<name>-start` and
|
|
88
|
+
* `<name>-end` (or `start-name` / `end-name`) as ISO `yyyy-mm-dd`.
|
|
89
|
+
* @element cm-date-range-picker
|
|
90
|
+
* @fires change - When the range changes: both dates picked, a preset chosen, or a typed date committed.
|
|
91
|
+
* @fires input - Same moment as `change`.
|
|
92
|
+
* @csspart box - The bordered box around the two inputs and the calendar button.
|
|
93
|
+
* @csspart calendar - The month grid.
|
|
94
|
+
* @csspart presets - The list of preset ranges.
|
|
95
|
+
*/
|
|
96
|
+
export class CmDateRangePicker extends CmLocalizedElement {
|
|
97
|
+
constructor() {
|
|
98
|
+
super(...arguments);
|
|
99
|
+
_CmDateRangePicker_instances.add(this);
|
|
100
|
+
/** Visible label above the box, e.g. "Order date". Required for accessibility unless the element has an aria-label. */
|
|
101
|
+
this.label = '';
|
|
102
|
+
/** One sentence under the box in text-tertiary. */
|
|
103
|
+
this.helpText = '';
|
|
104
|
+
/** Error message; turns the border critical and sets aria-invalid. */
|
|
105
|
+
this.error = '';
|
|
106
|
+
/** Form field name. The range is submitted as `<name>-start` and `<name>-end` unless `start-name` / `end-name` are set. */
|
|
107
|
+
this.name = '';
|
|
108
|
+
/** Form entry name for the start date (instead of `<name>-start`). `name` must still be set for the form to include the field. */
|
|
109
|
+
this.startName = '';
|
|
110
|
+
/** Form entry name for the end date (instead of `<name>-end`). */
|
|
111
|
+
this.endName = '';
|
|
112
|
+
/** Start of the range, ISO `yyyy-mm-dd`; empty when not set. */
|
|
113
|
+
this.start = '';
|
|
114
|
+
/** End of the range, ISO `yyyy-mm-dd`; empty when not set. */
|
|
115
|
+
this.end = '';
|
|
116
|
+
/** Earliest date that can be chosen, ISO `yyyy-mm-dd`. */
|
|
117
|
+
this.min = '';
|
|
118
|
+
/** Latest date that can be chosen, ISO `yyyy-mm-dd`. For reports, usually today. */
|
|
119
|
+
this.max = '';
|
|
120
|
+
_CmDateRangePicker_localeProp.set(this, '');
|
|
121
|
+
/** Dates that can't be chosen, as ISO strings. In HTML, a comma- or space-separated list. */
|
|
122
|
+
this.disabledDates = [];
|
|
123
|
+
/**
|
|
124
|
+
* Preset ranges shown beside the calendar: keys (`today`, `yesterday`, `last-7-days`, `last-30-days`, `last-90-days`,
|
|
125
|
+
* `this-month`, `last-month`) or `{ label, start, end }` objects. In HTML, a space-separated list of keys.
|
|
126
|
+
*/
|
|
127
|
+
this.presets = [];
|
|
128
|
+
/** The form will not submit until both dates are set. */
|
|
129
|
+
this.required = false;
|
|
130
|
+
/** Blocks interaction. Also set by a disabled `<fieldset>`. */
|
|
131
|
+
this.disabled = false;
|
|
132
|
+
/** Whether the calendar is showing. */
|
|
133
|
+
this.open = false;
|
|
134
|
+
/** `small`: 12px label, 14px values (filter panels). */
|
|
135
|
+
this.size = 'default';
|
|
136
|
+
this._startText = '';
|
|
137
|
+
this._endText = '';
|
|
138
|
+
this._focus = new Date();
|
|
139
|
+
this._draftStart = '';
|
|
140
|
+
this._draftEnd = '';
|
|
141
|
+
this._hover = null;
|
|
142
|
+
_CmDateRangePicker_internals.set(this, this.attachInternals());
|
|
143
|
+
_CmDateRangePicker_id.set(this, nextId('cm-drp'));
|
|
144
|
+
_CmDateRangePicker_default.set(this, null);
|
|
145
|
+
_CmDateRangePicker_keepText.set(this, false);
|
|
146
|
+
_CmDateRangePicker_focusGrid.set(this, false);
|
|
147
|
+
_CmDateRangePicker_picking.set(this, 'start');
|
|
148
|
+
_CmDateRangePicker_toggle.set(this, () => {
|
|
149
|
+
if (this.disabled)
|
|
150
|
+
return;
|
|
151
|
+
if (this.open)
|
|
152
|
+
this.open = false;
|
|
153
|
+
else {
|
|
154
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_commitText).call(this, 'start');
|
|
155
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_commitText).call(this, 'end');
|
|
156
|
+
this.show();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
_CmDateRangePicker_onInputKey.set(this, (which) => (e) => {
|
|
160
|
+
if (e.key === 'Enter')
|
|
161
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_commitText).call(this, which);
|
|
162
|
+
else if (e.key === 'ArrowDown' && e.altKey) {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_commitText).call(this, which);
|
|
165
|
+
this.show();
|
|
166
|
+
}
|
|
167
|
+
else if (e.key === 'Escape' && this.open) {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
this.open = false;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
_CmDateRangePicker_onGridKey.set(this, (e) => {
|
|
173
|
+
const next = gridKey(logicalKey(e, this), e, this._focus, __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_firstDay_get));
|
|
174
|
+
if (next) {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
this._focus = clamp(next, fromISO(this.min), fromISO(this.max));
|
|
177
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_focusGrid, true, "f");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_pick).call(this, this._focus);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
_CmDateRangePicker_onPopKey.set(this, (e) => {
|
|
186
|
+
if (e.key === 'Escape') {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
e.stopPropagation();
|
|
189
|
+
this.open = false;
|
|
190
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_focusTrigger).call(this);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
trapTab(e, e.currentTarget);
|
|
194
|
+
});
|
|
195
|
+
_CmDateRangePicker_onOutside.set(this, (e) => {
|
|
196
|
+
if (this.open && !e.composedPath().includes(this))
|
|
197
|
+
this.open = false;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* BCP 47 language for month and weekday names and the typed date order. Empty: the same language as every other
|
|
202
|
+
* component (`configure({ locale })`, else the nearest `lang` attribute, else the browser's).
|
|
203
|
+
*/
|
|
204
|
+
get locale() { return __classPrivateFieldGet(this, _CmDateRangePicker_localeProp, "f"); }
|
|
205
|
+
set locale(v) { const old = __classPrivateFieldGet(this, _CmDateRangePicker_localeProp, "f"); __classPrivateFieldSet(this, _CmDateRangePicker_localeProp, v ?? '', "f"); this.requestUpdate('locale', old); }
|
|
206
|
+
connectedCallback() {
|
|
207
|
+
super.connectedCallback();
|
|
208
|
+
if (!__classPrivateFieldGet(this, _CmDateRangePicker_default, "f"))
|
|
209
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_default, [this.start, this.end], "f");
|
|
210
|
+
document.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmDateRangePicker_onOutside, "f"), true);
|
|
211
|
+
}
|
|
212
|
+
disconnectedCallback() {
|
|
213
|
+
super.disconnectedCallback();
|
|
214
|
+
document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmDateRangePicker_onOutside, "f"), true);
|
|
215
|
+
}
|
|
216
|
+
get form() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").form; }
|
|
217
|
+
get validity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").validity; }
|
|
218
|
+
get validationMessage() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").validationMessage; }
|
|
219
|
+
checkValidity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").checkValidity(); }
|
|
220
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").reportValidity(); }
|
|
221
|
+
formResetCallback() {
|
|
222
|
+
[this.start, this.end] = __classPrivateFieldGet(this, _CmDateRangePicker_default, "f") ?? ['', ''];
|
|
223
|
+
this._startText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.start);
|
|
224
|
+
this._endText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.end);
|
|
225
|
+
this.open = false;
|
|
226
|
+
}
|
|
227
|
+
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
228
|
+
this.open = false; }
|
|
229
|
+
formStateRestoreCallback(state) { [this.start = '', this.end = ''] = (state ?? '').split('/'); }
|
|
230
|
+
/** Opens the calendar. */
|
|
231
|
+
show() {
|
|
232
|
+
if (this.disabled)
|
|
233
|
+
return;
|
|
234
|
+
this._draftStart = fromISO(this.start) ? this.start : '';
|
|
235
|
+
this._draftEnd = fromISO(this.end) ? this.end : '';
|
|
236
|
+
this._hover = null;
|
|
237
|
+
const t = new Date();
|
|
238
|
+
this._focus = clamp(fromISO(this.start) ?? new Date(t.getFullYear(), t.getMonth(), t.getDate()), fromISO(this.min), fromISO(this.max));
|
|
239
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_picking, 'start', "f");
|
|
240
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_focusGrid, true, "f");
|
|
241
|
+
this.open = true;
|
|
242
|
+
}
|
|
243
|
+
/** Closes the calendar without changing the range. */
|
|
244
|
+
close() { this.open = false; }
|
|
245
|
+
/** True when a date can't be chosen (outside min/max, in `disabledDates` or refused by `isDateDisabled`). */
|
|
246
|
+
isUnavailable(iso) {
|
|
247
|
+
const d = fromISO(iso);
|
|
248
|
+
if (!d)
|
|
249
|
+
return true;
|
|
250
|
+
const min = fromISO(this.min), max = fromISO(this.max);
|
|
251
|
+
if ((min && d < min) || (max && d > max))
|
|
252
|
+
return true;
|
|
253
|
+
return asList(this.disabledDates).includes(iso) || !!this.isDateDisabled?.(iso);
|
|
254
|
+
}
|
|
255
|
+
willUpdate(changed) {
|
|
256
|
+
if (!__classPrivateFieldGet(this, _CmDateRangePicker_keepText, "f")) {
|
|
257
|
+
if (changed.has('start'))
|
|
258
|
+
this._startText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.start);
|
|
259
|
+
if (changed.has('end'))
|
|
260
|
+
this._endText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.end);
|
|
261
|
+
}
|
|
262
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_keepText, false, "f");
|
|
263
|
+
if (changed.has('locale')) {
|
|
264
|
+
if (fromISO(this.start))
|
|
265
|
+
this._startText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.start);
|
|
266
|
+
if (fromISO(this.end))
|
|
267
|
+
this._endText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.end);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
updated() {
|
|
271
|
+
const s = fromISO(this.start), e = fromISO(this.end);
|
|
272
|
+
const fd = new FormData();
|
|
273
|
+
if (this.name || this.startName) {
|
|
274
|
+
if (s)
|
|
275
|
+
fd.append(this.startName || `${this.name}-start`, this.start);
|
|
276
|
+
}
|
|
277
|
+
if (this.name || this.endName) {
|
|
278
|
+
if (e)
|
|
279
|
+
fd.append(this.endName || `${this.name}-end`, this.end);
|
|
280
|
+
}
|
|
281
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setFormValue(s || e ? fd : null, `${this.start}/${this.end}`);
|
|
282
|
+
const inputs = this.renderRoot.querySelectorAll('input');
|
|
283
|
+
const [inS, inE] = [inputs[0] ?? undefined, inputs[1] ?? undefined];
|
|
284
|
+
const fmt = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get);
|
|
285
|
+
const min = fromISO(this.min), max = fromISO(this.max);
|
|
286
|
+
if (this.error)
|
|
287
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ customError: true }, this.error, inS);
|
|
288
|
+
else if (this._startText.trim() && !s)
|
|
289
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ badInput: true }, this.t('badStart', { pattern: __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_pattern_get) }), inS);
|
|
290
|
+
else if (this._endText.trim() && !e)
|
|
291
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ badInput: true }, this.t('badEnd', { pattern: __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_pattern_get) }), inE);
|
|
292
|
+
else if (this.required && (!s || !e))
|
|
293
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ valueMissing: true }, this.t('required'), !s ? inS : inE);
|
|
294
|
+
else if (s && e && e < s)
|
|
295
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ badInput: true }, this.t('endBeforeStart'), inE);
|
|
296
|
+
else if ((s && min && s < min) || (e && min && e < min))
|
|
297
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ rangeUnderflow: true }, this.t('rangeUnderflow', { date: fmt.medium(min) }), inS);
|
|
298
|
+
else if ((s && max && s > max) || (e && max && e > max))
|
|
299
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ rangeOverflow: true }, this.t('rangeOverflow', { date: fmt.medium(max) }), inE);
|
|
300
|
+
else if ((s && this.isUnavailable(this.start)) || (e && this.isUnavailable(this.end)))
|
|
301
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ customError: true }, this.t('unavailable'), inS);
|
|
302
|
+
else
|
|
303
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({});
|
|
304
|
+
if (this.open && __classPrivateFieldGet(this, _CmDateRangePicker_focusGrid, "f")) {
|
|
305
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_focusGrid, false, "f");
|
|
306
|
+
this.renderRoot.querySelector('td[tabindex="0"]')?.focus();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
render() {
|
|
310
|
+
const fmt = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get);
|
|
311
|
+
const s = fromISO(this.start), e = fromISO(this.end);
|
|
312
|
+
const described = [this.error && `${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-help`].filter(Boolean).join(' ');
|
|
313
|
+
const hostLabel = this.getAttribute('aria-label');
|
|
314
|
+
const name = this.label || hostLabel || '';
|
|
315
|
+
const presets = asList(this.presets).map((p) => resolvePreset(p, new Date(), (k) => this.t(k))).filter((p) => !!p);
|
|
316
|
+
const status = __classPrivateFieldGet(this, _CmDateRangePicker_picking, "f") === 'end' && this._draftStart
|
|
317
|
+
? this.t('chooseEnd', { date: fmt.medium(fromISO(this._draftStart)) })
|
|
318
|
+
: this.t('chooseStart');
|
|
319
|
+
const input = (which) => {
|
|
320
|
+
const text = which === 'start' ? this._startText : this._endText;
|
|
321
|
+
return html `<input id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-${which}" type="text" autocomplete="off" spellcheck="false"
|
|
322
|
+
.value=${live(text)} placeholder=${__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_pattern_get)}
|
|
323
|
+
aria-label=${which === 'start' ? this.startLabel || this.t('start') : this.endLabel || this.t('end')}
|
|
324
|
+
?required=${this.required} ?disabled=${this.disabled}
|
|
325
|
+
aria-invalid=${this.error ? 'true' : nothing} aria-describedby=${described || nothing}
|
|
326
|
+
@input=${(ev) => { ev.stopPropagation(); const v = ev.target.value; if (which === 'start')
|
|
327
|
+
this._startText = v;
|
|
328
|
+
else
|
|
329
|
+
this._endText = v; }}
|
|
330
|
+
@change=${() => __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_commitText).call(this, which)} @keydown=${__classPrivateFieldGet(this, _CmDateRangePicker_onInputKey, "f").call(this, which)} />`;
|
|
331
|
+
};
|
|
332
|
+
return html `<div class="field" role="group" aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-l` : nothing} aria-label=${!this.label && hostLabel ? hostLabel : nothing}>
|
|
333
|
+
${this.label
|
|
334
|
+
? html `<span class="label" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-l" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>`
|
|
335
|
+
: nothing}
|
|
336
|
+
<div class="wrap">
|
|
337
|
+
<div class="box" part="box">
|
|
338
|
+
${input('start')}<span class="sep" aria-hidden="true">–</span>${input('end')}
|
|
339
|
+
<button type="button" class="trigger" part="trigger" ?disabled=${this.disabled}
|
|
340
|
+
aria-label=${s && e ? this.t(name ? 'changeFor' : 'change', { label: name, start: fmt.long(s), end: fmt.long(e) }) : this.t(name ? 'chooseFor' : 'choose', { label: name })}
|
|
341
|
+
aria-haspopup="dialog" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-pop"
|
|
342
|
+
@click=${__classPrivateFieldGet(this, _CmDateRangePicker_toggle, "f")}><cm-icon name="calendar" size="18"></cm-icon></button>
|
|
343
|
+
</div>
|
|
344
|
+
<div class="pop" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-pop" part="popover" role="dialog" aria-modal="true" aria-label=${this.t('dialog')}
|
|
345
|
+
?hidden=${!this.open} @keydown=${__classPrivateFieldGet(this, _CmDateRangePicker_onPopKey, "f")}>
|
|
346
|
+
${this.open ? html `<div class="body">
|
|
347
|
+
${presets.length ? html `<ul class="presets" part="presets" aria-label=${this.t('presets')}>${presets.map((p) => html `<li>
|
|
348
|
+
<button type="button" class="preset" aria-pressed=${p.start === this.start && p.end === this.end ? 'true' : 'false'}
|
|
349
|
+
@click=${() => __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_applyPreset).call(this, p)}>${p.label}</button></li>`)}</ul>` : nothing}
|
|
350
|
+
<div class="cal">${renderGrid({
|
|
351
|
+
id: __classPrivateFieldGet(this, _CmDateRangePicker_id, "f"), fmt, firstDay: __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_firstDay_get), month: startOfMonth(this._focus), focus: this._focus,
|
|
352
|
+
min: fromISO(this.min), max: fromISO(this.max),
|
|
353
|
+
isDisabled: (d) => this.isUnavailable(toISO(d)),
|
|
354
|
+
mark: (d) => __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_mark).call(this, d),
|
|
355
|
+
note: (d) => { const m = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_mark).call(this, d); return m === 'start' ? this.t('startNote') : m === 'end' ? this.t('endNote') : ''; },
|
|
356
|
+
onPick: (d) => __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_pick).call(this, d), onKey: __classPrivateFieldGet(this, _CmDateRangePicker_onGridKey, "f"),
|
|
357
|
+
onMonth: (step) => { this._focus = clamp(addMonths(this._focus, step), fromISO(this.min), fromISO(this.max)); },
|
|
358
|
+
previousLabel: this.t('previousMonth'), nextLabel: this.t('nextMonth'),
|
|
359
|
+
onHover: (d) => { if (__classPrivateFieldGet(this, _CmDateRangePicker_picking, "f") === 'end')
|
|
360
|
+
this._hover = d; },
|
|
361
|
+
})}
|
|
362
|
+
<p class="status" aria-live="polite">${status}</p>
|
|
363
|
+
</div>
|
|
364
|
+
</div>` : nothing}
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
|
|
368
|
+
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
369
|
+
</div>`;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
_CmDateRangePicker_localeProp = new WeakMap(), _CmDateRangePicker_internals = new WeakMap(), _CmDateRangePicker_id = new WeakMap(), _CmDateRangePicker_default = new WeakMap(), _CmDateRangePicker_keepText = new WeakMap(), _CmDateRangePicker_focusGrid = new WeakMap(), _CmDateRangePicker_picking = new WeakMap(), _CmDateRangePicker_toggle = new WeakMap(), _CmDateRangePicker_onInputKey = new WeakMap(), _CmDateRangePicker_onGridKey = new WeakMap(), _CmDateRangePicker_onPopKey = new WeakMap(), _CmDateRangePicker_onOutside = new WeakMap(), _CmDateRangePicker_instances = new WeakSet(), _CmDateRangePicker_locale_get = function _CmDateRangePicker_locale_get() { return resolveLocale(this, this.locale); }, _CmDateRangePicker_fmt_get = function _CmDateRangePicker_fmt_get() { return dateFormat(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_locale_get)); }, _CmDateRangePicker_firstDay_get = function _CmDateRangePicker_firstDay_get() {
|
|
373
|
+
const n = Number(this.firstDayOfWeek);
|
|
374
|
+
return this.firstDayOfWeek == null || Number.isNaN(n) ? localeFirstDay(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_locale_get)) : ((Math.trunc(n) % 7) + 7) % 7;
|
|
375
|
+
}, _CmDateRangePicker_pattern_get = function _CmDateRangePicker_pattern_get() { return datePattern(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get), { d: this.t('patternDay'), m: this.t('patternMonth'), y: this.t('patternYear') }); }, _CmDateRangePicker_format = function _CmDateRangePicker_format(v) { const d = fromISO(v); return d ? __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get).short(d) : v; }, _CmDateRangePicker_emit = function _CmDateRangePicker_emit() {
|
|
376
|
+
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
377
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
378
|
+
}, _CmDateRangePicker_setRange = function _CmDateRangePicker_setRange(start, end) {
|
|
379
|
+
if (start === this.start && end === this.end)
|
|
380
|
+
return;
|
|
381
|
+
this.start = start;
|
|
382
|
+
this.end = end;
|
|
383
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_emit).call(this);
|
|
384
|
+
}, _CmDateRangePicker_commitText = function _CmDateRangePicker_commitText(which) {
|
|
385
|
+
const text = (which === 'start' ? this._startText : this._endText).trim();
|
|
386
|
+
const iso = text ? parseDate(text, __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get)) : '';
|
|
387
|
+
if (text && !iso)
|
|
388
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_keepText, true, "f");
|
|
389
|
+
const next = which === 'start' ? [iso ?? '', this.end] : [this.start, iso ?? ''];
|
|
390
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_setRange).call(this, ...next);
|
|
391
|
+
if (iso) {
|
|
392
|
+
if (which === 'start')
|
|
393
|
+
this._startText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, iso);
|
|
394
|
+
else
|
|
395
|
+
this._endText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, iso);
|
|
396
|
+
}
|
|
397
|
+
}, _CmDateRangePicker_pick = function _CmDateRangePicker_pick(d) {
|
|
398
|
+
const iso = toISO(d);
|
|
399
|
+
if (this.isUnavailable(iso))
|
|
400
|
+
return;
|
|
401
|
+
if (__classPrivateFieldGet(this, _CmDateRangePicker_picking, "f") === 'start' || !this._draftStart || iso < this._draftStart) {
|
|
402
|
+
this._draftStart = iso;
|
|
403
|
+
this._draftEnd = '';
|
|
404
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_picking, 'end', "f");
|
|
405
|
+
this._focus = d;
|
|
406
|
+
__classPrivateFieldSet(this, _CmDateRangePicker_focusGrid, true, "f");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
this._draftEnd = iso;
|
|
410
|
+
this.open = false;
|
|
411
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_setRange).call(this, this._draftStart, iso);
|
|
412
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_focusTrigger).call(this);
|
|
413
|
+
}, _CmDateRangePicker_applyPreset = function _CmDateRangePicker_applyPreset(p) {
|
|
414
|
+
this.open = false;
|
|
415
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_setRange).call(this, p.start, p.end);
|
|
416
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_focusTrigger).call(this);
|
|
417
|
+
}, _CmDateRangePicker_focusTrigger = function _CmDateRangePicker_focusTrigger() { this.renderRoot.querySelector('.trigger')?.focus(); }, _CmDateRangePicker_mark = function _CmDateRangePicker_mark(d) {
|
|
418
|
+
const iso = toISO(d);
|
|
419
|
+
const s = this._draftStart;
|
|
420
|
+
const e = this._draftEnd || (__classPrivateFieldGet(this, _CmDateRangePicker_picking, "f") === 'end' && s ? toISO(this._hover ?? this._focus) : '');
|
|
421
|
+
if (iso === s)
|
|
422
|
+
return 'start';
|
|
423
|
+
if (iso === e && e > s)
|
|
424
|
+
return 'end';
|
|
425
|
+
if (s && e && iso > s && iso < e)
|
|
426
|
+
return 'in-range';
|
|
427
|
+
return '';
|
|
428
|
+
};
|
|
429
|
+
CmDateRangePicker.formAssociated = true;
|
|
430
|
+
CmDateRangePicker.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
431
|
+
CmDateRangePicker.properties = {
|
|
432
|
+
label: {},
|
|
433
|
+
helpText: { attribute: 'help-text' },
|
|
434
|
+
error: { reflect: true },
|
|
435
|
+
name: { reflect: true },
|
|
436
|
+
startName: { attribute: 'start-name' },
|
|
437
|
+
endName: { attribute: 'end-name' },
|
|
438
|
+
start: {},
|
|
439
|
+
end: {},
|
|
440
|
+
min: {},
|
|
441
|
+
max: {},
|
|
442
|
+
locale: { noAccessor: true },
|
|
443
|
+
firstDayOfWeek: { type: Number, attribute: 'first-day-of-week' },
|
|
444
|
+
disabledDates: { attribute: 'disabled-dates', converter: listConverter },
|
|
445
|
+
isDateDisabled: { attribute: false },
|
|
446
|
+
presets: { converter: listConverter },
|
|
447
|
+
startLabel: { attribute: 'start-label', string: 'start' },
|
|
448
|
+
endLabel: { attribute: 'end-label', string: 'end' },
|
|
449
|
+
required: { type: Boolean, reflect: true },
|
|
450
|
+
disabled: { type: Boolean, reflect: true },
|
|
451
|
+
open: { type: Boolean, reflect: true },
|
|
452
|
+
size: { reflect: true },
|
|
453
|
+
_startText: { state: true },
|
|
454
|
+
_endText: { state: true },
|
|
455
|
+
_focus: { state: true },
|
|
456
|
+
_draftStart: { state: true },
|
|
457
|
+
_draftEnd: { state: true },
|
|
458
|
+
_hover: { state: true },
|
|
459
|
+
};
|
|
460
|
+
CmDateRangePicker.styles = [
|
|
461
|
+
base, dateFieldStyles, calendarStyles,
|
|
462
|
+
css `
|
|
463
|
+
.sep { flex: none; color: var(--cm-text-tertiary); }
|
|
464
|
+
input { flex: 0 1 6.6em; }
|
|
465
|
+
:host([size='small']) input { flex-basis: 6.6em; }
|
|
466
|
+
.trigger { margin-inline-start: auto; }
|
|
467
|
+
.body { display: flex; gap: var(--cm-space-15); }
|
|
468
|
+
.presets { display: flex; flex-direction: column; gap: 2px; min-width: 140px; margin: 0; padding: 0; padding-inline-end: var(--cm-space-15); list-style: none; border-inline-end: var(--cm-border-1) solid var(--cm-border-default); }
|
|
469
|
+
.preset {
|
|
470
|
+
width: 100%; min-height: 36px; padding: 6px var(--cm-space-10); border: 0; border-radius: var(--cm-radius-sm);
|
|
471
|
+
background: none; font: inherit; font-size: 14px; text-align: start; color: var(--cm-text-default); cursor: pointer;
|
|
472
|
+
}
|
|
473
|
+
.preset:hover { background: var(--cm-bg-hover); }
|
|
474
|
+
.preset[aria-pressed='true'] { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
|
|
475
|
+
.status { margin: var(--cm-space-10) 0 0; font-size: 12px; color: var(--cm-text-tertiary); }
|
|
476
|
+
@media (max-width: 640px) {
|
|
477
|
+
.body { flex-direction: column; }
|
|
478
|
+
.presets { flex-direction: row; flex-wrap: wrap; min-width: 0; padding: 0 0 var(--cm-space-10); border-inline-end: 0; border-block-end: var(--cm-border-1) solid var(--cm-border-default); }
|
|
479
|
+
.presets li { flex: 0 0 auto; }
|
|
480
|
+
.preset { width: auto; border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-full); min-height: 32px; }
|
|
481
|
+
}
|
|
482
|
+
`,
|
|
483
|
+
];
|
|
484
|
+
define('cm-date-range-picker', CmDateRangePicker);
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmLocalizedElement } from '../localize.js';
|
|
2
2
|
import './icon.js';
|
|
3
|
+
declare const strings: {
|
|
4
|
+
/** Text inside the empty zone. */
|
|
5
|
+
prompt: string;
|
|
6
|
+
/** Text of the tile that adds more files. */
|
|
7
|
+
addMore: string;
|
|
8
|
+
/** Accessible name of the list of chosen files. */
|
|
9
|
+
files: string;
|
|
10
|
+
/** Accessible name of each file's remove button. */
|
|
11
|
+
remove: string;
|
|
12
|
+
/** File sizes. `{size}` is a number formatted for the locale. */
|
|
13
|
+
kilobytes: string;
|
|
14
|
+
megabytes: string;
|
|
15
|
+
/** Validation messages. */
|
|
16
|
+
required: string;
|
|
17
|
+
wrongType: string;
|
|
18
|
+
tooLarge: string;
|
|
19
|
+
tooMany: string;
|
|
20
|
+
};
|
|
21
|
+
declare module '../localize.js' {
|
|
22
|
+
interface CmStrings {
|
|
23
|
+
fileUpload: typeof strings;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
3
26
|
/**
|
|
4
27
|
* Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
|
|
5
28
|
* Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
|
|
@@ -8,7 +31,7 @@ import './icon.js';
|
|
|
8
31
|
* @fires change - When files are added or removed. Read `files`.
|
|
9
32
|
* @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
|
|
10
33
|
*/
|
|
11
|
-
export declare class CmFileUpload extends
|
|
34
|
+
export declare class CmFileUpload extends CmLocalizedElement {
|
|
12
35
|
#private;
|
|
13
36
|
static formAssociated: boolean;
|
|
14
37
|
static shadowRootOptions: {
|
|
@@ -20,7 +43,9 @@ export declare class CmFileUpload extends LitElement {
|
|
|
20
43
|
static properties: {
|
|
21
44
|
label: {};
|
|
22
45
|
hint: {};
|
|
23
|
-
prompt: {
|
|
46
|
+
prompt: {
|
|
47
|
+
string: string;
|
|
48
|
+
};
|
|
24
49
|
name: {
|
|
25
50
|
reflect: boolean;
|
|
26
51
|
};
|
|
@@ -58,7 +83,7 @@ export declare class CmFileUpload extends LitElement {
|
|
|
58
83
|
label: string;
|
|
59
84
|
/** Rule shown next to the label in text-tertiary, e.g. "max. file size 300 KB". */
|
|
60
85
|
hint: string;
|
|
61
|
-
/** Text inside the zone. */
|
|
86
|
+
/** Text inside the zone. Default: the built-in string `prompt` ("Click here to upload"). */
|
|
62
87
|
prompt: string;
|
|
63
88
|
/** Form field name. */
|
|
64
89
|
name: string;
|
|
@@ -100,3 +125,4 @@ declare global {
|
|
|
100
125
|
'cm-file-upload': CmFileUpload;
|
|
101
126
|
}
|
|
102
127
|
}
|
|
128
|
+
export {};
|