@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
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.END_DATE = exports.START_DATE = void 0;
|
|
4
4
|
exports.useDateRangePicker = useDateRangePicker;
|
|
5
5
|
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
6
|
+
const use_now_1 = require("@uxf/core-react/hooks/use-now");
|
|
6
7
|
const react_1 = require("react");
|
|
7
8
|
const can_select_range_1 = require("../utils/can-select-range");
|
|
8
9
|
const date_string_1 = require("../utils/date-string");
|
|
@@ -18,8 +19,8 @@ const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
|
|
|
18
19
|
exports.START_DATE = "startDate";
|
|
19
20
|
exports.END_DATE = "endDate";
|
|
20
21
|
function useDateRangePicker(t0) {
|
|
21
|
-
const $ = (0, compiler_runtime_1.c)(
|
|
22
|
-
const { changeActiveMonthOnSelect: t1, datesConfig: t2, endDate, exactMinBookingDays: t3, firstDayOfWeek: t4, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays: t5, numberOfMonths: t6, onDatesChange, startDate, unavailableDates: t7 } = t0;
|
|
22
|
+
const $ = (0, compiler_runtime_1.c)(53);
|
|
23
|
+
const { changeActiveMonthOnSelect: t1, datesConfig: t2, endDate, exactMinBookingDays: t3, firstDayOfWeek: t4, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays: t5, numberOfMonths: t6, onDatesChange, startDate, timeZone, unavailableDates: t7 } = t0;
|
|
23
24
|
const changeActiveMonthOnSelect = t1 === undefined ? false : t1;
|
|
24
25
|
const datesConfig = t2 === undefined ? [] : t2;
|
|
25
26
|
const exactMinBookingDays = t3 === undefined ? false : t3;
|
|
@@ -27,6 +28,7 @@ function useDateRangePicker(t0) {
|
|
|
27
28
|
const minBookingDays = t5 === undefined ? 1 : t5;
|
|
28
29
|
const numberOfMonths = t6 === undefined ? 2 : t6;
|
|
29
30
|
const unavailableDates = t7 === undefined ? [] : t7;
|
|
31
|
+
const now = (0, use_now_1.useNow)();
|
|
30
32
|
let t8;
|
|
31
33
|
if ($[0] !== startDate) {
|
|
32
34
|
t8 = startDate ? (0, date_string_1.toDateString)(startDate) : null;
|
|
@@ -43,22 +45,24 @@ function useDateRangePicker(t0) {
|
|
|
43
45
|
const disabledDatesFromConfig = datesConfig.filter(_temp).flatMap(_temp2);
|
|
44
46
|
const allDisabledDates = [...unavailableDates.map(date_string_1.toDateString), ...disabledDatesFromConfig.map(date_string_1.toDateString)];
|
|
45
47
|
let t9;
|
|
46
|
-
if ($[2] !== initialVisibleMonth || $[3] !==
|
|
47
|
-
t9 = () =>
|
|
48
|
+
if ($[2] !== initialVisibleMonth || $[3] !== now || $[4] !== numberOfMonths || $[5] !== startDate || $[6] !== timeZone) {
|
|
49
|
+
t9 = () => { var _a; return (0, get_initial_months_1.getInitialMonths)(numberOfMonths, (_a = startDate !== null && startDate !== void 0 ? startDate : initialVisibleMonth) !== null && _a !== void 0 ? _a : (0, date_string_1.fromDateString)((0, date_string_1.todayDateString)(now, timeZone))); };
|
|
48
50
|
$[2] = initialVisibleMonth;
|
|
49
|
-
$[3] =
|
|
50
|
-
$[4] =
|
|
51
|
-
$[5] =
|
|
51
|
+
$[3] = now;
|
|
52
|
+
$[4] = numberOfMonths;
|
|
53
|
+
$[5] = startDate;
|
|
54
|
+
$[6] = timeZone;
|
|
55
|
+
$[7] = t9;
|
|
52
56
|
}
|
|
53
57
|
else {
|
|
54
|
-
t9 = $[
|
|
58
|
+
t9 = $[7];
|
|
55
59
|
}
|
|
56
60
|
const [activeMonths, setActiveMonths] = (0, react_1.useState)(t9);
|
|
57
61
|
const [hoveredDate, setHoveredDate] = (0, react_1.useState)(null);
|
|
58
62
|
const [focusedDate, setFocusedDate] = (0, react_1.useState)(normalizedStartDate);
|
|
59
63
|
const disabledDatesByUser = isDateBlockedProps || allDisabledDates.length > 0 ? date => { var _a; return (0, is_in_unavailable_dates_1.isInUnavailableDates)(allDisabledDates, date) || ((_a = isDateBlockedProps === null || isDateBlockedProps === void 0 ? void 0 : isDateBlockedProps((0, date_string_1.fromDateString)(date))) !== null && _a !== void 0 ? _a : false); } : null;
|
|
60
64
|
let t10;
|
|
61
|
-
if ($[
|
|
65
|
+
if ($[8] !== activeMonths || $[9] !== focusedDate || $[10] !== numberOfMonths) {
|
|
62
66
|
t10 = date_0 => {
|
|
63
67
|
const dateStr = (0, date_string_1.toDateString)(date_0);
|
|
64
68
|
setFocusedDate(dateStr);
|
|
@@ -67,13 +71,13 @@ function useDateRangePicker(t0) {
|
|
|
67
71
|
setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, date_0));
|
|
68
72
|
}
|
|
69
73
|
};
|
|
70
|
-
$[
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
+
$[8] = activeMonths;
|
|
75
|
+
$[9] = focusedDate;
|
|
76
|
+
$[10] = numberOfMonths;
|
|
77
|
+
$[11] = t10;
|
|
74
78
|
}
|
|
75
79
|
else {
|
|
76
|
-
t10 = $[
|
|
80
|
+
t10 = $[11];
|
|
77
81
|
}
|
|
78
82
|
const onDateFocus = t10;
|
|
79
83
|
const _isDateSelected = date_1 => {
|
|
@@ -81,13 +85,13 @@ function useDateRangePicker(t0) {
|
|
|
81
85
|
return (0, is_date_inside_range_1.isDateInsideRange)(dateStr_0, normalizedStartDate, normalizedEndDate) || (0, is_first_or_last_selected_date_1.isFirstOrLastSelectedDate)(dateStr_0, normalizedStartDate, normalizedEndDate);
|
|
82
86
|
};
|
|
83
87
|
let t11;
|
|
84
|
-
if ($[
|
|
88
|
+
if ($[12] !== normalizedStartDate) {
|
|
85
89
|
t11 = date_2 => (0, is_start_date_1.isStartDate)((0, date_string_1.toDateString)(date_2), normalizedStartDate);
|
|
86
|
-
$[
|
|
87
|
-
$[
|
|
90
|
+
$[12] = normalizedStartDate;
|
|
91
|
+
$[13] = t11;
|
|
88
92
|
}
|
|
89
93
|
else {
|
|
90
|
-
t11 = $[
|
|
94
|
+
t11 = $[13];
|
|
91
95
|
}
|
|
92
96
|
const _isStartDate = t11;
|
|
93
97
|
const _isEndDate = date_3 => (0, is_end_date_1.isEndDate)((0, date_string_1.toDateString)(date_3), normalizedEndDate);
|
|
@@ -103,13 +107,13 @@ function useDateRangePicker(t0) {
|
|
|
103
107
|
unavailableDates: allDisabledDates
|
|
104
108
|
});
|
|
105
109
|
let t12;
|
|
106
|
-
if ($[
|
|
110
|
+
if ($[14] !== focusedDate) {
|
|
107
111
|
t12 = date_6 => focusedDate !== null && (0, date_string_1.toDateString)(date_6) === focusedDate;
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
112
|
+
$[14] = focusedDate;
|
|
113
|
+
$[15] = t12;
|
|
110
114
|
}
|
|
111
115
|
else {
|
|
112
|
-
t12 = $[
|
|
116
|
+
t12 = $[15];
|
|
113
117
|
}
|
|
114
118
|
const isDateFocused = t12;
|
|
115
119
|
const _isDateHovered = date_7 => (0, is_date_hovered_1.isDateHovered)({
|
|
@@ -122,7 +126,7 @@ function useDateRangePicker(t0) {
|
|
|
122
126
|
isDateBlocked: disabledDatesByUser
|
|
123
127
|
});
|
|
124
128
|
let t13;
|
|
125
|
-
if ($[
|
|
129
|
+
if ($[16] !== activeMonths || $[17] !== focusedDate || $[18] !== numberOfMonths || $[19] !== onDateFocus) {
|
|
126
130
|
t13 = e => {
|
|
127
131
|
var _a, _b;
|
|
128
132
|
if ((e.key === "ArrowRight" || e.key === "ArrowLeft" || e.key === "ArrowDown" || e.key === "ArrowUp") && !focusedDate) {
|
|
@@ -131,18 +135,18 @@ function useDateRangePicker(t0) {
|
|
|
131
135
|
setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonthDate));
|
|
132
136
|
}
|
|
133
137
|
};
|
|
134
|
-
$[
|
|
135
|
-
$[
|
|
136
|
-
$[
|
|
137
|
-
$[
|
|
138
|
-
$[
|
|
138
|
+
$[16] = activeMonths;
|
|
139
|
+
$[17] = focusedDate;
|
|
140
|
+
$[18] = numberOfMonths;
|
|
141
|
+
$[19] = onDateFocus;
|
|
142
|
+
$[20] = t13;
|
|
139
143
|
}
|
|
140
144
|
else {
|
|
141
|
-
t13 = $[
|
|
145
|
+
t13 = $[20];
|
|
142
146
|
}
|
|
143
147
|
const onKeyDown = (0, react_1.useEffectEvent)(t13);
|
|
144
148
|
let t14;
|
|
145
|
-
if ($[
|
|
149
|
+
if ($[21] !== onKeyDown) {
|
|
146
150
|
t14 = () => {
|
|
147
151
|
const handleKeyDown = e_0 => onKeyDown(e_0);
|
|
148
152
|
const controller = new AbortController();
|
|
@@ -151,23 +155,23 @@ function useDateRangePicker(t0) {
|
|
|
151
155
|
});
|
|
152
156
|
return () => controller.abort();
|
|
153
157
|
};
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
158
|
+
$[21] = onKeyDown;
|
|
159
|
+
$[22] = t14;
|
|
156
160
|
}
|
|
157
161
|
else {
|
|
158
|
-
t14 = $[
|
|
162
|
+
t14 = $[22];
|
|
159
163
|
}
|
|
160
164
|
let t15;
|
|
161
|
-
if ($[
|
|
165
|
+
if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
|
|
162
166
|
t15 = [];
|
|
163
|
-
$[
|
|
167
|
+
$[23] = t15;
|
|
164
168
|
}
|
|
165
169
|
else {
|
|
166
|
-
t15 = $[
|
|
170
|
+
t15 = $[23];
|
|
167
171
|
}
|
|
168
172
|
(0, react_1.useEffect)(t14, t15);
|
|
169
173
|
let t16;
|
|
170
|
-
if ($[
|
|
174
|
+
if ($[24] !== onDatesChange) {
|
|
171
175
|
t16 = () => {
|
|
172
176
|
onDatesChange({
|
|
173
177
|
startDate: null,
|
|
@@ -175,11 +179,11 @@ function useDateRangePicker(t0) {
|
|
|
175
179
|
focusedInput: exports.START_DATE
|
|
176
180
|
});
|
|
177
181
|
};
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
182
|
+
$[24] = onDatesChange;
|
|
183
|
+
$[25] = t16;
|
|
180
184
|
}
|
|
181
185
|
else {
|
|
182
|
-
t16 = $[
|
|
186
|
+
t16 = $[25];
|
|
183
187
|
}
|
|
184
188
|
const onResetDates = t16;
|
|
185
189
|
const onDateSelect = function onDateSelect(date_8) {
|
|
@@ -299,12 +303,12 @@ function useDateRangePicker(t0) {
|
|
|
299
303
|
}
|
|
300
304
|
};
|
|
301
305
|
let t17;
|
|
302
|
-
if ($[
|
|
306
|
+
if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
|
|
303
307
|
t17 = d => setFocusedDate(d ? (0, date_string_1.toDateString)(d) : null);
|
|
304
|
-
$[
|
|
308
|
+
$[26] = t17;
|
|
305
309
|
}
|
|
306
310
|
else {
|
|
307
|
-
t17 = $[
|
|
311
|
+
t17 = $[26];
|
|
308
312
|
}
|
|
309
313
|
const t18 = (0, use_date_picker_navigation_1.useDatePickerNavigation)({
|
|
310
314
|
activeMonths,
|
|
@@ -315,26 +319,26 @@ function useDateRangePicker(t0) {
|
|
|
315
319
|
setFocusedDate: t17
|
|
316
320
|
});
|
|
317
321
|
let t19;
|
|
318
|
-
if ($[
|
|
322
|
+
if ($[27] !== focusedDate) {
|
|
319
323
|
t19 = focusedDate ? (0, date_string_1.fromDateString)(focusedDate) : null;
|
|
320
|
-
$[
|
|
321
|
-
$[
|
|
324
|
+
$[27] = focusedDate;
|
|
325
|
+
$[28] = t19;
|
|
322
326
|
}
|
|
323
327
|
else {
|
|
324
|
-
t19 = $[
|
|
328
|
+
t19 = $[28];
|
|
325
329
|
}
|
|
326
330
|
let t20;
|
|
327
|
-
if ($[
|
|
331
|
+
if ($[29] !== hoveredDate) {
|
|
328
332
|
t20 = hoveredDate ? (0, date_string_1.fromDateString)(hoveredDate) : null;
|
|
329
|
-
$[
|
|
330
|
-
$[
|
|
333
|
+
$[29] = hoveredDate;
|
|
334
|
+
$[30] = t20;
|
|
331
335
|
}
|
|
332
336
|
else {
|
|
333
|
-
t20 = $[
|
|
337
|
+
t20 = $[30];
|
|
334
338
|
}
|
|
335
339
|
const t21 = allDisabledDates.map(date_string_1.fromDateString);
|
|
336
340
|
let t22;
|
|
337
|
-
if ($[
|
|
341
|
+
if ($[31] !== _isDateBlocked || $[32] !== _isDateHovered || $[33] !== _isDateInsideRange || $[34] !== _isDateSelected || $[35] !== _isEndDate || $[36] !== _isStartDate || $[37] !== activeMonths || $[38] !== datesConfig || $[39] !== firstDayOfWeek || $[40] !== isDateFocused || $[41] !== numberOfMonths || $[42] !== onDateFocus || $[43] !== onDateHover || $[44] !== onDateSelect || $[45] !== onDatesSelect || $[46] !== onResetDates || $[47] !== t18 || $[48] !== t19 || $[49] !== t20 || $[50] !== t21 || $[51] !== timeZone) {
|
|
338
342
|
t22 = {
|
|
339
343
|
...t18,
|
|
340
344
|
activeMonths,
|
|
@@ -355,32 +359,34 @@ function useDateRangePicker(t0) {
|
|
|
355
359
|
onDateSelect,
|
|
356
360
|
onDatesSelect,
|
|
357
361
|
onResetDates,
|
|
362
|
+
timeZone,
|
|
358
363
|
unavailableDates: t21
|
|
359
364
|
};
|
|
360
|
-
$[
|
|
361
|
-
$[
|
|
362
|
-
$[
|
|
363
|
-
$[
|
|
364
|
-
$[
|
|
365
|
-
$[
|
|
366
|
-
$[
|
|
367
|
-
$[
|
|
368
|
-
$[
|
|
369
|
-
$[
|
|
370
|
-
$[
|
|
371
|
-
$[
|
|
372
|
-
$[
|
|
373
|
-
$[
|
|
374
|
-
$[
|
|
375
|
-
$[
|
|
376
|
-
$[
|
|
377
|
-
$[
|
|
378
|
-
$[
|
|
379
|
-
$[
|
|
380
|
-
$[
|
|
365
|
+
$[31] = _isDateBlocked;
|
|
366
|
+
$[32] = _isDateHovered;
|
|
367
|
+
$[33] = _isDateInsideRange;
|
|
368
|
+
$[34] = _isDateSelected;
|
|
369
|
+
$[35] = _isEndDate;
|
|
370
|
+
$[36] = _isStartDate;
|
|
371
|
+
$[37] = activeMonths;
|
|
372
|
+
$[38] = datesConfig;
|
|
373
|
+
$[39] = firstDayOfWeek;
|
|
374
|
+
$[40] = isDateFocused;
|
|
375
|
+
$[41] = numberOfMonths;
|
|
376
|
+
$[42] = onDateFocus;
|
|
377
|
+
$[43] = onDateHover;
|
|
378
|
+
$[44] = onDateSelect;
|
|
379
|
+
$[45] = onDatesSelect;
|
|
380
|
+
$[46] = onResetDates;
|
|
381
|
+
$[47] = t18;
|
|
382
|
+
$[48] = t19;
|
|
383
|
+
$[49] = t20;
|
|
384
|
+
$[50] = t21;
|
|
385
|
+
$[51] = timeZone;
|
|
386
|
+
$[52] = t22;
|
|
381
387
|
}
|
|
382
388
|
else {
|
|
383
|
-
t22 = $[
|
|
389
|
+
t22 = $[52];
|
|
384
390
|
}
|
|
385
391
|
return t22;
|
|
386
392
|
}
|
|
@@ -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_range_picker_1 = require("./use-date-range-picker");
|
|
@@ -268,3 +269,42 @@ test("date range select - with isDateBlocked callback", () => {
|
|
|
268
269
|
// onDatesChange should not be called when a blocked date (17th) is in the range
|
|
269
270
|
expect(onDatesChange).not.toHaveBeenCalled();
|
|
270
271
|
});
|
|
272
|
+
describe("time zone", () => {
|
|
273
|
+
// 0:30 on 1 December in Prague, still November in UTC and in Los Angeles
|
|
274
|
+
beforeEach(() => jest.setSystemTime(new Date("2026-11-30T23:30:00Z")));
|
|
275
|
+
afterAll(() => jest.setSystemTime(new Date("2021-09-25")));
|
|
276
|
+
test("opens on the month of today in the given time zone", () => {
|
|
277
|
+
const render = (timeZone) => (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
|
|
278
|
+
startDate: null,
|
|
279
|
+
endDate: null,
|
|
280
|
+
onDatesChange: () => undefined,
|
|
281
|
+
focusedInput: "startDate",
|
|
282
|
+
timeZone,
|
|
283
|
+
})).result.current;
|
|
284
|
+
expect(render("Europe/Prague").activeMonths[0]).toMatchObject({ year: 2026, month: 11 });
|
|
285
|
+
expect(render("America/Los_Angeles").activeMonths[0]).toMatchObject({ year: 2026, month: 10 });
|
|
286
|
+
expect(render("Europe/Prague").timeZone).toBe("Europe/Prague");
|
|
287
|
+
});
|
|
288
|
+
test("opens on initialVisibleMonth rather than today when there is no start date", () => {
|
|
289
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
|
|
290
|
+
startDate: null,
|
|
291
|
+
endDate: null,
|
|
292
|
+
onDatesChange: () => undefined,
|
|
293
|
+
focusedInput: "startDate",
|
|
294
|
+
initialVisibleMonth: new Date("2023-05-10"),
|
|
295
|
+
timeZone: "Europe/Prague",
|
|
296
|
+
}));
|
|
297
|
+
expect(result.current.activeMonths[0]).toMatchObject({ year: 2023, month: 4 });
|
|
298
|
+
});
|
|
299
|
+
test("opens on the start date rather than initialVisibleMonth", () => {
|
|
300
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
|
|
301
|
+
startDate: new Date("2024-03-10"),
|
|
302
|
+
endDate: null,
|
|
303
|
+
onDatesChange: () => undefined,
|
|
304
|
+
focusedInput: "endDate",
|
|
305
|
+
initialVisibleMonth: new Date("2023-05-10"),
|
|
306
|
+
timeZone: "Europe/Prague",
|
|
307
|
+
}));
|
|
308
|
+
expect(result.current.activeMonths[0]).toMatchObject({ year: 2024, month: 2 });
|
|
309
|
+
});
|
|
310
|
+
});
|
package/hooks/use-day.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface UseDayProps {
|
|
|
14
14
|
onDateHover: (date: Date) => void;
|
|
15
15
|
onDateSelect: (date: Date) => void;
|
|
16
16
|
preventScroll?: boolean;
|
|
17
|
+
/** IANA time zone whose calendar day is today, e.g. "Europe/Prague"; the device's when omitted. */
|
|
18
|
+
timeZone?: string;
|
|
17
19
|
/** @deprecated Pass the dates in `datesConfig` with `isDisabled: true`. */
|
|
18
20
|
unavailableDates?: Date[];
|
|
19
21
|
}
|
|
@@ -32,4 +34,4 @@ export interface UseDayReturnType {
|
|
|
32
34
|
onMouseEnter: () => void;
|
|
33
35
|
tabIndex: number;
|
|
34
36
|
}
|
|
35
|
-
export declare function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates, }: UseDayProps): UseDayReturnType;
|
|
37
|
+
export declare function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, timeZone, unavailableDates, }: UseDayProps): UseDayReturnType;
|
package/hooks/use-day.js
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDay = useDay;
|
|
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 empty_array_1 = require("@uxf/core/constants/empty-array");
|
|
6
7
|
const react_1 = require("react");
|
|
7
8
|
const date_string_1 = require("../utils/date-string");
|
|
8
9
|
const get_date_invervals_1 = require("../utils/get-date-invervals");
|
|
9
10
|
function useDay(t0) {
|
|
10
11
|
var _a;
|
|
11
|
-
const $ = (0, compiler_runtime_1.c)(
|
|
12
|
-
const { date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates: t1 } = t0;
|
|
12
|
+
const $ = (0, compiler_runtime_1.c)(51);
|
|
13
|
+
const { date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, timeZone, unavailableDates: t1 } = t0;
|
|
13
14
|
const unavailableDates = t1 === undefined ? empty_array_1.EMPTY_ARRAY : t1;
|
|
15
|
+
const now = (0, use_now_1.useNow)();
|
|
14
16
|
const disabledDatesFromConfig = (_a = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter(_temp).flatMap(_temp2)) !== null && _a !== void 0 ? _a : empty_array_1.EMPTY_ARRAY;
|
|
15
17
|
const disabledDates = [...unavailableDates, ...disabledDatesFromConfig].filter(_temp3);
|
|
16
18
|
let t2;
|
|
@@ -36,26 +38,28 @@ function useDay(t0) {
|
|
|
36
38
|
}
|
|
37
39
|
const onMouseEnter = t3;
|
|
38
40
|
let t4;
|
|
39
|
-
if ($[6]
|
|
40
|
-
t4 = (0, date_string_1.todayDateString)();
|
|
41
|
-
$[6] =
|
|
41
|
+
if ($[6] !== now || $[7] !== timeZone) {
|
|
42
|
+
t4 = (0, date_string_1.todayDateString)(now, timeZone);
|
|
43
|
+
$[6] = now;
|
|
44
|
+
$[7] = timeZone;
|
|
45
|
+
$[8] = t4;
|
|
42
46
|
}
|
|
43
47
|
else {
|
|
44
|
-
t4 = $[
|
|
48
|
+
t4 = $[8];
|
|
45
49
|
}
|
|
46
50
|
let t5;
|
|
47
|
-
if ($[
|
|
51
|
+
if ($[9] !== date) {
|
|
48
52
|
t5 = (0, date_string_1.toDateString)(date);
|
|
49
|
-
$[
|
|
50
|
-
$[
|
|
53
|
+
$[9] = date;
|
|
54
|
+
$[10] = t5;
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
53
|
-
t5 = $[
|
|
57
|
+
t5 = $[10];
|
|
54
58
|
}
|
|
55
59
|
const isToday = t4 === t5;
|
|
56
60
|
let t6;
|
|
57
61
|
let t7;
|
|
58
|
-
if ($[
|
|
62
|
+
if ($[11] !== date || $[12] !== dayRef || $[13] !== isDateFocused || $[14] !== preventScroll) {
|
|
59
63
|
t6 = () => {
|
|
60
64
|
if (dayRef && dayRef.current && isDateFocused(date)) {
|
|
61
65
|
dayRef.current.focus({
|
|
@@ -64,20 +68,20 @@ function useDay(t0) {
|
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
70
|
t7 = [dayRef, date, isDateFocused, preventScroll];
|
|
67
|
-
$[
|
|
68
|
-
$[
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
71
|
+
$[11] = date;
|
|
72
|
+
$[12] = dayRef;
|
|
73
|
+
$[13] = isDateFocused;
|
|
74
|
+
$[14] = preventScroll;
|
|
75
|
+
$[15] = t6;
|
|
76
|
+
$[16] = t7;
|
|
73
77
|
}
|
|
74
78
|
else {
|
|
75
|
-
t6 = $[
|
|
76
|
-
t7 = $[
|
|
79
|
+
t6 = $[15];
|
|
80
|
+
t7 = $[16];
|
|
77
81
|
}
|
|
78
82
|
(0, react_1.useEffect)(t6, t7);
|
|
79
83
|
let t8;
|
|
80
|
-
if ($[
|
|
84
|
+
if ($[17] !== date || $[18] !== onDateFocus) {
|
|
81
85
|
t8 = e => {
|
|
82
86
|
if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
83
87
|
e.preventDefault();
|
|
@@ -104,29 +108,29 @@ function useDay(t0) {
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
};
|
|
107
|
-
$[
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
111
|
+
$[17] = date;
|
|
112
|
+
$[18] = onDateFocus;
|
|
113
|
+
$[19] = t8;
|
|
110
114
|
}
|
|
111
115
|
else {
|
|
112
|
-
t8 = $[
|
|
116
|
+
t8 = $[19];
|
|
113
117
|
}
|
|
114
118
|
const onKeyDown = t8;
|
|
115
119
|
const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(disabledDates);
|
|
116
120
|
let t9;
|
|
117
|
-
if ($[
|
|
121
|
+
if ($[20] !== date) {
|
|
118
122
|
t9 = (0, date_string_1.toDateString)(date);
|
|
119
|
-
$[
|
|
120
|
-
$[
|
|
123
|
+
$[20] = date;
|
|
124
|
+
$[21] = t9;
|
|
121
125
|
}
|
|
122
126
|
else {
|
|
123
|
-
t9 = $[
|
|
127
|
+
t9 = $[21];
|
|
124
128
|
}
|
|
125
129
|
const dateStr = t9;
|
|
126
130
|
const _isFirstUnavailableDate = () => dateIntervals.some(interval => (0, date_string_1.toDateString)(interval.start) === dateStr);
|
|
127
131
|
const _isLastUnavailableDate = () => dateIntervals.some(interval_0 => (0, date_string_1.toDateString)(interval_0.end) === dateStr);
|
|
128
132
|
let t10;
|
|
129
|
-
if ($[
|
|
133
|
+
if ($[22] !== dateStr || $[23] !== datesConfig) {
|
|
130
134
|
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter(config_1 => config_1.dates.some(configDay => (0, date_string_1.toDateString)(configDay) === dateStr));
|
|
131
135
|
t10 = applicableDatesConfigs === null || applicableDatesConfigs === void 0 ? void 0 : applicableDatesConfigs.reduce((acc, curr) => {
|
|
132
136
|
if (!curr.flag) {
|
|
@@ -140,64 +144,64 @@ function useDay(t0) {
|
|
|
140
144
|
});
|
|
141
145
|
return acc;
|
|
142
146
|
}, []);
|
|
143
|
-
$[
|
|
144
|
-
$[
|
|
145
|
-
$[
|
|
147
|
+
$[22] = dateStr;
|
|
148
|
+
$[23] = datesConfig;
|
|
149
|
+
$[24] = t10;
|
|
146
150
|
}
|
|
147
151
|
else {
|
|
148
|
-
t10 = $[
|
|
152
|
+
t10 = $[24];
|
|
149
153
|
}
|
|
150
154
|
const flags = t10;
|
|
151
155
|
let t11;
|
|
152
|
-
if ($[
|
|
156
|
+
if ($[25] !== date || $[26] !== isDateHovered) {
|
|
153
157
|
t11 = isDateHovered(date);
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
158
|
+
$[25] = date;
|
|
159
|
+
$[26] = isDateHovered;
|
|
160
|
+
$[27] = t11;
|
|
157
161
|
}
|
|
158
162
|
else {
|
|
159
|
-
t11 = $[
|
|
163
|
+
t11 = $[27];
|
|
160
164
|
}
|
|
161
165
|
const isHovered = t11;
|
|
162
166
|
let t12;
|
|
163
|
-
if ($[
|
|
167
|
+
if ($[28] !== date || $[29] !== isDateBlocked || $[30] !== isHovered) {
|
|
164
168
|
t12 = isDateBlocked(date) && !isHovered;
|
|
165
|
-
$[
|
|
166
|
-
$[
|
|
167
|
-
$[
|
|
168
|
-
$[
|
|
169
|
+
$[28] = date;
|
|
170
|
+
$[29] = isDateBlocked;
|
|
171
|
+
$[30] = isHovered;
|
|
172
|
+
$[31] = t12;
|
|
169
173
|
}
|
|
170
174
|
else {
|
|
171
|
-
t12 = $[
|
|
175
|
+
t12 = $[31];
|
|
172
176
|
}
|
|
173
177
|
const isDisabled = t12;
|
|
174
178
|
const t13 = flags !== null && flags !== void 0 ? flags : empty_array_1.EMPTY_ARRAY;
|
|
175
179
|
const t14 = _isFirstUnavailableDate();
|
|
176
180
|
let t15;
|
|
177
|
-
if ($[
|
|
181
|
+
if ($[32] !== date || $[33] !== isDateInsideRange) {
|
|
178
182
|
t15 = isDateInsideRange ? isDateInsideRange(date) : false;
|
|
179
|
-
$[
|
|
180
|
-
$[
|
|
181
|
-
$[
|
|
183
|
+
$[32] = date;
|
|
184
|
+
$[33] = isDateInsideRange;
|
|
185
|
+
$[34] = t15;
|
|
182
186
|
}
|
|
183
187
|
else {
|
|
184
|
-
t15 = $[
|
|
188
|
+
t15 = $[34];
|
|
185
189
|
}
|
|
186
190
|
const t16 = _isLastUnavailableDate();
|
|
187
191
|
let t17;
|
|
188
|
-
if ($[
|
|
192
|
+
if ($[35] !== date || $[36] !== isDateSelected) {
|
|
189
193
|
t17 = isDateSelected(date);
|
|
190
|
-
$[
|
|
191
|
-
$[
|
|
192
|
-
$[
|
|
194
|
+
$[35] = date;
|
|
195
|
+
$[36] = isDateSelected;
|
|
196
|
+
$[37] = t17;
|
|
193
197
|
}
|
|
194
198
|
else {
|
|
195
|
-
t17 = $[
|
|
199
|
+
t17 = $[37];
|
|
196
200
|
}
|
|
197
201
|
const t18 = !isDisabled ? onClick : undefined;
|
|
198
202
|
const t19 = focusedDate === null || isDateFocused(date) ? 0 : -1;
|
|
199
203
|
let t20;
|
|
200
|
-
if ($[
|
|
204
|
+
if ($[38] !== isDisabled || $[39] !== isHovered || $[40] !== isToday || $[41] !== onKeyDown || $[42] !== onMouseEnter || $[43] !== t13 || $[44] !== t14 || $[45] !== t15 || $[46] !== t16 || $[47] !== t17 || $[48] !== t18 || $[49] !== t19) {
|
|
201
205
|
t20 = {
|
|
202
206
|
flags: t13,
|
|
203
207
|
disabledDate: isDisabled,
|
|
@@ -213,22 +217,22 @@ function useDay(t0) {
|
|
|
213
217
|
onMouseEnter,
|
|
214
218
|
tabIndex: t19
|
|
215
219
|
};
|
|
216
|
-
$[
|
|
217
|
-
$[
|
|
218
|
-
$[
|
|
219
|
-
$[
|
|
220
|
-
$[
|
|
221
|
-
$[
|
|
222
|
-
$[
|
|
223
|
-
$[
|
|
224
|
-
$[
|
|
225
|
-
$[
|
|
226
|
-
$[
|
|
227
|
-
$[
|
|
228
|
-
$[
|
|
220
|
+
$[38] = isDisabled;
|
|
221
|
+
$[39] = isHovered;
|
|
222
|
+
$[40] = isToday;
|
|
223
|
+
$[41] = onKeyDown;
|
|
224
|
+
$[42] = onMouseEnter;
|
|
225
|
+
$[43] = t13;
|
|
226
|
+
$[44] = t14;
|
|
227
|
+
$[45] = t15;
|
|
228
|
+
$[46] = t16;
|
|
229
|
+
$[47] = t17;
|
|
230
|
+
$[48] = t18;
|
|
231
|
+
$[49] = t19;
|
|
232
|
+
$[50] = t20;
|
|
229
233
|
}
|
|
230
234
|
else {
|
|
231
|
-
t20 = $[
|
|
235
|
+
t20 = $[50];
|
|
232
236
|
}
|
|
233
237
|
return t20;
|
|
234
238
|
}
|
package/hooks/use-day.test.js
CHANGED
|
@@ -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 dayjs_utils_1 = require("../utils/dayjs-utils");
|
|
@@ -156,3 +157,30 @@ test("actions", () => {
|
|
|
156
157
|
});
|
|
157
158
|
expect(result.current.isHovered).toBe(true);
|
|
158
159
|
});
|
|
160
|
+
describe("isToday", () => {
|
|
161
|
+
const renderDay = (date, timeZone) => (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
|
|
162
|
+
date: new Date(date),
|
|
163
|
+
focusedDate: null,
|
|
164
|
+
isDateBlocked: () => false,
|
|
165
|
+
isDateFocused: () => false,
|
|
166
|
+
isDateHovered: () => false,
|
|
167
|
+
isDateSelected: () => false,
|
|
168
|
+
onDateFocus: () => undefined,
|
|
169
|
+
onDateHover: () => undefined,
|
|
170
|
+
onDateSelect: () => undefined,
|
|
171
|
+
timeZone,
|
|
172
|
+
})).result.current.isToday;
|
|
173
|
+
// 0:30 in Prague, still 20 November in UTC and in Los Angeles
|
|
174
|
+
beforeEach(() => jest.setSystemTime(new Date("2026-11-20T23:30:00Z")));
|
|
175
|
+
afterAll(() => jest.setSystemTime(new Date("2021-09-06")));
|
|
176
|
+
test("is the day in the given time zone", () => {
|
|
177
|
+
expect(renderDay("2026-11-21", "Europe/Prague")).toBe(true);
|
|
178
|
+
expect(renderDay("2026-11-20", "Europe/Prague")).toBe(false);
|
|
179
|
+
expect(renderDay("2026-11-20", "America/Los_Angeles")).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
test("is the device's day without a time zone", () => {
|
|
182
|
+
const now = new Date();
|
|
183
|
+
const local = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
184
|
+
expect(renderDay(local)).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
package/hooks/use-decade.test.js
CHANGED