@uxf/datepicker 10.0.0-beta.9 → 10.8.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 (37) hide show
  1. package/contexts/date-picker-context.js +2 -0
  2. package/contexts/date-range-picker-context.js +1 -0
  3. package/contexts/time-picker-context.d.ts +1 -0
  4. package/contexts/time-picker-context.js +1 -0
  5. package/hooks/use-date-picker-navigation.js +1 -1
  6. package/hooks/use-date-picker.d.ts +4 -1
  7. package/hooks/use-date-picker.js +5 -3
  8. package/hooks/use-date-range-picker.d.ts +3 -0
  9. package/hooks/use-date-range-picker.js +3 -2
  10. package/hooks/use-day.d.ts +5 -1
  11. package/hooks/use-day.js +20 -3
  12. package/hooks/use-day.test.js +28 -0
  13. package/hooks/use-decade.js +1 -1
  14. package/hooks/use-hour.d.ts +2 -1
  15. package/hooks/use-hour.js +5 -3
  16. package/hooks/use-minute.d.ts +2 -1
  17. package/hooks/use-minute.js +5 -3
  18. package/hooks/use-month.js +1 -1
  19. package/hooks/use-time-picker.d.ts +3 -1
  20. package/hooks/use-time-picker.js +2 -1
  21. package/hooks/use-year.js +1 -1
  22. package/package.json +10 -16
  23. package/utils/can-select-range.js +1 -1
  24. package/utils/get-current-year-month-and-date.js +1 -1
  25. package/utils/get-date-intervals.test.d.ts +1 -0
  26. package/utils/get-date-intervals.test.js +39 -0
  27. package/utils/get-date-invervals.d.ts +3 -0
  28. package/utils/get-date-invervals.js +31 -0
  29. package/utils/get-days.js +1 -1
  30. package/utils/get-initial-months.js +1 -1
  31. package/utils/get-months.js +1 -1
  32. package/utils/get-next-active-month.js +1 -1
  33. package/utils/get-weekday-labels.js +1 -1
  34. package/utils/get-weekday-labels.test.js +1 -1
  35. package/utils/get-years.js +1 -1
  36. package/utils/is-date-blocked.js +1 -1
  37. package/utils/is-date-hovered.js +1 -1
@@ -29,4 +29,6 @@ exports.DatePickerContext = (0, react_1.createContext)({
29
29
  onDateHover: () => undefined,
30
30
  onDateSelect: () => undefined,
31
31
  onResetDates: () => undefined,
32
+ preventScroll: undefined,
33
+ unavailableDates: [],
32
34
  });
@@ -32,4 +32,5 @@ exports.DateRangePickerContext = (0, react_1.createContext)({
32
32
  onDateHover: () => undefined,
33
33
  onDateSelect: () => undefined,
34
34
  onResetDates: () => undefined,
35
+ unavailableDates: [],
35
36
  });
@@ -10,5 +10,6 @@ export type TimePickerContextProps = {
10
10
  onHourSelect: (hour: number) => void;
11
11
  onMinuteFocus: (minute: number) => void;
12
12
  onMinuteSelect: (minute: number) => void;
13
+ preventScroll?: boolean;
13
14
  };
14
15
  export declare const TimePickerContext: import("react").Context<TimePickerContextProps>;
@@ -13,4 +13,5 @@ exports.TimePickerContext = (0, react_1.createContext)({
13
13
  onHourSelect: () => undefined,
14
14
  onMinuteFocus: () => undefined,
15
15
  onMinuteSelect: () => undefined,
16
+ preventScroll: undefined,
16
17
  });
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDatePickerNavigation = void 0;
4
4
  const react_1 = require("react");
5
+ const dayjs_en_1 = require("../utils/dayjs-en");
5
6
  const get_initial_months_1 = require("../utils/get-initial-months");
6
7
  const get_next_active_month_1 = require("../utils/get-next-active-month");
