@uxf/datepicker 16.3.0 → 16.11.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/README.md +56 -43
- package/hooks/use-date-picker-navigation.test.js +1 -0
- package/hooks/use-date-picker.d.ts +4 -1
- package/hooks/use-date-picker.js +84 -78
- package/hooks/use-date-picker.test.js +34 -0
- package/hooks/use-date-range-picker.d.ts +4 -1
- package/hooks/use-date-range-picker.js +80 -74
- package/hooks/use-date-range-picker.test.js +40 -0
- package/hooks/use-day.d.ts +3 -1
- package/hooks/use-day.js +73 -69
- package/hooks/use-day.test.js +28 -0
- package/hooks/use-decade.test.js +1 -0
- package/hooks/use-hour.test.js +1 -0
- package/hooks/use-hours.test.js +1 -0
- package/hooks/use-minute.test.js +1 -0
- package/hooks/use-minutes.test.js +1 -0
- package/hooks/use-month.test.js +1 -0
- package/hooks/use-time-picker.test.js +1 -0
- package/hooks/use-year.test.js +1 -0
- package/jest.dst.config.js +2 -2
- package/package.json +5 -5
- package/utils/date-string.d.ts +5 -4
- package/utils/date-string.js +37 -6
- package/utils/date-string.test.js +28 -0
- package/utils/dst-robustness.test.js +10 -0
package/README.md
CHANGED
|
@@ -114,18 +114,19 @@ export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date
|
|
|
114
114
|
|
|
115
115
|
**UseDatePickerProps**
|
|
116
116
|
|
|
117
|
-
| name | type | required | default | description
|
|
118
|
-
| ------------------- | -------------------------------- | -------- | ------------- |
|
|
119
|
-
| firstDayOfWeek | `FirstDayOfWeek` | | `0` |
|
|
120
|
-
| initialVisibleMonth | `Date` | | |
|
|
121
|
-
| isDateBlocked | `(date: Date) => boolean` | | `() => false` |
|
|
122
|
-
| maxBookingDate | `Date` | | |
|
|
123
|
-
| minBookingDate | `Date` | | |
|
|
124
|
-
| numberOfMonths | `number` | | `1` |
|
|
125
|
-
| onDateChange | `(data: OnDateChangeType): void` | yes | |
|
|
126
|
-
| selectedDate | `Date \| null` | yes | |
|
|
127
|
-
|
|
|
128
|
-
|
|
|
117
|
+
| name | type | required | default | description |
|
|
118
|
+
| ------------------- | -------------------------------- | -------- | ------------- | ------------------------------------------------------------------------------------------------ |
|
|
119
|
+
| firstDayOfWeek | `FirstDayOfWeek` | | `0` | |
|
|
120
|
+
| initialVisibleMonth | `Date` | | | |
|
|
121
|
+
| isDateBlocked | `(date: Date) => boolean` | | `() => false` | |
|
|
122
|
+
| maxBookingDate | `Date` | | | |
|
|
123
|
+
| minBookingDate | `Date` | | | |
|
|
124
|
+
| numberOfMonths | `number` | | `1` | |
|
|
125
|
+
| onDateChange | `(data: OnDateChangeType): void` | yes | | |
|
|
126
|
+
| selectedDate | `Date \| null` | yes | | |
|
|
127
|
+
| timeZone | `string` | | | IANA zone of today and of the month shown first, e.g. `Europe/Prague`; the device's when omitted |
|
|
128
|
+
| unavailableDates | `Date[]` | | `[]` | @deprecated |
|
|
129
|
+
| datesConfig | `DatesConfig[]` | | `[]` | |
|
|
129
130
|
|
|
130
131
|
**UseDatePickerReturnType**
|
|
131
132
|
|
|
@@ -162,23 +163,24 @@ export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date
|
|
|
162
163
|
|
|
163
164
|
**UseDateRangePickerProps**
|
|
164
165
|
|
|
165
|
-
| name | type | required | default | description
|
|
166
|
-
| ------------------------- | --------------------------------- | -------- | ------------- |
|
|
167
|
-
| changeActiveMonthOnSelect | `boolean` | | `false` |
|
|
168
|
-
| endDate | `Date \| null` | yes | |
|
|
169
|
-
| exactMinBookingDays | `boolean` | | `false` |
|
|
170
|
-
| firstDayOfWeek | `FirstDayOfWeek` | | `0` |
|
|
171
|
-
| focusedInput | `FocusedInput` | yes | `startDate` |
|
|
172
|
-
| initialVisibleMonth | `Date` | | |
|
|
173
|
-
| isDateBlocked | `(date: Date) => boolean` | | `() => false` |
|
|
174
|
-
| maxBookingDate | `Date` | | |
|
|
175
|
-
| minBookingDate | `Date` | | |
|
|
176
|
-
| minBookingDates | `number` | | `1` |
|
|
177
|
-
| numberOfMonths | `number` | | `2` |
|
|
178
|
-
| onDatesChange | `(data: OnDatesChangeType): void` | yes | |
|
|
179
|
-
| startDate | `Date \| null` | yes | |
|
|
180
|
-
|
|
|
181
|
-
|
|
|
166
|
+
| name | type | required | default | description |
|
|
167
|
+
| ------------------------- | --------------------------------- | -------- | ------------- | ------------------------------------------------------------------------------------------------ |
|
|
168
|
+
| changeActiveMonthOnSelect | `boolean` | | `false` | |
|
|
169
|
+
| endDate | `Date \| null` | yes | | |
|
|
170
|
+
| exactMinBookingDays | `boolean` | | `false` | |
|
|
171
|
+
| firstDayOfWeek | `FirstDayOfWeek` | | `0` | |
|
|
172
|
+
| focusedInput | `FocusedInput` | yes | `startDate` | |
|
|
173
|
+
| initialVisibleMonth | `Date` | | | |
|
|
174
|
+
| isDateBlocked | `(date: Date) => boolean` | | `() => false` | |
|
|
175
|
+
| maxBookingDate | `Date` | | | |
|
|
176
|
+
| minBookingDate | `Date` | | | |
|
|
177
|
+
| minBookingDates | `number` | | `1` | |
|
|
178
|
+
| numberOfMonths | `number` | | `2` | |
|
|
179
|
+
| onDatesChange | `(data: OnDatesChangeType): void` | yes | | |
|
|
180
|
+
| startDate | `Date \| null` | yes | | |
|
|
181
|
+
| timeZone | `string` | | | IANA zone of today and of the month shown first, e.g. `Europe/Prague`; the device's when omitted |
|
|
182
|
+
| unavailableDates | `Date[]` | | `[]` | @deprecated |
|
|
183
|
+
| datesConfig | `DatesConfig[]` | | `[]` | |
|
|
182
184
|
|
|
183
185
|
**UseDateRangePickerReturnType**
|
|
184
186
|
|
|
@@ -272,20 +274,21 @@ export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date
|
|
|
272
274
|
|
|
273
275
|
**UseDayProps**
|
|
274
276
|
|
|
275
|
-
| name | type | required | default | description
|
|
276
|
-
| ---------------- | ------------------------- | -------- | ------- |
|
|
277
|
-
| date | `Date` | yes | |
|
|
278
|
-
| dayRef | `RefObject` | | |
|
|
279
|
-
| focusedDate | `Date \| null` | yes | |
|
|
280
|
-
| isDateBlocked | `(date: Date) => boolean` | yes | |
|
|
281
|
-
| isDateFocused | `(date: Date) => boolean` | yes | |
|
|
282
|
-
| isDateHovered | `(date: Date) => boolean` | yes | |
|
|
283
|
-
| isDateSelected | `(date: Date) => boolean` | yes | |
|
|
284
|
-
| onDateFocus | `(date: Date) => void` | yes | |
|
|
285
|
-
| onDateHover | `(date: Date) => void` | yes | |
|
|
286
|
-
| onDateSelect | `(date: Date) => void` | yes | |
|
|
287
|
-
|
|
|
288
|
-
|
|
|
277
|
+
| name | type | required | default | description |
|
|
278
|
+
| ---------------- | ------------------------- | -------- | ------- | ----------------------------------------------------------------------- |
|
|
279
|
+
| date | `Date` | yes | | |
|
|
280
|
+
| dayRef | `RefObject` | | | |
|
|
281
|
+
| focusedDate | `Date \| null` | yes | | |
|
|
282
|
+
| isDateBlocked | `(date: Date) => boolean` | yes | | |
|
|
283
|
+
| isDateFocused | `(date: Date) => boolean` | yes | | |
|
|
284
|
+
| isDateHovered | `(date: Date) => boolean` | yes | | |
|
|
285
|
+
| isDateSelected | `(date: Date) => boolean` | yes | | |
|
|
286
|
+
| onDateFocus | `(date: Date) => void` | yes | | |
|
|
287
|
+
| onDateHover | `(date: Date) => void` | yes | | |
|
|
288
|
+
| onDateSelect | `(date: Date) => void` | yes | | |
|
|
289
|
+
| timeZone | `string` | | | IANA zone whose calendar day is `isToday`; pass the picker's `timeZone` |
|
|
290
|
+
| unavailableDates | `Date[]` | | `[]` | @deprecated |
|
|
291
|
+
| datesConfig | `DatesConfig[]` | | | |
|
|
289
292
|
|
|
290
293
|
**UseDayReturnType**
|
|
291
294
|
|
|
@@ -305,6 +308,16 @@ export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date
|
|
|
305
308
|
| tabIndex | `number` | |
|
|
306
309
|
| flags | `Flag[]` | |
|
|
307
310
|
|
|
311
|
+
### Today and time zones
|
|
312
|
+
|
|
313
|
+
`isToday` and the month shown first are the calendar day in `timeZone`, or in the device's time zone when it is not set, never in UTC. Pass the zone when the calendar belongs to a place rather than to the visitor, e.g. a booking form of a clinic in Prague opened abroad: `useDatePicker({ timeZone: "Europe/Prague", … })` and `useDay({ timeZone: datePickerProps.timeZone, … })`. `CalendarProvider`, `DatePicker`, `DateRangePicker` and `DatetimePicker` of `@uxf/ui`, their `DatePickerInput`, `DateRangePickerInput` and `DatetimePickerInput`, and the date fields of `@uxf/form` take the same `timeZone` prop.
|
|
314
|
+
|
|
315
|
+
A calendar rendered on the server needs `timeZone` too: without it the server counts today in its own zone (often UTC) and the browser in the visitor's.
|
|
316
|
+
|
|
317
|
+
An empty or unknown zone name does not throw; the calendar then counts today in the device's time zone and the console warns once per name. Upgrading from the UTC today: [migration note](https://gitlab.uxf.cz/uxf/npm-packages/fe-monorepo/-/blob/master/docs/migration/datepicker-today-time-zone.md).
|
|
318
|
+
|
|
319
|
+
Today is read through `useNow` from `@uxf/core-react`: on the server and while hydrating it is the time the page was rendered at, so a page rendered before midnight and hydrated after it does not mismatch. Add `RenderTimeProvider` (or `PagesRouterRenderTimeProvider`) to get that on cached pages.
|
|
320
|
+
|
|
308
321
|
## Known issues
|
|
309
322
|
|
|
310
323
|
- keyboard navigation doesn't work for year and decade view
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/** @jest-environment jsdom */
|
|
3
4
|
const react_1 = require("@testing-library/react");
|
|
4
5
|
const react_2 = require("react");
|
|
5
6
|
const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
|
|
@@ -12,6 +12,8 @@ export interface UseDatePickerProps {
|
|
|
12
12
|
onDateChange: (data: OnDateChangeType) => void;
|
|
13
13
|
preventScroll?: boolean;
|
|
14
14
|
selectedDate: Date | null;
|
|
15
|
+
/** IANA time zone of today and of the month shown first, e.g. "Europe/Prague"; the device's when omitted. */
|
|
16
|
+
timeZone?: string;
|
|
15
17
|
/** @deprecated */
|
|
16
18
|
unavailableDates?: Date[];
|
|
17
19
|
}
|
|
@@ -32,7 +34,8 @@ export interface UseDatePickerReturnType extends UseDatePickerNavigationReturnTy
|
|
|
32
34
|
onResetDates: () => void;
|
|
33
35
|
preventScroll?: boolean;
|
|
34
36
|
selectedDate: Date | null;
|
|
37
|
+
timeZone?: string;
|
|
35
38
|
/** deprecated */
|
|
36
39
|
unavailableDates: Date[];
|
|
37
40
|
}
|
|
38
|
-
export declare function useDatePicker({ datesConfig, firstDayOfWeek, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, numberOfMonths, onDateChange, preventScroll, selectedDate, unavailableDates, }: UseDatePickerProps): UseDatePickerReturnType;
|
|
41
|
+
export declare function useDatePicker({ datesConfig, firstDayOfWeek, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, numberOfMonths, onDateChange, preventScroll, selectedDate, timeZone, unavailableDates, }: UseDatePickerProps): UseDatePickerReturnType;
|
package/hooks/use-date-picker.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDatePicker = useDatePicker;
|
|
4
4
|
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
5
|
+
const use_now_1 = require("@uxf/core-react/hooks/use-now");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
const date_string_1 = require("../utils/date-string");
|
|
7
8
|
const get_initial_months_1 = require("../utils/get-initial-months");
|
|
@@ -11,13 +12,14 @@ const is_in_unavailable_dates_1 = require("../utils/is-in-unavailable-dates");
|
|
|
11
12
|
const is_start_date_1 = require("../utils/is-start-date");
|
|
12
13
|
const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
|
|
13
14
|
function useDatePicker(t0) {
|
|
14
|
-
const $ = (0, compiler_runtime_1.c)(
|
|
15
|
-
const { datesConfig: t1, firstDayOfWeek: t2, initialVisibleMonth, isDateBlocked: t3, maxBookingDate, minBookingDate, numberOfMonths: t4, onDateChange, preventScroll, selectedDate, unavailableDates: t5 } = t0;
|
|
15
|
+
const $ = (0, compiler_runtime_1.c)(55);
|
|
16
|
+
const { datesConfig: t1, firstDayOfWeek: t2, initialVisibleMonth, isDateBlocked: t3, maxBookingDate, minBookingDate, numberOfMonths: t4, onDateChange, preventScroll, selectedDate, timeZone, unavailableDates: t5 } = t0;
|
|
16
17
|
const datesConfig = t1 === undefined ? [] : t1;
|
|
17
18
|
const firstDayOfWeek = t2 === undefined ? 0 : t2;
|
|
18
19
|
const isDateBlockedProps = t3 === undefined ? _temp : t3;
|
|
19
20
|
const numberOfMonths = t4 === undefined ? 1 : t4;
|
|
20
21
|
const unavailableDates = t5 === undefined ? [] : t5;
|
|
22
|
+
const now = (0, use_now_1.useNow)();
|
|
21
23
|
let t6;
|
|
22
24
|
if ($[0] !== selectedDate) {
|
|
23
25
|
t6 = selectedDate ? (0, date_string_1.toDateString)(selectedDate) : null;
|
|
@@ -33,22 +35,24 @@ function useDatePicker(t0) {
|
|
|
33
35
|
const disabledDatesFromConfig = datesConfig.filter(_temp2).flatMap(_temp3);
|
|
34
36
|
const allDisabledDates = [...unavailableDates.map(date_string_1.toDateString), ...disabledDatesFromConfig.map(date_string_1.toDateString)];
|
|
35
37
|
let t7;
|
|
36
|
-
if ($[2] !== initialVisibleMonth || $[3] !==
|
|
37
|
-
t7 = () =>
|
|
38
|
+
if ($[2] !== initialVisibleMonth || $[3] !== now || $[4] !== numberOfMonths || $[5] !== selectedDate || $[6] !== timeZone) {
|
|
39
|
+
t7 = () => { var _a; return (0, get_initial_months_1.getInitialMonths)(numberOfMonths, (_a = selectedDate !== null && selectedDate !== void 0 ? selectedDate : initialVisibleMonth) !== null && _a !== void 0 ? _a : (0, date_string_1.fromDateString)((0, date_string_1.todayDateString)(now, timeZone))); };
|
|
38
40
|
$[2] = initialVisibleMonth;
|
|
39
|
-
$[3] =
|
|
40
|
-
$[4] =
|
|
41
|
-
$[5] =
|
|
41
|
+
$[3] = now;
|
|
42
|
+
$[4] = numberOfMonths;
|
|
43
|
+
$[5] = selectedDate;
|
|
44
|
+
$[6] = timeZone;
|
|
45
|
+
$[7] = t7;
|
|
42
46
|
}
|
|
43
47
|
else {
|
|
44
|
-
t7 = $[
|
|
48
|
+
t7 = $[7];
|
|
45
49
|
}
|
|
46
50
|
const [activeMonths, setActiveMonths] = (0, react_1.useState)(t7);
|
|
47
51
|
const [hoveredDate, setHoveredDate] = (0, react_1.useState)(null);
|
|
48
52
|
const [focusedDate, setFocusedDate] = (0, react_1.useState)(normalizedSelectedDate);
|
|
49
53
|
const disabledDatesByUser = date => (0, is_in_unavailable_dates_1.isInUnavailableDates)(allDisabledDates, date) || isDateBlockedProps((0, date_string_1.fromDateString)(date));
|
|
50
54
|
let t8;
|
|
51
|
-
if ($[
|
|
55
|
+
if ($[8] !== activeMonths || $[9] !== focusedDate || $[10] !== numberOfMonths) {
|
|
52
56
|
t8 = date_0 => {
|
|
53
57
|
const dateStr = (0, date_string_1.toDateString)(date_0);
|
|
54
58
|
setFocusedDate(dateStr);
|
|
@@ -57,23 +61,23 @@ function useDatePicker(t0) {
|
|
|
57
61
|
setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, date_0));
|
|
58
62
|
}
|
|
59
63
|
};
|
|
60
|
-
$[
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
63
|
-
$[
|
|
64
|
+
$[8] = activeMonths;
|
|
65
|
+
$[9] = focusedDate;
|
|
66
|
+
$[10] = numberOfMonths;
|
|
67
|
+
$[11] = t8;
|
|
64
68
|
}
|
|
65
69
|
else {
|
|
66
|
-
t8 = $[
|
|
70
|
+
t8 = $[11];
|
|
67
71
|
}
|
|
68
72
|
const onDateFocus = t8;
|
|
69
73
|
let t9;
|
|
70
|
-
if ($[
|
|
74
|
+
if ($[12] !== normalizedSelectedDate) {
|
|
71
75
|
t9 = date_1 => (0, is_start_date_1.isStartDate)((0, date_string_1.toDateString)(date_1), normalizedSelectedDate);
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
76
|
+
$[12] = normalizedSelectedDate;
|
|
77
|
+
$[13] = t9;
|
|
74
78
|
}
|
|
75
79
|
else {
|
|
76
|
-
t9 = $[
|
|
80
|
+
t9 = $[13];
|
|
77
81
|
}
|
|
78
82
|
const _isDateSelected = t9;
|
|
79
83
|
const _isDateBlocked = date_2 => (0, is_date_blocked_1.isDateBlocked)({
|
|
@@ -87,13 +91,13 @@ function useDatePicker(t0) {
|
|
|
87
91
|
unavailableDates: allDisabledDates
|
|
88
92
|
});
|
|
89
93
|
let t10;
|
|
90
|
-
if ($[
|
|
94
|
+
if ($[14] !== focusedDate) {
|
|
91
95
|
t10 = date_3 => focusedDate !== null && (0, date_string_1.toDateString)(date_3) === focusedDate;
|
|
92
|
-
$[
|
|
93
|
-
$[
|
|
96
|
+
$[14] = focusedDate;
|
|
97
|
+
$[15] = t10;
|
|
94
98
|
}
|
|
95
99
|
else {
|
|
96
|
-
t10 = $[
|
|
100
|
+
t10 = $[15];
|
|
97
101
|
}
|
|
98
102
|
const isDateFocused = t10;
|
|
99
103
|
const _isDateHovered = date_4 => (0, is_date_hovered_1.isDateHovered)({
|
|
@@ -106,7 +110,7 @@ function useDatePicker(t0) {
|
|
|
106
110
|
isDateBlocked: disabledDatesByUser
|
|
107
111
|
});
|
|
108
112
|
let t11;
|
|
109
|
-
if ($[
|
|
113
|
+
if ($[16] !== activeMonths || $[17] !== focusedDate || $[18] !== numberOfMonths || $[19] !== onDateFocus) {
|
|
110
114
|
t11 = e => {
|
|
111
115
|
var _a, _b;
|
|
112
116
|
if ((e.key === "ArrowRight" || e.key === "ArrowLeft" || e.key === "ArrowDown" || e.key === "ArrowUp") && !focusedDate) {
|
|
@@ -115,18 +119,18 @@ function useDatePicker(t0) {
|
|
|
115
119
|
setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonthDate));
|
|
116
120
|
}
|
|
117
121
|
};
|
|
118
|
-
$[
|
|
119
|
-
$[
|
|
120
|
-
$[
|
|
121
|
-
$[
|
|
122
|
-
$[
|
|
122
|
+
$[16] = activeMonths;
|
|
123
|
+
$[17] = focusedDate;
|
|
124
|
+
$[18] = numberOfMonths;
|
|
125
|
+
$[19] = onDateFocus;
|
|
126
|
+
$[20] = t11;
|
|
123
127
|
}
|
|
124
128
|
else {
|
|
125
|
-
t11 = $[
|
|
129
|
+
t11 = $[20];
|
|
126
130
|
}
|
|
127
131
|
const onKeyDown = (0, react_1.useEffectEvent)(t11);
|
|
128
132
|
let t12;
|
|
129
|
-
if ($[
|
|
133
|
+
if ($[21] !== onKeyDown) {
|
|
130
134
|
t12 = () => {
|
|
131
135
|
const handleKeyDown = e_0 => onKeyDown(e_0);
|
|
132
136
|
const controller = new AbortController();
|
|
@@ -135,35 +139,35 @@ function useDatePicker(t0) {
|
|
|
135
139
|
});
|
|
136
140
|
return () => controller.abort();
|
|
137
141
|
};
|
|
138
|
-
$[
|
|
139
|
-
$[
|
|
142
|
+
$[21] = onKeyDown;
|
|
143
|
+
$[22] = t12;
|
|
140
144
|
}
|
|
141
145
|
else {
|
|
142
|
-
t12 = $[
|
|
146
|
+
t12 = $[22];
|
|
143
147
|
}
|
|
144
148
|
let t13;
|
|
145
|
-
if ($[
|
|
149
|
+
if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
|
|
146
150
|
t13 = [];
|
|
147
|
-
$[
|
|
151
|
+
$[23] = t13;
|
|
148
152
|
}
|
|
149
153
|
else {
|
|
150
|
-
t13 = $[
|
|
154
|
+
t13 = $[23];
|
|
151
155
|
}
|
|
152
156
|
(0, react_1.useEffect)(t12, t13);
|
|
153
157
|
let t14;
|
|
154
|
-
if ($[
|
|
158
|
+
if ($[24] !== onDateChange) {
|
|
155
159
|
t14 = () => {
|
|
156
160
|
onDateChange(null);
|
|
157
161
|
};
|
|
158
|
-
$[
|
|
159
|
-
$[
|
|
162
|
+
$[24] = onDateChange;
|
|
163
|
+
$[25] = t14;
|
|
160
164
|
}
|
|
161
165
|
else {
|
|
162
|
-
t14 = $[
|
|
166
|
+
t14 = $[25];
|
|
163
167
|
}
|
|
164
168
|
const onReset = t14;
|
|
165
169
|
let t15;
|
|
166
|
-
if ($[
|
|
170
|
+
if ($[26] !== normalizedSelectedDate || $[27] !== onDateChange || $[28] !== onReset) {
|
|
167
171
|
t15 = function onDateSelect(date_5) {
|
|
168
172
|
const dateStr_0 = (0, date_string_1.toDateString)(date_5);
|
|
169
173
|
if (dateStr_0 !== normalizedSelectedDate) {
|
|
@@ -173,13 +177,13 @@ function useDatePicker(t0) {
|
|
|
173
177
|
onReset();
|
|
174
178
|
}
|
|
175
179
|
};
|
|
176
|
-
$[
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
180
|
+
$[26] = normalizedSelectedDate;
|
|
181
|
+
$[27] = onDateChange;
|
|
182
|
+
$[28] = onReset;
|
|
183
|
+
$[29] = t15;
|
|
180
184
|
}
|
|
181
185
|
else {
|
|
182
|
-
t15 = $[
|
|
186
|
+
t15 = $[29];
|
|
183
187
|
}
|
|
184
188
|
const onDateSelect = t15;
|
|
185
189
|
const onDateHover = function onDateHover(date_6) {
|
|
@@ -200,12 +204,12 @@ function useDatePicker(t0) {
|
|
|
200
204
|
}
|
|
201
205
|
};
|
|
202
206
|
let t16;
|
|
203
|
-
if ($[
|
|
207
|
+
if ($[30] === Symbol.for("react.memo_cache_sentinel")) {
|
|
204
208
|
t16 = date_7 => setFocusedDate(date_7 ? (0, date_string_1.toDateString)(date_7) : null);
|
|
205
|
-
$[
|
|
209
|
+
$[30] = t16;
|
|
206
210
|
}
|
|
207
211
|
else {
|
|
208
|
-
t16 = $[
|
|
212
|
+
t16 = $[30];
|
|
209
213
|
}
|
|
210
214
|
const t17 = (0, use_date_picker_navigation_1.useDatePickerNavigation)({
|
|
211
215
|
activeMonths,
|
|
@@ -216,26 +220,26 @@ function useDatePicker(t0) {
|
|
|
216
220
|
setFocusedDate: t16
|
|
217
221
|
});
|
|
218
222
|
let t18;
|
|
219
|
-
if ($[
|
|
223
|
+
if ($[31] !== focusedDate) {
|
|
220
224
|
t18 = focusedDate ? (0, date_string_1.fromDateString)(focusedDate) : null;
|
|
221
|
-
$[
|
|
222
|
-
$[
|
|
225
|
+
$[31] = focusedDate;
|
|
226
|
+
$[32] = t18;
|
|
223
227
|
}
|
|
224
228
|
else {
|
|
225
|
-
t18 = $[
|
|
229
|
+
t18 = $[32];
|
|
226
230
|
}
|
|
227
231
|
let t19;
|
|
228
|
-
if ($[
|
|
232
|
+
if ($[33] !== hoveredDate) {
|
|
229
233
|
t19 = hoveredDate ? (0, date_string_1.fromDateString)(hoveredDate) : null;
|
|
230
|
-
$[
|
|
231
|
-
$[
|
|
234
|
+
$[33] = hoveredDate;
|
|
235
|
+
$[34] = t19;
|
|
232
236
|
}
|
|
233
237
|
else {
|
|
234
|
-
t19 = $[
|
|
238
|
+
t19 = $[34];
|
|
235
239
|
}
|
|
236
240
|
const t20 = allDisabledDates.map(date_string_1.fromDateString);
|
|
237
241
|
let t21;
|
|
238
|
-
if ($[
|
|
242
|
+
if ($[35] !== _isDateBlocked || $[36] !== _isDateHovered || $[37] !== _isDateSelected || $[38] !== activeMonths || $[39] !== datesConfig || $[40] !== firstDayOfWeek || $[41] !== isDateFocused || $[42] !== numberOfMonths || $[43] !== onDateFocus || $[44] !== onDateHover || $[45] !== onDateSelect || $[46] !== onReset || $[47] !== preventScroll || $[48] !== selectedDate || $[49] !== t17 || $[50] !== t18 || $[51] !== t19 || $[52] !== t20 || $[53] !== timeZone) {
|
|
239
243
|
t21 = {
|
|
240
244
|
...t17,
|
|
241
245
|
activeMonths,
|
|
@@ -254,30 +258,32 @@ function useDatePicker(t0) {
|
|
|
254
258
|
onResetDates: onReset,
|
|
255
259
|
preventScroll,
|
|
256
260
|
selectedDate,
|
|
261
|
+
timeZone,
|
|
257
262
|
unavailableDates: t20
|
|
258
263
|
};
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
$[
|
|
263
|
-
$[
|
|
264
|
-
$[
|
|
265
|
-
$[
|
|
266
|
-
$[
|
|
267
|
-
$[
|
|
268
|
-
$[
|
|
269
|
-
$[
|
|
270
|
-
$[
|
|
271
|
-
$[
|
|
272
|
-
$[
|
|
273
|
-
$[
|
|
274
|
-
$[
|
|
275
|
-
$[
|
|
276
|
-
$[
|
|
277
|
-
$[
|
|
264
|
+
$[35] = _isDateBlocked;
|
|
265
|
+
$[36] = _isDateHovered;
|
|
266
|
+
$[37] = _isDateSelected;
|
|
267
|
+
$[38] = activeMonths;
|
|
268
|
+
$[39] = datesConfig;
|
|
269
|
+
$[40] = firstDayOfWeek;
|
|
270
|
+
$[41] = isDateFocused;
|
|
271
|
+
$[42] = numberOfMonths;
|
|
272
|
+
$[43] = onDateFocus;
|
|
273
|
+
$[44] = onDateHover;
|
|
274
|
+
$[45] = onDateSelect;
|
|
275
|
+
$[46] = onReset;
|
|
276
|
+
$[47] = preventScroll;
|
|
277
|
+
$[48] = selectedDate;
|
|
278
|
+
$[49] = t17;
|
|
279
|
+
$[50] = t18;
|
|
280
|
+
$[51] = t19;
|
|
281
|
+
$[52] = t20;
|
|
282
|
+
$[53] = timeZone;
|
|
283
|
+
$[54] = t21;
|
|
278
284
|
}
|
|
279
285
|
else {
|
|
280
|
-
t21 = $[
|
|
286
|
+
t21 = $[54];
|
|
281
287
|
}
|
|
282
288
|
return t21;
|
|
283
289
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/** @jest-environment jsdom */
|
|
3
4
|
const react_1 = require("@testing-library/react");
|
|
4
5
|
const react_2 = require("react");
|
|
5
6
|
const use_date_picker_1 = require("./use-date-picker");
|
|
@@ -73,3 +74,36 @@ test("date select", () => {
|
|
|
73
74
|
});
|
|
74
75
|
expect(result.current.isDateSelected(BASE_DATE)).toBe(false);
|
|
75
76
|
});
|
|
77
|
+
describe("time zone", () => {
|
|
78
|
+
// 0:30 on 1 December in Prague, still November in UTC and in Los Angeles
|
|
79
|
+
beforeAll(() => {
|
|
80
|
+
jest.useFakeTimers();
|
|
81
|
+
jest.setSystemTime(new Date("2026-11-30T23:30:00Z"));
|
|
82
|
+
});
|
|
83
|
+
afterAll(() => jest.useRealTimers());
|
|
84
|
+
test("opens on the month of today in the given time zone", () => {
|
|
85
|
+
const render = (timeZone) => (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({ selectedDate: null, onDateChange: () => undefined, timeZone })).result
|
|
86
|
+
.current;
|
|
87
|
+
expect(render("Europe/Prague").activeMonths[0]).toMatchObject({ year: 2026, month: 11 });
|
|
88
|
+
expect(render("America/Los_Angeles").activeMonths[0]).toMatchObject({ year: 2026, month: 10 });
|
|
89
|
+
expect(render("Europe/Prague").timeZone).toBe("Europe/Prague");
|
|
90
|
+
});
|
|
91
|
+
test("opens on initialVisibleMonth rather than today when nothing is selected", () => {
|
|
92
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({
|
|
93
|
+
selectedDate: null,
|
|
94
|
+
initialVisibleMonth: new Date("2023-05-10"),
|
|
95
|
+
onDateChange: () => undefined,
|
|
96
|
+
timeZone: "Europe/Prague",
|
|
97
|
+
}));
|
|
98
|
+
expect(result.current.activeMonths[0]).toMatchObject({ year: 2023, month: 4 });
|
|
99
|
+
});
|
|
100
|
+
test("opens on the selected date rather than initialVisibleMonth", () => {
|
|
101
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({
|
|
102
|
+
selectedDate: new Date("2024-03-10"),
|
|
103
|
+
initialVisibleMonth: new Date("2023-05-10"),
|
|
104
|
+
onDateChange: () => undefined,
|
|
105
|
+
timeZone: "Europe/Prague",
|
|
106
|
+
}));
|
|
107
|
+
expect(result.current.activeMonths[0]).toMatchObject({ year: 2024, month: 2 });
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -24,6 +24,8 @@ export interface UseDateRangePickerProps {
|
|
|
24
24
|
onDatesChange: (data: OnDatesChangeProps) => void;
|
|
25
25
|
preventScroll?: boolean;
|
|
26
26
|
startDate: Date | null;
|
|
27
|
+
/** IANA time zone of today and of the month shown first, e.g. "Europe/Prague"; the device's when omitted. */
|
|
28
|
+
timeZone?: string;
|
|
27
29
|
/** @deprecated */
|
|
28
30
|
unavailableDates?: Date[];
|
|
29
31
|
}
|
|
@@ -47,6 +49,7 @@ export interface UseDateRangePickerReturnType extends UseDatePickerNavigationRet
|
|
|
47
49
|
onDatesSelect: (startDate: Date, endDate: Date | null) => void;
|
|
48
50
|
onResetDates: () => void;
|
|
49
51
|
preventScroll?: boolean;
|
|
52
|
+
timeZone?: string;
|
|
50
53
|
unavailableDates: Date[];
|
|
51
54
|
}
|
|
52
|
-
export declare function useDateRangePicker({ changeActiveMonthOnSelect, datesConfig, endDate, exactMinBookingDays, firstDayOfWeek, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays, numberOfMonths, onDatesChange, startDate, unavailableDates, }: UseDateRangePickerProps): UseDateRangePickerReturnType;
|
|
55
|
+
export declare function useDateRangePicker({ changeActiveMonthOnSelect, datesConfig, endDate, exactMinBookingDays, firstDayOfWeek, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays, numberOfMonths, onDatesChange, startDate, timeZone, unavailableDates, }: UseDateRangePickerProps): UseDateRangePickerReturnType;
|