@uxf/datepicker 11.11.3 → 11.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/contexts/date-picker-context.d.ts +0 -1
  2. package/contexts/date-picker-context.js +7 -7
  3. package/contexts/date-range-picker-context.d.ts +0 -1
  4. package/contexts/date-range-picker-context.js +7 -7
  5. package/contexts/time-picker-context.d.ts +0 -1
  6. package/hooks/use-date-picker-navigation.d.ts +7 -7
  7. package/hooks/use-date-picker-navigation.js +29 -11
  8. package/hooks/use-date-picker-navigation.test.js +13 -13
  9. package/hooks/use-date-picker.js +5 -5
  10. package/hooks/use-date-picker.test.js +12 -12
  11. package/hooks/use-date-range-picker.js +6 -5
  12. package/hooks/use-date-range-picker.test.js +11 -11
  13. package/hooks/use-day.js +4 -4
  14. package/hooks/use-day.test.js +10 -10
  15. package/hooks/use-decade.js +2 -2
  16. package/hooks/use-decade.test.js +3 -3
  17. package/hooks/use-hour.js +1 -2
  18. package/hooks/use-hour.test.js +6 -6
  19. package/hooks/use-hours.js +2 -2
  20. package/hooks/use-hours.test.js +3 -3
  21. package/hooks/use-minute.js +1 -2
  22. package/hooks/use-minute.test.js +6 -6
  23. package/hooks/use-minutes.js +2 -2
  24. package/hooks/use-minutes.test.js +3 -3
  25. package/hooks/use-month.js +2 -2
  26. package/hooks/use-month.test.js +3 -3
  27. package/hooks/use-time-picker.js +1 -2
  28. package/hooks/use-time-picker.test.js +17 -17
  29. package/hooks/use-year.js +2 -2
  30. package/hooks/use-year.test.js +3 -3
  31. package/package.json +6 -6
  32. package/utils/can-select-range.js +1 -2
  33. package/utils/get-current-year-month-and-date.js +1 -2
  34. package/utils/get-date-invervals.js +6 -5
  35. package/utils/get-date-month-and-year.js +1 -2
  36. package/utils/get-days.js +1 -2
  37. package/utils/get-each.js +1 -2
  38. package/utils/get-initial-months.js +1 -2
  39. package/utils/get-months.js +1 -2
  40. package/utils/get-next-active-month.js +1 -2
  41. package/utils/get-weekday-labels.js +1 -2
  42. package/utils/get-years.js +1 -2
  43. package/utils/is-browser.js +1 -1
  44. package/utils/is-date-blocked.js +2 -3
  45. package/utils/is-date-hovered.js +1 -2
  46. package/utils/is-date-inside-range.js +1 -2
  47. package/utils/is-end-date.js +2 -3
  48. package/utils/is-first-or-last-selected-date.js +2 -4
  49. package/utils/is-in-unavailable-dates.js +1 -2
  50. package/utils/is-start-date.js +2 -3
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { UseDatePickerReturnType } from "../hooks/use-date-picker";
3
2
  export type DatePickerContextProps = UseDatePickerReturnType;
4
3
  export declare const DatePickerContext: import("react").Context<UseDatePickerReturnType>;
