@tabworthy/components 0.15.0 → 0.16.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/cjs/{customParseFormat-l09KVyWD.js → date-error-CCtoCDtq.js} +3 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/tabworthy-components.cjs.js +1 -1
- package/dist/cjs/tabworthy-dates.cjs.entry.js +28 -26
- package/dist/cjs/tabworthy-times-picker.cjs.entry.js +29 -8
- package/dist/cjs/tabworthy-times.cjs.entry.js +47 -41
- package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +12 -9
- package/dist/collection/components/tabworthy-times/tabworthy-times.js +15 -8
- package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +49 -8
- package/dist/collection/utils/date-error.js +1 -0
- package/dist/components/p-BvcvP308.js +1 -0
- package/dist/{tabworthy-components/p-DkyM-7xr.js → components/p-DCgn1Avj.js} +1 -1
- package/dist/components/tabworthy-dates.js +1 -1
- package/dist/components/tabworthy-times-picker.js +1 -1
- package/dist/components/tabworthy-times.js +1 -1
- package/dist/esm/{customParseFormat-DkyM-7xr.js → date-error-DCgn1Avj.js} +3 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/tabworthy-components.js +1 -1
- package/dist/esm/tabworthy-dates.entry.js +12 -10
- package/dist/esm/tabworthy-times-picker.entry.js +29 -8
- package/dist/esm/tabworthy-times.entry.js +15 -9
- package/dist/tabworthy-components/p-5b21364f.entry.js +1 -0
- package/dist/tabworthy-components/p-82d70f28.entry.js +1 -0
- package/dist/{components/p-DkyM-7xr.js → tabworthy-components/p-DCgn1Avj.js} +1 -1
- package/dist/tabworthy-components/p-c57563a0.entry.js +1 -0
- package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
- package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.d.ts +3 -0
- package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.type.d.ts +40 -0
- package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/utils.d.ts +34 -0
- package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +4 -2
- package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +1 -0
- package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +6 -0
- package/dist/types/components.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/date-error.d.ts +2 -0
- package/package.json +1 -1
- package/dist/components/p-C_uZGgcG.js +0 -1
- package/dist/tabworthy-components/p-69334c34.entry.js +0 -1
- package/dist/tabworthy-components/p-af49d0fc.entry.js +0 -1
- package/dist/tabworthy-components/p-cee41e54.entry.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./index-B1s0tI-Z.js');
|
|
4
|
-
var
|
|
4
|
+
var dateError = require('./date-error-CCtoCDtq.js');
|
|
5
5
|
var utils = require('./utils-DGbdK8VF.js');
|
|
6
6
|
|
|
7
7
|
var localizedFormat$2 = {exports: {}};
|
|
@@ -20,10 +20,10 @@ function requireLocalizedFormat () {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
var localizedFormatExports = requireLocalizedFormat();
|
|
23
|
-
var localizedFormat = /*@__PURE__*/
|
|
23
|
+
var localizedFormat = /*@__PURE__*/dateError.getDefaultExportFromCjs(localizedFormatExports);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
dateError.dayjs.extend(dateError.customParseFormat);
|
|
26
|
+
dateError.dayjs.extend(localizedFormat);
|
|
27
27
|
const defaultLabels = {
|
|
28
28
|
selected: "selected",
|
|
29
29
|
openCalendar: "Choose time",
|
|
@@ -176,22 +176,22 @@ const TabworthyTimes = class {
|
|
|
176
176
|
}
|
|
177
177
|
// Try to parse the input value using the component's format first (strict mode)
|
|
178
178
|
// This prevents dayjs from misinterpreting date formats (e.g., DD/MM/YYYY as MM/DD/YYYY)
|
|
179
|
-
let parsed =
|
|
179
|
+
let parsed = dateError.dayjs(value, this.format, true);
|
|
180
180
|
// Fall back to loose parsing if strict format doesn't match
|
|
181
181
|
if (!parsed.isValid()) {
|
|
182
|
-
parsed =
|
|
182
|
+
parsed = dateError.dayjs(value);
|
|
183
183
|
}
|
|
184
184
|
if (parsed.isValid()) {
|
|
185
185
|
// Check minDate/maxDate bounds (supports both date-only and datetime strings)
|
|
186
|
-
if (this.minDate && parsed.isBefore(
|
|
186
|
+
if (this.minDate && parsed.isBefore(dateError.dayjs(this.minDate))) {
|
|
187
187
|
this.errorState = true;
|
|
188
|
-
this.errorMessage =
|
|
188
|
+
this.errorMessage = dateError.formatDateError(this.timesLabels.minDateError, this.formatBoundaryDate(this.minDate));
|
|
189
189
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
if (this.maxDate && parsed.isAfter(
|
|
192
|
+
if (this.maxDate && parsed.isAfter(dateError.dayjs(this.maxDate))) {
|
|
193
193
|
this.errorState = true;
|
|
194
|
-
this.errorMessage =
|
|
194
|
+
this.errorMessage = dateError.formatDateError(this.timesLabels.maxDateError, this.formatBoundaryDate(this.maxDate));
|
|
195
195
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
@@ -219,7 +219,7 @@ const TabworthyTimes = class {
|
|
|
219
219
|
this.errorChange.emit({ reason, message });
|
|
220
220
|
}
|
|
221
221
|
formatBoundaryDate(dateString) {
|
|
222
|
-
const parsed =
|
|
222
|
+
const parsed = dateError.dayjs(dateString);
|
|
223
223
|
if (!parsed.isValid())
|
|
224
224
|
return dateString;
|
|
225
225
|
const hasTime = dateString.includes("T") || dateString.includes(" ");
|
|
@@ -236,8 +236,8 @@ const TabworthyTimes = class {
|
|
|
236
236
|
getEffectiveMinTime() {
|
|
237
237
|
if (!this.minDate || !this.selectedDate)
|
|
238
238
|
return undefined;
|
|
239
|
-
const min =
|
|
240
|
-
const sel =
|
|
239
|
+
const min = dateError.dayjs(this.minDate);
|
|
240
|
+
const sel = dateError.dayjs(this.selectedDate);
|
|
241
241
|
if (!min.isValid() || !sel.isSame(min, "day"))
|
|
242
242
|
return undefined;
|
|
243
243
|
return {
|
|
@@ -249,8 +249,8 @@ const TabworthyTimes = class {
|
|
|
249
249
|
getEffectiveMaxTime() {
|
|
250
250
|
if (!this.maxDate || !this.selectedDate)
|
|
251
251
|
return undefined;
|
|
252
|
-
const max =
|
|
253
|
-
const sel =
|
|
252
|
+
const max = dateError.dayjs(this.maxDate);
|
|
253
|
+
const sel = dateError.dayjs(this.selectedDate);
|
|
254
254
|
if (!max.isValid() || !sel.isSame(max, "day"))
|
|
255
255
|
return undefined;
|
|
256
256
|
return {
|
|
@@ -262,10 +262,10 @@ const TabworthyTimes = class {
|
|
|
262
262
|
isDateOutOfBounds() {
|
|
263
263
|
if (!this.selectedDate)
|
|
264
264
|
return false;
|
|
265
|
-
const sel =
|
|
266
|
-
if (this.minDate && sel.isBefore(
|
|
265
|
+
const sel = dateError.dayjs(this.selectedDate);
|
|
266
|
+
if (this.minDate && sel.isBefore(dateError.dayjs(this.minDate), "day"))
|
|
267
267
|
return true;
|
|
268
|
-
if (this.maxDate && sel.isAfter(
|
|
268
|
+
if (this.maxDate && sel.isAfter(dateError.dayjs(this.maxDate), "day"))
|
|
269
269
|
return true;
|
|
270
270
|
return false;
|
|
271
271
|
}
|
|
@@ -274,9 +274,9 @@ const TabworthyTimes = class {
|
|
|
274
274
|
* available time if the current selection falls outside the allowed range.
|
|
275
275
|
*/
|
|
276
276
|
clampTimeToBounds(date) {
|
|
277
|
-
const sel =
|
|
277
|
+
const sel = dateError.dayjs(date);
|
|
278
278
|
if (this.minDate) {
|
|
279
|
-
const min =
|
|
279
|
+
const min = dateError.dayjs(this.minDate);
|
|
280
280
|
if (min.isValid() && sel.isSame(min, "day")) {
|
|
281
281
|
const curTotal = this.selectedHours * 3600 +
|
|
282
282
|
this.selectedMinutes * 60 +
|
|
@@ -290,7 +290,7 @@ const TabworthyTimes = class {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
if (this.maxDate) {
|
|
293
|
-
const max =
|
|
293
|
+
const max = dateError.dayjs(this.maxDate);
|
|
294
294
|
if (max.isValid() && sel.isSame(max, "day")) {
|
|
295
295
|
const curTotal = this.selectedHours * 3600 +
|
|
296
296
|
this.selectedMinutes * 60 +
|
|
@@ -313,7 +313,7 @@ const TabworthyTimes = class {
|
|
|
313
313
|
getDateForTimeOnlyValue() {
|
|
314
314
|
if (this.selectedDate)
|
|
315
315
|
return this.selectedDate;
|
|
316
|
-
const referenceDate =
|
|
316
|
+
const referenceDate = dateError.dayjs(this.referenceDate);
|
|
317
317
|
if (referenceDate.isValid())
|
|
318
318
|
return referenceDate.toDate();
|
|
319
319
|
return new Date();
|
|
@@ -340,7 +340,7 @@ const TabworthyTimes = class {
|
|
|
340
340
|
// Parse the first datetime value to set time picker
|
|
341
341
|
const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
|
|
342
342
|
if (firstValue) {
|
|
343
|
-
const parsed =
|
|
343
|
+
const parsed = dateError.dayjs(firstValue, this.format);
|
|
344
344
|
if (parsed.isValid()) {
|
|
345
345
|
this.selectedDate = parsed.toDate();
|
|
346
346
|
this.selectedHours = parsed.hour();
|
|
@@ -356,7 +356,7 @@ const TabworthyTimes = class {
|
|
|
356
356
|
if (this.pickerRef) {
|
|
357
357
|
if (Array.isArray(this.value)) {
|
|
358
358
|
const dates = this.value.reduce((acc, v) => {
|
|
359
|
-
const d =
|
|
359
|
+
const d = dateError.dayjs(v, this.format, true);
|
|
360
360
|
if (d.isValid())
|
|
361
361
|
acc.push(d.toDate());
|
|
362
362
|
return acc;
|
|
@@ -364,7 +364,7 @@ const TabworthyTimes = class {
|
|
|
364
364
|
this.pickerRef.value = dates.length ? dates : null;
|
|
365
365
|
}
|
|
366
366
|
else if (this.value) {
|
|
367
|
-
const parsedDate =
|
|
367
|
+
const parsedDate = dateError.dayjs(this.value, this.format, true);
|
|
368
368
|
if (parsedDate.isValid()) {
|
|
369
369
|
this.pickerRef.value = parsedDate.toDate();
|
|
370
370
|
}
|
|
@@ -391,7 +391,7 @@ const TabworthyTimes = class {
|
|
|
391
391
|
if (Array.isArray(date)) {
|
|
392
392
|
// Range mode
|
|
393
393
|
const formattedDates = date.map((d) => {
|
|
394
|
-
const m =
|
|
394
|
+
const m = dateError.dayjs(d)
|
|
395
395
|
.hour(this.selectedHours)
|
|
396
396
|
.minute(this.selectedMinutes)
|
|
397
397
|
.second(this.selectedSeconds);
|
|
@@ -403,7 +403,7 @@ const TabworthyTimes = class {
|
|
|
403
403
|
}
|
|
404
404
|
else {
|
|
405
405
|
// Single date mode
|
|
406
|
-
const m =
|
|
406
|
+
const m = dateError.dayjs(date)
|
|
407
407
|
.hour(this.selectedHours)
|
|
408
408
|
.minute(this.selectedMinutes)
|
|
409
409
|
.second(this.selectedSeconds);
|
|
@@ -419,18 +419,18 @@ const TabworthyTimes = class {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
isDateValid(date) {
|
|
422
|
-
const parsed =
|
|
422
|
+
const parsed = dateError.dayjs(date);
|
|
423
423
|
if (!parsed.isValid())
|
|
424
424
|
return false;
|
|
425
|
-
if (this.minDate && parsed.isBefore(
|
|
425
|
+
if (this.minDate && parsed.isBefore(dateError.dayjs(this.minDate), "day")) {
|
|
426
426
|
this.errorState = true;
|
|
427
|
-
this.errorMessage =
|
|
427
|
+
this.errorMessage = dateError.formatDateError(this.timesLabels.minDateError, this.formatBoundaryDate(this.minDate));
|
|
428
428
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
429
429
|
return false;
|
|
430
430
|
}
|
|
431
|
-
if (this.maxDate && parsed.isAfter(
|
|
431
|
+
if (this.maxDate && parsed.isAfter(dateError.dayjs(this.maxDate), "day")) {
|
|
432
432
|
this.errorState = true;
|
|
433
|
-
this.errorMessage =
|
|
433
|
+
this.errorMessage = dateError.formatDateError(this.timesLabels.maxDateError, this.formatBoundaryDate(this.maxDate));
|
|
434
434
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
435
435
|
return false;
|
|
436
436
|
}
|
|
@@ -448,16 +448,16 @@ const TabworthyTimes = class {
|
|
|
448
448
|
if (Array.isArray(this.internalValue)) {
|
|
449
449
|
// Format range
|
|
450
450
|
const formatted = this.internalValue
|
|
451
|
-
.map((v) =>
|
|
451
|
+
.map((v) => dateError.dayjs(v, this.format).format("lll"))
|
|
452
452
|
.join(` ${this.timesLabels.to} `);
|
|
453
453
|
this.inputRef.value = formatted;
|
|
454
454
|
}
|
|
455
455
|
else if (this.timeOnly) {
|
|
456
|
-
this.inputRef.value =
|
|
456
|
+
this.inputRef.value = dateError.dayjs(this.internalValue, this.format).format(this.showSeconds ? "LTS" : "LT");
|
|
457
457
|
}
|
|
458
458
|
else {
|
|
459
459
|
// Format single datetime
|
|
460
|
-
this.inputRef.value =
|
|
460
|
+
this.inputRef.value = dateError.dayjs(this.internalValue, this.format).format("lll");
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
getClassName(suffix) {
|
|
@@ -467,8 +467,8 @@ const TabworthyTimes = class {
|
|
|
467
467
|
if (!dateString)
|
|
468
468
|
return null;
|
|
469
469
|
const date = Array.isArray(dateString)
|
|
470
|
-
? dateString.map((d) =>
|
|
471
|
-
:
|
|
470
|
+
? dateString.map((d) => dateError.dayjs(d, this.format).toDate())
|
|
471
|
+
: dateError.dayjs(dateString, this.format).toDate();
|
|
472
472
|
return date;
|
|
473
473
|
}
|
|
474
474
|
async revertInput(newValue, clearError = false) {
|
|
@@ -491,20 +491,26 @@ const TabworthyTimes = class {
|
|
|
491
491
|
}
|
|
492
492
|
render() {
|
|
493
493
|
var _a;
|
|
494
|
-
return (index.h(index.Host, { key: '
|
|
494
|
+
return (index.h(index.Host, { key: '40aebf1f077c4766cbbb9bd3929f5d8d959b60a4', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState, "time-only": this.timeOnly }, index.h("label", { key: 'cbf04161329d320ebc9ae5b3a0fede08e3157afb', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: '2e7e46172b8d46b2f88047d93f9e4d35e5c841f3', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: '0fcf906d8bad7fe78e003bf881a6d22dcb42f4e8', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
495
495
|
[this.getClassName("input")]: true,
|
|
496
496
|
[this.inputClass]: !!this.inputClass
|
|
497
|
-
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (index.h("button", { key: '
|
|
497
|
+
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (index.h("button", { key: '7d63c31494474844633f64faf0aba4851574dce6', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
|
|
498
498
|
? this.timesLabels.openCalendar
|
|
499
|
-
: undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '
|
|
499
|
+
: undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '802a7f839dd33d19885918819ae4a3fa9f6cb838', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
500
500
|
if (this.pickerRef) {
|
|
501
501
|
this.pickerRef.modalIsOpen = true;
|
|
502
502
|
}
|
|
503
|
+
if (this.timeOnly && this.timePickerRef) {
|
|
504
|
+
this.timePickerRef.modalIsOpen = true;
|
|
505
|
+
}
|
|
503
506
|
}, onClosed: () => {
|
|
504
507
|
if (this.pickerRef) {
|
|
505
508
|
this.pickerRef.modalIsOpen = false;
|
|
506
509
|
}
|
|
507
|
-
|
|
510
|
+
if (this.timePickerRef) {
|
|
511
|
+
this.timePickerRef.modalIsOpen = false;
|
|
512
|
+
}
|
|
513
|
+
}, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '2ff172c30561b5962400dc2fa052162e01013c7a', class: this.getClassName("picker-container") }, !this.timeOnly && (index.h("tabworthy-dates-calendar", { key: '6456181b374cae4d91c01b9b7873c91bb08a8778', range: this.range, locale: this.locale, onSelectDate: (event) => this.handlePickerSelection(event.detail), onChangeMonth: (event) => this.handleChangedMonths(event.detail), onChangeYear: (event) => this.handleYearChange(event.detail), onRequestClose: () => { var _a; return (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close(); }, labels: this.datesCalendarLabels, ref: (el) => (this.pickerRef = el), startDate: this.startDate, firstDayOfWeek: this.firstDayOfWeek, showHiddenTitle: true, disabled: this.disabledState, showMonthStepper: this.showMonthStepper, showYearStepper: this.showYearStepper, showClearButton: this.showClearButton, showCloseButton: this.showCloseButton, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline, value: this.value ? this.toDate(this.value) : undefined, nextMonthButtonContent: this.nextMonthButtonContent, nextYearButtonContent: this.nextYearButtonContent, previousMonthButtonContent: this.previousMonthButtonContent, previousYearButtonContent: this.previousYearButtonContent, todayButtonContent: this.todayButtonContent, clearButtonContent: this.clearButtonContent, closeButtonContent: this.closeButtonContent }, index.h("div", { key: '4a89d517cfcf22cffccecddca841102cb913a8fb', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: '72d37f7058959877afa16b8336f834cc0e5aceba', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: 'bdba34da5c2a2a0af681e40516b0d48e8833e276', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime(), ref: (el) => (this.timePickerRef = el) })))), this.timeOnly && (index.h("div", { key: '50a2866b8e7a408f72d37ee540ecba546103d4f4', class: this.getClassName("time-section") }, index.h("tabworthy-times-picker", { key: 'de317aaa6579be60679cba468e5b28be8654aa5d', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime(), ref: (el) => (this.timePickerRef = el) }))))), this.errorState && (index.h("div", { key: '7617cfa25799dbbb8056abcba161284745022f44', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
508
514
|
}
|
|
509
515
|
get el() { return index.getElement(this); }
|
|
510
516
|
static get watchers() { return {
|
|
@@ -5,6 +5,7 @@ import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
|
5
5
|
dayjs.extend(customParseFormat);
|
|
6
6
|
import { getISODateString, parseDateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
7
7
|
import { chronoParseDate, chronoParseRange } from "../../../../shared/utils/chrono-parser/chrono-parser";
|
|
8
|
+
import { formatDateError } from "../../utils/date-error";
|
|
8
9
|
const defaultLabels = {
|
|
9
10
|
selected: "selected",
|
|
10
11
|
openCalendar: "Open calendar",
|
|
@@ -238,18 +239,13 @@ export class TabworthyDates {
|
|
|
238
239
|
minDate === null || minDate === void 0 ? void 0 : minDate.setDate(minDate.getDate() - 1);
|
|
239
240
|
}
|
|
240
241
|
if (!!parsedDate.reason) {
|
|
241
|
-
const formatLocalizedDate = (date) => Intl.DateTimeFormat(this.locale, {
|
|
242
|
-
day: "numeric",
|
|
243
|
-
month: "short",
|
|
244
|
-
year: "numeric"
|
|
245
|
-
}).format(date);
|
|
246
242
|
this.errorMessage = parsedDate.reason;
|
|
247
243
|
this.errorMessage = {
|
|
248
244
|
minDate: minDate
|
|
249
|
-
?
|
|
245
|
+
? formatDateError(this.datesLabels.minDateError, this.formatBoundaryDate(minDate))
|
|
250
246
|
: "",
|
|
251
247
|
maxDate: maxDate
|
|
252
|
-
?
|
|
248
|
+
? formatDateError(this.datesLabels.maxDateError, this.formatBoundaryDate(maxDate))
|
|
253
249
|
: "",
|
|
254
250
|
invalid: this.datesLabels.invalidDateError
|
|
255
251
|
}[parsedDate.reason];
|
|
@@ -332,6 +328,13 @@ export class TabworthyDates {
|
|
|
332
328
|
emitErrorChange(reason, message) {
|
|
333
329
|
this.errorChange.emit({ reason, message });
|
|
334
330
|
}
|
|
331
|
+
formatBoundaryDate(date) {
|
|
332
|
+
return Intl.DateTimeFormat(this.locale, {
|
|
333
|
+
day: "numeric",
|
|
334
|
+
month: "short",
|
|
335
|
+
year: "numeric"
|
|
336
|
+
}).format(date);
|
|
337
|
+
}
|
|
335
338
|
formatInput(enabled, useInputValue = true) {
|
|
336
339
|
if (this.shouldInputFormat() === false || enabled === false) {
|
|
337
340
|
if (this.internalValue) {
|
|
@@ -384,13 +387,13 @@ export class TabworthyDates {
|
|
|
384
387
|
const isoDate = typeof dateString === "string" ? dateString : parsed.format("YYYY-MM-DD");
|
|
385
388
|
if (this.minDate && isoDate < this.minDate) {
|
|
386
389
|
this.errorState = true;
|
|
387
|
-
this.errorMessage =
|
|
390
|
+
this.errorMessage = formatDateError(this.datesLabels.minDateError, this.formatBoundaryDate(parseDateString(this.minDate)));
|
|
388
391
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
389
392
|
return false;
|
|
390
393
|
}
|
|
391
394
|
if (this.maxDate && isoDate > this.maxDate) {
|
|
392
395
|
this.errorState = true;
|
|
393
|
-
this.errorMessage =
|
|
396
|
+
this.errorMessage = formatDateError(this.datesLabels.maxDateError, this.formatBoundaryDate(parseDateString(this.maxDate)));
|
|
394
397
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
395
398
|
return false;
|
|
396
399
|
}
|
|
@@ -5,6 +5,7 @@ import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
|
5
5
|
dayjs.extend(customParseFormat);
|
|
6
6
|
dayjs.extend(localizedFormat);
|
|
7
7
|
import { getISODateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
8
|
+
import { formatDateError } from "../../utils/date-error";
|
|
8
9
|
const defaultLabels = {
|
|
9
10
|
selected: "selected",
|
|
10
11
|
openCalendar: "Choose time",
|
|
@@ -161,13 +162,13 @@ export class TabworthyTimes {
|
|
|
161
162
|
// Check minDate/maxDate bounds (supports both date-only and datetime strings)
|
|
162
163
|
if (this.minDate && parsed.isBefore(dayjs(this.minDate))) {
|
|
163
164
|
this.errorState = true;
|
|
164
|
-
this.errorMessage =
|
|
165
|
+
this.errorMessage = formatDateError(this.timesLabels.minDateError, this.formatBoundaryDate(this.minDate));
|
|
165
166
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate))) {
|
|
169
170
|
this.errorState = true;
|
|
170
|
-
this.errorMessage =
|
|
171
|
+
this.errorMessage = formatDateError(this.timesLabels.maxDateError, this.formatBoundaryDate(this.maxDate));
|
|
171
172
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
172
173
|
return;
|
|
173
174
|
}
|
|
@@ -400,13 +401,13 @@ export class TabworthyTimes {
|
|
|
400
401
|
return false;
|
|
401
402
|
if (this.minDate && parsed.isBefore(dayjs(this.minDate), "day")) {
|
|
402
403
|
this.errorState = true;
|
|
403
|
-
this.errorMessage =
|
|
404
|
+
this.errorMessage = formatDateError(this.timesLabels.minDateError, this.formatBoundaryDate(this.minDate));
|
|
404
405
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
405
406
|
return false;
|
|
406
407
|
}
|
|
407
408
|
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate), "day")) {
|
|
408
409
|
this.errorState = true;
|
|
409
|
-
this.errorMessage =
|
|
410
|
+
this.errorMessage = formatDateError(this.timesLabels.maxDateError, this.formatBoundaryDate(this.maxDate));
|
|
410
411
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
411
412
|
return false;
|
|
412
413
|
}
|
|
@@ -467,20 +468,26 @@ export class TabworthyTimes {
|
|
|
467
468
|
}
|
|
468
469
|
render() {
|
|
469
470
|
var _a;
|
|
470
|
-
return (h(Host, { key: '
|
|
471
|
+
return (h(Host, { key: '40aebf1f077c4766cbbb9bd3929f5d8d959b60a4', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState, "time-only": this.timeOnly }, h("label", { key: 'cbf04161329d320ebc9ae5b3a0fede08e3157afb', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '2e7e46172b8d46b2f88047d93f9e4d35e5c841f3', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: '0fcf906d8bad7fe78e003bf881a6d22dcb42f4e8', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
471
472
|
[this.getClassName("input")]: true,
|
|
472
473
|
[this.inputClass]: !!this.inputClass
|
|
473
|
-
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: '
|
|
474
|
+
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: '7d63c31494474844633f64faf0aba4851574dce6', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
|
|
474
475
|
? this.timesLabels.openCalendar
|
|
475
|
-
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '
|
|
476
|
+
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '802a7f839dd33d19885918819ae4a3fa9f6cb838', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
476
477
|
if (this.pickerRef) {
|
|
477
478
|
this.pickerRef.modalIsOpen = true;
|
|
478
479
|
}
|
|
480
|
+
if (this.timeOnly && this.timePickerRef) {
|
|
481
|
+
this.timePickerRef.modalIsOpen = true;
|
|
482
|
+
}
|
|
479
483
|
}, onClosed: () => {
|
|
480
484
|
if (this.pickerRef) {
|
|
481
485
|
this.pickerRef.modalIsOpen = false;
|
|
482
486
|
}
|
|
483
|
-
|
|
487
|
+
if (this.timePickerRef) {
|
|
488
|
+
this.timePickerRef.modalIsOpen = false;
|
|
489
|
+
}
|
|
490
|
+
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '2ff172c30561b5962400dc2fa052162e01013c7a', class: this.getClassName("picker-container") }, !this.timeOnly && (h("tabworthy-dates-calendar", { key: '6456181b374cae4d91c01b9b7873c91bb08a8778', range: this.range, locale: this.locale, onSelectDate: (event) => this.handlePickerSelection(event.detail), onChangeMonth: (event) => this.handleChangedMonths(event.detail), onChangeYear: (event) => this.handleYearChange(event.detail), onRequestClose: () => { var _a; return (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close(); }, labels: this.datesCalendarLabels, ref: (el) => (this.pickerRef = el), startDate: this.startDate, firstDayOfWeek: this.firstDayOfWeek, showHiddenTitle: true, disabled: this.disabledState, showMonthStepper: this.showMonthStepper, showYearStepper: this.showYearStepper, showClearButton: this.showClearButton, showCloseButton: this.showCloseButton, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline, value: this.value ? this.toDate(this.value) : undefined, nextMonthButtonContent: this.nextMonthButtonContent, nextYearButtonContent: this.nextYearButtonContent, previousMonthButtonContent: this.previousMonthButtonContent, previousYearButtonContent: this.previousYearButtonContent, todayButtonContent: this.todayButtonContent, clearButtonContent: this.clearButtonContent, closeButtonContent: this.closeButtonContent }, h("div", { key: '4a89d517cfcf22cffccecddca841102cb913a8fb', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '72d37f7058959877afa16b8336f834cc0e5aceba', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'bdba34da5c2a2a0af681e40516b0d48e8833e276', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime(), ref: (el) => (this.timePickerRef = el) })))), this.timeOnly && (h("div", { key: '50a2866b8e7a408f72d37ee540ecba546103d4f4', class: this.getClassName("time-section") }, h("tabworthy-times-picker", { key: 'de317aaa6579be60679cba468e5b28be8654aa5d', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime(), ref: (el) => (this.timePickerRef = el) }))))), this.errorState && (h("div", { key: '7617cfa25799dbbb8056abcba161284745022f44', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
484
491
|
}
|
|
485
492
|
static get is() { return "tabworthy-times"; }
|
|
486
493
|
static get encapsulation() { return "scoped"; }
|
|
@@ -27,6 +27,7 @@ export class TabworthyTimesPicker {
|
|
|
27
27
|
this.labelsSrOnly = true;
|
|
28
28
|
this.disabled = false;
|
|
29
29
|
this.elementClassName = "tabworthy-times-picker";
|
|
30
|
+
this.modalIsOpen = false;
|
|
30
31
|
this.internalHours = this.hours;
|
|
31
32
|
this.internalMinutes = this.minutes;
|
|
32
33
|
this.internalSeconds = this.seconds;
|
|
@@ -129,6 +130,11 @@ export class TabworthyTimesPicker {
|
|
|
129
130
|
this.emitTimeChange();
|
|
130
131
|
};
|
|
131
132
|
}
|
|
133
|
+
watchModalIsOpen() {
|
|
134
|
+
if (this.modalIsOpen === true) {
|
|
135
|
+
this.moveFocusOnModalOpen = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
132
138
|
watchHours(newValue) {
|
|
133
139
|
this.internalHours = newValue;
|
|
134
140
|
this.period = newValue >= 12 ? "PM" : "AM";
|
|
@@ -145,6 +151,18 @@ export class TabworthyTimesPicker {
|
|
|
145
151
|
this.internalSeconds = this.seconds;
|
|
146
152
|
this.period = this.hours >= 12 ? "PM" : "AM";
|
|
147
153
|
}
|
|
154
|
+
componentDidRender() {
|
|
155
|
+
if (this.moveFocusOnModalOpen) {
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
this.focusHoursInput();
|
|
158
|
+
this.moveFocusOnModalOpen = false;
|
|
159
|
+
}, 100);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
focusHoursInput() {
|
|
163
|
+
var _a;
|
|
164
|
+
(_a = this.hoursInputRef) === null || _a === void 0 ? void 0 : _a.focus();
|
|
165
|
+
}
|
|
148
166
|
getDisplayHours() {
|
|
149
167
|
if (!this.useTwelveHourFormat) {
|
|
150
168
|
return this.internalHours;
|
|
@@ -246,22 +264,22 @@ export class TabworthyTimesPicker {
|
|
|
246
264
|
const displayHours = this.getDisplayHours();
|
|
247
265
|
const maxHours = this.useTwelveHourFormat ? 12 : 23;
|
|
248
266
|
const minHours = this.useTwelveHourFormat ? 1 : 0;
|
|
249
|
-
return (h(Host, { key: '
|
|
267
|
+
return (h(Host, { key: 'c307a1b94d1ec25702c286c7f36e4746df8c6bb7', class: this.elementClassName, "aria-label": this.labels.timePicker }, h("div", { key: 'c446911a0ddcb6282ab5507d359d56a42f533db3', class: `${this.elementClassName}__container` }, h("div", { key: '302c7e7e0c1bf71629ef2a71bb564f9571aad7be', class: `${this.elementClassName}__field` }, h("label", { key: '8ce64af4f416c3cdc0dd8943fc02ab9016d62099', htmlFor: `${this.elementClassName}-hours`, class: {
|
|
250
268
|
[`${this.elementClassName}__label`]: true,
|
|
251
269
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
252
|
-
} }, this.labels.hours), h("div", { key: '
|
|
270
|
+
} }, this.labels.hours), h("div", { key: '3f541e096c7bb3f436f358800588d5da7fccb34e', class: `${this.elementClassName}__control` }, h("button", { key: '31039ad972122c2a6f963190d38f379bb7dce71f', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--increment`, onClick: this.handleHourIncrement, disabled: this.disabled || this.isAtMaxHour(), "aria-label": this.labels.incrementHours }, h("svg", { key: '4b16f261f4fecc91973d858b6235fc8aac4f7605', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: 'fe60640cfa75911b862913a3076cbeea037a38f7', points: "18 15 12 9 6 15" }))), h("input", { key: 'a3a7eed2efc8b1789de698771e82e3f31f50e885', id: `${this.elementClassName}-hours`, ref: (el) => (this.hoursInputRef = el), type: "number", class: `${this.elementClassName}__input`, value: this.padZero(displayHours), min: minHours, max: maxHours, onInput: this.handleHourChange, disabled: this.disabled, "aria-label": this.labels.hours }), h("button", { key: '421b70976c21b2b33e21962780d13609a6b762a5', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--decrement`, onClick: this.handleHourDecrement, disabled: this.disabled || this.isAtMinHour(), "aria-label": this.labels.decrementHours }, h("svg", { key: 'ab87c0de149d43edcbebd1b2d4d00e4a3ebed5b3', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: '32f2d112c44434249d506d1e8222e25b34fb0d44', points: "6 9 12 15 18 9" }))))), h("div", { key: '54449a42e67f6f3c2318310bc12eeba24cebc56f', class: `${this.elementClassName}__separator` }, ":"), h("div", { key: 'f65d84751223424c3649d0fb9589cf3c1af091eb', class: `${this.elementClassName}__field` }, h("label", { key: '911244fd360371ee26b97eb9690c7b04340d6e88', htmlFor: `${this.elementClassName}-minutes`, class: {
|
|
253
271
|
[`${this.elementClassName}__label`]: true,
|
|
254
272
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
255
|
-
} }, this.labels.minutes), h("div", { key: '
|
|
256
|
-
h("div", { key: '
|
|
257
|
-
h("div", { key: '
|
|
273
|
+
} }, this.labels.minutes), h("div", { key: 'e5574834dd59e9c08dcee56b07bf8bf186f7ba4b', class: `${this.elementClassName}__control` }, h("button", { key: '2b091d643aa785b8ddeae55dd8c523cd5282719d', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--increment`, onClick: this.handleMinuteIncrement, disabled: this.disabled || this.isAtMaxMinute(), "aria-label": this.labels.incrementMinutes }, h("svg", { key: '23668a0f1299f86901d0e32e9f7f37bacd376665', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: '7f030c2d35147651ad86352c65dc6f8f00b2ba93', points: "18 15 12 9 6 15" }))), h("input", { key: 'b73ed30b3a7d25ef84bab23afa45172ce5d03944', id: `${this.elementClassName}-minutes`, type: "number", class: `${this.elementClassName}__input`, value: this.padZero(this.internalMinutes), min: 0, max: 59, onInput: this.handleMinuteChange, disabled: this.disabled, "aria-label": this.labels.minutes }), h("button", { key: '7ce7a36ef59e44afd474c427250adc352a8a6694', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--decrement`, onClick: this.handleMinuteDecrement, disabled: this.disabled || this.isAtMinMinute(), "aria-label": this.labels.decrementMinutes }, h("svg", { key: '49bcd0c73fde1f77c0d42978a76086abb5be6cc4', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: 'c503c319467e0aac6883db25b7d84a1d752aeaf9', points: "6 9 12 15 18 9" }))))), this.showSeconds && [
|
|
274
|
+
h("div", { key: 'be25b2045f9e74b0414e55f8d508f7c192e1772e', class: `${this.elementClassName}__separator` }, ":"),
|
|
275
|
+
h("div", { key: '85ceb01427ea52c231f1b6a3d78c95c6d603215c', class: `${this.elementClassName}__field` }, h("label", { key: '1a1adf9081b3e763e4fbc45b8bab812ae869edbb', htmlFor: `${this.elementClassName}-seconds`, class: {
|
|
258
276
|
[`${this.elementClassName}__label`]: true,
|
|
259
277
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
260
|
-
} }, this.labels.seconds), h("div", { key: '
|
|
261
|
-
], this.useTwelveHourFormat && (h("div", { key: '
|
|
278
|
+
} }, this.labels.seconds), h("div", { key: 'abce976c9d3143819c41ff64b54dfbcea41ddd88', class: `${this.elementClassName}__control` }, h("button", { key: '1416ee09b69a6d62d8ecd1394bb375fc01601e4a', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--increment`, onClick: this.handleSecondIncrement, disabled: this.disabled || this.isAtMaxSecond(), "aria-label": this.labels.incrementSeconds }, h("svg", { key: '1ab4adae2efa4a54286605be221cf2d424e98deb', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: '61ef61c721a39732a3aacdc9db5b63950796706b', points: "18 15 12 9 6 15" }))), h("input", { key: 'd5b40cf419b007e28f7f69ffe333601fcc3c701e', id: `${this.elementClassName}-seconds`, type: "number", class: `${this.elementClassName}__input`, value: this.padZero(this.internalSeconds), min: 0, max: 59, onInput: this.handleSecondChange, disabled: this.disabled, "aria-label": this.labels.seconds }), h("button", { key: '177306df5ba004bbd58df462a7d010f8903656eb', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--decrement`, onClick: this.handleSecondDecrement, disabled: this.disabled || this.isAtMinSecond(), "aria-label": this.labels.decrementSeconds }, h("svg", { key: '971169fce6fee5ccb8241faef04d633a0396e347', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, h("polyline", { key: '4c31a4b794cc6b421e8e2b3cdb322d584fe40e81', points: "6 9 12 15 18 9" })))))
|
|
279
|
+
], this.useTwelveHourFormat && (h("div", { key: 'b6e9916c6d14aaac6aa3ee1f1c3bd2624f01a344', class: `${this.elementClassName}__period` }, h("button", { key: 'c476a13007f840b5f9e5f058623b1846b33b72cf', type: "button", class: {
|
|
262
280
|
[`${this.elementClassName}__period-button`]: true,
|
|
263
281
|
[`${this.elementClassName}__period-button--active`]: this.period === "AM"
|
|
264
|
-
}, onClick: () => this.handlePeriodChange("AM"), disabled: this.disabled, "aria-label": this.labels.am, "aria-pressed": this.period === "AM" }, this.labels.am), h("button", { key: '
|
|
282
|
+
}, onClick: () => this.handlePeriodChange("AM"), disabled: this.disabled, "aria-label": this.labels.am, "aria-pressed": this.period === "AM" }, this.labels.am), h("button", { key: 'f4cc8df59e07cb53e9b72f376a17e10df357a335', type: "button", class: {
|
|
265
283
|
[`${this.elementClassName}__period-button`]: true,
|
|
266
284
|
[`${this.elementClassName}__period-button--active`]: this.period === "PM"
|
|
267
285
|
}, onClick: () => this.handlePeriodChange("PM"), disabled: this.disabled, "aria-label": this.labels.pm, "aria-pressed": this.period === "PM" }, this.labels.pm))))));
|
|
@@ -499,6 +517,26 @@ export class TabworthyTimesPicker {
|
|
|
499
517
|
},
|
|
500
518
|
"getter": false,
|
|
501
519
|
"setter": false
|
|
520
|
+
},
|
|
521
|
+
"modalIsOpen": {
|
|
522
|
+
"type": "boolean",
|
|
523
|
+
"mutable": false,
|
|
524
|
+
"complexType": {
|
|
525
|
+
"original": "boolean",
|
|
526
|
+
"resolved": "boolean",
|
|
527
|
+
"references": {}
|
|
528
|
+
},
|
|
529
|
+
"required": false,
|
|
530
|
+
"optional": true,
|
|
531
|
+
"docs": {
|
|
532
|
+
"tags": [],
|
|
533
|
+
"text": ""
|
|
534
|
+
},
|
|
535
|
+
"getter": false,
|
|
536
|
+
"setter": false,
|
|
537
|
+
"reflect": false,
|
|
538
|
+
"attribute": "modal-is-open",
|
|
539
|
+
"defaultValue": "false"
|
|
502
540
|
}
|
|
503
541
|
};
|
|
504
542
|
}
|
|
@@ -537,6 +575,9 @@ export class TabworthyTimesPicker {
|
|
|
537
575
|
static get elementRef() { return "el"; }
|
|
538
576
|
static get watchers() {
|
|
539
577
|
return [{
|
|
578
|
+
"propName": "modalIsOpen",
|
|
579
|
+
"methodName": "watchModalIsOpen"
|
|
580
|
+
}, {
|
|
540
581
|
"propName": "hours",
|
|
541
582
|
"methodName": "watchHours"
|
|
542
583
|
}, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const formatDateError = (label, date) => typeof label === "function" ? label(date) : `${label} ${date}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{p as t,H as s,c as i,h as e,d as h,t as n}from"./p-BiJ0HZVY.js";const a={hours:"Hours",minutes:"Minutes",seconds:"Seconds",am:"AM",pm:"PM",timePicker:"Time picker",incrementHours:"Increment hours",decrementHours:"Decrement hours",incrementMinutes:"Increment minutes",decrementMinutes:"Decrement minutes",incrementSeconds:"Increment seconds",decrementSeconds:"Decrement seconds"},o=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.timeChanged=i(this,"timeChanged",7),this.hours=12,this.minutes=0,this.seconds=0,this.useTwelveHourFormat=!1,this.showSeconds=!1,this.labels=a,this.labelsSrOnly=!0,this.disabled=!1,this.elementClassName="tabworthy-times-picker",this.modalIsOpen=!1,this.internalHours=this.hours,this.internalMinutes=this.minutes,this.internalSeconds=this.seconds,this.period=this.hours>=12?"PM":"AM",this.handleHourChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalHours=this.useTwelveHourFormat?"AM"===this.period?12===s?0:s:12===s?12:s+12:s,this.emitTimeChange())},this.handleMinuteChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalMinutes=s,this.emitTimeChange())},this.handlePeriodChange=t=>{if(this.period===t||!this.useTwelveHourFormat)return;this.period=t;const s=this.getDisplayHours();this.internalHours="AM"===t?12===s?0:s:12===s?12:s+12,this.emitTimeChange()},this.handleHourIncrement=()=>{if(this.useTwelveHourFormat){const t=this.getDisplayHours(),s=12===t?1:t+1;this.internalHours="AM"===this.period?12===s?0:s:12===s?12:s+12}else this.internalHours=(this.internalHours+1)%24;this.emitTimeChange()},this.handleHourDecrement=()=>{if(this.useTwelveHourFormat){const t=this.getDisplayHours(),s=1===t?12:t-1;this.internalHours="AM"===this.period?12===s?0:s:12===s?12:s+12}else this.internalHours=0===this.internalHours?23:this.internalHours-1;this.emitTimeChange()},this.handleMinuteIncrement=()=>{this.internalMinutes=(this.internalMinutes+1)%60,this.emitTimeChange()},this.handleMinuteDecrement=()=>{this.internalMinutes=0===this.internalMinutes?59:this.internalMinutes-1,this.emitTimeChange()},this.handleSecondChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalSeconds=s,this.emitTimeChange())},this.handleSecondIncrement=()=>{this.internalSeconds=(this.internalSeconds+1)%60,this.emitTimeChange()},this.handleSecondDecrement=()=>{this.internalSeconds=0===this.internalSeconds?59:this.internalSeconds-1,this.emitTimeChange()}}watchModalIsOpen(){!0===this.modalIsOpen&&(this.moveFocusOnModalOpen=!0)}watchHours(t){this.internalHours=t,this.period=t>=12?"PM":"AM"}watchMinutes(t){this.internalMinutes=t}watchSeconds(t){this.internalSeconds=t}componentWillLoad(){this.internalHours=this.hours,this.internalMinutes=this.minutes,this.internalSeconds=this.seconds,this.period=this.hours>=12?"PM":"AM"}componentDidRender(){this.moveFocusOnModalOpen&&setTimeout((()=>{this.focusHoursInput(),this.moveFocusOnModalOpen=!1}),100)}focusHoursInput(){var t;null===(t=this.hoursInputRef)||void 0===t||t.focus()}getDisplayHours(){return this.useTwelveHourFormat?0===this.internalHours?12:this.internalHours>12?this.internalHours-12:this.internalHours:this.internalHours}get24HourValue(){if(!this.useTwelveHourFormat)return this.internalHours;const t=this.getDisplayHours();return"AM"===this.period?12===t?0:t:12===t?12:t+12}emitTimeChange(){this.clampToBounds(),this.timeChanged.emit({hours:this.get24HourValue(),minutes:this.internalMinutes,seconds:this.showSeconds?this.internalSeconds:void 0,period:this.useTwelveHourFormat?this.period:void 0})}clampToBounds(){var t,s;const i=this.get24HourValue(),e=this.internalMinutes;if(this.minTime){const s=null!==(t=this.minTime.seconds)&&void 0!==t?t:0;(i<this.minTime.hours||i===this.minTime.hours&&e<this.minTime.minutes||i===this.minTime.hours&&e===this.minTime.minutes&&this.internalSeconds<s)&&(this.setInternal24Hours(this.minTime.hours),this.internalMinutes=this.minTime.minutes,this.internalSeconds=s)}if(this.maxTime){const t=null!==(s=this.maxTime.seconds)&&void 0!==s?s:59,i=this.get24HourValue(),e=this.internalMinutes;(i>this.maxTime.hours||i===this.maxTime.hours&&e>this.maxTime.minutes||i===this.maxTime.hours&&e===this.maxTime.minutes&&this.internalSeconds>t)&&(this.setInternal24Hours(this.maxTime.hours),this.internalMinutes=this.maxTime.minutes,this.internalSeconds=t)}}setInternal24Hours(t){this.internalHours=t,this.period=t>=12?"PM":"AM"}isAtMinHour(){return!!this.minTime&&this.get24HourValue()<=this.minTime.hours}isAtMaxHour(){return!!this.maxTime&&this.get24HourValue()>=this.maxTime.hours}isAtMinMinute(){return this.isAtMinHour()&&!!this.minTime&&this.internalMinutes<=this.minTime.minutes}isAtMaxMinute(){return this.isAtMaxHour()&&!!this.maxTime&&this.internalMinutes>=this.maxTime.minutes}isAtMinSecond(){var t;return this.isAtMinMinute()&&!!this.minTime&&this.internalSeconds<=(null!==(t=this.minTime.seconds)&&void 0!==t?t:0)}isAtMaxSecond(){var t;return this.isAtMaxMinute()&&!!this.maxTime&&this.internalSeconds>=(null!==(t=this.maxTime.seconds)&&void 0!==t?t:59)}padZero(t){return t.toString().padStart(2,"0")}render(){const t=this.getDisplayHours(),s=this.useTwelveHourFormat?12:23,i=this.useTwelveHourFormat?1:0;return e(h,{key:"c307a1b94d1ec25702c286c7f36e4746df8c6bb7",class:this.elementClassName,"aria-label":this.labels.timePicker},e("div",{key:"c446911a0ddcb6282ab5507d359d56a42f533db3",class:`${this.elementClassName}__container`},e("div",{key:"302c7e7e0c1bf71629ef2a71bb564f9571aad7be",class:`${this.elementClassName}__field`},e("label",{key:"8ce64af4f416c3cdc0dd8943fc02ab9016d62099",htmlFor:`${this.elementClassName}-hours`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.hours),e("div",{key:"3f541e096c7bb3f436f358800588d5da7fccb34e",class:`${this.elementClassName}__control`},e("button",{key:"31039ad972122c2a6f963190d38f379bb7dce71f",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleHourIncrement,disabled:this.disabled||this.isAtMaxHour(),"aria-label":this.labels.incrementHours},e("svg",{key:"4b16f261f4fecc91973d858b6235fc8aac4f7605",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"fe60640cfa75911b862913a3076cbeea037a38f7",points:"18 15 12 9 6 15"}))),e("input",{key:"a3a7eed2efc8b1789de698771e82e3f31f50e885",id:`${this.elementClassName}-hours`,ref:t=>this.hoursInputRef=t,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(t),min:i,max:s,onInput:this.handleHourChange,disabled:this.disabled,"aria-label":this.labels.hours}),e("button",{key:"421b70976c21b2b33e21962780d13609a6b762a5",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleHourDecrement,disabled:this.disabled||this.isAtMinHour(),"aria-label":this.labels.decrementHours},e("svg",{key:"ab87c0de149d43edcbebd1b2d4d00e4a3ebed5b3",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"32f2d112c44434249d506d1e8222e25b34fb0d44",points:"6 9 12 15 18 9"}))))),e("div",{key:"54449a42e67f6f3c2318310bc12eeba24cebc56f",class:`${this.elementClassName}__separator`},":"),e("div",{key:"f65d84751223424c3649d0fb9589cf3c1af091eb",class:`${this.elementClassName}__field`},e("label",{key:"911244fd360371ee26b97eb9690c7b04340d6e88",htmlFor:`${this.elementClassName}-minutes`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.minutes),e("div",{key:"e5574834dd59e9c08dcee56b07bf8bf186f7ba4b",class:`${this.elementClassName}__control`},e("button",{key:"2b091d643aa785b8ddeae55dd8c523cd5282719d",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleMinuteIncrement,disabled:this.disabled||this.isAtMaxMinute(),"aria-label":this.labels.incrementMinutes},e("svg",{key:"23668a0f1299f86901d0e32e9f7f37bacd376665",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"7f030c2d35147651ad86352c65dc6f8f00b2ba93",points:"18 15 12 9 6 15"}))),e("input",{key:"b73ed30b3a7d25ef84bab23afa45172ce5d03944",id:`${this.elementClassName}-minutes`,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(this.internalMinutes),min:0,max:59,onInput:this.handleMinuteChange,disabled:this.disabled,"aria-label":this.labels.minutes}),e("button",{key:"7ce7a36ef59e44afd474c427250adc352a8a6694",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleMinuteDecrement,disabled:this.disabled||this.isAtMinMinute(),"aria-label":this.labels.decrementMinutes},e("svg",{key:"49bcd0c73fde1f77c0d42978a76086abb5be6cc4",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"c503c319467e0aac6883db25b7d84a1d752aeaf9",points:"6 9 12 15 18 9"}))))),this.showSeconds&&[e("div",{key:"be25b2045f9e74b0414e55f8d508f7c192e1772e",class:`${this.elementClassName}__separator`},":"),e("div",{key:"85ceb01427ea52c231f1b6a3d78c95c6d603215c",class:`${this.elementClassName}__field`},e("label",{key:"1a1adf9081b3e763e4fbc45b8bab812ae869edbb",htmlFor:`${this.elementClassName}-seconds`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.seconds),e("div",{key:"abce976c9d3143819c41ff64b54dfbcea41ddd88",class:`${this.elementClassName}__control`},e("button",{key:"1416ee09b69a6d62d8ecd1394bb375fc01601e4a",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleSecondIncrement,disabled:this.disabled||this.isAtMaxSecond(),"aria-label":this.labels.incrementSeconds},e("svg",{key:"1ab4adae2efa4a54286605be221cf2d424e98deb",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"61ef61c721a39732a3aacdc9db5b63950796706b",points:"18 15 12 9 6 15"}))),e("input",{key:"d5b40cf419b007e28f7f69ffe333601fcc3c701e",id:`${this.elementClassName}-seconds`,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(this.internalSeconds),min:0,max:59,onInput:this.handleSecondChange,disabled:this.disabled,"aria-label":this.labels.seconds}),e("button",{key:"177306df5ba004bbd58df462a7d010f8903656eb",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleSecondDecrement,disabled:this.disabled||this.isAtMinSecond(),"aria-label":this.labels.decrementSeconds},e("svg",{key:"971169fce6fee5ccb8241faef04d633a0396e347",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},e("polyline",{key:"4c31a4b794cc6b421e8e2b3cdb322d584fe40e81",points:"6 9 12 15 18 9"})))))],this.useTwelveHourFormat&&e("div",{key:"b6e9916c6d14aaac6aa3ee1f1c3bd2624f01a344",class:`${this.elementClassName}__period`},e("button",{key:"c476a13007f840b5f9e5f058623b1846b33b72cf",type:"button",class:{[`${this.elementClassName}__period-button`]:!0,[`${this.elementClassName}__period-button--active`]:"AM"===this.period},onClick:()=>this.handlePeriodChange("AM"),disabled:this.disabled,"aria-label":this.labels.am,"aria-pressed":"AM"===this.period},this.labels.am),e("button",{key:"f4cc8df59e07cb53e9b72f376a17e10df357a335",type:"button",class:{[`${this.elementClassName}__period-button`]:!0,[`${this.elementClassName}__period-button--active`]:"PM"===this.period},onClick:()=>this.handlePeriodChange("PM"),disabled:this.disabled,"aria-label":this.labels.pm,"aria-pressed":"PM"===this.period},this.labels.pm))))}get el(){return this}static get watchers(){return{modalIsOpen:[{watchModalIsOpen:0}],hours:[{watchHours:0}],minutes:[{watchMinutes:0}],seconds:[{watchSeconds:0}]}}},[2,"tabworthy-times-picker",{hours:[1026],minutes:[1026],seconds:[1026],useTwelveHourFormat:[4,"use-twelve-hour-format"],showSeconds:[4,"show-seconds"],labels:[16],labelsSrOnly:[4,"labels-sr-only"],disabled:[4],elementClassName:[1,"element-class-name"],minTime:[16],maxTime:[16],modalIsOpen:[4,"modal-is-open"],internalHours:[32],internalMinutes:[32],internalSeconds:[32],period:[32]},void 0,{modalIsOpen:[{watchModalIsOpen:0}],hours:[{watchHours:0}],minutes:[{watchMinutes:0}],seconds:[{watchSeconds:0}]}]);function c(){"undefined"!=typeof customElements&&["tabworthy-times-picker"].forEach((t=>{"tabworthy-times-picker"===t&&(customElements.get(n(t))||customElements.define(n(t),o))}))}export{o as T,c as d}
|