react-day-picker 9.1.1 → 9.1.2
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 +8 -8
- package/dist/cjs/DayPicker.js +10 -10
- package/dist/cjs/DayPicker.js.map +1 -1
- package/dist/cjs/classes/CalendarDay.d.ts +1 -1
- package/dist/cjs/classes/CalendarDay.js.map +1 -1
- package/dist/cjs/components/WeekNumber.d.ts +1 -1
- package/dist/cjs/components/WeekNumber.js +2 -2
- package/dist/cjs/formatters/formatCaption.d.ts +1 -2
- package/dist/cjs/formatters/formatCaption.js.map +1 -1
- package/dist/cjs/formatters/formatDay.d.ts +1 -2
- package/dist/cjs/formatters/formatDay.js.map +1 -1
- package/dist/cjs/formatters/formatWeekdayName.d.ts +1 -2
- package/dist/cjs/formatters/formatWeekdayName.js.map +1 -1
- package/dist/cjs/helpers/getDateLib.d.ts +2 -1
- package/dist/cjs/helpers/getDateLib.js.map +1 -1
- package/dist/cjs/helpers/getDates.js +2 -2
- package/dist/cjs/helpers/getDates.js.map +1 -1
- package/dist/cjs/helpers/getDisplayMonths.d.ts +2 -1
- package/dist/cjs/helpers/getDisplayMonths.js.map +1 -1
- package/dist/cjs/helpers/getFocusableDate.d.ts +2 -1
- package/dist/cjs/helpers/getInitialMonth.js +5 -1
- package/dist/cjs/helpers/getInitialMonth.js.map +1 -1
- package/dist/cjs/helpers/getMonthOptions.d.ts +2 -2
- package/dist/cjs/helpers/getMonthOptions.js +6 -3
- package/dist/cjs/helpers/getMonthOptions.js.map +1 -1
- package/dist/cjs/helpers/getMonths.d.ts +2 -1
- package/dist/cjs/helpers/getMonths.js.map +1 -1
- package/dist/cjs/helpers/getNavMonth.d.ts +3 -2
- package/dist/cjs/helpers/getNavMonth.js +11 -3
- package/dist/cjs/helpers/getNavMonth.js.map +1 -1
- package/dist/cjs/helpers/getNextFocus.d.ts +2 -1
- package/dist/cjs/helpers/getNextMonth.d.ts +2 -1
- package/dist/cjs/helpers/getNextMonth.js.map +1 -1
- package/dist/cjs/helpers/getPreviousMonth.d.ts +2 -1
- package/dist/cjs/helpers/getPreviousMonth.js.map +1 -1
- package/dist/cjs/helpers/getWeekdays.d.ts +1 -2
- package/dist/cjs/helpers/getWeekdays.js +5 -1
- package/dist/cjs/helpers/getWeekdays.js.map +1 -1
- package/dist/cjs/helpers/getYearOptions.d.ts +2 -1
- package/dist/cjs/helpers/getYearOptions.js +6 -5
- package/dist/cjs/helpers/getYearOptions.js.map +1 -1
- package/dist/cjs/labels/labelGrid.d.ts +1 -2
- package/dist/cjs/labels/labelGrid.js.map +1 -1
- package/dist/cjs/labels/labelWeekday.d.ts +1 -2
- package/dist/cjs/labels/labelWeekday.js.map +1 -1
- package/dist/cjs/lib/dateLib.d.ts +66 -3
- package/dist/cjs/lib/dateLib.js +0 -2
- package/dist/cjs/lib/dateLib.js.map +1 -1
- package/dist/cjs/selection/useMulti.d.ts +2 -1
- package/dist/cjs/selection/useRange.d.ts +2 -1
- package/dist/cjs/selection/useSingle.d.ts +2 -1
- package/dist/cjs/types/props.d.ts +15 -5
- package/dist/cjs/types/selection.d.ts +14 -5
- package/dist/cjs/types/shared.d.ts +17 -8
- package/dist/cjs/useCalendar.d.ts +1 -1
- package/dist/cjs/useDayPicker.d.ts +30 -6
- package/dist/cjs/useDayPicker.js +10 -2
- package/dist/cjs/useDayPicker.js.map +1 -1
- package/dist/cjs/useFocus.d.ts +2 -1
- package/dist/cjs/useGetModifiers.d.ts +2 -1
- package/dist/cjs/useGetModifiers.js +6 -1
- package/dist/cjs/useGetModifiers.js.map +1 -1
- package/dist/cjs/useSelection.d.ts +2 -1
- package/dist/cjs/useSelection.js.map +1 -1
- package/dist/cjs/utils/addToRange.d.ts +2 -1
- package/dist/cjs/utils/addToRange.js.map +1 -1
- package/dist/cjs/utils/dateMatchModifiers.d.ts +2 -1
- package/dist/cjs/utils/dateMatchModifiers.js.map +1 -1
- package/dist/cjs/utils/rangeIncludesDate.d.ts +2 -1
- package/dist/cjs/utils/rangeIncludesDate.js.map +1 -1
- package/dist/cjs/utils/typeguards.d.ts +2 -1
- package/dist/esm/DayPicker.js +10 -10
- package/dist/esm/DayPicker.js.map +1 -1
- package/dist/esm/classes/CalendarDay.d.ts +1 -1
- package/dist/esm/classes/CalendarDay.js.map +1 -1
- package/dist/esm/components/WeekNumber.d.ts +1 -1
- package/dist/esm/components/WeekNumber.js +2 -2
- package/dist/esm/formatters/formatCaption.d.ts +1 -2
- package/dist/esm/formatters/formatCaption.js.map +1 -1
- package/dist/esm/formatters/formatDay.d.ts +1 -2
- package/dist/esm/formatters/formatDay.js.map +1 -1
- package/dist/esm/formatters/formatWeekdayName.d.ts +1 -2
- package/dist/esm/formatters/formatWeekdayName.js.map +1 -1
- package/dist/esm/helpers/getDateLib.d.ts +2 -1
- package/dist/esm/helpers/getDateLib.js.map +1 -1
- package/dist/esm/helpers/getDates.js +2 -2
- package/dist/esm/helpers/getDates.js.map +1 -1
- package/dist/esm/helpers/getDisplayMonths.d.ts +2 -1
- package/dist/esm/helpers/getDisplayMonths.js.map +1 -1
- package/dist/esm/helpers/getFocusableDate.d.ts +2 -1
- package/dist/esm/helpers/getInitialMonth.js +5 -1
- package/dist/esm/helpers/getInitialMonth.js.map +1 -1
- package/dist/esm/helpers/getMonthOptions.d.ts +2 -2
- package/dist/esm/helpers/getMonthOptions.js +6 -3
- package/dist/esm/helpers/getMonthOptions.js.map +1 -1
- package/dist/esm/helpers/getMonths.d.ts +2 -1
- package/dist/esm/helpers/getMonths.js.map +1 -1
- package/dist/esm/helpers/getNavMonth.d.ts +3 -2
- package/dist/esm/helpers/getNavMonth.js +11 -3
- package/dist/esm/helpers/getNavMonth.js.map +1 -1
- package/dist/esm/helpers/getNextFocus.d.ts +2 -1
- package/dist/esm/helpers/getNextMonth.d.ts +2 -1
- package/dist/esm/helpers/getNextMonth.js.map +1 -1
- package/dist/esm/helpers/getPreviousMonth.d.ts +2 -1
- package/dist/esm/helpers/getPreviousMonth.js.map +1 -1
- package/dist/esm/helpers/getWeekdays.d.ts +1 -2
- package/dist/esm/helpers/getWeekdays.js +5 -1
- package/dist/esm/helpers/getWeekdays.js.map +1 -1
- package/dist/esm/helpers/getYearOptions.d.ts +2 -1
- package/dist/esm/helpers/getYearOptions.js +6 -5
- package/dist/esm/helpers/getYearOptions.js.map +1 -1
- package/dist/esm/labels/labelGrid.d.ts +1 -2
- package/dist/esm/labels/labelGrid.js.map +1 -1
- package/dist/esm/labels/labelWeekday.d.ts +1 -2
- package/dist/esm/labels/labelWeekday.js.map +1 -1
- package/dist/esm/lib/dateLib.d.ts +66 -3
- package/dist/esm/lib/dateLib.js +0 -2
- package/dist/esm/lib/dateLib.js.map +1 -1
- package/dist/esm/selection/useMulti.d.ts +2 -1
- package/dist/esm/selection/useRange.d.ts +2 -1
- package/dist/esm/selection/useSingle.d.ts +2 -1
- package/dist/esm/types/props.d.ts +15 -5
- package/dist/esm/types/selection.d.ts +14 -5
- package/dist/esm/types/shared.d.ts +17 -8
- package/dist/esm/useCalendar.d.ts +1 -1
- package/dist/esm/useDayPicker.d.ts +30 -6
- package/dist/esm/useDayPicker.js +10 -2
- package/dist/esm/useDayPicker.js.map +1 -1
- package/dist/esm/useFocus.d.ts +2 -1
- package/dist/esm/useGetModifiers.d.ts +2 -1
- package/dist/esm/useGetModifiers.js +6 -1
- package/dist/esm/useGetModifiers.js.map +1 -1
- package/dist/esm/useSelection.d.ts +2 -1
- package/dist/esm/useSelection.js.map +1 -1
- package/dist/esm/utils/addToRange.d.ts +2 -1
- package/dist/esm/utils/addToRange.js.map +1 -1
- package/dist/esm/utils/dateMatchModifiers.d.ts +2 -1
- package/dist/esm/utils/dateMatchModifiers.js.map +1 -1
- package/dist/esm/utils/rangeIncludesDate.d.ts +2 -1
- package/dist/esm/utils/rangeIncludesDate.js.map +1 -1
- package/dist/esm/utils/typeguards.d.ts +2 -1
- package/examples/Input.test.tsx +1 -1
- package/examples/ModifiersHidden.test.tsx +1 -1
- package/examples/Range.test.tsx +1 -1
- package/examples/RangeShiftKey.tsx +1 -1
- package/examples/SingleMockDate.test.tsx +39 -0
- package/examples/WeekStartsOn.tsx +7 -0
- package/examples/Weeknumber.test.tsx +2 -2
- package/examples/WeeknumberCustom.tsx +2 -2
- package/examples/__snapshots__/Range.test.tsx.snap +84 -100
- package/examples/__snapshots__/StylingCssModules.test.tsx.snap +42 -50
- package/examples/index.ts +1 -0
- package/package.json +4 -3
- package/src/DayPicker.test.tsx +13 -0
- package/src/DayPicker.tsx +4 -8
- package/src/classes/CalendarDay.ts +1 -1
- package/src/components/WeekNumber.tsx +3 -3
- package/src/formatters/formatCaption.ts +5 -2
- package/src/formatters/formatDay.ts +1 -2
- package/src/formatters/formatWeekdayName.ts +1 -2
- package/src/helpers/getDateLib.ts +2 -2
- package/src/helpers/getDates.ts +2 -3
- package/src/helpers/getDisplayMonths.ts +2 -1
- package/src/helpers/getFocusableDate.ts +1 -1
- package/src/helpers/getInitialMonth.ts +5 -1
- package/src/helpers/getMonthOptions.ts +8 -5
- package/src/helpers/getMonths.ts +2 -1
- package/src/helpers/getNavMonth.ts +14 -5
- package/src/helpers/getNextFocus.tsx +1 -1
- package/src/helpers/getNextMonth.ts +2 -1
- package/src/helpers/getPreviousMonth.ts +2 -1
- package/src/helpers/getWeekdays.ts +6 -3
- package/src/helpers/getYearOptions.ts +8 -7
- package/src/labels/labelGrid.ts +1 -2
- package/src/labels/labelWeekday.ts +1 -2
- package/src/lib/dateLib.ts +95 -3
- package/src/selection/useMulti.tsx +1 -1
- package/src/selection/useRange.tsx +1 -1
- package/src/selection/useSingle.tsx +1 -1
- package/src/types/props.ts +15 -6
- package/src/types/selection.ts +12 -9
- package/src/types/shared.ts +17 -9
- package/src/useCalendar.ts +1 -1
- package/src/useDayPicker.ts +30 -6
- package/src/useFocus.ts +1 -1
- package/src/useGetModifiers.tsx +8 -2
- package/src/useSelection.ts +2 -1
- package/src/utils/addToRange.ts +2 -2
- package/src/utils/dateMatchModifiers.ts +2 -2
- package/src/utils/rangeIncludesDate.ts +2 -2
- package/src/utils/typeguards.ts +1 -1
- package/website/docs/development/code-of-conduct.md +5 -7
- package/website/docs/development/contributing.md +9 -0
- package/website/docs/docs/localization.mdx +23 -29
- package/website/docs/docs/selection-modes.mdx +21 -21
- package/website/docs/guides/custom-components.mdx +10 -10
- package/website/docs/development/contributing.mdx +0 -11
package/src/DayPicker.tsx
CHANGED
|
@@ -279,7 +279,6 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
279
279
|
>
|
|
280
280
|
{!props.hideNavigation && (
|
|
281
281
|
<components.Nav
|
|
282
|
-
role="navigation"
|
|
283
282
|
className={classNames[UI.Nav]}
|
|
284
283
|
style={styles?.[UI.Nav]}
|
|
285
284
|
aria-label={labelNav()}
|
|
@@ -413,15 +412,14 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
413
412
|
{!props.hideWeekdays && (
|
|
414
413
|
<components.Weekdays
|
|
415
414
|
className={classNames[UI.Weekdays]}
|
|
416
|
-
role="row"
|
|
417
415
|
style={styles?.[UI.Weekdays]}
|
|
418
416
|
>
|
|
419
417
|
{showWeekNumber && (
|
|
420
418
|
<components.WeekNumberHeader
|
|
421
419
|
aria-label={labelWeekNumberHeader(labelOptions)}
|
|
422
420
|
className={classNames[UI.WeekNumberHeader]}
|
|
423
|
-
role="columnheader"
|
|
424
421
|
style={styles?.[UI.WeekNumberHeader]}
|
|
422
|
+
scope="col"
|
|
425
423
|
>
|
|
426
424
|
{formatWeekNumberHeader()}
|
|
427
425
|
</components.WeekNumberHeader>
|
|
@@ -435,8 +433,8 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
435
433
|
)}
|
|
436
434
|
className={classNames[UI.Weekday]}
|
|
437
435
|
key={i}
|
|
438
|
-
role="columnheader"
|
|
439
436
|
style={styles?.[UI.Weekday]}
|
|
437
|
+
scope="col"
|
|
440
438
|
>
|
|
441
439
|
{formatWeekdayName(weekday, formatOptions, dateLib)}
|
|
442
440
|
</components.Weekday>
|
|
@@ -445,7 +443,6 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
445
443
|
)}
|
|
446
444
|
<components.Weeks
|
|
447
445
|
className={classNames[UI.Weeks]}
|
|
448
|
-
role="rowgroup"
|
|
449
446
|
style={styles?.[UI.Weeks]}
|
|
450
447
|
>
|
|
451
448
|
{calendarMonth.weeks.map((week, weekIndex) => {
|
|
@@ -453,19 +450,18 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
453
450
|
<components.Week
|
|
454
451
|
className={classNames[UI.Week]}
|
|
455
452
|
key={week.weekNumber}
|
|
456
|
-
role="row"
|
|
457
453
|
style={styles?.[UI.Week]}
|
|
458
454
|
week={week}
|
|
459
455
|
>
|
|
460
456
|
{showWeekNumber && (
|
|
461
457
|
<components.WeekNumber
|
|
462
458
|
week={week}
|
|
463
|
-
role="rowheader"
|
|
464
459
|
style={styles?.[UI.WeekNumber]}
|
|
465
460
|
aria-label={labelWeekNumber(week.weekNumber, {
|
|
466
461
|
locale
|
|
467
462
|
})}
|
|
468
463
|
className={classNames[UI.WeekNumber]}
|
|
464
|
+
scope="row"
|
|
469
465
|
>
|
|
470
466
|
{formatWeekNumber(week.weekNumber)}
|
|
471
467
|
</components.WeekNumber>
|
|
@@ -526,7 +522,6 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
526
522
|
key={`${dateLib.format(date, "yyyy-MM-dd")}_${dateLib.format(day.displayMonth, "yyyy-MM")}`}
|
|
527
523
|
day={day}
|
|
528
524
|
modifiers={modifiers}
|
|
529
|
-
role="gridcell"
|
|
530
525
|
className={className.join(" ")}
|
|
531
526
|
style={style}
|
|
532
527
|
aria-hidden={modifiers.hidden || undefined}
|
|
@@ -549,6 +544,7 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
549
544
|
<components.DayButton
|
|
550
545
|
className={classNames[UI.DayButton]}
|
|
551
546
|
style={styles?.[UI.DayButton]}
|
|
547
|
+
type="button"
|
|
552
548
|
day={day}
|
|
553
549
|
modifiers={modifiers}
|
|
554
550
|
disabled={modifiers.disabled || undefined}
|
|
@@ -12,10 +12,10 @@ export function WeekNumber(
|
|
|
12
12
|
props: {
|
|
13
13
|
/** The week to render. */
|
|
14
14
|
week: CalendarWeek;
|
|
15
|
-
} & JSX.IntrinsicElements["
|
|
15
|
+
} & JSX.IntrinsicElements["th"]
|
|
16
16
|
) {
|
|
17
|
-
const { week, ...
|
|
18
|
-
return <
|
|
17
|
+
const { week, ...thProps } = props;
|
|
18
|
+
return <th {...thProps} />;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type WeekNumberProps = Parameters<typeof WeekNumber>[0];
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
FormatOptions,
|
|
3
|
+
dateLib as defaultDateLib,
|
|
4
|
+
type DateLib
|
|
5
|
+
} from "../lib/index.js";
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Format the caption of the month.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { FormatOptions } from "../lib/dateLib.js";
|
|
1
|
+
import type { FormatOptions, DateLib } from "../lib/dateLib.js";
|
|
2
2
|
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
3
|
-
import type { DateLib } from "../types/index.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Format the day date shown in the day cell.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { FormatOptions } from "../lib/dateLib.js";
|
|
1
|
+
import type { FormatOptions, DateLib } from "../lib/dateLib.js";
|
|
2
2
|
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
3
|
-
import type { DateLib } from "../types/index.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Format the weekday name to be displayed in the weekdays header.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dateLib } from "../lib/dateLib.js";
|
|
2
|
-
import type {
|
|
1
|
+
import { dateLib, type DateLib } from "../lib/dateLib.js";
|
|
2
|
+
import type { DayPickerProps } from "../types/index.js";
|
|
3
3
|
|
|
4
4
|
export function getDateLib(customLib: DayPickerProps["dateLib"]): DateLib {
|
|
5
5
|
return {
|
package/src/helpers/getDates.ts
CHANGED
|
@@ -26,8 +26,7 @@ export function getDates(
|
|
|
26
26
|
differenceInCalendarDays,
|
|
27
27
|
differenceInCalendarMonths,
|
|
28
28
|
isAfter,
|
|
29
|
-
endOfMonth
|
|
30
|
-
Date
|
|
29
|
+
endOfMonth
|
|
31
30
|
} = dateLib;
|
|
32
31
|
|
|
33
32
|
const startWeekFirstDate = ISOWeek
|
|
@@ -61,7 +60,7 @@ export function getDates(
|
|
|
61
60
|
if (fixedWeeks && dates.length < extraDates) {
|
|
62
61
|
for (let i = 0; i < 7; i++) {
|
|
63
62
|
const date = addDays(dates[dates.length - 1], 1);
|
|
64
|
-
dates.push(
|
|
63
|
+
dates.push(date);
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
return dates;
|
|
@@ -21,7 +21,11 @@ export function getInitialMonth(
|
|
|
21
21
|
const {
|
|
22
22
|
month,
|
|
23
23
|
defaultMonth,
|
|
24
|
-
today = props.timeZone
|
|
24
|
+
today = props.timeZone
|
|
25
|
+
? TZDate.tz(props.timeZone)
|
|
26
|
+
: dateLib.Date
|
|
27
|
+
? new dateLib.Date()
|
|
28
|
+
: new Date(),
|
|
25
29
|
numberOfMonths = 1,
|
|
26
30
|
endMonth,
|
|
27
31
|
startMonth
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DropdownOption } from "../components/Dropdown.js";
|
|
2
|
-
import type { Locale } from "../lib/dateLib.js";
|
|
3
|
-
import type {
|
|
2
|
+
import type { Locale, DateLib } from "../lib/dateLib.js";
|
|
3
|
+
import type { Formatters } from "../types/index.js";
|
|
4
4
|
|
|
5
5
|
/** Return the months to show in the dropdown. */
|
|
6
6
|
export function getMonthOptions(
|
|
@@ -14,7 +14,7 @@ export function getMonthOptions(
|
|
|
14
14
|
if (!navStart) return undefined;
|
|
15
15
|
if (!navEnd) return undefined;
|
|
16
16
|
|
|
17
|
-
const { addMonths, startOfMonth, isBefore
|
|
17
|
+
const { addMonths, startOfMonth, isBefore } = dateLib;
|
|
18
18
|
const year = displayMonth.getFullYear();
|
|
19
19
|
|
|
20
20
|
const months: number[] = [];
|
|
@@ -28,9 +28,12 @@ export function getMonthOptions(
|
|
|
28
28
|
});
|
|
29
29
|
const options = sortedMonths.map((value) => {
|
|
30
30
|
const label = formatters.formatMonthDropdown(value, locale);
|
|
31
|
+
const month = dateLib.Date
|
|
32
|
+
? new dateLib.Date(year, value)
|
|
33
|
+
: new Date(year, value);
|
|
31
34
|
const disabled =
|
|
32
|
-
(navStart &&
|
|
33
|
-
(navEnd &&
|
|
35
|
+
(navStart && month < startOfMonth(navStart)) ||
|
|
36
|
+
(navEnd && month > startOfMonth(navEnd)) ||
|
|
34
37
|
false;
|
|
35
38
|
return { value, label, disabled };
|
|
36
39
|
});
|
package/src/helpers/getMonths.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CalendarWeek, CalendarDay, CalendarMonth } from "../classes/index.js";
|
|
2
|
-
import type { DateLib
|
|
2
|
+
import type { DateLib } from "../lib/index.js";
|
|
3
|
+
import type { DayPickerProps } from "../types/index.js";
|
|
3
4
|
|
|
4
5
|
/** Return the months to display in the calendar. */
|
|
5
6
|
export function getMonths(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TZDate } from "@date-fns/tz";
|
|
2
2
|
|
|
3
|
-
import type { DateLib
|
|
3
|
+
import type { DateLib } from "../lib/index.js";
|
|
4
|
+
import type { DayPickerProps } from "../types/index.js";
|
|
4
5
|
|
|
5
6
|
/** Return the start and end months for the calendar navigation. */
|
|
6
7
|
export function getNavMonths(
|
|
@@ -11,6 +12,7 @@ export function getNavMonths(
|
|
|
11
12
|
| "startMonth"
|
|
12
13
|
| "today"
|
|
13
14
|
| "timeZone"
|
|
15
|
+
| "dateLib"
|
|
14
16
|
// Deprecated:
|
|
15
17
|
| "fromMonth"
|
|
16
18
|
| "fromYear"
|
|
@@ -27,8 +29,7 @@ export function getNavMonths(
|
|
|
27
29
|
startOfMonth,
|
|
28
30
|
endOfMonth,
|
|
29
31
|
addYears,
|
|
30
|
-
endOfYear
|
|
31
|
-
Date
|
|
32
|
+
endOfYear
|
|
32
33
|
} = dateLib;
|
|
33
34
|
|
|
34
35
|
// Handle deprecated code
|
|
@@ -54,7 +55,11 @@ export function getNavMonths(
|
|
|
54
55
|
} else if (!startMonth && hasDropdowns) {
|
|
55
56
|
const today =
|
|
56
57
|
props.today ??
|
|
57
|
-
(props.timeZone
|
|
58
|
+
(props.timeZone
|
|
59
|
+
? TZDate.tz(props.timeZone)
|
|
60
|
+
: dateLib.Date
|
|
61
|
+
? new dateLib.Date()
|
|
62
|
+
: new Date());
|
|
58
63
|
startMonth = startOfYear(addYears(today, -100));
|
|
59
64
|
}
|
|
60
65
|
if (endMonth) {
|
|
@@ -64,7 +69,11 @@ export function getNavMonths(
|
|
|
64
69
|
} else if (!endMonth && hasDropdowns) {
|
|
65
70
|
const today =
|
|
66
71
|
props.today ??
|
|
67
|
-
(props.timeZone
|
|
72
|
+
(props.timeZone
|
|
73
|
+
? TZDate.tz(props.timeZone)
|
|
74
|
+
: dateLib.Date
|
|
75
|
+
? new dateLib.Date()
|
|
76
|
+
: new Date());
|
|
68
77
|
endMonth = endOfYear(today);
|
|
69
78
|
}
|
|
70
79
|
return [
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { TZDate } from "@date-fns/tz";
|
|
2
2
|
|
|
3
|
-
import type { Locale } from "../lib/dateLib.js";
|
|
3
|
+
import type { Locale, DateLib } from "../lib/dateLib.js";
|
|
4
4
|
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
5
|
-
import type { DateLib } from "../types/index.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Generate a series of 7 days, starting from the week, to use for formatting
|
|
@@ -18,7 +17,11 @@ export function getWeekdays(
|
|
|
18
17
|
/** @ignore */
|
|
19
18
|
dateLib: DateLib = defaultDateLib
|
|
20
19
|
): Date[] {
|
|
21
|
-
const date = timeZone
|
|
20
|
+
const date = timeZone
|
|
21
|
+
? TZDate.tz(timeZone)
|
|
22
|
+
: dateLib.Date
|
|
23
|
+
? new dateLib.Date()
|
|
24
|
+
: new Date();
|
|
22
25
|
const start = ISOWeek
|
|
23
26
|
? dateLib.startOfISOWeek(date)
|
|
24
27
|
: dateLib.startOfWeek(date, { locale, weekStartsOn });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DropdownOption } from "../components/Dropdown.js";
|
|
2
|
-
import type { DateLib
|
|
2
|
+
import type { DateLib } from "../lib/dateLib.js";
|
|
3
|
+
import type { Formatters } from "../types/index.js";
|
|
3
4
|
|
|
4
5
|
/** Return the years to show in the dropdown. */
|
|
5
6
|
export function getYearOptions(
|
|
@@ -17,8 +18,7 @@ export function getYearOptions(
|
|
|
17
18
|
endOfYear,
|
|
18
19
|
addYears,
|
|
19
20
|
isBefore,
|
|
20
|
-
isSameYear
|
|
21
|
-
Date
|
|
21
|
+
isSameYear
|
|
22
22
|
} = dateLib;
|
|
23
23
|
const month = displayMonth.getMonth();
|
|
24
24
|
const firstNavYear = startOfYear(calendarStart);
|
|
@@ -32,11 +32,12 @@ export function getYearOptions(
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return years.map((value) => {
|
|
35
|
+
const year = dateLib.Date
|
|
36
|
+
? new dateLib.Date(value, month)
|
|
37
|
+
: new Date(value, month);
|
|
35
38
|
const disabled =
|
|
36
|
-
(calendarStart &&
|
|
37
|
-
(month &&
|
|
38
|
-
calendarEnd &&
|
|
39
|
-
new Date(value, month) > startOfMonth(calendarEnd)) ||
|
|
39
|
+
(calendarStart && year < startOfMonth(calendarStart)) ||
|
|
40
|
+
(month && calendarEnd && year > startOfMonth(calendarEnd)) ||
|
|
40
41
|
false;
|
|
41
42
|
const label = formatters.formatYearDropdown(value);
|
|
42
43
|
return {
|
package/src/labels/labelGrid.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { LabelOptions } from "../lib/dateLib.js";
|
|
1
|
+
import type { LabelOptions, DateLib } from "../lib/dateLib.js";
|
|
2
2
|
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
3
|
-
import { DateLib } from "../types/index.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Return an ARIA label for the month grid, that will be announced when entering
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { LabelOptions } from "../lib/dateLib.js";
|
|
1
|
+
import type { LabelOptions, DateLib } from "../lib/dateLib.js";
|
|
2
2
|
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
3
|
-
import type { DateLib } from "../types/index.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* The ARIA label for the Weekday column header.
|
package/src/lib/dateLib.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { GenericDateConstructor } from "date-fns";
|
|
2
1
|
import type {
|
|
3
2
|
FormatOptions as DateFnsFormatOptions,
|
|
4
3
|
Locale as DateFnsLocale
|
|
@@ -43,6 +42,101 @@ export type Locale = DateFnsLocale;
|
|
|
43
42
|
|
|
44
43
|
export type { Month as DateFnsMonth } from "date-fns";
|
|
45
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The date library used by DayPicker. It's a subset of the date-fns functions
|
|
47
|
+
* plus an optional Date constructor.
|
|
48
|
+
*
|
|
49
|
+
* Override the default date library with the `dateLib` prop.
|
|
50
|
+
*/
|
|
51
|
+
export type DateLib = {
|
|
52
|
+
/** The constructor of the date object. */
|
|
53
|
+
Date?: DateConstructor | undefined;
|
|
54
|
+
|
|
55
|
+
/** Adds the specified number of days to the given date. */
|
|
56
|
+
addDays: typeof addDays;
|
|
57
|
+
|
|
58
|
+
/** Adds the specified number of months to the given date. */
|
|
59
|
+
addMonths: typeof addMonths;
|
|
60
|
+
|
|
61
|
+
/** Adds the specified number of weeks to the given date. */
|
|
62
|
+
addWeeks: typeof addWeeks;
|
|
63
|
+
|
|
64
|
+
/** Adds the specified number of years to the given date. */
|
|
65
|
+
addYears: typeof addYears;
|
|
66
|
+
|
|
67
|
+
/** Returns the number of calendar days between the given dates. */
|
|
68
|
+
differenceInCalendarDays: typeof differenceInCalendarDays;
|
|
69
|
+
|
|
70
|
+
/** Returns the number of calendar months between the given dates. */
|
|
71
|
+
differenceInCalendarMonths: typeof differenceInCalendarMonths;
|
|
72
|
+
|
|
73
|
+
/** Returns the end of an ISO week for the given date. */
|
|
74
|
+
endOfISOWeek: typeof endOfISOWeek;
|
|
75
|
+
|
|
76
|
+
/** Returns the end of the month for the given date. */
|
|
77
|
+
endOfMonth: typeof endOfMonth;
|
|
78
|
+
|
|
79
|
+
/** Returns the end of the week for the given date. */
|
|
80
|
+
endOfWeek: typeof endOfWeek;
|
|
81
|
+
|
|
82
|
+
/** Returns the end of the year for the given date. */
|
|
83
|
+
endOfYear: typeof endOfYear;
|
|
84
|
+
|
|
85
|
+
/** Formats the given date using the specified format string. */
|
|
86
|
+
format: typeof format;
|
|
87
|
+
|
|
88
|
+
/** Returns the ISO week number for the given date. */
|
|
89
|
+
getISOWeek: typeof getISOWeek;
|
|
90
|
+
|
|
91
|
+
/** Returns the week number for the given date. */
|
|
92
|
+
getWeek: typeof getWeek;
|
|
93
|
+
|
|
94
|
+
/** Checks if the first date is after the second date. */
|
|
95
|
+
isAfter: typeof isAfter;
|
|
96
|
+
|
|
97
|
+
/** Checks if the first date is before the second date. */
|
|
98
|
+
isBefore: typeof isBefore;
|
|
99
|
+
|
|
100
|
+
/** Checks if the given value is a date. */
|
|
101
|
+
isDate: typeof isDate;
|
|
102
|
+
|
|
103
|
+
/** Checks if the given dates are the same day. */
|
|
104
|
+
isSameDay: typeof isSameDay;
|
|
105
|
+
|
|
106
|
+
/** Checks if the given dates are in the same month. */
|
|
107
|
+
isSameMonth: typeof isSameMonth;
|
|
108
|
+
|
|
109
|
+
/** Checks if the given dates are in the same year. */
|
|
110
|
+
isSameYear: typeof isSameYear;
|
|
111
|
+
|
|
112
|
+
/** Returns the maximum of the given dates. */
|
|
113
|
+
max: typeof max;
|
|
114
|
+
|
|
115
|
+
/** Returns the minimum of the given dates. */
|
|
116
|
+
min: typeof min;
|
|
117
|
+
|
|
118
|
+
/** Sets the month for the given date. */
|
|
119
|
+
setMonth: typeof setMonth;
|
|
120
|
+
|
|
121
|
+
/** Sets the year for the given date. */
|
|
122
|
+
setYear: typeof setYear;
|
|
123
|
+
|
|
124
|
+
/** Returns the start of the day for the given date. */
|
|
125
|
+
startOfDay: typeof startOfDay;
|
|
126
|
+
|
|
127
|
+
/** Returns the start of an ISO week for the given date. */
|
|
128
|
+
startOfISOWeek: typeof startOfISOWeek;
|
|
129
|
+
|
|
130
|
+
/** Returns the start of the month for the given date. */
|
|
131
|
+
startOfMonth: typeof startOfMonth;
|
|
132
|
+
|
|
133
|
+
/** Returns the start of the week for the given date. */
|
|
134
|
+
startOfWeek: typeof startOfWeek;
|
|
135
|
+
|
|
136
|
+
/** Returns the start of the year for the given date. */
|
|
137
|
+
startOfYear: typeof startOfYear;
|
|
138
|
+
};
|
|
139
|
+
|
|
46
140
|
/**
|
|
47
141
|
* The default date library to use with the date picker.
|
|
48
142
|
*
|
|
@@ -50,8 +144,6 @@ export type { Month as DateFnsMonth } from "date-fns";
|
|
|
50
144
|
* @internal
|
|
51
145
|
*/
|
|
52
146
|
export const dateLib = {
|
|
53
|
-
/** The constructor of the date object. */
|
|
54
|
-
Date: Date as GenericDateConstructor<Date>,
|
|
55
147
|
addDays,
|
|
56
148
|
addMonths,
|
|
57
149
|
addWeeks,
|
package/src/types/props.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import type { DeprecatedUI } from "../UI.js";
|
|
4
|
-
import type { Locale } from "../lib/dateLib.js";
|
|
4
|
+
import type { Locale, DateLib } from "../lib/dateLib.js";
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
7
|
ClassNames,
|
|
@@ -16,8 +16,7 @@ import type {
|
|
|
16
16
|
DayEventHandler,
|
|
17
17
|
Modifiers,
|
|
18
18
|
DateRange,
|
|
19
|
-
Mode
|
|
20
|
-
DateLib
|
|
19
|
+
Mode
|
|
21
20
|
} from "./shared.js";
|
|
22
21
|
|
|
23
22
|
/**
|
|
@@ -353,8 +352,8 @@ export interface PropsBase {
|
|
|
353
352
|
/** Add the language tag to the container element. */
|
|
354
353
|
lang?: HTMLDivElement["lang"];
|
|
355
354
|
/**
|
|
356
|
-
* The locale object used to localize dates. Pass a locale from
|
|
357
|
-
* localize the calendar.
|
|
355
|
+
* The locale object used to localize dates. Pass a locale from
|
|
356
|
+
* `react-day-picker/locale` to localize the calendar.
|
|
358
357
|
*
|
|
359
358
|
* @example
|
|
360
359
|
* import { es } from "react-day-picker/locale";
|
|
@@ -362,6 +361,7 @@ export interface PropsBase {
|
|
|
362
361
|
*
|
|
363
362
|
* @defaultValue enUS - The English locale default of `date-fns`.
|
|
364
363
|
* @see https://daypicker.dev/docs/localization
|
|
364
|
+
* @see https://github.com/date-fns/date-fns/tree/main/src/locale for a list of the supported locales
|
|
365
365
|
*/
|
|
366
366
|
locale?: Partial<Locale> | undefined;
|
|
367
367
|
/**
|
|
@@ -485,7 +485,16 @@ export interface PropsBase {
|
|
|
485
485
|
onDayTouchStart?: DayEventHandler<React.TouchEvent>;
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
/**
|
|
488
|
+
/**
|
|
489
|
+
* Shared handler type for `onSelect` callback when a selection mode is set.
|
|
490
|
+
*
|
|
491
|
+
* @template T - The type of the selected item.
|
|
492
|
+
* @callback OnSelectHandler
|
|
493
|
+
* @param {T} selected - The selected item after the event.
|
|
494
|
+
* @param {Date} triggerDate - The date when the event was triggered.
|
|
495
|
+
* @param {Modifiers} modifiers - The modifiers associated with the event.
|
|
496
|
+
* @param {React.MouseEvent | React.KeyboardEvent} e - The event object.
|
|
497
|
+
*/
|
|
489
498
|
export type OnSelectHandler<T> = (
|
|
490
499
|
selected: T,
|
|
491
500
|
triggerDate: Date,
|
package/src/types/selection.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DayPickerProps } from "./props.js";
|
|
2
|
-
import type { DateRange, Modifiers } from "./shared.js";
|
|
2
|
+
import type { DateRange, Mode, Modifiers } from "./shared.js";
|
|
3
3
|
|
|
4
4
|
export type Selection<T extends DayPickerProps> = {
|
|
5
5
|
/** The selected date(s). */
|
|
@@ -25,25 +25,28 @@ export type SelectedValue<T> = T extends { mode: "single"; required?: boolean }
|
|
|
25
25
|
? SelectedRange<T>
|
|
26
26
|
: undefined;
|
|
27
27
|
|
|
28
|
-
export type SelectHandlerSingle<T extends
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export type SelectHandlerSingle<T extends { required?: boolean | undefined }> =
|
|
29
|
+
(
|
|
30
|
+
triggerDate: Date,
|
|
31
|
+
modifiers: Modifiers,
|
|
32
|
+
e: React.MouseEvent | React.KeyboardEvent
|
|
33
|
+
) => T["required"] extends true ? Date : Date | undefined;
|
|
33
34
|
|
|
34
|
-
export type SelectHandlerMulti<T extends
|
|
35
|
+
export type SelectHandlerMulti<T extends { required?: boolean | undefined }> = (
|
|
35
36
|
triggerDate: Date,
|
|
36
37
|
modifiers: Modifiers,
|
|
37
38
|
e: React.MouseEvent | React.KeyboardEvent
|
|
38
39
|
) => T["required"] extends true ? Date[] : Date[] | undefined;
|
|
39
40
|
|
|
40
|
-
export type SelectHandlerRange<T extends
|
|
41
|
+
export type SelectHandlerRange<T extends { required?: boolean | undefined }> = (
|
|
41
42
|
triggerDate: Date,
|
|
42
43
|
modifiers: Modifiers,
|
|
43
44
|
e: React.MouseEvent | React.KeyboardEvent
|
|
44
45
|
) => T["required"] extends true ? DateRange : DateRange | undefined;
|
|
45
46
|
|
|
46
|
-
export type SelectHandler<
|
|
47
|
+
export type SelectHandler<
|
|
48
|
+
T extends { mode?: Mode | undefined; required?: boolean | undefined }
|
|
49
|
+
> = T extends {
|
|
47
50
|
mode: "single";
|
|
48
51
|
}
|
|
49
52
|
? SelectHandlerSingle<T>
|