@tabworthy/components 0.12.3 → 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.
Files changed (44) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/tabworthy-components.cjs.js +1 -1
  3. package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +39 -15
  4. package/dist/cjs/tabworthy-dates.cjs.entry.js +52 -12
  5. package/dist/cjs/tabworthy-times-picker.cjs.entry.js +82 -10
  6. package/dist/cjs/tabworthy-times.cjs.entry.js +109 -4
  7. package/dist/cjs/{utils-y5Vtky2t.js → utils-DGbdK8VF.js} +29 -8
  8. package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +148 -12
  9. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +39 -15
  10. package/dist/collection/components/tabworthy-times/tabworthy-times.js +262 -3
  11. package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +128 -10
  12. package/dist/components/p-BzY8iIVW.js +1 -0
  13. package/dist/components/p-C_uZGgcG.js +1 -0
  14. package/dist/components/tabworthy-dates-calendar.js +1 -1
  15. package/dist/components/tabworthy-dates.js +1 -1
  16. package/dist/components/tabworthy-times-picker.js +1 -1
  17. package/dist/components/tabworthy-times.js +1 -1
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/esm/tabworthy-components.js +1 -1
  20. package/dist/esm/tabworthy-dates-calendar_2.entry.js +39 -15
  21. package/dist/esm/tabworthy-dates.entry.js +52 -12
  22. package/dist/esm/tabworthy-times-picker.entry.js +82 -10
  23. package/dist/esm/tabworthy-times.entry.js +109 -4
  24. package/dist/esm/{utils-BVHu5CWV.js → utils-CoFOnMSw.js} +29 -9
  25. package/dist/shared/utils/utils.js +28 -8
  26. package/dist/tabworthy-components/p-69334c34.entry.js +1 -0
  27. package/dist/tabworthy-components/p-71f5c261.entry.js +1 -0
  28. package/dist/tabworthy-components/p-7cd6ccc1.entry.js +1 -0
  29. package/dist/tabworthy-components/{p-BVHu5CWV.js → p-CoFOnMSw.js} +1 -1
  30. package/dist/tabworthy-components/p-ed3c60d6.entry.js +1 -0
  31. package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
  32. package/dist/themes/light.css +1 -1
  33. package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +11 -0
  34. package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +15 -1
  35. package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +15 -0
  36. package/dist/types/components.d.ts +47 -4
  37. package/dist/types/home/runner/work/tabworthy-components/tabworthy-components/.stencil/shared/utils/utils.d.ts +6 -0
  38. package/package.json +1 -1
  39. package/dist/components/p-BTQaxOHo.js +0 -1
  40. package/dist/components/p-CkD8Cvl_.js +0 -1
  41. package/dist/tabworthy-components/p-04240a8d.entry.js +0 -1
  42. package/dist/tabworthy-components/p-1743bf7a.entry.js +0 -1
  43. package/dist/tabworthy-components/p-744ffef9.entry.js +0 -1
  44. package/dist/tabworthy-components/p-8ccc0de2.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-y5Vtky2t.js');
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,10 +397,12 @@ const TabworthyTimes = class {
294
397
  }
295
398
  render() {
296
399
  var _a;
297
- return (index.h(index.Host, { key: '671702979dddb6a19cfa78a95df28a958af56df9', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: '7b23263f899b3a59d43f3f2922e9c98a0bc62524', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: '453d585bee8dd0262aadec8ba816cd22c51cffea', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: 'd2ec7de2b31f3c1a6b9acb4f57341530cb8431dc', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
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: '77b42f53ad8a5e0d5d70ea41f999f95d61942a83', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '3633f9e7839b8947da48f83ac3808156bea8515d', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
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
404
+ ? this.timesLabels.openCalendar
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: () => {
301
406
  if (this.pickerRef) {
302
407
  this.pickerRef.modalIsOpen = true;
303
408
  }
@@ -305,7 +410,7 @@ const TabworthyTimes = class {
305
410
  if (this.pickerRef) {
306
411
  this.pickerRef.modalIsOpen = false;
307
412
  }
308
- }, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '706e2fdcd7e4ecf77f5ee63f4c5ced7951593735', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: 'cb027f3fe4d2bf73abea9ec6511fe11305e28aba', 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 }, index.h("div", { key: '2287a25cdec6fc40c36833c250536f99cabe5cbf', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: '540cfd69b4ca3618ecd22f9d1ed3d240ed8eeee9', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: '79e8c05c3ba4af1ef46a78c6d6fcb211dec7abd5', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState, onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels }))))), this.errorState && (index.h("div", { key: '4a568e01f57652308adb7a8c115ab6649fc591fc', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
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))));
309
414
  }
310
415
  get el() { return index.getElement(this); }