@@ -13,13 +13,13 @@ exports.DatePickerContext = (0, react_1.createContext)({
13
13
  canGoToYear: () => true,
14
14
  firstDayOfWeek: 0,
15
15
  focusedDate: null,
16
- goToDate: () => undefined,
17
- goToNextMonths: () => undefined,
18
- goToNextMonthsByOneMonth: () => undefined,
19
- goToNextYear: () => undefined,
20
- goToPrevMonths: () => undefined,
21
- goToPrevMonthsByOneMonth: () => undefined,
22
- goToPrevYear: () => undefined,
16
+ goToDate: () => [],
17
+ goToNextMonths: () => [],
18
+ goToNextMonthsByOneMonth: () => [],
19
+ goToNextYear: () => [],
20
+ goToPrevMonths: () => [],
21
+ goToPrevMonthsByOneMonth: () => [],
22
+ goToPrevYear: () => [],
23
23
  hoveredDate: null,
24
24
  isDateBlocked: () => false,
25
25
  isDateFocused: () => false,
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { UseDateRangePickerReturnType } from "../hooks/use-date-range-picker";
3
2
  export type DatePickerContextProps = UseDateRangePickerReturnType;
4
3
  export declare const DateRangePickerContext: import("react").Context<UseDateRangePickerReturnType>;
@@ -13,13 +13,13 @@ exports.DateRangePickerContext = (0, react_1.createContext)({
13
13
  canGoToYear: () => true,
14
14
  firstDayOfWeek: 0,
15
15
  focusedDate: null,
16
- goToDate: () => undefined,
17
- goToNextMonths: () => undefined,
18
- goToNextMonthsByOneMonth: () => undefined,
19
- goToNextYear: () => undefined,
20
- goToPrevMonths: () => undefined,
21
- goToPrevMonthsByOneMonth: () => undefined,
22
- goToPrevYear: () => undefined,
16
+ goToDate: () => [],
17
+ goToNextMonths: () => [],
18
+ goToNextMonthsByOneMonth: () => [],
19
+ goToNextYear: () => [],
20
+ goToPrevMonths: () => [],
21
+ goToPrevMonthsByOneMonth: () => [],
22
+ goToPrevYear: () => [],
23
23
  hoveredDate: null,
24
24
  isDateBlocked: () => false,
25
25
  isDateFocused: () => false,
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type TimePickerContextProps = {
3
2
  focusedHour: number | null;
4
3
  focusedMinute: number | null;
@@ -15,12 +15,12 @@ export interface UseDatePickerNavigationReturnType {
15
15
  canGoToPrevMonth: boolean;
16
16
  canGoToPrevYear: boolean;
17
17
  canGoToYear: (month: Date) => boolean;
18
- goToDate: (date: Date) => void;
19
- goToNextMonths: () => void;
20
- goToNextMonthsByOneMonth: () => void;
21
- goToNextYear: (numYears?: number) => void;
22
- goToPrevMonths: () => void;
23
- goToPrevMonthsByOneMonth: () => void;
24
- goToPrevYear: (numYears?: number) => void;
18
+ goToDate: (date: Date) => MonthType[];
19
+ goToNextMonths: () => MonthType[];
20
+ goToNextMonthsByOneMonth: () => MonthType[];
21
+ goToNextYear: (numYears?: number) => MonthType[];
22
+ goToPrevMonths: () => MonthType[];
23
+ goToPrevMonthsByOneMonth: () => MonthType[];
24
+ goToPrevYear: (numYears?: number) => MonthType[];
25
25
  }
26
26
  export declare function useDatePickerNavigation({ activeMonths, setActiveMonths, setFocusedDate, minBookingDate, maxBookingDate, numberOfMonths, }: UseDatePickerNavigationProps): UseDatePickerNavigationReturnType;
@@ -1,47 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDatePickerNavigation = void 0;
3
+ exports.useDatePickerNavigation = useDatePickerNavigation;
4
4
  const react_1 = require("react");
5
5
  const dayjs_en_1 = require("../utils/dayjs-en");
6
6
  const get_initial_months_1 = require("../utils/get-initial-months");
7
7
  const get_next_active_month_1 = require("../utils/get-next-active-month");
8
8
  function useDatePickerNavigation({ activeMonths, setActiveMonths, setFocusedDate, minBookingDate, maxBookingDate, numberOfMonths, }) {
9
+ var _a, _b, _c, _d;
9
10
  const goToPrevMonths = (0, react_1.useCallback)(() => {
10
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1));
11
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1);
12
+ setActiveMonths(newActiveMonths);
11
13
  setFocusedDate(null);
14
+ return newActiveMonths;
12
15
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
13
16
  const goToPrevMonthsByOneMonth = (0, react_1.useCallback)(() => {
14
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1, 1));
17
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1, 1);
18
+ setActiveMonths(newActiveMonths);
15
19
  setFocusedDate(null);
20
+ return newActiveMonths;
16
21
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
17
22
  const goToNextMonths = (0, react_1.useCallback)(() => {
18
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1));
23
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1);
24
+ setActiveMonths(newActiveMonths);
19
25
  setFocusedDate(null);
26
+ return newActiveMonths;
20
27
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
21
28
  const goToNextMonthsByOneMonth = (0, react_1.useCallback)(() => {
22
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1, 1));
29
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, 1, 1);
30
+ setActiveMonths(newActiveMonths);
23
31
  setFocusedDate(null);
32
+ return newActiveMonths;
24
33
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
25
34
  const goToDate = (0, react_1.useCallback)((date) => {
26
- setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, date));
35
+ const newActiveMonths = (0, get_initial_months_1.getInitialMonths)(numberOfMonths, date);
36
+ setActiveMonths(newActiveMonths);
27
37
  setFocusedDate(null);
38
+ return newActiveMonths;
28
39
  }, [numberOfMonths, setActiveMonths, setFocusedDate]);
