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.
Files changed (197) hide show
  1. package/README.md +8 -8
  2. package/dist/cjs/DayPicker.js +10 -10
  3. package/dist/cjs/DayPicker.js.map +1 -1
  4. package/dist/cjs/classes/CalendarDay.d.ts +1 -1
  5. package/dist/cjs/classes/CalendarDay.js.map +1 -1
  6. package/dist/cjs/components/WeekNumber.d.ts +1 -1
  7. package/dist/cjs/components/WeekNumber.js +2 -2
  8. package/dist/cjs/formatters/formatCaption.d.ts +1 -2
  9. package/dist/cjs/formatters/formatCaption.js.map +1 -1
  10. package/dist/cjs/formatters/formatDay.d.ts +1 -2
  11. package/dist/cjs/formatters/formatDay.js.map +1 -1
  12. package/dist/cjs/formatters/formatWeekdayName.d.ts +1 -2
  13. package/dist/cjs/formatters/formatWeekdayName.js.map +1 -1
  14. package/dist/cjs/helpers/getDateLib.d.ts +2 -1
  15. package/dist/cjs/helpers/getDateLib.js.map +1 -1
  16. package/dist/cjs/helpers/getDates.js +2 -2
  17. package/dist/cjs/helpers/getDates.js.map +1 -1
  18. package/dist/cjs/helpers/getDisplayMonths.d.ts +2 -1
  19. package/dist/cjs/helpers/getDisplayMonths.js.map +1 -1
  20. package/dist/cjs/helpers/getFocusableDate.d.ts +2 -1
  21. package/dist/cjs/helpers/getInitialMonth.js +5 -1
  22. package/dist/cjs/helpers/getInitialMonth.js.map +1 -1
  23. package/dist/cjs/helpers/getMonthOptions.d.ts +2 -2
  24. package/dist/cjs/helpers/getMonthOptions.js +6 -3
  25. package/dist/cjs/helpers/getMonthOptions.js.map +1 -1
  26. package/dist/cjs/helpers/getMonths.d.ts +2 -1
  27. package/dist/cjs/helpers/getMonths.js.map +1 -1
  28. package/dist/cjs/helpers/getNavMonth.d.ts +3 -2
  29. package/dist/cjs/helpers/getNavMonth.js +11 -3
  30. package/dist/cjs/helpers/getNavMonth.js.map +1 -1
  31. package/dist/cjs/helpers/getNextFocus.d.ts +2 -1
  32. package/dist/cjs/helpers/getNextMonth.d.ts +2 -1
  33. package/dist/cjs/helpers/getNextMonth.js.map +1 -1
  34. package/dist/cjs/helpers/getPreviousMonth.d.ts +2 -1
  35. package/dist/cjs/helpers/getPreviousMonth.js.map +1 -1
  36. package/dist/cjs/helpers/getWeekdays.d.ts +1 -2
  37. package/dist/cjs/helpers/getWeekdays.js +5 -1
  38. package/dist/cjs/helpers/getWeekdays.js.map +1 -1
  39. package/dist/cjs/helpers/getYearOptions.d.ts +2 -1
  40. package/dist/cjs/helpers/getYearOptions.js +6 -5
  41. package/dist/cjs/helpers/getYearOptions.js.map +1 -1
  42. package/dist/cjs/labels/labelGrid.d.ts +1 -2
  43. package/dist/cjs/labels/labelGrid.js.map +1 -1
  44. package/dist/cjs/labels/labelWeekday.d.ts +1 -2
  45. package/dist/cjs/labels/labelWeekday.js.map +1 -1
  46. package/dist/cjs/lib/dateLib.d.ts +66 -3
  47. package/dist/cjs/lib/dateLib.js +0 -2
  48. package/dist/cjs/lib/dateLib.js.map +1 -1
  49. package/dist/cjs/selection/useMulti.d.ts +2 -1
  50. package/dist/cjs/selection/useRange.d.ts +2 -1
  51. package/dist/cjs/selection/useSingle.d.ts +2 -1
  52. package/dist/cjs/types/props.d.ts +15 -5
  53. package/dist/cjs/types/selection.d.ts +14 -5
  54. package/dist/cjs/types/shared.d.ts +17 -8
  55. package/dist/cjs/useCalendar.d.ts +1 -1
  56. package/dist/cjs/useDayPicker.d.ts +30 -6
  57. package/dist/cjs/useDayPicker.js +10 -2
  58. package/dist/cjs/useDayPicker.js.map +1 -1
  59. package/dist/cjs/useFocus.d.ts +2 -1
  60. package/dist/cjs/useGetModifiers.d.ts +2 -1
  61. package/dist/cjs/useGetModifiers.js +6 -1
  62. package/dist/cjs/useGetModifiers.js.map +1 -1
  63. package/dist/cjs/useSelection.d.ts +2 -1
  64. package/dist/cjs/useSelection.js.map +1 -1
  65. package/dist/cjs/utils/addToRange.d.ts +2 -1
  66. package/dist/cjs/utils/addToRange.js.map +1 -1
  67. package/dist/cjs/utils/dateMatchModifiers.d.ts +2 -1
  68. package/dist/cjs/utils/dateMatchModifiers.js.map +1 -1
  69. package/dist/cjs/utils/rangeIncludesDate.d.ts +2 -1
  70. package/dist/cjs/utils/rangeIncludesDate.js.map +1 -1
  71. package/dist/cjs/utils/typeguards.d.ts +2 -1
  72. package/dist/esm/DayPicker.js +10 -10
  73. package/dist/esm/DayPicker.js.map +1 -1
  74. package/dist/esm/classes/CalendarDay.d.ts +1 -1
  75. package/dist/esm/classes/CalendarDay.js.map +1 -1
  76. package/dist/esm/components/WeekNumber.d.ts +1 -1
  77. package/dist/esm/components/WeekNumber.js +2 -2
  78. package/dist/esm/formatters/formatCaption.d.ts +1 -2
  79. package/dist/esm/formatters/formatCaption.js.map +1 -1
  80. package/dist/esm/formatters/formatDay.d.ts +1 -2
  81. package/dist/esm/formatters/formatDay.js.map +1 -1
  82. package/dist/esm/formatters/formatWeekdayName.d.ts +1 -2
  83. package/dist/esm/formatters/formatWeekdayName.js.map +1 -1
  84. package/dist/esm/helpers/getDateLib.d.ts +2 -1
  85. package/dist/esm/helpers/getDateLib.js.map +1 -1
  86. package/dist/esm/helpers/getDates.js +2 -2
  87. package/dist/esm/helpers/getDates.js.map +1 -1
  88. package/dist/esm/helpers/getDisplayMonths.d.ts +2 -1
  89. package/dist/esm/helpers/getDisplayMonths.js.map +1 -1
  90. package/dist/esm/helpers/getFocusableDate.d.ts +2 -1
  91. package/dist/esm/helpers/getInitialMonth.js +5 -1
  92. package/dist/esm/helpers/getInitialMonth.js.map +1 -1
  93. package/dist/esm/helpers/getMonthOptions.d.ts +2 -2
  94. package/dist/esm/helpers/getMonthOptions.js +6 -3
  95. package/dist/esm/helpers/getMonthOptions.js.map +1 -1
  96. package/dist/esm/helpers/getMonths.d.ts +2 -1
  97. package/dist/esm/helpers/getMonths.js.map +1 -1
  98. package/dist/esm/helpers/getNavMonth.d.ts +3 -2
  99. package/dist/esm/helpers/getNavMonth.js +11 -3
  100. package/dist/esm/helpers/getNavMonth.js.map +1 -1
  101. package/dist/esm/helpers/getNextFocus.d.ts +2 -1
  102. package/dist/esm/helpers/getNextMonth.d.ts +2 -1
  103. package/dist/esm/helpers/getNextMonth.js.map +1 -1
  104. package/dist/esm/helpers/getPreviousMonth.d.ts +2 -1
  105. package/dist/esm/helpers/getPreviousMonth.js.map +1 -1
  106. package/dist/esm/helpers/getWeekdays.d.ts +1 -2
  107. package/dist/esm/helpers/getWeekdays.js +5 -1
  108. package/dist/esm/helpers/getWeekdays.js.map +1 -1
  109. package/dist/esm/helpers/getYearOptions.d.ts +2 -1
  110. package/dist/esm/helpers/getYearOptions.js +6 -5
  111. package/dist/esm/helpers/getYearOptions.js.map +1 -1
  112. package/dist/esm/labels/labelGrid.d.ts +1 -2
  113. package/dist/esm/labels/labelGrid.js.map +1 -1
  114. package/dist/esm/labels/labelWeekday.d.ts +1 -2
  115. package/dist/esm/labels/labelWeekday.js.map +1 -1
  116. package/dist/esm/lib/dateLib.d.ts +66 -3
  117. package/dist/esm/lib/dateLib.js +0 -2
  118. package/dist/esm/lib/dateLib.js.map +1 -1
  119. package/dist/esm/selection/useMulti.d.ts +2 -1
  120. package/dist/esm/selection/useRange.d.ts +2 -1
  121. package/dist/esm/selection/useSingle.d.ts +2 -1
  122. package/dist/esm/types/props.d.ts +15 -5
  123. package/dist/esm/types/selection.d.ts +14 -5
  124. package/dist/esm/types/shared.d.ts +17 -8
  125. package/dist/esm/useCalendar.d.ts +1 -1
  126. package/dist/esm/useDayPicker.d.ts +30 -6
  127. package/dist/esm/useDayPicker.js +10 -2
  128. package/dist/esm/useDayPicker.js.map +1 -1
  129. package/dist/esm/useFocus.d.ts +2 -1
  130. package/dist/esm/useGetModifiers.d.ts +2 -1
  131. package/dist/esm/useGetModifiers.js +6 -1
  132. package/dist/esm/useGetModifiers.js.map +1 -1
  133. package/dist/esm/useSelection.d.ts +2 -1
  134. package/dist/esm/useSelection.js.map +1 -1
  135. package/dist/esm/utils/addToRange.d.ts +2 -1
  136. package/dist/esm/utils/addToRange.js.map +1 -1
  137. package/dist/esm/utils/dateMatchModifiers.d.ts +2 -1
  138. package/dist/esm/utils/dateMatchModifiers.js.map +1 -1
  139. package/dist/esm/utils/rangeIncludesDate.d.ts +2 -1
  140. package/dist/esm/utils/rangeIncludesDate.js.map +1 -1
  141. package/dist/esm/utils/typeguards.d.ts +2 -1
  142. package/examples/Input.test.tsx +1 -1
  143. package/examples/ModifiersHidden.test.tsx +1 -1
  144. package/examples/Range.test.tsx +1 -1
  145. package/examples/RangeShiftKey.tsx +1 -1
  146. package/examples/SingleMockDate.test.tsx +39 -0
  147. package/examples/WeekStartsOn.tsx +7 -0
  148. package/examples/Weeknumber.test.tsx +2 -2
  149. package/examples/WeeknumberCustom.tsx +2 -2
  150. package/examples/__snapshots__/Range.test.tsx.snap +84 -100
  151. package/examples/__snapshots__/StylingCssModules.test.tsx.snap +42 -50
  152. package/examples/index.ts +1 -0
  153. package/package.json +4 -3
  154. package/src/DayPicker.test.tsx +13 -0
  155. package/src/DayPicker.tsx +4 -8
  156. package/src/classes/CalendarDay.ts +1 -1
  157. package/src/components/WeekNumber.tsx +3 -3
  158. package/src/formatters/formatCaption.ts +5 -2
  159. package/src/formatters/formatDay.ts +1 -2
  160. package/src/formatters/formatWeekdayName.ts +1 -2
  161. package/src/helpers/getDateLib.ts +2 -2
  162. package/src/helpers/getDates.ts +2 -3
  163. package/src/helpers/getDisplayMonths.ts +2 -1
  164. package/src/helpers/getFocusableDate.ts +1 -1
  165. package/src/helpers/getInitialMonth.ts +5 -1
  166. package/src/helpers/getMonthOptions.ts +8 -5
  167. package/src/helpers/getMonths.ts +2 -1
  168. package/src/helpers/getNavMonth.ts +14 -5
  169. package/src/helpers/getNextFocus.tsx +1 -1
  170. package/src/helpers/getNextMonth.ts +2 -1
  171. package/src/helpers/getPreviousMonth.ts +2 -1
  172. package/src/helpers/getWeekdays.ts +6 -3
  173. package/src/helpers/getYearOptions.ts +8 -7
  174. package/src/labels/labelGrid.ts +1 -2
  175. package/src/labels/labelWeekday.ts +1 -2
  176. package/src/lib/dateLib.ts +95 -3
  177. package/src/selection/useMulti.tsx +1 -1
  178. package/src/selection/useRange.tsx +1 -1
  179. package/src/selection/useSingle.tsx +1 -1
  180. package/src/types/props.ts +15 -6
  181. package/src/types/selection.ts +12 -9
  182. package/src/types/shared.ts +17 -9
  183. package/src/useCalendar.ts +1 -1
  184. package/src/useDayPicker.ts +30 -6
  185. package/src/useFocus.ts +1 -1
  186. package/src/useGetModifiers.tsx +8 -2
  187. package/src/useSelection.ts +2 -1
  188. package/src/utils/addToRange.ts +2 -2
  189. package/src/utils/dateMatchModifiers.ts +2 -2
  190. package/src/utils/rangeIncludesDate.ts +2 -2
  191. package/src/utils/typeguards.ts +1 -1
  192. package/website/docs/development/code-of-conduct.md +5 -7
  193. package/website/docs/development/contributing.md +9 -0
  194. package/website/docs/docs/localization.mdx +23 -29
  195. package/website/docs/docs/selection-modes.mdx +21 -21
  196. package/website/docs/guides/custom-components.mdx +10 -10
  197. package/website/docs/development/contributing.mdx +0 -11
