@tabworthy/components 0.11.3 → 0.12.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 +45 -0
- 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 +8 -8
- package/dist/cjs/tabworthy-dates.cjs.entry.js +50 -22
- package/dist/cjs/tabworthy-times-picker.cjs.entry.js +8 -8
- package/dist/cjs/tabworthy-times.cjs.entry.js +52 -26
- package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +70 -17
- package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +1 -1
- package/dist/collection/components/tabworthy-modal/tabworthy-dates-modal.js +3 -3
- package/dist/collection/components/tabworthy-times/tabworthy-times.js +35 -25
- package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +8 -8
- package/dist/components/{p-B6lbpNd2.js → p-BTQaxOHo.js} +1 -1
- package/dist/components/{p-CIQgnOXj.js → p-CMIEIvTW.js} +1 -1
- package/dist/components/p-DkyM-7xr.js +1 -0
- package/dist/components/{p-CGo5md1l.js → p-M03P4DAz.js} +1 -1
- package/dist/components/tabworthy-dates-calendar.js +1 -1
- package/dist/components/tabworthy-dates-modal.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 +41 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/tabworthy-components.js +1 -1
- package/dist/esm/tabworthy-dates-calendar_2.entry.js +7 -7
- package/dist/esm/tabworthy-dates.entry.js +49 -21
- package/dist/esm/tabworthy-times-picker.entry.js +8 -8
- package/dist/esm/tabworthy-times.entry.js +52 -26
- package/dist/tabworthy-components/{p-60793499.entry.js → p-1743bf7a.entry.js} +1 -1
- package/dist/tabworthy-components/p-744ffef9.entry.js +1 -0
- package/dist/tabworthy-components/p-DkyM-7xr.js +1 -0
- package/dist/tabworthy-components/p-bc07c40b.entry.js +1 -0
- package/dist/tabworthy-components/{p-f1688c61.entry.js → p-df93e5d4.entry.js} +1 -1
- 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 +3 -0
- package/dist/types/components/tabworthy-dates-calendar/tabworthy-dates-calendar.d.ts +1 -1
- package/dist/types/components/tabworthy-modal/tabworthy-dates-modal.d.ts +1 -1
- package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +1 -1
- package/dist/types/components.d.ts +9 -0
- package/package.json +2 -3
- package/dist/cjs/moment-CdViwxPQ.js +0 -5681
- package/dist/components/p-Mki5YqAR.js +0 -8
- package/dist/esm/moment-Mki5YqAR.js +0 -5679
- package/dist/tabworthy-components/p-Mki5YqAR.js +0 -8
- package/dist/tabworthy-components/p-d4a7458b.entry.js +0 -1
- package/dist/tabworthy-components/p-ea7b79b0.entry.js +0 -1
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./index-B1s0tI-Z.js');
|
|
4
|
-
var
|
|
4
|
+
var customParseFormat = require('./customParseFormat-l09KVyWD.js');
|
|
5
5
|
var utils = require('./utils-y5Vtky2t.js');
|
|
6
6
|
|
|
7
|
+
var localizedFormat$2 = {exports: {}};
|
|
8
|
+
|
|
9
|
+
var localizedFormat$1 = localizedFormat$2.exports;
|
|
10
|
+
|
|
11
|
+
var hasRequiredLocalizedFormat;
|
|
12
|
+
|
|
13
|
+
function requireLocalizedFormat () {
|
|
14
|
+
if (hasRequiredLocalizedFormat) return localizedFormat$2.exports;
|
|
15
|
+
hasRequiredLocalizedFormat = 1;
|
|
16
|
+
(function (module, exports) {
|
|
17
|
+
!function(e,t){module.exports=t();}(localizedFormat$1,(function(){var e={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(t,o,n){var r=o.prototype,i=r.format;n.en.formats=e,r.format=function(t){ void 0===t&&(t="YYYY-MM-DDTHH:mm:ssZ");var o=this.$locale().formats,n=function(t,o){return t.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,n,r){var i=r&&r.toUpperCase();return n||o[r]||e[r]||o[i].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(e,t,o){return t||o.slice(1)}))}))}(t,void 0===o?{}:o);return i.call(this,n)};}}));
|
|
18
|
+
} (localizedFormat$2));
|
|
19
|
+
return localizedFormat$2.exports;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var localizedFormatExports = requireLocalizedFormat();
|
|
23
|
+
var localizedFormat = /*@__PURE__*/customParseFormat.getDefaultExportFromCjs(localizedFormatExports);
|
|
24
|
+
|
|
25
|
+
customParseFormat.dayjs.extend(customParseFormat.customParseFormat);
|
|
26
|
+
customParseFormat.dayjs.extend(localizedFormat);
|
|
7
27
|
const defaultLabels = {
|
|
8
28
|
selected: "selected",
|
|
9
29
|
openCalendar: "Choose time",
|
|
@@ -15,9 +35,10 @@ const defaultLabels = {
|
|
|
15
35
|
disabledDateError: `Please choose an available date`,
|
|
16
36
|
to: "to",
|
|
17
37
|
startDate: "Start date",
|
|
38
|
+
yearSelect: "Select year",
|
|
18
39
|
timeLabel: "Time"
|
|
19
40
|
};
|
|
20
|
-
const
|
|
41
|
+
const TabworthyTimes = class {
|
|
21
42
|
constructor(hostRef) {
|
|
22
43
|
index.registerInstance(this, hostRef);
|
|
23
44
|
this.selectDateTime = index.createEvent(this, "selectDateTime", 7);
|
|
@@ -131,11 +152,16 @@ const InclusiveTimes = class {
|
|
|
131
152
|
};
|
|
132
153
|
this.handleInputChange = (event) => {
|
|
133
154
|
const value = event.target.value;
|
|
134
|
-
// Try to parse the input value
|
|
135
|
-
|
|
155
|
+
// Try to parse the input value using the component's format first (strict mode)
|
|
156
|
+
// This prevents dayjs from misinterpreting date formats (e.g., DD/MM/YYYY as MM/DD/YYYY)
|
|
157
|
+
let parsed = customParseFormat.dayjs(value, this.format, true);
|
|
158
|
+
// Fall back to loose parsing if strict format doesn't match
|
|
159
|
+
if (!parsed.isValid()) {
|
|
160
|
+
parsed = customParseFormat.dayjs(value);
|
|
161
|
+
}
|
|
136
162
|
if (parsed.isValid()) {
|
|
137
|
-
this.selectedHours = parsed.
|
|
138
|
-
this.selectedMinutes = parsed.
|
|
163
|
+
this.selectedHours = parsed.hour();
|
|
164
|
+
this.selectedMinutes = parsed.minute();
|
|
139
165
|
this.updateValue(parsed.toDate());
|
|
140
166
|
}
|
|
141
167
|
};
|
|
@@ -168,12 +194,12 @@ const InclusiveTimes = class {
|
|
|
168
194
|
// Parse the first datetime value to set time picker
|
|
169
195
|
const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
|
|
170
196
|
if (firstValue) {
|
|
171
|
-
const parsed =
|
|
197
|
+
const parsed = customParseFormat.dayjs(firstValue, this.format);
|
|
172
198
|
if (parsed.isValid()) {
|
|
173
199
|
this.selectedDate = parsed.toDate();
|
|
174
|
-
this.selectedHours = parsed.
|
|
175
|
-
this.selectedMinutes = parsed.
|
|
176
|
-
this.selectedSeconds = parsed.
|
|
200
|
+
this.selectedHours = parsed.hour();
|
|
201
|
+
this.selectedMinutes = parsed.minute();
|
|
202
|
+
this.selectedSeconds = parsed.second();
|
|
177
203
|
}
|
|
178
204
|
}
|
|
179
205
|
}
|
|
@@ -185,10 +211,10 @@ const InclusiveTimes = class {
|
|
|
185
211
|
if (Array.isArray(date)) {
|
|
186
212
|
// Range mode
|
|
187
213
|
const formattedDates = date.map((d) => {
|
|
188
|
-
const m =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
214
|
+
const m = customParseFormat.dayjs(d)
|
|
215
|
+
.hour(this.selectedHours)
|
|
216
|
+
.minute(this.selectedMinutes)
|
|
217
|
+
.second(this.selectedSeconds);
|
|
192
218
|
return m.format(this.format);
|
|
193
219
|
});
|
|
194
220
|
this.internalValue = formattedDates;
|
|
@@ -197,10 +223,10 @@ const InclusiveTimes = class {
|
|
|
197
223
|
}
|
|
198
224
|
else {
|
|
199
225
|
// Single date mode
|
|
200
|
-
const m =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
226
|
+
const m = customParseFormat.dayjs(date)
|
|
227
|
+
.hour(this.selectedHours)
|
|
228
|
+
.minute(this.selectedMinutes)
|
|
229
|
+
.second(this.selectedSeconds);
|
|
204
230
|
const formatted = m.format(this.format);
|
|
205
231
|
this.internalValue = formatted;
|
|
206
232
|
this.value = formatted;
|
|
@@ -218,13 +244,13 @@ const InclusiveTimes = class {
|
|
|
218
244
|
if (Array.isArray(this.internalValue)) {
|
|
219
245
|
// Format range
|
|
220
246
|
const formatted = this.internalValue
|
|
221
|
-
.map((v) =>
|
|
247
|
+
.map((v) => customParseFormat.dayjs(v, this.format).format("lll"))
|
|
222
248
|
.join(` ${this.timesLabels.to} `);
|
|
223
249
|
this.inputRef.value = formatted;
|
|
224
250
|
}
|
|
225
251
|
else {
|
|
226
252
|
// Format single datetime
|
|
227
|
-
this.inputRef.value =
|
|
253
|
+
this.inputRef.value = customParseFormat.dayjs(this.internalValue, this.format).format("lll");
|
|
228
254
|
}
|
|
229
255
|
}
|
|
230
256
|
getClassName(suffix) {
|
|
@@ -234,8 +260,8 @@ const InclusiveTimes = class {
|
|
|
234
260
|
if (!dateString)
|
|
235
261
|
return null;
|
|
236
262
|
const date = Array.isArray(dateString)
|
|
237
|
-
? dateString.map((d) =>
|
|
238
|
-
:
|
|
263
|
+
? dateString.map((d) => customParseFormat.dayjs(d, this.format).toDate())
|
|
264
|
+
: customParseFormat.dayjs(dateString, this.format).toDate();
|
|
239
265
|
return date;
|
|
240
266
|
}
|
|
241
267
|
async clearValue() {
|
|
@@ -252,10 +278,10 @@ const InclusiveTimes = class {
|
|
|
252
278
|
}
|
|
253
279
|
render() {
|
|
254
280
|
var _a;
|
|
255
|
-
return (index.h(index.Host, { key: '
|
|
281
|
+
return (index.h(index.Host, { key: '16801875a7a022afd2db87e489ff69133e27773d', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: 'f0aa269a9677dbda54d31ea0fa32e69f6ef19114', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: 'a3fa49e1735adb2e32d0dbd4b5fe21d1b1e9ba9c', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: 'dab0c8ff6a9f941b1e3c8a801b2e0de8262beda2', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
256
282
|
[this.getClassName("input")]: true,
|
|
257
283
|
[this.inputClass]: !!this.inputClass
|
|
258
|
-
}, 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: '
|
|
284
|
+
}, 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: 'c072cedad6d4567b3688e434a7173441b4a11026', 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: '4a4e37ff7f76d51389153b52d281fdc1a8f861d5', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
259
285
|
if (this.pickerRef) {
|
|
260
286
|
this.pickerRef.modalIsOpen = true;
|
|
261
287
|
}
|
|
@@ -263,7 +289,7 @@ const InclusiveTimes = class {
|
|
|
263
289
|
if (this.pickerRef) {
|
|
264
290
|
this.pickerRef.modalIsOpen = false;
|
|
265
291
|
}
|
|
266
|
-
}, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '
|
|
292
|
+
}, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '9b03ffb9df5a041d802647d66af53eafec187c7f', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: '0caab550470b253542d93e29ddadcde85fe7caad', 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: '655aa9bb049f76dba44f18684fec6550ab8aac22', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: 'b695207bda87835f57240f72bea88dc57470c170', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: 'f17bf595f1df723dc04d87ef86a5f5a6152b506a', 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: '8bf64ca388076cd5f1ad73b763993dbc7736b08c', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
267
293
|
}
|
|
268
294
|
get el() { return index.getElement(this); }
|
|
269
295
|
static get watchers() { return {
|
|
@@ -279,4 +305,4 @@ const InclusiveTimes = class {
|
|
|
279
305
|
}; }
|
|
280
306
|
};
|
|
281
307
|
|
|
282
|
-
exports.tabworthy_times =
|
|
308
|
+
exports.tabworthy_times = TabworthyTimes;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
2
|
import { announce } from "@react-aria/live-announcer";
|
|
3
|
-
import
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
5
|
+
dayjs.extend(customParseFormat);
|
|
4
6
|
import { getISODateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
5
7
|
import { chronoParseDate, chronoParseRange } from "../../../../shared/utils/chrono-parser/chrono-parser";
|
|
6
8
|
const defaultLabels = {
|
|
@@ -10,6 +12,7 @@ const defaultLabels = {
|
|
|
10
12
|
invalidDateError: "We could not find a matching date",
|
|
11
13
|
minDateError: `Please fill in a date after `,
|
|
12
14
|
maxDateError: `Please fill in a date before `,
|
|
15
|
+
yearSelect: "Select year",
|
|
13
16
|
rangeOutOfBoundsError: `Please enter a valid range of dates`,
|
|
14
17
|
disabledDateError: `Please choose an available date`,
|
|
15
18
|
to: "to",
|
|
@@ -20,6 +23,8 @@ export class TabworthyDates {
|
|
|
20
23
|
constructor() {
|
|
21
24
|
// Enable or disable range mode
|
|
22
25
|
this.range = false;
|
|
26
|
+
// Enable year-only mode (shows only year input, no calendar)
|
|
27
|
+
this.yearOnly = false;
|
|
23
28
|
// A label for the text field
|
|
24
29
|
this.label = this.range
|
|
25
30
|
? "Choose a date range (any way you like)"
|
|
@@ -129,6 +134,23 @@ export class TabworthyDates {
|
|
|
129
134
|
var _a;
|
|
130
135
|
(_a = this.changeYear) === null || _a === void 0 ? void 0 : _a.emit(yearDetail);
|
|
131
136
|
};
|
|
137
|
+
this.handleYearInputChange = (event) => {
|
|
138
|
+
var _a;
|
|
139
|
+
const year = +event.target.value;
|
|
140
|
+
if (!year || isNaN(year))
|
|
141
|
+
return;
|
|
142
|
+
const minYear = this.minDate ? parseInt(this.minDate.slice(0, 4), 10) : 1;
|
|
143
|
+
const maxYear = this.maxDate
|
|
144
|
+
? parseInt(this.maxDate.slice(0, 4), 10)
|
|
145
|
+
: 9999;
|
|
146
|
+
if (year < minYear || year > maxYear)
|
|
147
|
+
return;
|
|
148
|
+
const newValue = dayjs().year(year).startOf("year").format(this.format);
|
|
149
|
+
this.internalValue = newValue;
|
|
150
|
+
this.value = newValue;
|
|
151
|
+
(_a = this.changeYear) === null || _a === void 0 ? void 0 : _a.emit({ year });
|
|
152
|
+
this.selectDate.emit(newValue);
|
|
153
|
+
};
|
|
132
154
|
this.handleRangeChange = async (value) => {
|
|
133
155
|
this.errorState = false;
|
|
134
156
|
if (value.length === 0) {
|
|
@@ -259,7 +281,7 @@ export class TabworthyDates {
|
|
|
259
281
|
}
|
|
260
282
|
return {
|
|
261
283
|
value: parsedDate && parsedDate.value instanceof Date
|
|
262
|
-
?
|
|
284
|
+
? dayjs(parsedDate.value).format(this.format)
|
|
263
285
|
: undefined,
|
|
264
286
|
reason: parsedDate && parsedDate.reason ? parsedDate.reason : undefined
|
|
265
287
|
};
|
|
@@ -274,11 +296,11 @@ export class TabworthyDates {
|
|
|
274
296
|
updateValue(newValue) {
|
|
275
297
|
// Range
|
|
276
298
|
if (Array.isArray(newValue)) {
|
|
277
|
-
this.internalValue = newValue.map((date) =>
|
|
299
|
+
this.internalValue = newValue.map((date) => dayjs(date).format(this.format));
|
|
278
300
|
}
|
|
279
301
|
// Single
|
|
280
302
|
else {
|
|
281
|
-
this.internalValue =
|
|
303
|
+
this.internalValue = dayjs(newValue).format(this.format);
|
|
282
304
|
}
|
|
283
305
|
if (this.pickerRef) {
|
|
284
306
|
this.pickerRef.value = newValue;
|
|
@@ -307,7 +329,7 @@ export class TabworthyDates {
|
|
|
307
329
|
return; // Range date is invalid, leave the text field as is
|
|
308
330
|
let output = "";
|
|
309
331
|
this.internalValue.forEach((value, index) => {
|
|
310
|
-
const parsedDate =
|
|
332
|
+
const parsedDate = dayjs(useInputValue ? this.inputRef.value : value, this.format, true);
|
|
311
333
|
const dateToFormat = parsedDate.isValid()
|
|
312
334
|
? parsedDate.toDate()
|
|
313
335
|
: removeTimezoneOffset(new Date(useInputValue ? this.inputRef.value : value));
|
|
@@ -320,7 +342,7 @@ export class TabworthyDates {
|
|
|
320
342
|
this.inputRef.value = output;
|
|
321
343
|
}
|
|
322
344
|
else {
|
|
323
|
-
const parsedDate =
|
|
345
|
+
const parsedDate = dayjs(useInputValue ? this.inputRef.value : this.internalValue, this.format, true);
|
|
324
346
|
const dateToFormat = parsedDate.isValid()
|
|
325
347
|
? parsedDate.toDate()
|
|
326
348
|
: removeTimezoneOffset(new Date(useInputValue ? this.inputRef.value : this.internalValue));
|
|
@@ -339,7 +361,7 @@ export class TabworthyDates {
|
|
|
339
361
|
if (newValue.length === 2)
|
|
340
362
|
(_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close();
|
|
341
363
|
// Convert ISO dates to specified format
|
|
342
|
-
this.internalValue = newValue.map((date) =>
|
|
364
|
+
this.internalValue = newValue.map((date) => dayjs(date).format(this.format));
|
|
343
365
|
this.errorState = false;
|
|
344
366
|
if (document.activeElement !== this.inputRef) {
|
|
345
367
|
this.formatInput(true, false);
|
|
@@ -350,7 +372,7 @@ export class TabworthyDates {
|
|
|
350
372
|
(_b = this.modalRef) === null || _b === void 0 ? void 0 : _b.close();
|
|
351
373
|
// Convert ISO date to specified format
|
|
352
374
|
const formattedDate = newValue
|
|
353
|
-
?
|
|
375
|
+
? dayjs(newValue).format(this.format)
|
|
354
376
|
: "";
|
|
355
377
|
this.inputRef.value = formattedDate;
|
|
356
378
|
this.internalValue = formattedDate;
|
|
@@ -368,8 +390,8 @@ export class TabworthyDates {
|
|
|
368
390
|
return;
|
|
369
391
|
}
|
|
370
392
|
const newValueInIsoFormat = Array.isArray(newValue)
|
|
371
|
-
? newValue.map((date) =>
|
|
372
|
-
:
|
|
393
|
+
? newValue.map((date) => dayjs(date, this.format).toISOString())
|
|
394
|
+
: dayjs(newValue, this.format).toISOString();
|
|
373
395
|
let content = "";
|
|
374
396
|
if (Array.isArray(newValueInIsoFormat)) {
|
|
375
397
|
if (newValueInIsoFormat.length === 1) {
|
|
@@ -412,7 +434,7 @@ export class TabworthyDates {
|
|
|
412
434
|
if (this.pickerRef) {
|
|
413
435
|
if (Array.isArray(value)) {
|
|
414
436
|
const dates = value.reduce((acc, v) => {
|
|
415
|
-
const d =
|
|
437
|
+
const d = dayjs(v, this.format, true);
|
|
416
438
|
if (d.isValid())
|
|
417
439
|
acc.push(d.toDate());
|
|
418
440
|
return acc;
|
|
@@ -421,7 +443,7 @@ export class TabworthyDates {
|
|
|
421
443
|
}
|
|
422
444
|
else {
|
|
423
445
|
if (value) {
|
|
424
|
-
const parsedDate =
|
|
446
|
+
const parsedDate = dayjs(value, this.format, true);
|
|
425
447
|
if (parsedDate.isValid()) {
|
|
426
448
|
this.pickerRef.value = parsedDate.toDate();
|
|
427
449
|
}
|
|
@@ -441,10 +463,21 @@ export class TabworthyDates {
|
|
|
441
463
|
}
|
|
442
464
|
render() {
|
|
443
465
|
var _a;
|
|
444
|
-
|
|
466
|
+
// Year-only mode: show just a year number input
|
|
467
|
+
if (this.yearOnly) {
|
|
468
|
+
const currentYear = this.value
|
|
469
|
+
? parseInt(String(this.value).slice(0, 4), 10)
|
|
470
|
+
: new Date().getFullYear();
|
|
471
|
+
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", { "aria-label": this.datesLabels.yearSelect, class: {
|
|
472
|
+
[this.getClassName("year-select")]: true,
|
|
473
|
+
[this.getClassName("input")]: true,
|
|
474
|
+
[this.inputClass]: !!this.inputClass
|
|
475
|
+
}, "aria-disabled": this.disabledState, disabled: this.disabledState, max: this.maxDate ? this.maxDate.slice(0, 4) : 9999, min: this.minDate ? this.minDate.slice(0, 4) : 1, name: "year", id: this.id ? `${this.id}-input` : undefined, onChange: this.handleYearInputChange, type: "number", value: currentYear, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState })), this.errorState && (h("div", { class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
476
|
+
}
|
|
477
|
+
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: {
|
|
445
478
|
[this.getClassName("input")]: true,
|
|
446
479
|
[this.inputClass]: !!this.inputClass
|
|
447
|
-
}, 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", {
|
|
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: () => {
|
|
448
481
|
if (!this.pickerRef)
|
|
449
482
|
return;
|
|
450
483
|
this.pickerRef.modalIsOpen = true;
|
|
@@ -452,11 +485,11 @@ export class TabworthyDates {
|
|
|
452
485
|
if (!this.pickerRef)
|
|
453
486
|
return;
|
|
454
487
|
this.pickerRef.modalIsOpen = false;
|
|
455
|
-
}, inline: this.inline, appendTo: this.appendTo }, h("tabworthy-dates-calendar", {
|
|
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 &&
|
|
456
489
|
((_a = this.quickButtons) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
|
|
457
|
-
this.chronoSupportedLocale && (h("div", {
|
|
490
|
+
this.chronoSupportedLocale && (h("div", { class: this.getClassName("quick-group"), role: "group", "aria-label": this.datesLabels.quickSelection }, this.quickButtons.map((buttonText) => {
|
|
458
491
|
return (h("button", { class: this.getClassName("quick-button"), onClick: this.handleQuickButtonClick, disabled: this.disabledState, type: "button" }, buttonText));
|
|
459
|
-
}))), this.errorState && (h("div", {
|
|
492
|
+
}))), this.errorState && (h("div", { class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
460
493
|
}
|
|
461
494
|
static get is() { return "tabworthy-dates"; }
|
|
462
495
|
static get encapsulation() { return "scoped"; }
|
|
@@ -530,6 +563,26 @@ export class TabworthyDates {
|
|
|
530
563
|
"attribute": "range",
|
|
531
564
|
"defaultValue": "false"
|
|
532
565
|
},
|
|
566
|
+
"yearOnly": {
|
|
567
|
+
"type": "boolean",
|
|
568
|
+
"mutable": false,
|
|
569
|
+
"complexType": {
|
|
570
|
+
"original": "boolean",
|
|
571
|
+
"resolved": "boolean",
|
|
572
|
+
"references": {}
|
|
573
|
+
},
|
|
574
|
+
"required": false,
|
|
575
|
+
"optional": true,
|
|
576
|
+
"docs": {
|
|
577
|
+
"tags": [],
|
|
578
|
+
"text": ""
|
|
579
|
+
},
|
|
580
|
+
"getter": false,
|
|
581
|
+
"setter": false,
|
|
582
|
+
"reflect": false,
|
|
583
|
+
"attribute": "year-only",
|
|
584
|
+
"defaultValue": "false"
|
|
585
|
+
},
|
|
533
586
|
"label": {
|
|
534
587
|
"type": "string",
|
|
535
588
|
"mutable": false,
|
|
@@ -17,7 +17,7 @@ const defaultLabels = {
|
|
|
17
17
|
chooseAsStartDate: "choose as start date",
|
|
18
18
|
chooseAsEndDate: "choose as end date"
|
|
19
19
|
};
|
|
20
|
-
export class
|
|
20
|
+
export class TabworthyDatesCalendar {
|
|
21
21
|
constructor() {
|
|
22
22
|
this.disabled = false;
|
|
23
23
|
this.modalIsOpen = false;
|
|
@@ -5,7 +5,7 @@ import { createPopper } from "@popperjs/core";
|
|
|
5
5
|
/**
|
|
6
6
|
* @slot slot - The dialog content
|
|
7
7
|
*/
|
|
8
|
-
export class
|
|
8
|
+
export class TabworthyDatesModal {
|
|
9
9
|
constructor() {
|
|
10
10
|
this.inline = false;
|
|
11
11
|
/** Preferred placement of the dropdown (Popper.js placement) */
|
|
@@ -190,7 +190,7 @@ export class InclusiveDatesModal {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
render() {
|
|
193
|
-
return (h(Host, { key: '
|
|
193
|
+
return (h(Host, { key: '488fb845bb3a168c45f715b5f7315a80e1857589', showing: this.showing, ref: (r) => r && (this.el = r) }, !this.inline && this.showing && (h("div", { key: 'd6263beffa3dbeaa7f0e5e65c1f2627c07164648', part: "body", ref: (r) => {
|
|
194
194
|
if (r) {
|
|
195
195
|
this.bodyRef = r;
|
|
196
196
|
// Setup portal and create popper when ref is set
|
|
@@ -207,7 +207,7 @@ export class InclusiveDatesModal {
|
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
}, style: { visibility: this.positioned ? "visible" : "hidden" }, onKeyDown: this.onKeyDown, role: "dialog", tabindex: -1, "aria-hidden": !this.showing, "aria-label": this.label, "aria-modal": this.showing }, h("focus-trap", { key: '
|
|
210
|
+
}, style: { visibility: this.positioned ? "visible" : "hidden" }, onKeyDown: this.onKeyDown, role: "dialog", tabindex: -1, "aria-hidden": !this.showing, "aria-label": this.label, "aria-modal": this.showing }, h("focus-trap", { key: '7ffb9cc684198ab9f3b127a4abe5f60f3241cd49' }, h("div", { key: 'c6c7c14220c01969f3a5c92dda882685f4c43268', part: "content" }, h("slot", { key: 'a1e6ce7ed152f61b3970e20b40e36bb13ee7580a' }))))), this.inline && (h("div", { key: '632750cfce76139771642e03051f5c4a654db56a', part: "content" }, h("slot", { key: 'c1aa297a6ffdeee55840a9e05adddb7220e7f954' })))));
|
|
211
211
|
}
|
|
212
212
|
static get is() { return "tabworthy-dates-modal"; }
|
|
213
213
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
|
-
import
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
4
|
+
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
5
|
+
dayjs.extend(customParseFormat);
|
|
6
|
+
dayjs.extend(localizedFormat);
|
|
3
7
|
import { getISODateString, removeTimezoneOffset } from "../../../../shared/utils/utils";
|
|
4
8
|
const defaultLabels = {
|
|
5
9
|
selected: "selected",
|
|
@@ -12,9 +16,10 @@ const defaultLabels = {
|
|
|
12
16
|
disabledDateError: `Please choose an available date`,
|
|
13
17
|
to: "to",
|
|
14
18
|
startDate: "Start date",
|
|
19
|
+
yearSelect: "Select year",
|
|
15
20
|
timeLabel: "Time"
|
|
16
21
|
};
|
|
17
|
-
export class
|
|
22
|
+
export class TabworthyTimes {
|
|
18
23
|
constructor() {
|
|
19
24
|
// Enable or disable range mode
|
|
20
25
|
this.range = false;
|
|
@@ -124,11 +129,16 @@ export class InclusiveTimes {
|
|
|
124
129
|
};
|
|
125
130
|
this.handleInputChange = (event) => {
|
|
126
131
|
const value = event.target.value;
|
|
127
|
-
// Try to parse the input value
|
|
128
|
-
|
|
132
|
+
// Try to parse the input value using the component's format first (strict mode)
|
|
133
|
+
// This prevents dayjs from misinterpreting date formats (e.g., DD/MM/YYYY as MM/DD/YYYY)
|
|
134
|
+
let parsed = dayjs(value, this.format, true);
|
|
135
|
+
// Fall back to loose parsing if strict format doesn't match
|
|
136
|
+
if (!parsed.isValid()) {
|
|
137
|
+
parsed = dayjs(value);
|
|
138
|
+
}
|
|
129
139
|
if (parsed.isValid()) {
|
|
130
|
-
this.selectedHours = parsed.
|
|
131
|
-
this.selectedMinutes = parsed.
|
|
140
|
+
this.selectedHours = parsed.hour();
|
|
141
|
+
this.selectedMinutes = parsed.minute();
|
|
132
142
|
this.updateValue(parsed.toDate());
|
|
133
143
|
}
|
|
134
144
|
};
|
|
@@ -161,12 +171,12 @@ export class InclusiveTimes {
|
|
|
161
171
|
// Parse the first datetime value to set time picker
|
|
162
172
|
const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
|
|
163
173
|
if (firstValue) {
|
|
164
|
-
const parsed =
|
|
174
|
+
const parsed = dayjs(firstValue, this.format);
|
|
165
175
|
if (parsed.isValid()) {
|
|
166
176
|
this.selectedDate = parsed.toDate();
|
|
167
|
-
this.selectedHours = parsed.
|
|
168
|
-
this.selectedMinutes = parsed.
|
|
169
|
-
this.selectedSeconds = parsed.
|
|
177
|
+
this.selectedHours = parsed.hour();
|
|
178
|
+
this.selectedMinutes = parsed.minute();
|
|
179
|
+
this.selectedSeconds = parsed.second();
|
|
170
180
|
}
|
|
171
181
|
}
|
|
172
182
|
}
|
|
@@ -178,10 +188,10 @@ export class InclusiveTimes {
|
|
|
178
188
|
if (Array.isArray(date)) {
|
|
179
189
|
// Range mode
|
|
180
190
|
const formattedDates = date.map((d) => {
|
|
181
|
-
const m =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
const m = dayjs(d)
|
|
192
|
+
.hour(this.selectedHours)
|
|
193
|
+
.minute(this.selectedMinutes)
|
|
194
|
+
.second(this.selectedSeconds);
|
|
185
195
|
return m.format(this.format);
|
|
186
196
|
});
|
|
187
197
|
this.internalValue = formattedDates;
|
|
@@ -190,10 +200,10 @@ export class InclusiveTimes {
|
|
|
190
200
|
}
|
|
191
201
|
else {
|
|
192
202
|
// Single date mode
|
|
193
|
-
const m =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
const m = dayjs(date)
|
|
204
|
+
.hour(this.selectedHours)
|
|
205
|
+
.minute(this.selectedMinutes)
|
|
206
|
+
.second(this.selectedSeconds);
|
|
197
207
|
const formatted = m.format(this.format);
|
|
198
208
|
this.internalValue = formatted;
|
|
199
209
|
this.value = formatted;
|
|
@@ -211,13 +221,13 @@ export class InclusiveTimes {
|
|
|
211
221
|
if (Array.isArray(this.internalValue)) {
|
|
212
222
|
// Format range
|
|
213
223
|
const formatted = this.internalValue
|
|
214
|
-
.map((v) =>
|
|
224
|
+
.map((v) => dayjs(v, this.format).format("lll"))
|
|
215
225
|
.join(` ${this.timesLabels.to} `);
|
|
216
226
|
this.inputRef.value = formatted;
|
|
217
227
|
}
|
|
218
228
|
else {
|
|
219
229
|
// Format single datetime
|
|
220
|
-
this.inputRef.value =
|
|
230
|
+
this.inputRef.value = dayjs(this.internalValue, this.format).format("lll");
|
|
221
231
|
}
|
|
222
232
|
}
|
|
223
233
|
getClassName(suffix) {
|
|
@@ -227,8 +237,8 @@ export class InclusiveTimes {
|
|
|
227
237
|
if (!dateString)
|
|
228
238
|
return null;
|
|
229
239
|
const date = Array.isArray(dateString)
|
|
230
|
-
? dateString.map((d) =>
|
|
231
|
-
:
|
|
240
|
+
? dateString.map((d) => dayjs(d, this.format).toDate())
|
|
241
|
+
: dayjs(dateString, this.format).toDate();
|
|
232
242
|
return date;
|
|
233
243
|
}
|
|
234
244
|
async clearValue() {
|
|
@@ -245,10 +255,10 @@ export class InclusiveTimes {
|
|
|
245
255
|
}
|
|
246
256
|
render() {
|
|
247
257
|
var _a;
|
|
248
|
-
return (h(Host, { key: '
|
|
258
|
+
return (h(Host, { key: '16801875a7a022afd2db87e489ff69133e27773d', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: 'f0aa269a9677dbda54d31ea0fa32e69f6ef19114', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: 'a3fa49e1735adb2e32d0dbd4b5fe21d1b1e9ba9c', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: 'dab0c8ff6a9f941b1e3c8a801b2e0de8262beda2', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
249
259
|
[this.getClassName("input")]: true,
|
|
250
260
|
[this.inputClass]: !!this.inputClass
|
|
251
|
-
}, 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: '
|
|
261
|
+
}, 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: 'c072cedad6d4567b3688e434a7173441b4a11026', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '4a4e37ff7f76d51389153b52d281fdc1a8f861d5', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
252
262
|
if (this.pickerRef) {
|
|
253
263
|
this.pickerRef.modalIsOpen = true;
|
|
254
264
|
}
|
|
@@ -256,7 +266,7 @@ export class InclusiveTimes {
|
|
|
256
266
|
if (this.pickerRef) {
|
|
257
267
|
this.pickerRef.modalIsOpen = false;
|
|
258
268
|
}
|
|
259
|
-
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '
|
|
269
|
+
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '9b03ffb9df5a041d802647d66af53eafec187c7f', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '0caab550470b253542d93e29ddadcde85fe7caad', 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 }, h("div", { key: '655aa9bb049f76dba44f18684fec6550ab8aac22', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: 'b695207bda87835f57240f72bea88dc57470c170', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'f17bf595f1df723dc04d87ef86a5f5a6152b506a', 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 && (h("div", { key: '8bf64ca388076cd5f1ad73b763993dbc7736b08c', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
260
270
|
}
|
|
261
271
|
static get is() { return "tabworthy-times"; }
|
|
262
272
|
static get encapsulation() { return "scoped"; }
|