7
- const dayjs_en_1 = require("../utils/dayjs-en");
8
8
  function useDatePickerNavigation({ activeMonths, setActiveMonths, setFocusedDate, minBookingDate, maxBookingDate, numberOfMonths, }) {
9
9
  const goToPrevMonths = (0, react_1.useCallback)(() => {
10
10
  setActiveMonths((0, get_next_active_month_1.getNextActiveMonth)(activeMonths, numberOfMonths, -1));
@@ -9,6 +9,7 @@ export interface UseDatePickerProps {
9
9
  minBookingDate?: Date;
10
10
  numberOfMonths?: number;
11
11
  onDateChange: (data: OnDateChangeType) => void;
12
+ preventScroll?: boolean;
12
13
  selectedDate: Date | null;
13
14
  unavailableDates?: Date[];
14
15
  }
@@ -26,5 +27,7 @@ export interface UseDatePickerReturnType extends UseDatePickerNavigationReturnTy
26
27
  onDateHover: (date: Date | null) => void;
27
28
  onDateSelect: (date: Date) => void;
28
29
  onResetDates: () => void;
30
+ preventScroll?: boolean;
31
+ unavailableDates: Date[];
29
32
  }
30
- export declare function useDatePicker({ firstDayOfWeek, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, numberOfMonths, onDateChange, selectedDate, unavailableDates, }: UseDatePickerProps): UseDatePickerReturnType;
33
+ export declare function useDatePicker({ firstDayOfWeek, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, numberOfMonths, onDateChange, preventScroll, selectedDate, unavailableDates, }: UseDatePickerProps): UseDatePickerReturnType;
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDatePicker = void 0;
4
4
  const react_1 = require("react");
5
+ const dayjs_en_1 = require("../utils/dayjs-en");
5
6
  const get_initial_months_1 = require("../utils/get-initial-months");
7
+ const is_browser_1 = require("../utils/is-browser");
6
8
  const is_date_blocked_1 = require("../utils/is-date-blocked");
7
9
  const is_date_hovered_1 = require("../utils/is-date-hovered");
8
10
  const is_in_unavailable_dates_1 = require("../utils/is-in-unavailable-dates");
9
11
  const is_start_date_1 = require("../utils/is-start-date");
10
12
  const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
11
- const is_browser_1 = require("../utils/is-browser");
12
- const dayjs_en_1 = require("../utils/dayjs-en");
13
- function useDatePicker({ firstDayOfWeek = 0, initialVisibleMonth, isDateBlocked: isDateBlockedProps = () => false, maxBookingDate, minBookingDate, numberOfMonths = 1, onDateChange, selectedDate, unavailableDates = [], }) {
13
+ function useDatePicker({ firstDayOfWeek = 0, initialVisibleMonth, isDateBlocked: isDateBlockedProps = () => false, maxBookingDate, minBookingDate, numberOfMonths = 1, onDateChange, preventScroll, selectedDate, unavailableDates = [], }) {
14
14
  const [activeMonths, setActiveMonths] = (0, react_1.useState)(() => selectedDate
15
15
  ? (0, get_initial_months_1.getInitialMonths)(numberOfMonths, selectedDate)
16
16
  : (0, get_initial_months_1.getInitialMonths)(numberOfMonths, initialVisibleMonth || null));
@@ -109,6 +109,8 @@ function useDatePicker({ firstDayOfWeek = 0, initialVisibleMonth, isDateBlocked:
109
109
  onDateHover,
110
110
  onDateSelect,
111
111
  onResetDates: onReset,
112
+ preventScroll,
113
+ unavailableDates,
112
114
  };
113
115
  }
114
116
  exports.useDatePicker = useDatePicker;
@@ -21,6 +21,7 @@ export interface UseDateRangePickerProps {
21
21
  minBookingDays?: number;
22
22
  numberOfMonths?: number;
23
23
  onDatesChange: (data: OnDatesChangeProps) => void;
24
+ preventScroll?: boolean;
24
25
  startDate: Date | null;
25
26
  unavailableDates?: Date[];
26
27
  }
@@ -41,5 +42,7 @@ export interface UseDateRangePickerReturnType extends UseDatePickerNavigationRet
41
42
  onDateHover: (date: Date | null) => void;
42
43
  onDateSelect: (date: Date) => void;
43
44
  onResetDates: () => void;
45
+ preventScroll?: boolean;
46
+ unavailableDates: Date[];
44
47
  }
45
48
  export declare function useDateRangePicker({ changeActiveMonthOnSelect, endDate, exactMinBookingDays, firstDayOfWeek, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays, numberOfMonths, onDatesChange, startDate, unavailableDates, }: UseDateRangePickerProps): UseDateRangePickerReturnType;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDateRangePicker = exports.END_DATE = exports.START_DATE = void 0;
4
4
  const react_1 = require("react");
5
5
  const can_select_range_1 = require("../utils/can-select-range");
6
+ const dayjs_en_1 = require("../utils/dayjs-en");
6
7
  const get_initial_months_1 = require("../utils/get-initial-months");
8
+ const is_browser_1 = require("../utils/is-browser");
7
9
  const is_date_blocked_1 = require("../utils/is-date-blocked");
8
10
  const is_date_hovered_1 = require("../utils/is-date-hovered");
9
11
  const is_date_inside_range_1 = require("../utils/is-date-inside-range");
@@ -12,8 +14,6 @@ const is_first_or_last_selected_date_1 = require("../utils/is-first-or-last-sele
12
14
  const is_in_unavailable_dates_1 = require("../utils/is-in-unavailable-dates");
13
15
  const is_start_date_1 = require("../utils/is-start-date");
14
16
  const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
15
- const is_browser_1 = require("../utils/is-browser");
16
- const dayjs_en_1 = require("../utils/dayjs-en");
17
17
  exports.START_DATE = "startDate";
18
18
  exports.END_DATE = "endDate";
19
19
  function useDateRangePicker({ changeActiveMonthOnSelect = false, endDate, exactMinBookingDays = false, firstDayOfWeek = 0, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps = () => false, maxBookingDate, minBookingDate, minBookingDays = 1, numberOfMonths = 2, onDatesChange, startDate, unavailableDates = [], }) {
@@ -220,6 +220,7 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, endDate, exactM
220
220
  onDateHover,
221
221
  onDateSelect,
222
222
  onResetDates,
223
+ unavailableDates,
223
224
  };
224
225
  }
225
226
  exports.useDateRangePicker = useDateRangePicker;
@@ -11,8 +11,12 @@ export interface UseDayProps {
11
11
  onDateFocus: (date: Date) => void;
12
12
  onDateHover: (date: Date) => void;
13
13
  onDateSelect: (date: Date) => void;
14
+ preventScroll?: boolean;
15
+ unavailableDates: Date[];
14
16
  }
15
17
  export interface UseDayReturnType {
18
+ isFirstDisabled: boolean;
19
+ isLastDisabled: boolean;
16
20
  disabledDate: boolean;
17
21
  isHovered: boolean;
18
22
  isSelected: boolean;
@@ -24,4 +28,4 @@ export interface UseDayReturnType {
24
28
  onMouseEnter: () => void;
25
29
  tabIndex: number;
26
30
  }
27
- export declare function useDay({ date, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, }: UseDayProps): UseDayReturnType;
31
+ export declare function useDay({ date, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates, }: UseDayProps): UseDayReturnType;
package/hooks/use-day.js CHANGED
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.useDay = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
4
8
  const react_1 = require("react");
5
9
  const dayjs_en_1 = require("../utils/dayjs-en");
6
- function useDay({ date, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, }) {
10
+ const get_date_invervals_1 = require("../utils/get-date-invervals");
11
+ function useDay({ date, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates, }) {
7
12
  const onClick = (0, react_1.useCallback)(() => onDateSelect(date), [date, onDateSelect]);
8
13
  const onMouseEnter = (0, react_1.useCallback)(() => onDateHover(date), [date, onDateHover]);
9
14
  const disabled = isDateBlocked(date) && !isDateHovered(date);
10
15
  const isToday = (0, dayjs_en_1.dayjsEn)().isSame(date, "day");
11
16
  (0, react_1.useEffect)(() => {
12
17
  if (dayRef && dayRef.current && isDateFocused(date)) {
13
- dayRef.current.focus();
18
+ dayRef.current.focus({
19
+ preventScroll,
20
+ });
14
21
  }
15
- }, [dayRef, date, isDateFocused]);
22
+ }, [dayRef, date, isDateFocused, preventScroll]);
16
23
  const onKeyDown = (0, react_1.useCallback)((e) => {
17
24
  if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
18
25
  e.preventDefault();
@@ -32,8 +39,18 @@ function useDay({ date, dayRef, focusedDate, isDateBlocked, isDateFocused, isDat
32
39
  }
33
40
  }
34
41
  }, [date, onDateFocus]);
42
+ const sortedUnavailableDates = unavailableDates.slice().sort((a, b) => a.getTime() - b.getTime());
43
+ const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(sortedUnavailableDates);
44
+ const _isFirstUnavailableDate = () => {
45
+ return dateIntervals.some((interval) => (0, dayjs_1.default)(interval.start).isSame(date, "day"));
46
+ };
47
+ const _isLastUnavailableDate = () => {
48
+ return dateIntervals.some((interval) => (0, dayjs_1.default)(interval.end).isSame(date, "day"));
49
+ };
35
50
  return {
36
51
  disabledDate: disabled,
52
+ isFirstDisabled: _isFirstUnavailableDate(),
53
+ isLastDisabled: _isLastUnavailableDate(),
37
54
  isHovered: isDateHovered(date),
38
55
  isSelected: isDateSelected(date),
39
56
  isInsideRange: isDateInsideRange ? isDateInsideRange(date) : false,
@@ -24,9 +24,36 @@ test("useDay", () => {
24
24
  isDateInsideRange: () => false,
25
25
  onDateHover: () => undefined,
26
26
  onDateSelect: () => undefined,
27
+ unavailableDates: [],
27
28
  }));
28
29
  expect(result.current.tabIndex).toBe(0);
29
30
  expect(result.current.disabledDate).toBe(false);
31
+ expect(result.current.isFirstDisabled).toBe(false);
32
+ expect(result.current.isLastDisabled).toBe(false);
33
+ expect(result.current.isHovered).toBe(false);
34
+ expect(result.current.isToday).toBe(false);
35
+ expect(result.current.isSelected).toBe(false);
36
+ expect(result.current.isInsideRange).toBe(false);
37
+ expect(result.current.isWithinHoverRange).toBe(false);
38
+ });
39
+ test("useDay with unavailableDates", () => {
40
+ const { result } = (0, react_hooks_1.renderHook)(() => (0, use_day_1.useDay)({
41
+ date: new Date("2021-09-05"),
42
+ isDateBlocked: () => true,
43
+ focusedDate: null,
44
+ onDateFocus: () => undefined,
45
+ isDateFocused: () => false,
46
+ isDateHovered: () => false,
47
+ isDateSelected: () => false,
48
+ isDateInsideRange: () => false,
49
+ onDateHover: () => undefined,
50
+ onDateSelect: () => undefined,
51
+ unavailableDates: [new Date("2021-09-05")],
52
+ }));
53
+ expect(result.current.tabIndex).toBe(0);
54
+ expect(result.current.disabledDate).toBe(true);
55
+ expect(result.current.isFirstDisabled).toBe(true);
56
+ expect(result.current.isLastDisabled).toBe(true);
30
57
  expect(result.current.isHovered).toBe(false);
31
58
  expect(result.current.isToday).toBe(false);
32
59
  expect(result.current.isSelected).toBe(false);
@@ -51,6 +78,7 @@ test("actions", () => {
51
78
  onDateHover: (date) => (hoveredDate = date),
52
79
  onDateSelect: (date) => (selectedDate = date),
53
80
  dayRef: ref.current,
81
+ unavailableDates: [new Date("2021-09-05")],
54
82
  }));
55
83
  // hover
56
84
  expect(result.current.isHovered).toBe(false);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDecade = exports.decadeLabelFormatFn = exports.yearLabelFormatFn = void 0;
4
4
  const react_1 = require("react");
5
- const get_years_1 = require("../utils/get-years");
6
5
  const dayjs_en_1 = require("../utils/dayjs-en");
6
+ const get_years_1 = require("../utils/get-years");
7
7
  const yearLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("YYYY");
8
8
  exports.yearLabelFormatFn = yearLabelFormatFn;
9
9
  const decadeLabelFormatFn = (start, end) => `${(0, dayjs_en_1.dayjsEn)(start).format("YYYY")} \u2013 ${(0, dayjs_en_1.dayjsEn)(end).format("YYYY")}`;
@@ -7,6 +7,7 @@ export interface UseHourProps {
7
7
  isHourSelected: (hour: number) => boolean;
8
8
  onHourFocus: (hour: number) => void;
9
9
  onHourSelect: (hour: number) => void;
10
+ preventScroll?: boolean;
10
11
  }
11
12
  export interface UseHourReturnType {
12
13
  isSelected: boolean;
@@ -14,4 +15,4 @@ export interface UseHourReturnType {
14
15
  onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;
15
16
  tabIndex: number;
16
17
  }
17
- export declare function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, onHourFocus, onHourSelect, }: UseHourProps): UseHourReturnType;
18
+ export declare function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, onHourFocus, onHourSelect, preventScroll, }: UseHourProps): UseHourReturnType;
package/hooks/use-hour.js CHANGED
@@ -2,13 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useHour = void 0;
4
4
  const react_1 = require("react");