@@ -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
- * The modifiers that are matching a day in the calendar.
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
- * today: false, // the day is not today
331
- * selected: true, // the day is selected
332
- * weekend: false // the day is not in the weekend
333
- * // etc
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
 
@@ -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.
@@ -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<DayPickerProps> | undefined
18
+ | DayPickerContext<{
19
+ mode?: Mode | undefined;
20
+ required?: boolean | undefined;
21
+ }>
22
+ | undefined
19
23
  >(undefined);
20
24
 
21
- export type DayPickerContext<T extends DayPickerProps> = {
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
- * Return the context to work with `<DayPicker />` inside custom components.
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<T extends DayPickerProps>(props?: T) {
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 as DayPickerContext<T>;
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";
@@ -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, DayPickerProps, Modifiers } from "./types/index.js";
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 ?? (props.timeZone ? TZDate.tz(props.timeZone) : new dateLib.Date())
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);
@@ -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 { DateLib, DayPickerProps } from "./types/index.js";
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>(
@@ -1,5 +1,5 @@
1
- import { dateLib as defaultDateLib } from "../lib/index.js";
2
- import type { DateRange, DateLib } from "../types/index.js";
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 { DateLib, Matcher } from "../types/index.js";
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, DateLib } from "../types/index.js";
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.
@@ -1,8 +1,8 @@
1
+ import type { DateLib } from "../lib/index.js";
1
2
  import type {
2
3
  DateAfter,
3
4
  DateBefore,
4
5
  DateInterval,
5
- DateLib,
6
6
  DateRange,
7
7
  DayOfWeek
8
8
  } from "../types/index.js";