29
40
  const goToPrevYear = (0, react_1.useCallback)((numYears = 1) => {
30
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -(numYears * 12 - numberOfMonths + 1)));
41
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -(numYears * 12 - numberOfMonths + 1));
42
+ setActiveMonths(newActiveMonths);
31
43
  setFocusedDate(null);
44
+ return newActiveMonths;
32
45
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
33
46
  const goToNextYear = (0, react_1.useCallback)((numYears = 1) => {
34
- setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, numYears * 12 - numberOfMonths + 1));
47
+ const newActiveMonths = (0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, numYears * 12 - numberOfMonths + 1);
48
+ setActiveMonths(newActiveMonths);
35
49
  setFocusedDate(null);
50
+ return newActiveMonths;
36
51
  }, [activeMonths, numberOfMonths, setActiveMonths, setFocusedDate]);
37
- const canGoToPrevMonth = minBookingDate ? !(0, dayjs_en_1.dayjsEn)(activeMonths[0].date).isBefore((0, dayjs_en_1.dayjsEn)(minBookingDate)) : true;
52
+ const canGoToPrevMonth = minBookingDate
53
+ ? !(0, dayjs_en_1.dayjsEn)((_b = (_a = activeMonths.at(0)) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : new Date()).isBefore((0, dayjs_en_1.dayjsEn)(minBookingDate))
54
+ : true;
38
55
  const canGoToNextMonth = maxBookingDate
39
56
  ? !(0, dayjs_en_1.dayjsEn)(activeMonths[activeMonths.length - 1].date)
40
57
  .endOf("month")
41
58
  .isAfter((0, dayjs_en_1.dayjsEn)(maxBookingDate))
42
59
  : true;
43
60
  const canGoToPrevYear = minBookingDate
44
- ? !(0, dayjs_en_1.dayjsEn)(activeMonths[0].date).startOf("year").isBefore((0, dayjs_en_1.dayjsEn)(minBookingDate))
61
+ ? !(0, dayjs_en_1.dayjsEn)((_d = (_c = activeMonths.at(0)) === null || _c === void 0 ? void 0 : _c.date) !== null && _d !== void 0 ? _d : new Date())
62
+ .startOf("year")
63
+ .isBefore((0, dayjs_en_1.dayjsEn)(minBookingDate))
45
64
  : true;
46
65
  const canGoToNextYear = maxBookingDate
47
66
  ? !(0, dayjs_en_1.dayjsEn)(activeMonths[activeMonths.length - 1].date)
@@ -81,4 +100,3 @@ function useDatePickerNavigation({ activeMonths, setActiveMonths, setFocusedDate
81
100
  goToPrevYear,
82
101
  };
83
102
  }
84
- exports.useDatePickerNavigation = useDatePickerNavigation;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_hooks_1 = require("@testing-library/react-hooks");
4
- const react_1 = require("react");
3
+ const react_1 = require("@testing-library/react");
4
+ const react_2 = require("react");
5
5
  const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
6
6
  const ACTIVE_MONTHS = [{ date: new Date("2021-09-01"), month: 8, year: 2021 }];
7
7
  test("base data", () => {
8
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
8
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
9
9
  activeMonths: ACTIVE_MONTHS,
10
10
  setActiveMonths: () => undefined,
11
11
  numberOfMonths: 1,
@@ -19,7 +19,7 @@ test("base data", () => {
19
19
  expect(result.current.canGoToYear(new Date("2020-01-01"))).toBe(true);
20
20
  });
21
21
  test("base data with min and max date", () => {
22
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
22
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
23
23
  activeMonths: ACTIVE_MONTHS,
24
24
  setActiveMonths: () => undefined,
25
25
  numberOfMonths: 1,
@@ -35,8 +35,8 @@ test("base data with min and max date", () => {
35
35
  expect(result.current.canGoToYear(new Date("2026-01-01"))).toBe(false);
36
36
  });
37
37
  test("actions", () => {
38
- const { result: state } = (0, react_hooks_1.renderHook)(() => (0, react_1.useState)([{ month: 8, year: 2021, date: new Date("2021-09-01") }]));
39
- const { result, rerender } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
38
+ const { result: state } = (0, react_1.renderHook)(() => (0, react_2.useState)([{ month: 8, year: 2021, date: new Date("2021-09-01") }]));
39
+ const { result, rerender } = (0, react_1.renderHook)(() => (0, use_date_picker_navigation_1.useDatePickerNavigation)({
40
40
  activeMonths: state.current[0],
41
41
  setActiveMonths: (data) => state.current[1](data),
42
42
  numberOfMonths: 1,
@@ -46,28 +46,28 @@ test("actions", () => {
46
46
  }));
47
47
  // go to year 2020
48
48
  expect(result.current.canGoToPrevYear).toBe(true);
49
- (0, react_hooks_1.act)(() => {
49
+ (0, react_1.act)(() => {
50
50
  result.current.goToPrevYear();
51
51
  rerender();
52
52
  });
53
53
  expect(result.current.canGoToPrevYear).toBe(false);
54
54
  expect(result.current.canGoToNextYear).toBe(true);
55
55
  // go to year 2022
56
- (0, react_hooks_1.act)(() => {
56
+ (0, react_1.act)(() => {
57
57
  result.current.goToNextYear(2);
58
58
  rerender();
59
59
  });
60
60
  expect(result.current.canGoToPrevYear).toBe(true);
61
61
  expect(result.current.canGoToNextYear).toBe(false);
62
62
  // go back to year 2021
63
- (0, react_hooks_1.act)(() => {
63
+ (0, react_1.act)(() => {
64
64
  result.current.goToPrevYear();
65
65
  rerender();
66
66
  });
67
67
  expect(result.current.canGoToPrevYear).toBe(true);
68
68
  expect(result.current.canGoToNextYear).toBe(true);
69
69
  // go to prev month
70
- (0, react_hooks_1.act)(() => {
70
+ (0, react_1.act)(() => {
71
71
  result.current.goToPrevMonths();
72
72
  result.current.goToPrevMonthsByOneMonth();
73
73
  rerender();
@@ -75,7 +75,7 @@ test("actions", () => {
75
75
  expect(result.current.canGoToPrevMonth).toBe(true);
76
76
  expect(result.current.canGoToNextMonth).toBe(true);
77
77
  // go to next month
78
- (0, react_hooks_1.act)(() => {
78
+ (0, react_1.act)(() => {
79
79
  result.current.goToNextMonths();
80
80
  result.current.goToNextMonthsByOneMonth();
81
81
  rerender();
@@ -83,13 +83,13 @@ test("actions", () => {
83
83
  expect(result.current.canGoToPrevMonth).toBe(true);
84
84
  expect(result.current.canGoToNextMonth).toBe(true);
85
85
  // go to month
86
- (0, react_hooks_1.act)(() => {
86
+ (0, react_1.act)(() => {
87
87
  result.current.goToDate(new Date("2020-12-30"));
88
88
  rerender();
89
89
  });
90
90
  expect(result.current.canGoToPrevMonth).toBe(false);
91
91
  expect(result.current.canGoToNextMonth).toBe(true);
92
- (0, react_hooks_1.act)(() => {
92
+ (0, react_1.act)(() => {
93
93
  result.current.goToDate(new Date("2022-03-01"));
94
94
  rerender();
95
95
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDatePicker = void 0;
3
+ exports.useDatePicker = useDatePicker;
4
4
  const react_1 = require("react");
5
5
  const dayjs_en_1 = require("../utils/dayjs-en");
6
6
  const get_initial_months_1 = require("../utils/get-initial-months");
@@ -52,11 +52,12 @@ function useDatePicker({ datesConfig = [], firstDayOfWeek = 0, initialVisibleMon
52
52
  return;
53
53
  }
54
54
  function handleKeyDown(e) {
55
+ var _a, _b;
55
56
  if ((e.key === "ArrowRight" || e.key === "ArrowLeft" || e.key === "ArrowDown" || e.key === "ArrowUp") &&
56
57
  !focusedDate) {
57
- const activeMonth = activeMonths[0];
58
- onDateFocus(activeMonth.date);
59
- setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonth.date));
58
+ const activeMonthDate = (_b = (_a = activeMonths.at(0)) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : new Date();
59
+ onDateFocus(activeMonthDate);
60
+ setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonthDate));
60
61
  }
61
62
  }
62
63
  window.addEventListener("keydown", handleKeyDown);
@@ -116,4 +117,3 @@ function useDatePicker({ datesConfig = [], firstDayOfWeek = 0, initialVisibleMon
116
117
  unavailableDates: disabledDates,
117
118
  };
118
119
  }
119
- exports.useDatePicker = useDatePicker;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_hooks_1 = require("@testing-library/react-hooks");
4
- const react_1 = require("react");
3
+ const react_1 = require("@testing-library/react");
4
+ const react_2 = require("react");
5
5
  const use_date_picker_1 = require("./use-date-picker");
6
6
  test("base data", () => {
7
7
  const BASE_DATE = new Date("2021-09-15");
8
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({
8
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({
9
9
  selectedDate: BASE_DATE,
10
10
  onDateChange: () => undefined,
11
11
  minBookingDate: new Date("2020-01-01"),
@@ -25,12 +25,12 @@ test("base data", () => {
25
25
  });
26
26
  test("date focus", () => {
27
27
  const BASE_DATE = new Date("2021-09-15");
28
- const { result: state } = (0, react_hooks_1.renderHook)(() => (0, react_1.useState)(BASE_DATE));
29
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({ selectedDate: state.current[0], onDateChange: (date) => state.current[1](date) }));
28
+ const { result: state } = (0, react_1.renderHook)(() => (0, react_2.useState)(BASE_DATE));
29
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({ selectedDate: state.current[0], onDateChange: (date) => state.current[1](date) }));
30
30
  const NEW_DATE = new Date("2022-12-22");
31
31
  expect(result.current.isDateFocused(BASE_DATE)).toBe(true);
32
32
  expect(result.current.isDateFocused(NEW_DATE)).toBe(false);
33
- (0, react_hooks_1.act)(() => {
33
+ (0, react_1.act)(() => {
34
34
  result.current.onDateFocus(NEW_DATE);
35
35
  });
36
36
  expect(result.current.isDateFocused(NEW_DATE)).toBe(true);
@@ -38,31 +38,31 @@ test("date focus", () => {
38
38
  });
39
39
  test("date select", () => {
40
40
  const BASE_DATE = new Date("2021-09-15");
41
- const { result: state } = (0, react_hooks_1.renderHook)(() => (0, react_1.useState)(BASE_DATE));
42
- const { result, rerender } = (0, react_hooks_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({ selectedDate: state.current[0], onDateChange: (date) => state.current[1](date) }));
41
+ const { result: state } = (0, react_1.renderHook)(() => (0, react_2.useState)(BASE_DATE));
42
+ const { result, rerender } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({ selectedDate: state.current[0], onDateChange: (date) => state.current[1](date) }));
43
43
  const NEW_DATE = new Date("2022-12-22");
44
44
  expect(result.current.isDateSelected(BASE_DATE)).toBe(true);
45
45
  expect(result.current.isDateSelected(NEW_DATE)).toBe(false);
46
- (0, react_hooks_1.act)(() => {
46
+ (0, react_1.act)(() => {
47
47
  result.current.onDateSelect(NEW_DATE);
48
48
  rerender();
49
49
  });
50
50
  expect(result.current.isDateSelected(NEW_DATE)).toBe(true);
51
51
  expect(result.current.isDateSelected(BASE_DATE)).toBe(false);
52
52
  // select another
53
- (0, react_hooks_1.act)(() => {
53
+ (0, react_1.act)(() => {
54
54
  result.current.onDateSelect(BASE_DATE);
55
55
  rerender();
56
56
  });
57
57
  expect(result.current.isDateSelected(BASE_DATE)).toBe(true);
58
58
  // select save (deselect)
59
- (0, react_hooks_1.act)(() => {
59
+ (0, react_1.act)(() => {
60
60
  result.current.onDateSelect(BASE_DATE);
61
61
  rerender();
62
62
  });
63
63
  expect(result.current.isDateSelected(BASE_DATE)).toBe(false);
64
64
  // reset
65
- (0, react_hooks_1.act)(() => {
65
+ (0, react_1.act)(() => {
66
66
  result.current.onDateSelect(BASE_DATE);
67
67
  result.current.onResetDates();
68
68
  rerender();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDateRangePicker = exports.END_DATE = exports.START_DATE = void 0;
3
+ exports.END_DATE = exports.START_DATE = void 0;
4
+ exports.useDateRangePicker = useDateRangePicker;
4
5
  const react_1 = require("react");
5
6
  const can_select_range_1 = require("../utils/can-select-range");
6
7
  const dayjs_en_1 = require("../utils/dayjs-en");
@@ -61,11 +62,12 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
61
62
  return;
62
63
  }
63
64
  function handleKeyDown(e) {
65
+ var _a, _b;
64
66
  if ((e.key === "ArrowRight" || e.key === "ArrowLeft" || e.key === "ArrowDown" || e.key === "ArrowUp") &&
65
67
  !focusedDate) {
66
- const activeMonth = activeMonths[0];
67
- onDateFocus(activeMonth.date);
68
- setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonth.date));
68
+ const activeMonthDate = (_b = (_a = activeMonths.at(0)) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : new Date();
69
+ onDateFocus(activeMonthDate);
70
+ setActiveMonths((0, get_initial_months_1.getInitialMonths)(numberOfMonths, activeMonthDate));
69
71
  }
70
72
  }
71
73
  window.addEventListener("keydown", handleKeyDown);
@@ -226,4 +228,3 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
226
228
  unavailableDates: disabledDates,
227
229
  };
228
230
  }
229
- exports.useDateRangePicker = useDateRangePicker;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_hooks_1 = require("@testing-library/react-hooks");
4
- const react_1 = require("react");
3
+ const react_1 = require("@testing-library/react");
4
+ const react_2 = require("react");
5
5
  const use_date_range_picker_1 = require("./use-date-range-picker");
6
6
  beforeAll(() => {
7
7
  jest.useFakeTimers();
8
8
  jest.setSystemTime(new Date("2021-09-25"));
9
9
  });
10
10
  test("base data", () => {
11
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
11
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
12
12
  startDate: null,
13
13
  endDate: null,
14
14
  onDatesChange: () => undefined,
@@ -35,8 +35,8 @@ test("base data", () => {
35
35
  });
36
36
  test("date focus", () => {
37
37
  const BASE_DATE = new Date("2021-09-15");
38
- const { result: state } = (0, react_hooks_1.renderHook)(() => (0, react_1.useState)({ startDate: null, endDate: null, focusedInput: "startDate" }));
39
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
38
+ const { result: state } = (0, react_1.renderHook)(() => (0, react_2.useState)({ startDate: null, endDate: null, focusedInput: "startDate" }));
39
+ const { result } = (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
40
40
  startDate: state.current[0].startDate,
41
41
  endDate: state.current[0].endDate,
42
42
  onDatesChange: (data) => state.current[1](data),
@@ -46,7 +46,7 @@ test("date focus", () => {
46
46
  const NEW_DATE = new Date("2022-12-22");
47
47
  expect(result.current.isDateFocused(BASE_DATE)).toBe(false);
48
48
  expect(result.current.isDateFocused(NEW_DATE)).toBe(false);
49
- (0, react_hooks_1.act)(() => {
49
+ (0, react_1.act)(() => {
50
50
  result.current.onDateFocus(NEW_DATE);
51
51
  });
52
52
  expect(result.current.isDateFocused(NEW_DATE)).toBe(true);
@@ -54,8 +54,8 @@ test("date focus", () => {
54
54
  });
55
55
  test("date select", () => {
56
56
  const BASE_DATE = new Date("2021-09-15");
57
- const { result: state } = (0, react_hooks_1.renderHook)(() => (0, react_1.useState)({ startDate: null, endDate: null, focusedInput: "startDate" }));
58
- const { result, rerender } = (0, react_hooks_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
57
+ const { result: state } = (0, react_1.renderHook)(() => (0, react_2.useState)({ startDate: null, endDate: null, focusedInput: "startDate" }));
58
+ const { result, rerender } = (0, react_1.renderHook)(() => (0, use_date_range_picker_1.useDateRangePicker)({
59
59
  startDate: state.current[0].startDate,
60
60
  endDate: state.current[0].endDate,
61
61
  onDatesChange: (data) => state.current[1](data),
@@ -65,20 +65,20 @@ test("date select", () => {
65
65
  const NEW_DATE = new Date("2022-12-22");
66
66
  expect(result.current.isDateSelected(BASE_DATE)).toBe(false);
67
67
  expect(result.current.isDateSelected(NEW_DATE)).toBe(false);
68
- (0, react_hooks_1.act)(() => {
68
+ (0, react_1.act)(() => {
69
69
  result.current.onDateSelect(NEW_DATE);
70
70
  rerender();
71
71
  });
72
72
  expect(result.current.isDateSelected(NEW_DATE)).toBe(true);
73
73
  expect(result.current.isDateSelected(BASE_DATE)).toBe(false);
74
74
  // select another
75
- (0, react_hooks_1.act)(() => {
75
+ (0, react_1.act)(() => {
76
76
  result.current.onDateSelect(BASE_DATE);
77
77
  rerender();
78
78
  });
79
79
  expect(result.current.isDateSelected(BASE_DATE)).toBe(true);
80
80
  // reset
81
- (0, react_hooks_1.act)(() => {
81
+ (0, react_1.act)(() => {
82
82
  result.current.onDateSelect(BASE_DATE);
83
83
  result.current.onResetDates();
84
84
  rerender();
package/hooks/use-day.js CHANGED
@@ -3,14 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useDay = void 0;
6
+ exports.useDay = useDay;
7
+ const empty_array_1 = require("@uxf/core/constants/empty-array");
7
8
  const dayjs_1 = __importDefault(require("dayjs"));
8
9
  const react_1 = require("react");
9
10
  const dayjs_en_1 = require("../utils/dayjs-en");
10
11
  const get_date_invervals_1 = require("../utils/get-date-invervals");
11
12
  function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates, }) {
12
13
  var _a;
13
- const disabledDatesFromConfig = (_a = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.isDisabled).flatMap((config) => config.dates)) !== null && _a !== void 0 ? _a : [];
14
+ const disabledDatesFromConfig = (_a = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.isDisabled).flatMap((config) => config.dates)) !== null && _a !== void 0 ? _a : empty_array_1.EMPTY_ARRAY;
14
15
  // merge and filter duplicates
15
16
  const disabledDates = [...unavailableDates, ...disabledDatesFromConfig].filter((day, index, self) => index === self.findIndex((d) => d.getTime() === day.getTime()));
16
17
  const onClick = (0, react_1.useCallback)(() => onDateSelect(date), [date, onDateSelect]);
@@ -64,7 +65,7 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
64
65
  return acc;
65
66
  }, []);
66
67
  return {
67
- flags: flags !== null && flags !== void 0 ? flags : [],
68
+ flags: flags !== null && flags !== void 0 ? flags : empty_array_1.EMPTY_ARRAY,
68
69
  disabledDate: disabled,
69
70
  isFirstDisabled: _isFirstUnavailableDate(),
70
71
  isHovered: isDateHovered(date),
@@ -79,4 +80,3 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
79
80
  tabIndex: focusedDate === null || isDateFocused(date) ? 0 : -1,
80
81
  };
81
82
  }
82
- exports.useDay = useDay;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_hooks_1 = require("@testing-library/react-hooks");
6
+ const react_1 = require("@testing-library/react");
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
- const react_1 = require("react");
8
+ const react_2 = require("react");
9
9
  const use_day_1 = require("./use-day");
10
10
  const e = { preventDefault: () => undefined, key: undefined };
11
11
  beforeAll(() => {
@@ -13,7 +13,7 @@ beforeAll(() => {
13
13
  jest.setSystemTime(new Date("2021-09-06"));
14
14
  });
15
15
  test("useDay", () => {
16
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_day_1.useDay)({
16
+ const { result } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
17
17
  date: new Date("2021-09-05"),
18
18
  datesConfig: [],
19
19
  focusedDate: null,
@@ -38,7 +38,7 @@ test("useDay", () => {
38
38
  expect(result.current.isWithinHoverRange).toBe(false);
39
39
  });
40
40
  test("useDay with unavailableDates", () => {
41
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_day_1.useDay)({
41
+ const { result } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
42
42
  date: new Date("2021-09-05"),
43
43
  datesConfig: [],
44
44
  focusedDate: null,
@@ -63,7 +63,7 @@ test("useDay with unavailableDates", () => {
63
63
  expect(result.current.isWithinHoverRange).toBe(false);
64
64
  });
65
65
  test("useDay with datesConfig", () => {
66
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_day_1.useDay)({
66
+ const { result } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
67
67
  date: new Date("2021-09-05"),
68
68
  datesConfig: [{ dates: [new Date("2021-09-05")], flag: "custom-classname", isDisabled: true }],
69
69
  focusedDate: null,
@@ -93,8 +93,8 @@ test("actions", () => {
93
93
  let selectedDate = null;
94
94
  let focusedDate = null;
95
95
  const insideRangeDate = null;
96
- const { result: ref } = (0, react_hooks_1.renderHook)(() => (0, react_1.useRef)(null));
97
- const { result, rerender } = (0, react_hooks_1.renderHook)(() => (0, use_day_1.useDay)({
96
+ const { result: ref } = (0, react_1.renderHook)(() => (0, react_2.useRef)(null));
97
+ const { result, rerender } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
98
98
  date: new Date("2021-09-05"),
99
99
  datesConfig: [],
100
100
  dayRef: ref.current,
@@ -111,7 +111,7 @@ test("actions", () => {
111
111
  }));
112
112
  // hover
113
113
  expect(result.current.isHovered).toBe(false);
114
- (0, react_hooks_1.act)(() => {
114
+ (0, react_1.act)(() => {
115
115
  result.current.onMouseEnter();
116
116
  rerender();
117
117
  });
@@ -119,7 +119,7 @@ test("actions", () => {
119
119
  expect(result.current.tabIndex).toBe(0);
120
120
  // select
121
121
  expect(result.current.isSelected).toBe(false);
122
- (0, react_hooks_1.act)(() => {
122
+ (0, react_1.act)(() => {
123
123
  if (result.current.onClick) {
124
124
  result.current.onClick();
125
125
  }
@@ -128,7 +128,7 @@ test("actions", () => {
128
128
  expect(result.current.isSelected).toBe(true);
129
129
  expect(result.current.isInsideRange).toBe(false);
130
130
  // keyDown
131
- (0, react_hooks_1.act)(() => {
131
+ (0, react_1.act)(() => {
132
132
  e.key = "ArrowRight";
133
133
  result.current.onKeyDown(e);
134
134
  e.key = "ArrowLeft";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDecade = exports.decadeLabelFormatFn = exports.yearLabelFormatFn = void 0;
3
+ exports.decadeLabelFormatFn = exports.yearLabelFormatFn = void 0;
4
+ exports.useDecade = useDecade;
4
5
  const react_1 = require("react");
5
6
  const dayjs_en_1 = require("../utils/dayjs-en");
6
7
  const get_years_1 = require("../utils/get-years");
@@ -18,4 +19,3 @@ function useDecade({ yearLabelFormat = exports.yearLabelFormatFn, decadeLabelFor
18
19
  decadeLabel: decadeLabelFormat(startYear, endYear),
19
20
  };
20
21
  }
21
- exports.useDecade = useDecade;
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_hooks_1 = require("@testing-library/react-hooks");
6
+ const react_1 = require("@testing-library/react");
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
8
  const use_decade_1 = require("./use-decade");
9
9
  test("useDecade", () => {
10
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_decade_1.useDecade)({
10
+ const { result } = (0, react_1.renderHook)(() => (0, use_decade_1.useDecade)({
11
11
  year: 2021,
12
12
  }));
13
13
  expect(result.current.decadeLabel).toBe("2017 – 2025");
@@ -24,7 +24,7 @@ test("useDecade", () => {
24
24
  ]);
25
25
  });
26
26
  test("useDecade with custom formats", () => {
27
- const { result } = (0, react_hooks_1.renderHook)(() => (0, use_decade_1.useDecade)({
27
+ const { result } = (0, react_1.renderHook)(() => (0, use_decade_1.useDecade)({
28
28
  year: 2021,
29
29
  decadeLabelFormat: (start, end) => `${(0, dayjs_1.default)(start).format("YY")} - ${(0, dayjs_1.default)(end).format("YY")}`,
30
30
  yearLabelFormat: (date) => (0, dayjs_1.default)(date).format("YY"),
package/hooks/use-hour.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useHour = void 0;
3
+ exports.useHour = useHour;
4
4
  const react_1 = require("react");
5
5
  function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, onHourFocus, onHourSelect, preventScroll, }) {
6
6
  const onClick = (0, react_1.useCallback)(() => onHourSelect(hour), [hour, onHourSelect]);
@@ -37,4 +37,3 @@ function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, on
37
37
  tabIndex: focusedHour === null || isHourFocused(hour) ? 0 : -1,
38
38
  };
39
39
  }
40
- exports.useHour = useHour;