5
- function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, onHourFocus, onHourSelect, }) {
5
+ function useHour({ hour, hourRef, focusedHour, isHourFocused, isHourSelected, onHourFocus, onHourSelect, preventScroll, }) {
6
6
  const onClick = (0, react_1.useCallback)(() => onHourSelect(hour), [hour, onHourSelect]);
7
7
  (0, react_1.useEffect)(() => {
8
8
  if (hourRef && hourRef.current && isHourFocused(hour)) {
9
- hourRef.current.focus();
9
+ hourRef.current.focus({
10
+ preventScroll,
11
+ });
10
12
  }
11
- }, [hourRef, hour, isHourFocused]);
13
+ }, [hourRef, hour, isHourFocused, preventScroll]);
12
14
  const onKeyDown = (0, react_1.useCallback)((e) => {
13
15
  if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
14
16
  e.preventDefault();
@@ -7,6 +7,7 @@ export interface UseMinuteProps {
7
7
  isMinuteSelected: (minute: number) => boolean;
8
8
  onMinuteFocus: (minute: number) => void;
9
9
  onMinuteSelect: (minute: number) => void;
10
+ preventScroll?: boolean;
10
11
  }
11
12
  export interface UseMinuteReturnType {
12
13
  isSelected: boolean;
@@ -14,4 +15,4 @@ export interface UseMinuteReturnType {
14
15
  onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;
15
16
  tabIndex: number;
16
17
  }
17
- export declare function useMinute({ minute, minuteRef, focusedMinute, isMinuteFocused, isMinuteSelected, onMinuteFocus, onMinuteSelect, }: UseMinuteProps): UseMinuteReturnType;
18
+ export declare function useMinute({ minute, minuteRef, focusedMinute, isMinuteFocused, isMinuteSelected, onMinuteFocus, onMinuteSelect, preventScroll, }: UseMinuteProps): UseMinuteReturnType;
@@ -2,13 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMinute = void 0;
4
4
  const react_1 = require("react");
5
- function useMinute({ minute, minuteRef, focusedMinute, isMinuteFocused, isMinuteSelected, onMinuteFocus, onMinuteSelect, }) {
5
+ function useMinute({ minute, minuteRef, focusedMinute, isMinuteFocused, isMinuteSelected, onMinuteFocus, onMinuteSelect, preventScroll, }) {
6
6
  const onClick = (0, react_1.useCallback)(() => onMinuteSelect(minute), [minute, onMinuteSelect]);
7
7
  (0, react_1.useEffect)(() => {
8
8
  if (minuteRef && minuteRef.current && isMinuteFocused(minute)) {
9
- minuteRef.current.focus();
9
+ minuteRef.current.focus({
10
+ preventScroll,
11
+ });
10
12
  }
11
- }, [minuteRef, minute, isMinuteFocused]);
13
+ }, [minuteRef, minute, isMinuteFocused, preventScroll]);
12
14
  const onKeyDown = (0, react_1.useCallback)((e) => {
13
15
  if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
14
16
  e.preventDefault();
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMonth = exports.monthLabelFormatFn = exports.weekdayLabelFormatFn = exports.dayLabelFormatFn = void 0;
4
4
  const react_1 = require("react");
5
+ const dayjs_en_1 = require("../utils/dayjs-en");
5
6
  const get_days_1 = require("../utils/get-days");
6
7
  const get_weekday_labels_1 = require("../utils/get-weekday-labels");
7
- const dayjs_en_1 = require("../utils/dayjs-en");
8
8
  const dayLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("DD");
9
9
  exports.dayLabelFormatFn = dayLabelFormatFn;
10
10
  const weekdayLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("dd"); // localization
@@ -6,6 +6,7 @@ export type OnTimeChangeType = TimeType | null;
6
6
  export interface UseTimePickerProps {
7
7
  onSelectCallback?: () => void;
8
8
  onTimeChange: (data: OnTimeChangeType) => void;
9
+ preventScroll?: boolean;
9
10
  selectedTime: TimeType | null;
10
11
  }
11
12
  export interface UseTimePickerReturnType {
@@ -24,5 +25,6 @@ export interface UseTimePickerReturnType {
24
25
  onHourSelect: (hour: number) => void;
25
26
  onMinuteFocus: (minute: number) => void;
26
27
  onMinuteSelect: (minute: number) => void;
28
+ preventScroll?: boolean;
27
29
  }
28
- export declare function useTimePicker({ selectedTime, onTimeChange, onSelectCallback, }: UseTimePickerProps): UseTimePickerReturnType;
30
+ export declare function useTimePicker({ selectedTime, onTimeChange, onSelectCallback, preventScroll, }: UseTimePickerProps): UseTimePickerReturnType;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTimePicker = void 0;
4
4
  const react_1 = require("react");
5
- function useTimePicker({ selectedTime, onTimeChange, onSelectCallback, }) {
5
+ function useTimePicker({ selectedTime, onTimeChange, onSelectCallback, preventScroll, }) {
6
6
  var _a, _b;
7
7
  const [focusedHour, setFocusedHour] = (0, react_1.useState)((_a = selectedTime === null || selectedTime === void 0 ? void 0 : selectedTime.hour) !== null && _a !== void 0 ? _a : null);
8
8
  const [focusedMinute, setFocusedMinute] = (0, react_1.useState)((_b = selectedTime === null || selectedTime === void 0 ? void 0 : selectedTime.minute) !== null && _b !== void 0 ? _b : null);
@@ -78,6 +78,7 @@ function useTimePicker({ selectedTime, onTimeChange, onSelectCallback, }) {
78
78
  onHourSelect,
79
79
  onMinuteFocus,
80
80
  onMinuteSelect,
81
+ preventScroll,
81
82
  };
82
83
  }
83
84
  exports.useTimePicker = useTimePicker;
package/hooks/use-year.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useYear = exports.yearLabelFormatFn = exports.monthLabelFormatFn = void 0;
4
4
  const react_1 = require("react");
5
- const get_months_1 = require("../utils/get-months");
6
5
  const dayjs_en_1 = require("../utils/dayjs-en");
6
+ const get_months_1 = require("../utils/get-months");
7
7
  const monthLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("MMMM"); // localized
8
8
  exports.monthLabelFormatFn = monthLabelFormatFn;
9
9
  const yearLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("YYYY");
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@uxf/datepicker",
3
- "version": "10.0.0-beta.9",
3
+ "version": "10.8.0",
4
4
  "description": "A set of React hooks to create an awesome datepicker.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "tsc -P tsconfig.json",
8
- "typecheck": "tsc --noEmit --skipLibCheck",
9
- "jest": "jest --coverage=true"
8
+ "typecheck": "tsc --noEmit --skipLibCheck"
10
9
  },
11
10
  "publishConfig": {
12
11
  "access": "public"
@@ -15,26 +14,21 @@
15
14
  "type": "git",
16
15
  "url": "git+https://gitlab.com/uxf-npm/datepicker.git"
17
16
  },
18
- "devDependencies": {
19
- "@testing-library/react-hooks": "^7.0.1",
20
- "@types/react": "18.2.6",
21
- "eslint": "^8.8.0",
22
- "react": "18.2.0"
23
- },
24
17
  "author": "UX Fans s.r.o.",
25
18
  "license": "ISC",
26
19
  "bugs": {
27
20
  "url": "https://gitlab.com/uxf-npm/datepicker/issues"
28
21
  },
29
22
  "homepage": "https://gitlab.com/uxf-npm/datepicker#readme",
30
- "dependencies": {
31
- "dayjs": "^1.11.5"
32
- },
33
23
  "peerDependencies": {
34
- "react": ">=17"
24
+ "react": ">=18.2.0",
25
+ "react-dom": ">=18.2.0"
35
26
  },
36
- "volta": {
37
- "node": "16.5.0",
38
- "yarn": "1.22.19"
27
+ "devDependencies": {
28
+ "@testing-library/react-hooks": "7.0.2",
29
+ "@types/react": "18.2.27",
30
+ "@types/react-dom": "18.2.12",
31
+ "react": "18.2.0",
32
+ "react-dom": "18.2.0"
39
33
  }
40
34
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.canSelectRange = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  // eslint-disable-next-line complexity
7
7
  function canSelectRange({ startDate, endDate, isDateBlocked, minBookingDays, exactMinBookingDays, minBookingDate, maxBookingDate, }) {
8
8
  const isStartDateAfterOrEqualMinDate = minBookingDate
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCurrentYearMonthAndDate = void 0;
4
- const get_date_month_and_year_1 = require("./get-date-month-and-year");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_date_month_and_year_1 = require("./get-date-month-and-year");
6
6
  function getCurrentYearMonthAndDate() {
7
7
  return (0, get_date_month_and_year_1.getDateMonthAndYear)((0, dayjs_en_1.dayjsEn)().startOf("day").toDate());
8
8
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const dayjs_1 = __importDefault(require("dayjs"));
7
+ const get_date_invervals_1 = require("./get-date-invervals");
8
+ describe("getDateIntervals", () => {
9
+ it("should return empty array for empty input", () => {
10
+ expect((0, get_date_invervals_1.getDateIntervals)([])).toStrictEqual([]);
11
+ });
12
+ it("should return single date as an interval", () => {
13
+ const date = (0, dayjs_1.default)("2023-10-12").toDate();
14
+ expect((0, get_date_invervals_1.getDateIntervals)([date])).toStrictEqual([{ start: date, end: date }]);
15
+ });
16
+ it("should group contiguous dates into intervals", () => {
17
+ const dates = [
18
+ (0, dayjs_1.default)("2023-10-12").toDate(),
19
+ (0, dayjs_1.default)("2023-10-13").toDate(),
20
+ (0, dayjs_1.default)("2023-10-14").toDate(),
21
+ (0, dayjs_1.default)("2023-10-16").toDate(),
22
+ (0, dayjs_1.default)("2023-10-17").toDate(),
23
+ ];
24
+ const expected = [
25
+ { start: dates[0], end: dates[2] },
26
+ { start: dates[3], end: dates[4] },
27
+ ];
28
+ expect((0, get_date_invervals_1.getDateIntervals)(dates)).toStrictEqual(expected);
29
+ });
30
+ it("should handle non-contiguous dates", () => {
31
+ const dates = [(0, dayjs_1.default)("2023-10-12").toDate(), (0, dayjs_1.default)("2023-10-14").toDate(), (0, dayjs_1.default)("2023-10-16").toDate()];
32
+ const expected = [
33
+ { start: dates[0], end: dates[0] },
34
+ { start: dates[1], end: dates[1] },
35
+ { start: dates[2], end: dates[2] },
36
+ ];
37
+ expect((0, get_date_invervals_1.getDateIntervals)(dates)).toStrictEqual(expected);
38
+ });
39
+ });
@@ -0,0 +1,3 @@
1
+ type ReturnType = Record<"start" | "end", Date>[];
2
+ export declare function getDateIntervals(dates: Date[]): ReturnType;
3
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDateIntervals = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ function getDateIntervals(dates) {
9
+ const intervals = [];
10
+ let currentStart = dates[0];
11
+ let currentEnd = dates[0];
12
+ for (let i = 1; i < dates.length; i++) {
13
+ const currentDate = dates[i];
14
+ const nextDate = (0, dayjs_1.default)(currentEnd).add(1, "day").toDate();
15
+ // If the current date matches the expected next date, it's contiguous
16
+ if ((0, dayjs_1.default)(currentDate).isSame(nextDate, "day")) {
17
+ currentEnd = currentDate;
18
+ }
19
+ else {
20
+ intervals.push({ start: currentStart, end: currentEnd });
21
+ currentStart = currentDate;
22
+ currentEnd = currentDate;
23
+ }
24
+ }
25
+ if (dates[0]) {
26
+ // Push the last interval
27
+ intervals.push({ start: currentStart, end: currentEnd });
28
+ }
29
+ return intervals;
30
+ }
31
+ exports.getDateIntervals = getDateIntervals;
package/utils/get-days.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDays = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  function getDays({ year, month, firstDayOfWeek = 0, dayLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("DD"), }) {
7
7
  const date = new Date(year, month);
8
8
  const lastDayOfWeek = firstDayOfWeek + 7;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInitialMonths = void 0;
4
+ const dayjs_en_1 = require("./dayjs-en");
4
5
  const get_current_year_month_and_date_1 = require("./get-current-year-month-and-date");
5
6
  const get_date_month_and_year_1 = require("./get-date-month-and-year");
6
- const dayjs_en_1 = require("./dayjs-en");
7
7
  function getInitialMonths(numberOfMonths, startDate) {
8
8
  const firstMonth = startDate ? (0, get_date_month_and_year_1.getDateMonthAndYear)(startDate) : (0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)();
9
9
  let prevMonthDate = firstMonth.date;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMonths = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  function getMonths({ year, monthLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("MMMM"), }) {
7
7
  const date = new Date(year, 0);
8
8
  const yearStart = (0, dayjs_en_1.dayjsEn)(date).startOf("year").toDate();
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextActiveMonth = void 0;
4
- const get_date_month_and_year_1 = require("./get-date-month-and-year");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_date_month_and_year_1 = require("./get-date-month-and-year");
6
6
  function getNextActiveMonth(activeMonth, numberOfMonths, counter, step) {
7
7
  let prevMonth;
8
8
  if (step) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWeekdayLabels = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  function getWeekdayLabels({ firstDayOfWeek = 0, weekdayLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("dd"), }) {
7
7
  const now = new Date();
8
8
  const arr = (0, get_each_1.getEach)((0, dayjs_en_1.dayjsEn)(now).startOf("week").add(firstDayOfWeek, "day").toDate(), (0, dayjs_en_1.dayjsEn)(now).endOf("week").add(firstDayOfWeek, "day").toDate(), "day");
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dayjs_1 = __importDefault(require("dayjs"));
7
- const get_weekday_labels_1 = require("./get-weekday-labels");
8
7
  require("dayjs/locale/cs");
8
+ const get_weekday_labels_1 = require("./get-weekday-labels");
9
9
  test("getWeekdayLabels", () => {
10
10
  expect((0, get_weekday_labels_1.getWeekdayLabels)({})).toStrictEqual(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
11
11
  });
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getYears = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  function getYears({ startYear, endYear, yearLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("YYYY"), }) {
7
7
  return (0, get_each_1.getEach)(startYear, endYear, "year").map((d) => ({
8
8
  date: d,
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isDateBlocked = void 0;
4
- const is_in_unavailable_dates_1 = require("./is-in-unavailable-dates");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const is_in_unavailable_dates_1 = require("./is-in-unavailable-dates");
6
6
  function isDateBlocked({ date, minBookingDate, maxBookingDate, isDateBlockedFn, startDate, endDate, minBookingDays = 1, unavailableDates = [], }) {
7
7
  const compareMinDate = minBookingDate
8
8
  ? new Date(minBookingDate.getFullYear(), minBookingDate.getMonth(), minBookingDate.getDate(), 0, 0, 0)
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isDateHovered = void 0;
4
- const get_each_1 = require("./get-each");
5
4
  const dayjs_en_1 = require("./dayjs-en");
5
+ const get_each_1 = require("./get-each");
6
6
  function isDateHovered({ date, startDate, endDate, isDateBlocked, hoveredDate, minBookingDays, exactMinBookingDays, }) {
7
7
  if (
8
8
  // exact min booking days