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/types/shared.ts
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
labelWeekNumberHeader,
|
|
27
27
|
labelYearDropdown
|
|
28
28
|
} from "../labels/index.js";
|
|
29
|
-
import { dateLib } from "../lib/index.js";
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
31
|
* Selection modes supported by DayPicker.
|
|
@@ -104,9 +103,6 @@ export type CustomComponents = {
|
|
|
104
103
|
YearsDropdown: typeof components.YearsDropdown;
|
|
105
104
|
};
|
|
106
105
|
|
|
107
|
-
/** @private */
|
|
108
|
-
export type DateLib = typeof dateLib;
|
|
109
|
-
|
|
110
106
|
/** Represent a map of formatters used to render localized content. */
|
|
111
107
|
export type Formatters = {
|
|
112
108
|
/** Format the caption of a month grid. */
|
|
@@ -323,15 +319,27 @@ export type Styles = {
|
|
|
323
319
|
};
|
|
324
320
|
|
|
325
321
|
/**
|
|
326
|
-
*
|
|
322
|
+
* Represents the modifiers that match a specific day in the calendar.
|
|
323
|
+
*
|
|
324
|
+
* - Retrieve modifiers using the {@link OnSelectHandler} via the `onSelect` prop,
|
|
325
|
+
* or within custom components using the {@link useDayPicker} hook.
|
|
326
|
+
* - Includes built-in modifiers from {@link DayFlag} and {@link SelectionState}.
|
|
327
|
+
* - Add custom modifiers using the `modifiers` prop.
|
|
327
328
|
*
|
|
328
329
|
* @example
|
|
329
330
|
* const modifiers: Modifiers = {
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
331
|
+
* today: false, // the day is not today
|
|
332
|
+
* selected: true, // the day is selected
|
|
333
|
+
* disabled: false, // the day is not disabled
|
|
334
|
+
* outside: false, // the day is not outside the month
|
|
335
|
+
* focused: false, // the day is not focused
|
|
336
|
+
*
|
|
337
|
+
* weekend: false // custom modifier example for matching a weekend
|
|
338
|
+
* booked: true // custom modifier example for matching a booked day
|
|
339
|
+
* available: false // custom modifier example for matching an available day
|
|
334
340
|
* };
|
|
341
|
+
*
|
|
342
|
+
* @see https://daypicker.dev/guides/custom-modifiers
|
|
335
343
|
*/
|
|
336
344
|
export type Modifiers = Record<string, boolean>;
|
|
337
345
|
|
package/src/useCalendar.ts
CHANGED
|
@@ -15,8 +15,8 @@ import { getNextMonth } from "./helpers/getNextMonth.js";
|
|
|
15
15
|
import { getPreviousMonth } from "./helpers/getPreviousMonth.js";
|
|
16
16
|
import { getWeeks } from "./helpers/getWeeks.js";
|
|
17
17
|
import { useControlledValue } from "./helpers/useControlledValue.js";
|
|
18
|
+
import type { DateLib } from "./lib/index.js";
|
|
18
19
|
import type { DayPickerProps } from "./types/props.js";
|
|
19
|
-
import type { DateLib } from "./types/shared.js";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Return the calendar object to work with the calendar in custom components.
|
package/src/useDayPicker.ts
CHANGED
|
@@ -2,23 +2,37 @@ import { createContext, useContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { CalendarDay } from "./classes/CalendarDay.js";
|
|
4
4
|
import { CalendarMonth } from "./classes/CalendarMonth.js";
|
|
5
|
-
import type { DayPickerProps } from "./types/props.js";
|
|
6
5
|
import type { SelectedValue, SelectHandler } from "./types/selection.js";
|
|
7
6
|
import {
|
|
8
7
|
ClassNames,
|
|
9
8
|
CustomComponents,
|
|
10
9
|
Formatters,
|
|
11
10
|
Labels,
|
|
11
|
+
Mode,
|
|
12
12
|
Modifiers,
|
|
13
13
|
Styles
|
|
14
14
|
} from "./types/shared.js";
|
|
15
15
|
|
|
16
16
|
/** @private */
|
|
17
17
|
export const dayPickerContext = createContext<
|
|
18
|
-
DayPickerContext<
|
|
18
|
+
| DayPickerContext<{
|
|
19
|
+
mode?: Mode | undefined;
|
|
20
|
+
required?: boolean | undefined;
|
|
21
|
+
}>
|
|
22
|
+
| undefined
|
|
19
23
|
>(undefined);
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Represents the context for the DayPicker component, providing various
|
|
27
|
+
* properties and methods to interact with the calendar.
|
|
28
|
+
*
|
|
29
|
+
* @template T - The type of the DayPicker props, which must optionally include
|
|
30
|
+
* `mode` and `required` properties. This type can be used to refine the type
|
|
31
|
+
* returned by the hook.
|
|
32
|
+
*/
|
|
33
|
+
export type DayPickerContext<
|
|
34
|
+
T extends { mode?: Mode | undefined; required?: boolean | undefined }
|
|
35
|
+
> = {
|
|
22
36
|
/** The months displayed in the calendar. */
|
|
23
37
|
months: CalendarMonth[];
|
|
24
38
|
/** The next month to display. */
|
|
@@ -48,15 +62,25 @@ export type DayPickerContext<T extends DayPickerProps> = {
|
|
|
48
62
|
};
|
|
49
63
|
|
|
50
64
|
/**
|
|
51
|
-
*
|
|
65
|
+
* Returns the context to work with `<DayPicker />` inside custom components.
|
|
66
|
+
*
|
|
67
|
+
* This hook provides access to the DayPicker context, which includes various
|
|
68
|
+
* properties and methods to interact with the DayPicker component. It must be
|
|
69
|
+
* used within a custom component.
|
|
52
70
|
*
|
|
71
|
+
* @template T - Use this type to refine the returned context type with a
|
|
72
|
+
* specific selection mode.
|
|
73
|
+
* @returns {DayPickerContext<T>} The context to work with DayPicker.
|
|
74
|
+
* @throws {Error} If the hook is used outside of a DayPicker provider.
|
|
53
75
|
* @group Hooks
|
|
54
76
|
* @see https://daypicker.dev/guides/custom-components
|
|
55
77
|
*/
|
|
56
|
-
export function useDayPicker<
|
|
78
|
+
export function useDayPicker<
|
|
79
|
+
T extends { mode?: Mode | undefined; required?: boolean | undefined }
|
|
80
|
+
>(): DayPickerContext<T> {
|
|
57
81
|
const context = useContext(dayPickerContext);
|
|
58
82
|
if (context === undefined) {
|
|
59
83
|
throw new Error("useDayPicker() must be used within a custom component.");
|
|
60
84
|
}
|
|
61
|
-
return context
|
|
85
|
+
return context;
|
|
62
86
|
}
|
package/src/useFocus.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { useState } from "react";
|
|
|
3
3
|
import type { CalendarDay } from "./classes/index.js";
|
|
4
4
|
import { calculateFocusTarget } from "./helpers/calculateFocusTarget.js";
|
|
5
5
|
import { getNextFocus } from "./helpers/getNextFocus.js";
|
|
6
|
+
import type { DateLib } from "./lib/index.js";
|
|
6
7
|
import type {
|
|
7
8
|
MoveFocusBy,
|
|
8
9
|
MoveFocusDir,
|
|
9
|
-
DateLib,
|
|
10
10
|
DayPickerProps,
|
|
11
11
|
Modifiers
|
|
12
12
|
} from "./types/index.js";
|
package/src/useGetModifiers.tsx
CHANGED
|
@@ -2,7 +2,8 @@ import { TZDate } from "@date-fns/tz";
|
|
|
2
2
|
|
|
3
3
|
import { DayFlag, SelectionState } from "./UI.js";
|
|
4
4
|
import { CalendarDay } from "./classes/index.js";
|
|
5
|
-
import type { DateLib
|
|
5
|
+
import type { DateLib } from "./lib/index.js";
|
|
6
|
+
import type { DayPickerProps, Modifiers } from "./types/index.js";
|
|
6
7
|
import { dateMatchModifiers } from "./utils/dateMatchModifiers.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -51,7 +52,12 @@ export function useGetModifiers(
|
|
|
51
52
|
|
|
52
53
|
const isToday = isSameDay(
|
|
53
54
|
date,
|
|
54
|
-
today ??
|
|
55
|
+
today ??
|
|
56
|
+
(props.timeZone
|
|
57
|
+
? TZDate.tz(props.timeZone)
|
|
58
|
+
: dateLib.Date
|
|
59
|
+
? new dateLib.Date()
|
|
60
|
+
: new Date())
|
|
55
61
|
);
|
|
56
62
|
|
|
57
63
|
if (isOutside) internalModifiersMap.outside.push(day);
|
package/src/useSelection.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type DateLib } from "./lib/index.js";
|
|
1
2
|
import { useMulti } from "./selection/useMulti.js";
|
|
2
3
|
import { useRange } from "./selection/useRange.js";
|
|
3
4
|
import { useSingle } from "./selection/useSingle.js";
|
|
4
|
-
import type {
|
|
5
|
+
import type { DayPickerProps } from "./types/index.js";
|
|
5
6
|
import { Selection } from "./types/selection.js";
|
|
6
7
|
|
|
7
8
|
export function useSelection<T extends DayPickerProps>(
|
package/src/utils/addToRange.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
2
|
-
import type { DateRange
|
|
1
|
+
import { dateLib as defaultDateLib, type DateLib } from "../lib/index.js";
|
|
2
|
+
import type { DateRange } from "../types/index.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Add a day to an existing range.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dateLib as defaultDateLib } from "../lib/dateLib.js";
|
|
2
|
-
import type {
|
|
1
|
+
import { dateLib as defaultDateLib, type DateLib } from "../lib/dateLib.js";
|
|
2
|
+
import type { Matcher } from "../types/index.js";
|
|
3
3
|
|
|
4
4
|
import { rangeIncludesDate } from "./rangeIncludesDate.js";
|
|
5
5
|
import {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
2
|
-
import type { DateRange
|
|
1
|
+
import { dateLib as defaultDateLib, type DateLib } from "../lib/index.js";
|
|
2
|
+
import type { DateRange } from "../types/index.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Determines whether a given date is inside a specified date range.
|
package/src/utils/typeguards.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
2
|
+
hide_title: true
|
|
3
|
+
title: Code Of Conduct
|
|
4
|
+
sidebar_position: 2
|
|
3
5
|
---
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
import CodeOfConduct from "../../../.github/CODE_OF_CONDUCT.md";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This documentation is still a work in progress. If you have any questions, ask to the [discussions](https://github.com/gpbl/react-day-picker/discussions) page on Github.
|
|
10
|
-
|
|
11
|
-
:::
|
|
9
|
+
<CodeOfConduct />
|
|
@@ -12,21 +12,14 @@ Learn how to set the locale, changing the time zone, and adjust other calendar o
|
|
|
12
12
|
| --------- | ------------------------------------------ | ----------------------------------- |
|
|
13
13
|
| `locale` | [`Locale`](https://date-fns.org/docs/I18n) | Set the locale. Default is `en-US`. |
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```bash ts
|
|
18
|
-
// import the locale object
|
|
19
|
-
import { es } from "react-day-picker/locale";
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
By default, the locale is set to English (US). To localize the calendar, pass the imported [`Locale`](https://date-fns.org/docs/I18n) object to the `locale` prop.
|
|
23
|
-
|
|
24
|
-
For example, to localize the calendar in Spanish, import the `es` locale object from `date-fns` and pass it to the component.
|
|
15
|
+
To set a different locale, import the locale object from `react-day-picker/locale`and pass it to the`locale` prop.
|
|
25
16
|
|
|
26
17
|
```tsx
|
|
18
|
+
// import the locale object
|
|
27
19
|
import { es } from "react-day-picker/locale";
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
// use the locale object
|
|
22
|
+
<DayPicker locale={es} />;
|
|
30
23
|
```
|
|
31
24
|
|
|
32
25
|
<BrowserWindow>
|
|
@@ -56,16 +49,16 @@ import { DayPicker, defaultLocale } from "react-day-picker";
|
|
|
56
49
|
|
|
57
50
|
## Changing the Time Zone {#time-zone}
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
| ---------- | -------- | ---------------------------------------------- |
|
|
61
|
-
| `timeZone` | `string` | Set a time zone for the dates in the calendar. |
|
|
62
|
-
|
|
63
|
-
:::warning Experimental Feature
|
|
52
|
+
:::warning Experimental Feature (since v9.1.1)
|
|
64
53
|
|
|
65
|
-
|
|
54
|
+
DayPicker supports time zones through the `date-fns` library. For more information, refer to the [date-fns time zones documentation](https://date-fns.org/v4.1.0/docs/Time-Zones). If you encounter any issues, please [report them on GitHub](https://github.com/gpbl/react-day-picker/issues). Thank you!
|
|
66
55
|
|
|
67
56
|
:::
|
|
68
57
|
|
|
58
|
+
| Prop Name | Type | Description |
|
|
59
|
+
| ---------- | -------- | ---------------------------------------------- |
|
|
60
|
+
| `timeZone` | `string` | Set a time zone for the dates in the calendar. |
|
|
61
|
+
|
|
69
62
|
Use the `timeZone` prop to set a different time zone for the calendar. See [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
70
63
|
for a list of the possible values.
|
|
71
64
|
|
|
@@ -82,13 +75,15 @@ for a list of the possible values.
|
|
|
82
75
|
|
|
83
76
|
When working with time zones, make sure to use the `TZDate` object instead of the native `Date` object. The `TZDate` object is exported from [@date-fns/tz](https://github.com/date-fns/date-fns-tz). Refer to their documentation for more information.
|
|
84
77
|
|
|
85
|
-
To initialize a date in a specific time zone,
|
|
78
|
+
- To initialize a date in a specific time zone, create a `new TZDate()` object or the `TZDate.tz`.
|
|
86
79
|
|
|
87
80
|
```tsx
|
|
81
|
+
import { DayPicker, TZDate } from "react-day-picker";
|
|
82
|
+
|
|
88
83
|
export function TimeZone() {
|
|
89
84
|
const timeZone = "America/New_York";
|
|
90
85
|
const [selected, setSelected] = useState<Date | undefined>(
|
|
91
|
-
TZDate
|
|
86
|
+
new TZDate(2024, 12, 10, timeZone) // Make sure you use `TZDate` instead of `Date`
|
|
92
87
|
);
|
|
93
88
|
return (
|
|
94
89
|
<DayPicker
|
|
@@ -103,30 +98,29 @@ export function TimeZone() {
|
|
|
103
98
|
|
|
104
99
|
## Calendar Options
|
|
105
100
|
|
|
106
|
-
| Prop Name | Type | Description
|
|
107
|
-
| ----------------------- | --------------------------------------------- |
|
|
108
|
-
| `weekStartsOn` | `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` |
|
|
109
|
-
| `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year.
|
|
110
|
-
| `ISOWeek` | `boolean` |
|
|
101
|
+
| Prop Name | Type | Description |
|
|
102
|
+
| ----------------------- | --------------------------------------------- | ------------------------------------------------------------------------ |
|
|
103
|
+
| `weekStartsOn` | `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` | Change the first day of the week. |
|
|
104
|
+
| `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year. |
|
|
105
|
+
| `ISOWeek` | `boolean` | Switch to [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date). |
|
|
111
106
|
|
|
112
107
|
### First Date of the Week
|
|
113
108
|
|
|
114
109
|
Use the `weekStartsOn` prop to set the first day of the week.
|
|
115
110
|
|
|
116
111
|
```tsx
|
|
117
|
-
<DayPicker
|
|
112
|
+
<DayPicker weekStartsOn={0} /> // Start the week on Sunday
|
|
118
113
|
```
|
|
119
114
|
|
|
120
115
|
<BrowserWindow>
|
|
121
|
-
<Examples.
|
|
116
|
+
<Examples.WeekStartsOn />
|
|
122
117
|
</BrowserWindow>
|
|
123
118
|
|
|
124
119
|
### First Week Contains Date
|
|
125
120
|
|
|
126
|
-
The `firstWeekContainsDate` prop sets the first day of the year's initial week, which is used to calculate week numbers.
|
|
121
|
+
The `firstWeekContainsDate` prop sets the first day of the year's initial week, which is used to calculate week numbers. Acceptable values are `1` for Monday and `4` for Thursday.
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
- For more information, see [Week Numbering](https://en.wikipedia.org/wiki/Week#Numbering) and the [getWeek function](https://date-fns.org/docs/getWeek).
|
|
123
|
+
For more information, see [Week Numbering](https://en.wikipedia.org/wiki/Week#Numbering) on Wikipedia and the [getWeek function](https://date-fns.org/docs/getWeek) from `date-fns`.
|
|
130
124
|
|
|
131
125
|
```tsx
|
|
132
126
|
<DayPicker
|
|
@@ -18,7 +18,7 @@ The `mode` prop determines the selection mode. Use the `disabled` prop to preven
|
|
|
18
18
|
| `disabled` | [`Matcher`](../api/type-aliases/Matcher.md) \| `Matcher[]` | Disabled days that cannot be selected. |
|
|
19
19
|
| `selected` | `Date` \| `Date[]` \| [`DateRange`](../api/type-aliases/DateRange.md) \| `undefined` | The selected day(s). |
|
|
20
20
|
| `required` | `boolean` | When `true`, the selection is required. |
|
|
21
|
-
| `onSelect` | `(
|
|
21
|
+
| `onSelect` | [`OnSelectHandler`](../api/type-aliases/OnSelectHandler.md) | Event callback when a date is selected. |
|
|
22
22
|
|
|
23
23
|
## Single Mode
|
|
24
24
|
|
|
@@ -34,11 +34,11 @@ When the `mode` prop is set to `"single"`, only one day can be selected at a tim
|
|
|
34
34
|
|
|
35
35
|
### Single Mode Props
|
|
36
36
|
|
|
37
|
-
| Prop Name | Type
|
|
38
|
-
| ---------- |
|
|
39
|
-
| `selected` | `Date \| undefined`
|
|
40
|
-
| `onSelect` | `
|
|
41
|
-
| `required` | `boolean`
|
|
37
|
+
| Prop Name | Type | Description |
|
|
38
|
+
| ---------- | ------------------------------------------------------------------------------ | --------------------------------------- |
|
|
39
|
+
| `selected` | `Date \| undefined` | The selected date. |
|
|
40
|
+
| `onSelect` | [`OnSelectHandler<Date \| undefined>`](../api/type-aliases/OnSelectHandler.md) | Event callback when a date is selected. |
|
|
41
|
+
| `required` | `boolean` | Make the selection required. |
|
|
42
42
|
|
|
43
43
|
### Controlled Selections
|
|
44
44
|
|
|
@@ -81,13 +81,13 @@ Set the `mode` prop to `"multiple"` to enable the selection of multiple days in
|
|
|
81
81
|
|
|
82
82
|
### Multiple Mode Props
|
|
83
83
|
|
|
84
|
-
| Prop Name | Type
|
|
85
|
-
| ---------- |
|
|
86
|
-
| `selected` | `Date[] \| undefined`
|
|
87
|
-
| `onSelect` | `
|
|
88
|
-
| `min` | `number`
|
|
89
|
-
| `max` | `number`
|
|
90
|
-
| `required` | `boolean`
|
|
84
|
+
| Prop Name | Type | Description |
|
|
85
|
+
| ---------- | -------------------------------------------------------------------------------- | --------------------------------------- |
|
|
86
|
+
| `selected` | `Date[] \| undefined` | The selected dates. |
|
|
87
|
+
| `onSelect` | [`OnSelectHandler<Date[] \| undefined>`](../api/type-aliases/OnSelectHandler.md) | Event callback when a date is selected. |
|
|
88
|
+
| `min` | `number` | The minimum dates that can be selected. |
|
|
89
|
+
| `max` | `number` | The maximum dates that can be selected. |
|
|
90
|
+
| `required` | `boolean` | Make the selection required. |
|
|
91
91
|
|
|
92
92
|
Use the `selected` and `onSelect` props to manage the selected date:
|
|
93
93
|
|
|
@@ -139,14 +139,14 @@ Set the `mode` prop to `"range"` to enable the selection of a continuous range o
|
|
|
139
139
|
|
|
140
140
|
### Range Mode Props
|
|
141
141
|
|
|
142
|
-
| Prop Name | Type
|
|
143
|
-
| ----------------- |
|
|
144
|
-
| `selected` | [`DateRange`](../api/type-aliases/DateRange.md)
|
|
145
|
-
| `onSelect` | `
|
|
146
|
-
| `required` | `boolean`
|
|
147
|
-
| `min` | `number`
|
|
148
|
-
| `max` | `number`
|
|
149
|
-
| `excludeDisabled` | `boolean`
|
|
142
|
+
| Prop Name | Type | Description |
|
|
143
|
+
| ----------------- | ----------------------------------------------------------------------------------- | --------------------------------------- |
|
|
144
|
+
| `selected` | [`DateRange`](../api/type-aliases/DateRange.md) | The selected range. |
|
|
145
|
+
| `onSelect` | [`OnSelectHandler<DateRange \| undefined>`](../api/type-aliases/OnSelectHandler.md) | Event callback when a date is selected. |
|
|
146
|
+
| `required` | `boolean` | Make the selection required. |
|
|
147
|
+
| `min` | `number` | The minimum dates that can be selected. |
|
|
148
|
+
| `max` | `number` | The maximum dates that can be selected. |
|
|
149
|
+
| `excludeDisabled` | `boolean` | Exclude disabled dates from the range. |
|
|
150
150
|
|
|
151
151
|
### Min and Max Dates
|
|
152
152
|
|
|
@@ -22,13 +22,13 @@ When customizing components, familiarize yourself with the [API Reference](../ap
|
|
|
22
22
|
|
|
23
23
|
:::note Custom Components vs Formatters
|
|
24
24
|
|
|
25
|
-
Custom components
|
|
25
|
+
Custom components allow you to extend DayPicker beyond just using [formatters](../docs/translation.mdx#custom-formatters). While formatters modify the content within the calendar, custom components enable you to alter the structure of the HTML elements.
|
|
26
26
|
|
|
27
27
|
:::
|
|
28
28
|
|
|
29
29
|
## Implementing a Custom Component
|
|
30
30
|
|
|
31
|
-
Pass the components
|
|
31
|
+
Pass the components to customize to the `components` prop. See the [list of custom components](#list-of-custom-components) below.
|
|
32
32
|
|
|
33
33
|
```tsx
|
|
34
34
|
<DayPicker
|
|
@@ -72,12 +72,6 @@ Pass the components you want to customize to the `components` prop. See the [lis
|
|
|
72
72
|
|
|
73
73
|
## Examples
|
|
74
74
|
|
|
75
|
-
:::note
|
|
76
|
-
|
|
77
|
-
We are adding new examples soon. What are you using custom components for? [Let us know](https://github.com/gpbl/react-day-picker/discussions).
|
|
78
|
-
|
|
79
|
-
:::
|
|
80
|
-
|
|
81
75
|
### Intercepting Click Events
|
|
82
76
|
|
|
83
77
|
For example, you can use a custom [DayButton](../api/functions/DayButton.md) to select days with a double-click event.
|
|
@@ -118,9 +112,15 @@ export function MyDatePicker() {
|
|
|
118
112
|
<Examples.CustomDayButton />
|
|
119
113
|
</BrowserWindow>
|
|
120
114
|
|
|
115
|
+
What are you using custom components for? [Let us know](https://github.com/gpbl/react-day-picker/discussions).
|
|
116
|
+
|
|
121
117
|
## DayPicker Hook
|
|
122
118
|
|
|
123
|
-
In a custom component,
|
|
119
|
+
In a custom component, import the `useDayPicker` hook to access the DayPicker context.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { useDayPicker } from "react-day-picker";
|
|
123
|
+
```
|
|
124
124
|
|
|
125
125
|
| Function | Return value | Description |
|
|
126
126
|
| :------------------------------------------------- | ------------------------------------------------------------- | :--------------------------------------------------------------------------- |
|
|
@@ -128,7 +128,7 @@ In a custom component, you can use the [`useDayPicker`](../api/functions/useDayP
|
|
|
128
128
|
|
|
129
129
|
### DayPicker Context
|
|
130
130
|
|
|
131
|
-
The
|
|
131
|
+
The DayPicker context provides the current state of the calendar, including the selected days, modifiers, and navigation state.
|
|
132
132
|
|
|
133
133
|
| Name | Type | Description |
|
|
134
134
|
| --------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- |
|