@@ -1,11 +1,9 @@
1
1
  ---
2
- draft: true
2
+ hide_title: true
3
+ title: Code Of Conduct
4
+ sidebar_position: 2
3
5
  ---
4
6
 
5
- # Code Of Conduct
7
+ import CodeOfConduct from "../../../.github/CODE_OF_CONDUCT.md";
6
8
 
7
- :::info Draft
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 />
@@ -0,0 +1,9 @@
1
+ ---
2
+ hide_title: true
3
+ title: Contributing
4
+ sidebar_position: 1
5
+ ---
6
+
7
+ import Contributing from "../../../CONTRIBUTING.md";
8
+
9
+ <Contributing />
@@ -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
- DayPicker export the [date-fns](https://date-fns.org) locales for easier calendar localization. To set a different locale, import it from `react-day-picker/locale`.
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
- <DayPicker locale={es} />; // Set the locale to Spanish
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
- | Prop Name | Type | Description |
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
- Time zones are supported by the `TZDate` object by the [@date-fns/tz](https://github.com/date-fns/tz) package. If you encounter any issues, please [report them](https://github.com/gpbl/react-day-picker/issues). Thank you!
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, use the `tz` method:
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.tz(timeZone) // Make sure you use `TZDate` instead of `Date`
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` | Display the days falling into the other months. |
109
- | `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year. |
110
- | `ISOWeek` | `boolean` | Use [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date). |
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 locale={es} weekStartsOn={0} /> // Start the week on Domingo
112
+ <DayPicker weekStartsOn={0} /> // Start the week on Sunday
118
113
  ```
119
114
 
120
115
  <BrowserWindow>
121
- <Examples.SpanishWeekStartsOn />
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
- - Acceptable values are `1` for Monday and `4` for Thursday.
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` | `(selected, triggerDate, modifiers, e) => void` | Event callback when a date is selected. |
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 | Description |
38
- | ---------- | ----------------------------------------------- | --------------------------------------- |
39
- | `selected` | `Date \| undefined` | The selected date. |
40
- | `onSelect` | `(selected, triggerDate, modifiers, e) => void` | Event callback when a date is selected. |
41
- | `required` | `boolean` | Make the selection required. |
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 | Description |
85
- | ---------- | ---------------------------------------- | --------------------------------------- |
86
- | `selected` | `Date[] \| undefined` | The selected dates. |
87
- | `onSelect` | `(selected, date, modifiers, e) => void` | 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. |
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 | Description |
143
- | ----------------- | ----------------------------------------------- | --------------------------------------- |
144
- | `selected` | [`DateRange`](../api/type-aliases/DateRange.md) | The selected range. |
145
- | `onSelect` | `(selected, triggerDate, modifiers, e) => void` | 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. |
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 let you extend DayPicker beyond what [formatters](../docs/translation.mdx#custom-formatters) can do. Formatters change the content of the calendar, while custom components can change the structure of the HTML elements..
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 you want to customize to the `components` prop. See the [list of custom components](#list-of-custom-components) below.
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, you can use the [`useDayPicker`](../api/functions/useDayPicker.md) hook to access the DayPicker context.
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 [DayPicker context](../api/type-aliases/DayPickerContext.md) provides the current state of the calendar, including the selected days, modifiers, and navigation state.
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
  | --------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- |
@@ -1,11 +0,0 @@
1
- ---
2
- draft: true
3
- ---
4
-
5
- # Contributing
6
-
7
- :::info Draft
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
- :::