@entur/datepicker 12.0.0 → 12.0.1
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/datepicker.mjs
CHANGED
|
@@ -64,7 +64,7 @@ const nativeDateToDateTime = (date, timeZone, offset2) => {
|
|
|
64
64
|
);
|
|
65
65
|
};
|
|
66
66
|
function nativeDateToDateValue(date, noTimeOnlyDate = false, timeZone, offset2) {
|
|
67
|
-
if (date
|
|
67
|
+
if (date == null) return null;
|
|
68
68
|
if (noTimeOnlyDate)
|
|
69
69
|
return new CalendarDate(
|
|
70
70
|
date.getFullYear(),
|
|
@@ -74,7 +74,7 @@ function nativeDateToDateValue(date, noTimeOnlyDate = false, timeZone, offset2)
|
|
|
74
74
|
return nativeDateToDateTime(date, timeZone, offset2);
|
|
75
75
|
}
|
|
76
76
|
function nativeDateToTimeValue(date, noDateOnlyTime = false, timeZone, offset2) {
|
|
77
|
-
if (date
|
|
77
|
+
if (date == null) return null;
|
|
78
78
|
if (noDateOnlyTime)
|
|
79
79
|
return new Time(
|
|
80
80
|
date.getHours(),
|
|
@@ -85,7 +85,7 @@ function nativeDateToTimeValue(date, noDateOnlyTime = false, timeZone, offset2)
|
|
|
85
85
|
return nativeDateToDateTime(date, timeZone, offset2);
|
|
86
86
|
}
|
|
87
87
|
function timeOrDateValueToNativeDate(value, timeZoneForCalendarDateTime) {
|
|
88
|
-
if (value
|
|
88
|
+
if (value == null) return null;
|
|
89
89
|
if (!("day" in value)) {
|
|
90
90
|
const date = /* @__PURE__ */ new Date();
|
|
91
91
|
date.setHours(value.hour);
|
|
@@ -124,7 +124,7 @@ const convertValueToType = ({
|
|
|
124
124
|
type,
|
|
125
125
|
timezone = "Europe/Oslo"
|
|
126
126
|
}) => {
|
|
127
|
-
if (value
|
|
127
|
+
if (value == null) return null;
|
|
128
128
|
switch (type) {
|
|
129
129
|
case "CalendarDate":
|
|
130
130
|
if (!("day" in value)) return today(timezone);
|
|
@@ -161,7 +161,7 @@ const focusSegment = (ref, segment) => {
|
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
function getWeekNumberForDate(date) {
|
|
164
|
-
if (date
|
|
164
|
+
if (date == null) return -1;
|
|
165
165
|
const calendarDate = convertValueToType({
|
|
166
166
|
value: date,
|
|
167
167
|
type: "CalendarDate"
|
|
@@ -185,7 +185,7 @@ function handleOnChange({
|
|
|
185
185
|
convertValueToType({
|
|
186
186
|
value,
|
|
187
187
|
type: forcedReturnType ?? "ZonedDateTime",
|
|
188
|
-
timezone: (value
|
|
188
|
+
timezone: (value != null && "timeZone" in value ? value.timeZone : void 0) ?? (selectedDate != null && "timeZone" in selectedDate ? selectedDate.timeZone : void 0)
|
|
189
189
|
})
|
|
190
190
|
);
|
|
191
191
|
}
|
|
@@ -207,7 +207,8 @@ function shouldUseAriaAlert(variant) {
|
|
|
207
207
|
return false;
|
|
208
208
|
}
|
|
209
209
|
const DateField = ({
|
|
210
|
-
|
|
210
|
+
// normalize undefined to null so the field stays controlled and empty
|
|
211
|
+
selectedDate = null,
|
|
211
212
|
onChange,
|
|
212
213
|
label,
|
|
213
214
|
locale: customLocale,
|
|
@@ -554,7 +555,8 @@ const Calendar = ({
|
|
|
554
555
|
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_Calendar, { ...props }) });
|
|
555
556
|
};
|
|
556
557
|
const _Calendar = ({
|
|
557
|
-
|
|
558
|
+
// normalize undefined to null so the calendar stays controlled and empty
|
|
559
|
+
selectedDate = null,
|
|
558
560
|
onChange,
|
|
559
561
|
minDate,
|
|
560
562
|
maxDate,
|
|
@@ -715,7 +717,8 @@ const RangeCalendar = ({
|
|
|
715
717
|
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_RangeCalendar, { ...props }) });
|
|
716
718
|
};
|
|
717
719
|
const _RangeCalendar = ({
|
|
718
|
-
|
|
720
|
+
// normalize undefined to null so the calendar stays controlled and empty
|
|
721
|
+
value = null,
|
|
719
722
|
onChange,
|
|
720
723
|
minDate,
|
|
721
724
|
maxDate,
|
|
@@ -782,7 +785,8 @@ const _RangeCalendar = ({
|
|
|
782
785
|
);
|
|
783
786
|
};
|
|
784
787
|
const DatePicker = ({
|
|
785
|
-
|
|
788
|
+
// normalize undefined to null so the picker stays controlled and empty
|
|
789
|
+
selectedDate = null,
|
|
786
790
|
locale,
|
|
787
791
|
disabled,
|
|
788
792
|
readOnly,
|
|
@@ -1048,7 +1052,8 @@ const TimePickerArrowButton = ({
|
|
|
1048
1052
|
);
|
|
1049
1053
|
};
|
|
1050
1054
|
const TimePicker = ({
|
|
1051
|
-
|
|
1055
|
+
// normalize undefined to null so the picker stays controlled and empty
|
|
1056
|
+
selectedTime = null,
|
|
1052
1057
|
onChange,
|
|
1053
1058
|
disabled,
|
|
1054
1059
|
readOnly,
|
|
@@ -1280,7 +1285,8 @@ const SimpleTimePicker = ({
|
|
|
1280
1285
|
padding = "default",
|
|
1281
1286
|
prepend,
|
|
1282
1287
|
readOnly,
|
|
1283
|
-
|
|
1288
|
+
// normalize undefined to null so the picker stays controlled and empty
|
|
1289
|
+
selectedTime = null,
|
|
1284
1290
|
showSeconds,
|
|
1285
1291
|
style,
|
|
1286
1292
|
variant,
|