311
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 = removeTimezoneOffset(new Date(minDate));
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 = removeTimezoneOffset(new Date(maxDate));
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
- const firstDate = new Date(year, month, 1);
168
- firstDate.setDate(firstDate.getDate() - 1);
169
- const lastDate = new Date(year, month + 1, 0);
170
- lastDate.setDate(firstDate.getDate() + 1);
171
- return (!dateIsWithinBounds(firstDate, minDate, maxDate) &&
172
- !dateIsWithinBounds(lastDate, minDate, maxDate));
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} ${getISODateString(minDate)}`
239
+ ? `${this.datesLabels.minDateError} ${formatLocalizedDate(minDate)}`
238
240
  : "",
239
241
  maxDate: maxDate
240
- ? `${this.datesLabels.maxDateError} ${getISODateString(maxDate)}`
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
@@ -477,7 +514,9 @@ export class TabworthyDates {
477
514
  return (h(Host, null, h("label", { htmlFor: this.id ? `${this.id}-input` : undefined, class: this.getClassName("label") }, this.label), h("br", null), h("div", { class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { disabled: this.disabledState || this.disableFreeformInput, id: this.id ? `${this.id}-input` : undefined, type: "text", placeholder: this.placeholder, class: {
478
515
  [this.getClassName("input")]: true,
479
516
  [this.inputClass]: !!this.inputClass
480
- }, ref: (r) => (this.inputRef = r), onChange: this.handleChange, onFocus: () => this.formatInput(false), onBlur: () => this.formatInput(true, false), "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.datesLabels.openCalendar)))), h("tabworthy-dates-modal", { label: this.datesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
517
+ }, ref: (r) => (this.inputRef = r), onChange: this.handleChange, onFocus: () => this.formatInput(false), onBlur: () => this.formatInput(true, false), "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
518
+ ? this.datesLabels.openCalendar
519
+ : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.datesLabels.openCalendar)))), h("tabworthy-dates-modal", { label: this.datesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
481
520
  if (!this.pickerRef)
482
521
  return;
483
522
  this.pickerRef.modalIsOpen = true;
@@ -485,7 +524,7 @@ export class TabworthyDates {
485
524
  if (!this.pickerRef)
486
525
  return;
487
526
  this.pickerRef.modalIsOpen = false;
488
- }, inline: this.inline, appendTo: this.appendTo }, h("tabworthy-dates-calendar", { 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 ? this.datesCalendarLabels : undefined, 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, showKeyboardHint: this.showKeyboardHint, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline })), this.showQuickButtons &&
527
+ }, inline: this.inline, appendTo: this.appendTo }, h("tabworthy-dates-calendar", { 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 ? this.datesCalendarLabels : undefined, 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, showKeyboardHint: this.showKeyboardHint, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline, nextMonthButtonContent: this.nextMonthButtonContent, nextYearButtonContent: this.nextYearButtonContent, previousMonthButtonContent: this.previousMonthButtonContent, previousYearButtonContent: this.previousYearButtonContent, todayButtonContent: this.todayButtonContent, clearButtonContent: this.clearButtonContent, closeButtonContent: this.closeButtonContent })), this.showQuickButtons &&
489
528
  ((_a = this.quickButtons) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
490
529
  this.chronoSupportedLocale && (h("div", { class: this.getClassName("quick-group"), role: "group", "aria-label": this.datesLabels.quickSelection }, this.quickButtons.map((buttonText) => {
491
530
  return (h("button", { class: this.getClassName("quick-button"), onClick: this.handleQuickButtonClick, disabled: this.disabledState, type: "button" }, buttonText));
@@ -887,6 +926,44 @@ export class TabworthyDates {
887
926
  "reflect": false,
888
927
  "attribute": "next-year-button-content"
889
928
  },
929
+ "previousMonthButtonContent": {
930
+ "type": "string",
931
+ "mutable": false,
932
+ "complexType": {
933
+ "original": "string",
934
+ "resolved": "string",
935
+ "references": {}
936
+ },
937
+ "required": false,
938
+ "optional": true,
939
+ "docs": {
940
+ "tags": [],
941
+ "text": ""
942
+ },
943
+ "getter": false,
944
+ "setter": false,
945
+ "reflect": false,
946
+ "attribute": "previous-month-button-content"
947
+ },
948
+ "previousYearButtonContent": {
949
+ "type": "string",
950
+ "mutable": false,
951
+ "complexType": {
952
+ "original": "string",
953
+ "resolved": "string",
954
+ "references": {}
955
+ },
956
+ "required": false,
957
+ "optional": true,
958
+ "docs": {
959
+ "tags": [],
960
+ "text": ""
961
+ },
962
+ "getter": false,
963
+ "setter": false,
964
+ "reflect": false,
965
+ "attribute": "previous-year-button-content"
966
+ },
890
967
  "showYearStepper": {
891
968
  "type": "boolean",
892
969
  "mutable": false,
@@ -1147,6 +1224,44 @@ export class TabworthyDates {
1147
1224
  "reflect": false,
1148
1225
  "attribute": "today-button-content"
1149
1226
  },
1227
+ "clearButtonContent": {
1228
+ "type": "string",
1229
+ "mutable": false,
1230
+ "complexType": {
1231
+ "original": "string",
1232
+ "resolved": "string",
1233
+ "references": {}
1234
+ },
1235
+ "required": false,
1236
+ "optional": true,
1237
+ "docs": {
1238
+ "tags": [],
1239
+ "text": ""
1240
+ },
1241
+ "getter": false,
1242
+ "setter": false,
1243
+ "reflect": false,
1244
+ "attribute": "clear-button-content"
1245
+ },
1246
+ "closeButtonContent": {
1247
+ "type": "string",
1248
+ "mutable": false,
1249
+ "complexType": {
1250
+ "original": "string",
1251
+ "resolved": "string",
1252
+ "references": {}
1253
+ },
1254
+ "required": false,
1255
+ "optional": true,
1256
+ "docs": {
1257
+ "tags": [],
1258
+ "text": ""
1259
+ },
1260
+ "getter": false,
1261
+ "setter": false,
1262
+ "reflect": false,
1263
+ "attribute": "close-button-content"
1264
+ },
1150
1265
  "calendarButtonContent": {
1151
1266
  "type": "string",
1152
1267
  "mutable": false,
@@ -1297,6 +1412,27 @@ export class TabworthyDates {
1297
1412
  }
1298
1413
  }
1299
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
+ }
1300
1436
  }, {
1301
1437
  "method": "componentReady",
1302
1438
  "name": "componentReady",