@tabworthy/components 0.12.4 → 0.13.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/loader.cjs.js +1 -1
- package/dist/cjs/tabworthy-components.cjs.js +1 -1
- package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +35 -17
- package/dist/cjs/tabworthy-dates.cjs.entry.js +48 -10
- package/dist/cjs/tabworthy-times-picker.cjs.entry.js +82 -10
- package/dist/cjs/tabworthy-times.cjs.entry.js +108 -5
- package/dist/cjs/{utils-y5Vtky2t.js → utils-DGbdK8VF.js} +29 -8
- package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +68 -10
- package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +35 -17
- package/dist/collection/components/tabworthy-times/tabworthy-times.js +128 -4
- package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +128 -10
- package/dist/components/p-BzY8iIVW.js +1 -0
- package/dist/components/p-C_uZGgcG.js +1 -0
- package/dist/components/tabworthy-dates-calendar.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/loader.js +1 -1
- package/dist/esm/tabworthy-components.js +1 -1
- package/dist/esm/tabworthy-dates-calendar_2.entry.js +35 -17
- package/dist/esm/tabworthy-dates.entry.js +48 -10
- package/dist/esm/tabworthy-times-picker.entry.js +82 -10
- package/dist/esm/tabworthy-times.entry.js +108 -5
- package/dist/esm/{utils-BVHu5CWV.js → utils-CoFOnMSw.js} +29 -9
- package/dist/shared/utils/utils.js +28 -8
- package/dist/tabworthy-components/p-69334c34.entry.js +1 -0
- package/dist/tabworthy-components/p-71f5c261.entry.js +1 -0
- package/dist/tabworthy-components/p-7cd6ccc1.entry.js +1 -0
- package/dist/tabworthy-components/{p-BVHu5CWV.js → p-CoFOnMSw.js} +1 -1
- package/dist/tabworthy-components/p-ed3c60d6.entry.js +1 -0
- package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
- package/dist/themes/light.css +1 -1
- package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +7 -0
- package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +8 -1
- package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +15 -0
- package/dist/types/components.d.ts +14 -4
- package/dist/types/home/runner/work/tabworthy-components/tabworthy-components/.stencil/shared/utils/utils.d.ts +6 -0
- package/package.json +1 -1
- package/dist/components/p-BTQaxOHo.js +0 -1
- package/dist/components/p-DAc3jaFB.js +0 -1
- package/dist/tabworthy-components/p-1743bf7a.entry.js +0 -1
- package/dist/tabworthy-components/p-28192b55.entry.js +0 -1
- package/dist/tabworthy-components/p-3b548ae1.entry.js +0 -1
- package/dist/tabworthy-components/p-626a5c0b.entry.js +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var index = require('./index-B1s0tI-Z.js');
|
|
4
4
|
var customParseFormat = require('./customParseFormat-l09KVyWD.js');
|
|
5
|
-
var utils = require('./utils-
|
|
5
|
+
var utils = require('./utils-DGbdK8VF.js');
|
|
6
6
|
|
|
7
7
|
var localizedFormat$2 = {exports: {}};
|
|
8
8
|
|
|
@@ -42,6 +42,7 @@ const TabworthyTimes = class {
|
|
|
42
42
|
index.registerInstance(this, hostRef);
|
|
43
43
|
this.selectDateTime = index.createEvent(this, "selectDateTime", 7);
|
|
44
44
|
this.changeYear = index.createEvent(this, "changeYear", 7);
|
|
45
|
+
this.errorChange = index.createEvent(this, "errorChange", 7);
|
|
45
46
|
this.componentReady = index.createEvent(this, "componentReady", 7);
|
|
46
47
|
// Enable or disable range mode
|
|
47
48
|
this.range = false;
|
|
@@ -103,6 +104,8 @@ const TabworthyTimes = class {
|
|
|
103
104
|
if (this.range && dates.length === 2) {
|
|
104
105
|
const startDate = utils.removeTimezoneOffset(new Date(dates[0]));
|
|
105
106
|
const endDate = utils.removeTimezoneOffset(new Date(dates[1]));
|
|
107
|
+
if (!this.isDateValid(startDate) || !this.isDateValid(endDate))
|
|
108
|
+
return;
|
|
106
109
|
this.updateValue([startDate, endDate]);
|
|
107
110
|
// Update calendar with selected dates
|
|
108
111
|
if (this.pickerRef) {
|
|
@@ -111,6 +114,8 @@ const TabworthyTimes = class {
|
|
|
111
114
|
}
|
|
112
115
|
else {
|
|
113
116
|
const date = utils.removeTimezoneOffset(new Date(dates[0]));
|
|
117
|
+
if (!this.isDateValid(date))
|
|
118
|
+
return;
|
|
114
119
|
this.updateValue(date);
|
|
115
120
|
// Update calendar with selected date
|
|
116
121
|
if (this.pickerRef) {
|
|
@@ -169,6 +174,25 @@ const TabworthyTimes = class {
|
|
|
169
174
|
parsed = customParseFormat.dayjs(value);
|
|
170
175
|
}
|
|
171
176
|
if (parsed.isValid()) {
|
|
177
|
+
// Check minDate/maxDate bounds (supports both date-only and datetime strings)
|
|
178
|
+
if (this.minDate && parsed.isBefore(customParseFormat.dayjs(this.minDate))) {
|
|
179
|
+
this.errorState = true;
|
|
180
|
+
this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
|
|
181
|
+
this.emitErrorChange("minDate", this.errorMessage);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (this.maxDate && parsed.isAfter(customParseFormat.dayjs(this.maxDate))) {
|
|
185
|
+
this.errorState = true;
|
|
186
|
+
this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
|
|
187
|
+
this.emitErrorChange("maxDate", this.errorMessage);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (this.disableDate(parsed.toDate())) {
|
|
191
|
+
this.errorState = true;
|
|
192
|
+
this.errorMessage = this.timesLabels.disabledDateError;
|
|
193
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
172
196
|
this.errorState = false;
|
|
173
197
|
this.selectedHours = parsed.hour();
|
|
174
198
|
this.selectedMinutes = parsed.minute();
|
|
@@ -179,9 +203,64 @@ const TabworthyTimes = class {
|
|
|
179
203
|
// Set error state for invalid/garbage input
|
|
180
204
|
this.errorState = true;
|
|
181
205
|
this.errorMessage = this.timesLabels.invalidDateError;
|
|
206
|
+
this.emitErrorChange("invalid", this.errorMessage);
|
|
182
207
|
}
|
|
183
208
|
};
|
|
184
209
|
}
|
|
210
|
+
emitErrorChange(reason, message) {
|
|
211
|
+
this.errorChange.emit({ reason, message });
|
|
212
|
+
}
|
|
213
|
+
formatBoundaryDate(dateString) {
|
|
214
|
+
const parsed = customParseFormat.dayjs(dateString);
|
|
215
|
+
if (!parsed.isValid())
|
|
216
|
+
return dateString;
|
|
217
|
+
const hasTime = dateString.includes("T") || dateString.includes(" ");
|
|
218
|
+
if (!hasTime) {
|
|
219
|
+
return Intl.DateTimeFormat(this.locale, {
|
|
220
|
+
day: "numeric",
|
|
221
|
+
month: "short",
|
|
222
|
+
year: "numeric"
|
|
223
|
+
}).format(parsed.toDate());
|
|
224
|
+
}
|
|
225
|
+
const options = Object.assign({ day: "numeric", month: "short", year: "numeric", hour: "numeric", minute: "numeric" }, (this.showSeconds ? { second: "numeric" } : {}));
|
|
226
|
+
return Intl.DateTimeFormat(this.locale, options).format(parsed.toDate());
|
|
227
|
+
}
|
|
228
|
+
getEffectiveMinTime() {
|
|
229
|
+
if (!this.minDate || !this.selectedDate)
|
|
230
|
+
return undefined;
|
|
231
|
+
const min = customParseFormat.dayjs(this.minDate);
|
|
232
|
+
const sel = customParseFormat.dayjs(this.selectedDate);
|
|
233
|
+
if (!min.isValid() || !sel.isSame(min, "day"))
|
|
234
|
+
return undefined;
|
|
235
|
+
return {
|
|
236
|
+
hours: min.hour(),
|
|
237
|
+
minutes: min.minute(),
|
|
238
|
+
seconds: min.second()
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
getEffectiveMaxTime() {
|
|
242
|
+
if (!this.maxDate || !this.selectedDate)
|
|
243
|
+
return undefined;
|
|
244
|
+
const max = customParseFormat.dayjs(this.maxDate);
|
|
245
|
+
const sel = customParseFormat.dayjs(this.selectedDate);
|
|
246
|
+
if (!max.isValid() || !sel.isSame(max, "day"))
|
|
247
|
+
return undefined;
|
|
248
|
+
return {
|
|
249
|
+
hours: max.hour(),
|
|
250
|
+
minutes: max.minute(),
|
|
251
|
+
seconds: max.second()
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
isDateOutOfBounds() {
|
|
255
|
+
if (!this.selectedDate)
|
|
256
|
+
return false;
|
|
257
|
+
const sel = customParseFormat.dayjs(this.selectedDate);
|
|
258
|
+
if (this.minDate && sel.isBefore(customParseFormat.dayjs(this.minDate), "day"))
|
|
259
|
+
return true;
|
|
260
|
+
if (this.maxDate && sel.isAfter(customParseFormat.dayjs(this.maxDate), "day"))
|
|
261
|
+
return true;
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
185
264
|
shouldInputFormat() {
|
|
186
265
|
if (typeof this.inputShouldFormat === "string") {
|
|
187
266
|
return this.inputShouldFormat === "true";
|
|
@@ -254,6 +333,30 @@ const TabworthyTimes = class {
|
|
|
254
333
|
this.formatInput();
|
|
255
334
|
}
|
|
256
335
|
}
|
|
336
|
+
isDateValid(date) {
|
|
337
|
+
const parsed = customParseFormat.dayjs(date);
|
|
338
|
+
if (!parsed.isValid())
|
|
339
|
+
return false;
|
|
340
|
+
if (this.minDate && parsed.isBefore(customParseFormat.dayjs(this.minDate))) {
|
|
341
|
+
this.errorState = true;
|
|
342
|
+
this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
|
|
343
|
+
this.emitErrorChange("minDate", this.errorMessage);
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (this.maxDate && parsed.isAfter(customParseFormat.dayjs(this.maxDate))) {
|
|
347
|
+
this.errorState = true;
|
|
348
|
+
this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
|
|
349
|
+
this.emitErrorChange("maxDate", this.errorMessage);
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (this.disableDate(date)) {
|
|
353
|
+
this.errorState = true;
|
|
354
|
+
this.errorMessage = this.timesLabels.disabledDateError;
|
|
355
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
257
360
|
formatInput() {
|
|
258
361
|
if (!this.internalValue)
|
|
259
362
|
return;
|
|
@@ -294,12 +397,12 @@ const TabworthyTimes = class {
|
|
|
294
397
|
}
|
|
295
398
|
render() {
|
|
296
399
|
var _a;
|
|
297
|
-
return (index.h(index.Host, { key: '
|
|
400
|
+
return (index.h(index.Host, { key: 'd258bd87c60aa773bd178e1e74eeb32934d8f068', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: '5e7a53cb36c350794af9fed2371c89823726ee2f', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: '986905f117271cfb82a1f8415d55536a590ac2bc', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: '9ad436c1e0c8a427c1665db16913cddf93d94fed', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
298
401
|
[this.getClassName("input")]: true,
|
|
299
402
|
[this.inputClass]: !!this.inputClass
|
|
300
|
-
}, 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: '
|
|
403
|
+
}, 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: 'd537e6f3251bada7ad50bbe1ca2c562737205897', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
|
|
301
404
|
? this.timesLabels.openCalendar
|
|
302
|
-
: undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '
|
|
405
|
+
: undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '241700195e1d028f8d8b6b55af7de3aee09163ea', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
303
406
|
if (this.pickerRef) {
|
|
304
407
|
this.pickerRef.modalIsOpen = true;
|
|
305
408
|
}
|
|
@@ -307,7 +410,7 @@ const TabworthyTimes = class {
|
|
|
307
410
|
if (this.pickerRef) {
|
|
308
411
|
this.pickerRef.modalIsOpen = false;
|
|
309
412
|
}
|
|
310
|
-
}, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '
|
|
413
|
+
}, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: 'b99aa129e4d1d600971bc4d21b2c6a4316ff64cf', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: '6ac11c01936e2155c023d286d912ba87e0ed3415', 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: '7eead2c25334abce43fe7371436a52b0970e648b', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: '06ac45a5eaaaa56d39825f941b0951f99c4b28e9', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: 'ba4187a2a369cff58ca0ecf3a60abfeff3ba9ca3', 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() }))))), this.errorState && (index.h("div", { key: 'c187d0bd982a5184aa796ffe8be4ed91c340230d', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
311
414
|
}
|
|
312
415
|
get el() { return index.getElement(this); }
|
|
313
416
|
static get watchers() { return {
|
|
@@ -138,6 +138,17 @@ function removeTimezoneOffset(date) {
|
|
|
138
138
|
newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset());
|
|
139
139
|
return newDate;
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Parse a date boundary string to a local Date.
|
|
143
|
+
* Date-only strings ("YYYY-MM-DD") are parsed as UTC by JS, so we apply removeTimezoneOffset.
|
|
144
|
+
* Datetime strings (containing "T" or space+time) are already parsed as local time.
|
|
145
|
+
*/
|
|
146
|
+
function parseDateString(dateString) {
|
|
147
|
+
const hasTime = dateString.includes("T") ||
|
|
148
|
+
/\d{4}-\d{2}-\d{2}\s\d{2}:/.test(dateString);
|
|
149
|
+
const parsed = new Date(dateString);
|
|
150
|
+
return hasTime ? parsed : removeTimezoneOffset(parsed);
|
|
151
|
+
}
|
|
141
152
|
function subDays(date, days) {
|
|
142
153
|
const newDate = new Date(date);
|
|
143
154
|
newDate.setDate(newDate.getDate() - days);
|
|
@@ -145,7 +156,7 @@ function subDays(date, days) {
|
|
|
145
156
|
}
|
|
146
157
|
function dateIsWithinLowerBounds(date, minDate) {
|
|
147
158
|
if (minDate) {
|
|
148
|
-
const min =
|
|
159
|
+
const min = parseDateString(minDate);
|
|
149
160
|
return date >= min || isSameDay(min, date);
|
|
150
161
|
}
|
|
151
162
|
else
|
|
@@ -153,7 +164,7 @@ function dateIsWithinLowerBounds(date, minDate) {
|
|
|
153
164
|
}
|
|
154
165
|
function dateIsWithinUpperBounds(date, maxDate) {
|
|
155
166
|
if (maxDate) {
|
|
156
|
-
const max =
|
|
167
|
+
const max = parseDateString(maxDate);
|
|
157
168
|
return date <= max || isSameDay(date, max);
|
|
158
169
|
}
|
|
159
170
|
else
|
|
@@ -164,12 +175,21 @@ function dateIsWithinBounds(date, minDate, maxDate) {
|
|
|
164
175
|
dateIsWithinUpperBounds(date, maxDate));
|
|
165
176
|
}
|
|
166
177
|
function monthIsDisabled(month, year, minDate, maxDate) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
if (minDate) {
|
|
179
|
+
const min = parseDateString(minDate);
|
|
180
|
+
const minYear = min.getFullYear();
|
|
181
|
+
const minMonth = min.getMonth();
|
|
182
|
+
if (year < minYear || (year === minYear && month < minMonth))
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (maxDate) {
|
|
186
|
+
const max = parseDateString(maxDate);
|
|
187
|
+
const maxYear = max.getFullYear();
|
|
188
|
+
const maxMonth = max.getMonth();
|
|
189
|
+
if (year > maxYear || (year === maxYear && month > maxMonth))
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
173
193
|
}
|
|
174
194
|
function isValidISODate(dateString) {
|
|
175
195
|
var isoFormat = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -210,5 +230,6 @@ exports.isDateInRange = isDateInRange;
|
|
|
210
230
|
exports.isSameDay = isSameDay;
|
|
211
231
|
exports.isValidISODate = isValidISODate;
|
|
212
232
|
exports.monthIsDisabled = monthIsDisabled;
|
|
233
|
+
exports.parseDateString = parseDateString;
|
|
213
234
|
exports.removeTimezoneOffset = removeTimezoneOffset;
|
|
214
235
|
exports.subDays = subDays;
|
|
@@ -3,7 +3,7 @@ import { announce } from "@react-aria/live-announcer";
|
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
4
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
5
5
|
dayjs.extend(customParseFormat);
|
|
6
|
-
import { getISODateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
6
|
+
import { getISODateString, parseDateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
7
7
|
import { chronoParseDate, chronoParseRange } from "../../../../shared/utils/chrono-parser/chrono-parser";
|
|
8
8
|
const defaultLabels = {
|
|
9
9
|
selected: "selected",
|
|
@@ -184,6 +184,7 @@ export class TabworthyDates {
|
|
|
184
184
|
maxDate: ""
|
|
185
185
|
}[parsedRange.reason];
|
|
186
186
|
}
|
|
187
|
+
this.emitErrorChange(parsedRange === null || parsedRange === void 0 ? void 0 : parsedRange.reason, this.errorMessage);
|
|
187
188
|
}
|
|
188
189
|
};
|
|
189
190
|
this.handleSingleDateChange = async (value) => {
|
|
@@ -206,6 +207,7 @@ export class TabworthyDates {
|
|
|
206
207
|
if (this.disableDate(parsedDate.value)) {
|
|
207
208
|
this.errorState = true;
|
|
208
209
|
this.errorMessage = this.datesLabels.disabledDateError;
|
|
210
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
209
211
|
}
|
|
210
212
|
else {
|
|
211
213
|
this.updateValue(parsedDate.value);
|
|
@@ -218,30 +220,31 @@ export class TabworthyDates {
|
|
|
218
220
|
let maxDate = undefined;
|
|
219
221
|
let minDate = undefined;
|
|
220
222
|
if (this.maxDate) {
|
|
221
|
-
maxDate = this.maxDate
|
|
222
|
-
? removeTimezoneOffset(new Date(this.maxDate))
|
|
223
|
-
: undefined;
|
|
223
|
+
maxDate = this.maxDate ? parseDateString(this.maxDate) : undefined;
|
|
224
224
|
maxDate === null || maxDate === void 0 ? void 0 : maxDate.setDate(maxDate.getDate() + 1);
|
|
225
225
|
}
|
|
226
226
|
if (this.minDate) {
|
|
227
|
-
minDate = this.minDate
|
|
228
|
-
? removeTimezoneOffset(new Date(this.minDate))
|
|
229
|
-
: undefined;
|
|
227
|
+
minDate = this.minDate ? parseDateString(this.minDate) : undefined;
|
|
230
228
|
minDate === null || minDate === void 0 ? void 0 : minDate.setDate(minDate.getDate() - 1);
|
|
231
229
|
}
|
|
232
230
|
if (!!parsedDate.reason) {
|
|
231
|
+
const formatLocalizedDate = (date) => Intl.DateTimeFormat(this.locale, {
|
|
232
|
+
day: "numeric",
|
|
233
|
+
month: "short",
|
|
234
|
+
year: "numeric"
|
|
235
|
+
}).format(date);
|
|
233
236
|
this.errorMessage = parsedDate.reason;
|
|
234
237
|
this.errorMessage = {
|
|
235
|
-
// TODO: Add locale date formatting to these messages
|
|
236
238
|
minDate: minDate
|
|
237
|
-
? `${this.datesLabels.minDateError} ${
|
|
239
|
+
? `${this.datesLabels.minDateError} ${formatLocalizedDate(minDate)}`
|
|
238
240
|
: "",
|
|
239
241
|
maxDate: maxDate
|
|
240
|
-
? `${this.datesLabels.maxDateError} ${
|
|
242
|
+
? `${this.datesLabels.maxDateError} ${formatLocalizedDate(maxDate)}`
|
|
241
243
|
: "",
|
|
242
244
|
invalid: this.datesLabels.invalidDateError
|
|
243
245
|
}[parsedDate.reason];
|
|
244
246
|
}
|
|
247
|
+
this.emitErrorChange(parsedDate === null || parsedDate === void 0 ? void 0 : parsedDate.reason, this.errorMessage);
|
|
245
248
|
}
|
|
246
249
|
};
|
|
247
250
|
this.handleChange = async (event) => {
|
|
@@ -310,6 +313,9 @@ export class TabworthyDates {
|
|
|
310
313
|
this.selectDate.emit(this.internalValue);
|
|
311
314
|
this.announceDateChange(this.internalValue);
|
|
312
315
|
}
|
|
316
|
+
emitErrorChange(reason, message) {
|
|
317
|
+
this.errorChange.emit({ reason, message });
|
|
318
|
+
}
|
|
313
319
|
formatInput(enabled, useInputValue = true) {
|
|
314
320
|
if (this.shouldInputFormat() === false || enabled === false) {
|
|
315
321
|
if (this.internalValue) {
|
|
@@ -355,9 +361,37 @@ export class TabworthyDates {
|
|
|
355
361
|
}
|
|
356
362
|
}
|
|
357
363
|
}
|
|
364
|
+
isPickedDateValid(dateString) {
|
|
365
|
+
const parsed = dayjs(dateString);
|
|
366
|
+
if (!parsed.isValid())
|
|
367
|
+
return false;
|
|
368
|
+
const isoDate = typeof dateString === "string" ? dateString : parsed.format("YYYY-MM-DD");
|
|
369
|
+
if (this.minDate && isoDate < this.minDate) {
|
|
370
|
+
this.errorState = true;
|
|
371
|
+
this.errorMessage = `${this.datesLabels.minDateError} ${this.minDate}`;
|
|
372
|
+
this.emitErrorChange("minDate", this.errorMessage);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (this.maxDate && isoDate > this.maxDate) {
|
|
376
|
+
this.errorState = true;
|
|
377
|
+
this.errorMessage = `${this.datesLabels.maxDateError} ${this.maxDate}`;
|
|
378
|
+
this.emitErrorChange("maxDate", this.errorMessage);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
if (this.disableDate(parsed.toDate())) {
|
|
382
|
+
this.errorState = true;
|
|
383
|
+
this.errorMessage = this.datesLabels.disabledDateError;
|
|
384
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
358
389
|
handlePickerSelection(newValue) {
|
|
359
390
|
var _a, _b;
|
|
360
391
|
if (this.isRangeValue(newValue)) {
|
|
392
|
+
// Validate each date in the range
|
|
393
|
+
if (newValue.some((date) => !this.isPickedDateValid(date)))
|
|
394
|
+
return;
|
|
361
395
|
if (newValue.length === 2)
|
|
362
396
|
(_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close();
|
|
363
397
|
// Convert ISO dates to specified format
|
|
@@ -369,6 +403,9 @@ export class TabworthyDates {
|
|
|
369
403
|
this.announceDateChange(this.internalValue);
|
|
370
404
|
}
|
|
371
405
|
else {
|
|
406
|
+
// Validate the single date
|
|
407
|
+
if (newValue && !this.isPickedDateValid(newValue))
|
|
408
|
+
return;
|
|
372
409
|
(_b = this.modalRef) === null || _b === void 0 ? void 0 : _b.close();
|
|
373
410
|
// Convert ISO date to specified format
|
|
374
411
|
const formattedDate = newValue
|
|
@@ -1375,6 +1412,27 @@ export class TabworthyDates {
|
|
|
1375
1412
|
}
|
|
1376
1413
|
}
|
|
1377
1414
|
}
|
|
1415
|
+
}, {
|
|
1416
|
+
"method": "errorChange",
|
|
1417
|
+
"name": "errorChange",
|
|
1418
|
+
"bubbles": true,
|
|
1419
|
+
"cancelable": true,
|
|
1420
|
+
"composed": true,
|
|
1421
|
+
"docs": {
|
|
1422
|
+
"tags": [],
|
|
1423
|
+
"text": ""
|
|
1424
|
+
},
|
|
1425
|
+
"complexType": {
|
|
1426
|
+
"original": "ErrorChangeEventDetails",
|
|
1427
|
+
"resolved": "ErrorChangeEventDetails",
|
|
1428
|
+
"references": {
|
|
1429
|
+
"ErrorChangeEventDetails": {
|
|
1430
|
+
"location": "local",
|
|
1431
|
+
"path": "/home/runner/work/tabworthy-components/tabworthy-components/src/components/tabworthy-dates/tabworthy-dates.tsx",
|
|
1432
|
+
"id": "src/components/tabworthy-dates/tabworthy-dates.tsx::ErrorChangeEventDetails"
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1378
1436
|
}, {
|
|
1379
1437
|
"method": "componentReady",
|
|
1380
1438
|
"name": "componentReady",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
|
-
import { addDays, dateIsWithinLowerBounds, dateIsWithinUpperBounds, getDaysOfMonth, getFirstOfMonth, getISODateString, getLastOfMonth, getMonth, getMonths, getNextDay, getNextMonth, getNextYear, getPreviousDay, getPreviousMonth, getPreviousYear, getWeekDays, getYear, isDateInRange, isSameDay, monthIsDisabled, removeTimezoneOffset, subDays } from "../../../../shared/utils/utils";
|
|
2
|
+
import { addDays, dateIsWithinLowerBounds, dateIsWithinUpperBounds, getDaysOfMonth, getFirstOfMonth, getISODateString, getLastOfMonth, getMonth, getMonths, getNextDay, getNextMonth, getNextYear, getPreviousDay, getPreviousMonth, getPreviousYear, getWeekDays, getYear, isDateInRange, isSameDay, monthIsDisabled, parseDateString, removeTimezoneOffset, subDays } from "../../../../shared/utils/utils";
|
|
3
3
|
import { dateIsWithinBounds } from "../../../../shared/utils/utils";
|
|
4
4
|
const defaultLabels = {
|
|
5
5
|
clearButton: "Clear value",
|
|
@@ -43,16 +43,34 @@ export class TabworthyDatesCalendar {
|
|
|
43
43
|
this.updateWeekdays();
|
|
44
44
|
};
|
|
45
45
|
this.nextMonth = () => {
|
|
46
|
-
|
|
46
|
+
const next = getNextMonth(this.currentDate);
|
|
47
|
+
if (this.disabled ||
|
|
48
|
+
monthIsDisabled(next.getMonth(), next.getFullYear(), this.minDate, this.maxDate))
|
|
49
|
+
return;
|
|
50
|
+
this.updateCurrentDate(next);
|
|
47
51
|
};
|
|
48
52
|
this.nextYear = () => {
|
|
49
|
-
|
|
53
|
+
const next = getNextYear(this.currentDate);
|
|
54
|
+
if (this.disabled ||
|
|
55
|
+
(this.maxDate &&
|
|
56
|
+
parseDateString(this.maxDate).getFullYear() < next.getFullYear()))
|
|
57
|
+
return;
|
|
58
|
+
this.updateCurrentDate(next, false, true);
|
|
50
59
|
};
|
|
51
60
|
this.previousMonth = () => {
|
|
52
|
-
|
|
61
|
+
const prev = getPreviousMonth(this.currentDate);
|
|
62
|
+
if (this.disabled ||
|
|
63
|
+
monthIsDisabled(prev.getMonth(), prev.getFullYear(), this.minDate, this.maxDate))
|
|
64
|
+
return;
|
|
65
|
+
this.updateCurrentDate(prev);
|
|
53
66
|
};
|
|
54
67
|
this.previousYear = () => {
|
|
55
|
-
|
|
68
|
+
const prev = getPreviousYear(this.currentDate);
|
|
69
|
+
if (this.disabled ||
|
|
70
|
+
(this.minDate &&
|
|
71
|
+
parseDateString(this.minDate).getFullYear() > prev.getFullYear()))
|
|
72
|
+
return;
|
|
73
|
+
this.updateCurrentDate(prev, false, true);
|
|
56
74
|
};
|
|
57
75
|
this.showToday = () => {
|
|
58
76
|
this.updateCurrentDate(new Date(), true);
|
|
@@ -256,9 +274,9 @@ export class TabworthyDatesCalendar {
|
|
|
256
274
|
const month = date.getMonth();
|
|
257
275
|
const year = date.getFullYear();
|
|
258
276
|
if (!dateIsWithinLowerBounds(date, this.minDate))
|
|
259
|
-
date =
|
|
277
|
+
date = parseDateString(this.minDate);
|
|
260
278
|
if (!dateIsWithinUpperBounds(date, this.maxDate))
|
|
261
|
-
date =
|
|
279
|
+
date = parseDateString(this.maxDate);
|
|
262
280
|
const monthChanged = month !== ((_a = this.currentDate) === null || _a === void 0 ? void 0 : _a.getMonth()) ||
|
|
263
281
|
year !== this.currentDate.getFullYear();
|
|
264
282
|
if (monthChanged) {
|
|
@@ -315,11 +333,11 @@ export class TabworthyDatesCalendar {
|
|
|
315
333
|
year: {
|
|
316
334
|
prev: this.disabled ||
|
|
317
335
|
(!!this.minDate &&
|
|
318
|
-
|
|
336
|
+
parseDateString(this.minDate).getFullYear() >
|
|
319
337
|
getPreviousYear(this.currentDate).getFullYear()),
|
|
320
338
|
next: this.disabled ||
|
|
321
339
|
(!!this.maxDate &&
|
|
322
|
-
|
|
340
|
+
parseDateString(this.maxDate).getFullYear() <
|
|
323
341
|
getNextYear(this.currentDate).getFullYear())
|
|
324
342
|
},
|
|
325
343
|
month: {
|
|
@@ -329,15 +347,15 @@ export class TabworthyDatesCalendar {
|
|
|
329
347
|
monthIsDisabled(getNextMonth(this.currentDate).getMonth(), getNextMonth(this.currentDate).getFullYear(), this.minDate, this.maxDate)
|
|
330
348
|
}
|
|
331
349
|
};
|
|
332
|
-
return (h(Host, { key: '
|
|
350
|
+
return (h(Host, { key: '60e2a56f8a1aadceb57d7f445098060293a0f937' }, h("div", { key: '12fd35c03b0c34e4ad88e4e491fcc685de5f09b2', class: {
|
|
333
351
|
[`${this.getClassName()}-wrapper`]: true,
|
|
334
352
|
[`${this.getClassName()}-wrapper--inline`]: this.inline
|
|
335
|
-
} }, h("div", { key: '
|
|
353
|
+
} }, h("div", { key: 'ad36d1e260a7a89110c53fc86e339eb5a259a4fc', class: {
|
|
336
354
|
[this.getClassName()]: true,
|
|
337
355
|
[`${this.getClassName()}--disabled`]: this.disabled
|
|
338
|
-
} }, h("div", { key: '
|
|
356
|
+
} }, h("div", { key: '181b9ed0a6a9d6073d67f270d6b14efc28f6a6b2', class: this.getClassName("header") }, this.showHiddenTitle && (h("span", { key: '580656924dc3ba028458591399791423797d58d7', "aria-atomic": "true", "aria-live": "polite", class: "visually-hidden" }, this.getTitle())), this.showYearStepper && (h("button", { key: '7822100c140418bc3cb65ae39a32a3ebc1f53bc2', "aria-label": this.labels.previousYearButton, class: this.getClassName("previous-year-button"), "aria-disabled": disabled.year.prev, innerHTML: this.previousYearButtonContent || undefined, onClick: this.previousYear, type: "button" }, h("svg", { key: '9408d89cf59c268c3e44801297f1a7776a594539', fill: "none", height: "24", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "24" }, h("polyline", { key: 'b9108784891de5eb7acef5c14425e90c25fc514a', points: "11 17 6 12 11 7" }), h("polyline", { key: 'a2fbabe46f6a0584d5c4b54296b9db13e979c818', points: "18 17 13 12 18 7" })))), this.showMonthStepper && (h("button", { key: '8e515d4fa9fde9f0e16fc2ff5629049039df09e0', "aria-label": this.labels.previousMonthButton, class: this.getClassName("previous-month-button"), "aria-disabled": disabled.month.prev, innerHTML: this.previousMonthButtonContent || undefined, onClick: this.previousMonth, type: "button" }, h("svg", { key: '5248668ca2f843102193fb57beb8a3a4b4edbb96', fill: "none", height: "24", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "24" }, h("polyline", { key: '021c514ec8fb801fd0d3dbf250fc8d55b9c9ef08', points: "15 18 9 12 15 6" })))), h("span", { key: '8fab6b75376e1399b6ea07e3545ddcfa3eb120d8', class: this.getClassName("current-month") }, h("select", { key: '01f8fbd5a76c91b0bf121c2589af72860abe2a22', "aria-label": this.labels.monthSelect, class: this.getClassName("month-select"), "aria-disabled": this.disabled, name: "month", onChange: this.onMonthSelect }, getMonths(this.locale).map((month, index) => {
|
|
339
357
|
return (h("option", { key: month, selected: this.currentDate.getMonth() === index, value: index + 1, disabled: monthIsDisabled(index, this.currentDate.getFullYear(), this.minDate, this.maxDate) }, month));
|
|
340
|
-
})), h("input", { key: '
|
|
358
|
+
})), h("input", { key: 'cb126814e09a6ae81ce8a6db10152decef97d66a', "aria-label": this.labels.yearSelect, class: this.getClassName("year-select"), "aria-disabled": this.disabled, max: this.maxDate ? this.maxDate.slice(0, 4) : 9999, min: this.minDate ? this.minDate.slice(0, 4) : 1, name: "year", onChange: this.onYearSelect, type: "number", value: this.currentDate.getFullYear() })), this.showMonthStepper && (h("button", { key: '9ad3e382b769ada1ecb746a55c37c54d0c6b06e1', "aria-label": this.labels.nextMonthButton, class: this.getClassName("next-month-button"), "aria-disabled": disabled.month.next, innerHTML: this.nextMonthButtonContent || undefined, onClick: this.nextMonth, type: "button" }, h("svg", { key: '7ecdf33b13950c8972b5b3a66bd086f700967fad', fill: "none", height: "24", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "24" }, h("polyline", { key: '78768373bb23d06e8babd79a77fb0a899ea5e942', points: "9 18 15 12 9 6" })))), this.showYearStepper && (h("button", { key: 'ab920b5dbdf0bf6000c58718d0d3a0e9a31bbebd', "aria-label": this.labels.nextYearButton, class: this.getClassName("next-year-button"), "aria-disabled": disabled.year.next, innerHTML: this.nextYearButtonContent || undefined, onClick: this.nextYear, type: "button" }, h("svg", { key: '7f5c83e6333e6c33984961722c855f2609e0999e', fill: "none", height: "24", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "24" }, h("polyline", { key: 'dd3eed1b08d0373a089beb91eb9cb6b62b477b3b', points: "13 17 18 12 13 7" }), h("polyline", { key: 'fa989db37ceaf95817aef623770b895b3c10d0b4', points: "6 17 11 12 6 7" }))))), h("div", { key: '5b41060ca782df39e19ba35ec71d4425ae5c3a2a', class: this.getClassName("body") }, h("table", { key: '357337fd3a5f05cc204982682c99f99c46dd4b29', class: this.getClassName("calendar"), onKeyDown: this.onKeyDown, role: "grid", "aria-label": this.getTitle() }, h("thead", { key: '8fa7ecfada004b39dd406eb9079de3eab66fe298', class: this.getClassName("calendar-header") }, h("tr", { key: '364f6021007700c2da60082fca32e4896e071ccd', class: this.getClassName("weekday-row") }, (_a = this.weekdays) === null || _a === void 0 ? void 0 : _a.map((weekday) => (h("th", { role: "columnheader", abbr: weekday[1], class: this.getClassName("weekday"), key: weekday[0], scope: "col" }, h("span", { "aria-hidden": "true" }, weekday[0]), h("span", { class: "visually-hidden" }, weekday[1])))))), h("tbody", { key: 'e0269bd5bfe1310a8950635441edc472e3a5f413' }, this.getCalendarRows().map((calendarRow) => {
|
|
341
359
|
const rowKey = `row-${calendarRow[0].getMonth()}-${calendarRow[0].getDate()}`;
|
|
342
360
|
return (h("tr", { class: this.getClassName("calendar-row"), key: rowKey }, calendarRow.map((day) => {
|
|
343
361
|
var _a, _b, _c;
|
|
@@ -404,14 +422,14 @@ export class TabworthyDatesCalendar {
|
|
|
404
422
|
? 0
|
|
405
423
|
: -1 }, h(Tag, { "aria-hidden": "true" }, day.getDate()), h("span", { class: "visually-hidden" }, getScreenReaderText())));
|
|
406
424
|
})));
|
|
407
|
-
})))), showFooter && (h("div", { key: '
|
|
425
|
+
})))), showFooter && (h("div", { key: '4d18b821b06e4eb7fd2f1a1210fcab01d3acdd00', class: this.getClassName("footer") }, h("div", { key: 'fec534b0bff03bfe3e15a8842abbcca9b57e9a1c', class: this.getClassName("footer-buttons") }, this.showTodayButton && (h("button", { key: '0d8aed7413f313c2ab6aa9a634093de1d46cd7ce', "aria-label": this.todayButtonContent
|
|
408
426
|
? this.labels.todayButton
|
|
409
|
-
: undefined, class: this.getClassName("today-button"), disabled: this.disabled, innerHTML: this.todayButtonContent || undefined, onClick: this.showToday, type: "button" }, !this.todayButtonContent && this.labels.todayButton)), this.showClearButton && (h("button", { key: '
|
|
427
|
+
: undefined, class: this.getClassName("today-button"), disabled: this.disabled, innerHTML: this.todayButtonContent || undefined, onClick: this.showToday, type: "button" }, !this.todayButtonContent && this.labels.todayButton)), this.showClearButton && (h("button", { key: '176c535cb85d6b95d40324a55aa11e1bc2faaa61', "aria-label": this.clearButtonContent
|
|
410
428
|
? this.labels.clearButton
|
|
411
|
-
: undefined, class: this.getClassName("clear-button"), disabled: this.disabled, innerHTML: this.clearButtonContent || undefined, onClick: this.clear, type: "button" }, !this.clearButtonContent && this.labels.clearButton)), this.showCloseButton && (h("button", { key: '
|
|
429
|
+
: undefined, class: this.getClassName("clear-button"), disabled: this.disabled, innerHTML: this.clearButtonContent || undefined, onClick: this.clear, type: "button" }, !this.clearButtonContent && this.labels.clearButton)), this.showCloseButton && (h("button", { key: 'cea15baf92edabea6841510459c6b05ebfaf81fa', "aria-label": this.closeButtonContent
|
|
412
430
|
? this.labels.closeButton
|
|
413
431
|
: undefined, class: this.getClassName("close-button"), disabled: this.disabled, innerHTML: this.closeButtonContent || undefined, onClick: this.close, type: "button" }, !this.closeButtonContent && this.labels.closeButton))), this.showKeyboardHint &&
|
|
414
|
-
!window.matchMedia("(pointer: coarse)").matches && (h("button", { key: '
|
|
432
|
+
!window.matchMedia("(pointer: coarse)").matches && (h("button", { key: '51a48353fbb94243d93047141e26b8c8ef5545b2', type: "button", onClick: () => alert("Todo: Add Keyboard helper!"), class: this.getClassName("keyboard-hint") }, h("svg", { key: '2991aa978689e3a0bd4c795a8629451e252ccf41', xmlns: "http://www.w3.org/2000/svg", height: "1em", width: "1em", viewBox: "0 0 48 48", fill: "currentColor" }, h("path", { key: 'b84c3846f234a79e8c78eae3118aa2a9f24b8377', d: "M7 38q-1.2 0-2.1-.925Q4 36.15 4 35V13q0-1.2.9-2.1.9-.9 2.1-.9h34q1.2 0 2.1.9.9.9.9 2.1v22q0 1.15-.9 2.075Q42.2 38 41 38Zm0-3h34V13H7v22Zm8-3.25h18v-3H15Zm-4.85-6.25h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm-24.7-6.25h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3ZM7 35V13v22Z" })), this.labels.keyboardHint))))), h("slot", { key: '86e8fb8907bf11951461baaf41f92b29ce0cc413', name: "after-calendar" }))));
|
|
415
433
|
}
|
|
416
434
|
static get is() { return "tabworthy-dates-calendar"; }
|
|
417
435
|
static get encapsulation() { return "scoped"; }
|