react-day-picker 9.1.0 → 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 (251) hide show
  1. package/README.md +8 -8
  2. package/dist/cjs/DayPicker.js +11 -11
  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.d.ts +1 -1
  17. package/dist/cjs/helpers/getDates.js +3 -3
  18. package/dist/cjs/helpers/getDates.js.map +1 -1
  19. package/dist/cjs/helpers/getDisplayMonths.d.ts +2 -1
  20. package/dist/cjs/helpers/getDisplayMonths.js.map +1 -1
  21. package/dist/cjs/helpers/getFocusableDate.d.ts +2 -1
  22. package/dist/cjs/helpers/getInitialMonth.d.ts +1 -1
  23. package/dist/cjs/helpers/getInitialMonth.js +6 -1
  24. package/dist/cjs/helpers/getInitialMonth.js.map +1 -1
  25. package/dist/cjs/helpers/getMonthOptions.d.ts +2 -2
  26. package/dist/cjs/helpers/getMonthOptions.js +6 -3
  27. package/dist/cjs/helpers/getMonthOptions.js.map +1 -1
  28. package/dist/cjs/helpers/getMonths.d.ts +3 -2
  29. package/dist/cjs/helpers/getMonths.js.map +1 -1
  30. package/dist/cjs/helpers/getNavMonth.d.ts +3 -2
  31. package/dist/cjs/helpers/getNavMonth.js +16 -3
  32. package/dist/cjs/helpers/getNavMonth.js.map +1 -1
  33. package/dist/cjs/helpers/getNextFocus.d.ts +3 -2
  34. package/dist/cjs/helpers/getNextFocus.js.map +1 -1
  35. package/dist/cjs/helpers/getNextMonth.d.ts +2 -1
  36. package/dist/cjs/helpers/getNextMonth.js.map +1 -1
  37. package/dist/cjs/helpers/getPreviousMonth.d.ts +2 -1
  38. package/dist/cjs/helpers/getPreviousMonth.js.map +1 -1
  39. package/dist/cjs/helpers/getWeekdays.d.ts +2 -3
  40. package/dist/cjs/helpers/getWeekdays.js +9 -3
  41. package/dist/cjs/helpers/getWeekdays.js.map +1 -1
  42. package/dist/cjs/helpers/getYearOptions.d.ts +2 -1
  43. package/dist/cjs/helpers/getYearOptions.js +6 -5
  44. package/dist/cjs/helpers/getYearOptions.js.map +1 -1
  45. package/dist/cjs/labels/labelGrid.d.ts +1 -2
  46. package/dist/cjs/labels/labelGrid.js.map +1 -1
  47. package/dist/cjs/labels/labelWeekday.d.ts +1 -2
  48. package/dist/cjs/labels/labelWeekday.js.map +1 -1
  49. package/dist/cjs/lib/dateLib.d.ts +66 -3
  50. package/dist/cjs/lib/dateLib.js +0 -2
  51. package/dist/cjs/lib/dateLib.js.map +1 -1
  52. package/dist/cjs/lib/index.d.ts +1 -0
  53. package/dist/cjs/lib/index.js +3 -0
  54. package/dist/cjs/lib/index.js.map +1 -1
  55. package/dist/cjs/locale.d.ts +1 -0
  56. package/dist/cjs/locale.js +18 -0
  57. package/dist/cjs/locale.js.map +1 -0
  58. package/dist/cjs/selection/useMulti.d.ts +2 -1
  59. package/dist/cjs/selection/useMulti.js +5 -2
  60. package/dist/cjs/selection/useMulti.js.map +1 -1
  61. package/dist/cjs/selection/useRange.d.ts +2 -1
  62. package/dist/cjs/selection/useRange.js +5 -2
  63. package/dist/cjs/selection/useRange.js.map +1 -1
  64. package/dist/cjs/selection/useSingle.d.ts +2 -1
  65. package/dist/cjs/selection/useSingle.js +5 -2
  66. package/dist/cjs/selection/useSingle.js.map +1 -1
  67. package/dist/cjs/types/props.d.ts +31 -6
  68. package/dist/cjs/types/selection.d.ts +14 -5
  69. package/dist/cjs/types/shared.d.ts +17 -8
  70. package/dist/cjs/useCalendar.d.ts +2 -2
  71. package/dist/cjs/useCalendar.js +6 -0
  72. package/dist/cjs/useCalendar.js.map +1 -1
  73. package/dist/cjs/useDayPicker.d.ts +30 -6
  74. package/dist/cjs/useDayPicker.js +10 -2
  75. package/dist/cjs/useDayPicker.js.map +1 -1
  76. package/dist/cjs/useFocus.d.ts +2 -1
  77. package/dist/cjs/useGetModifiers.d.ts +2 -1
  78. package/dist/cjs/useGetModifiers.js +8 -2
  79. package/dist/cjs/useGetModifiers.js.map +1 -1
  80. package/dist/cjs/useSelection.d.ts +2 -1
  81. package/dist/cjs/useSelection.js.map +1 -1
  82. package/dist/cjs/utc.js +1 -2
  83. package/dist/cjs/utc.js.map +1 -1
  84. package/dist/cjs/utils/addToRange.d.ts +2 -1
  85. package/dist/cjs/utils/addToRange.js.map +1 -1
  86. package/dist/cjs/utils/dateMatchModifiers.d.ts +2 -1
  87. package/dist/cjs/utils/dateMatchModifiers.js.map +1 -1
  88. package/dist/cjs/utils/rangeIncludesDate.d.ts +2 -1
  89. package/dist/cjs/utils/rangeIncludesDate.js.map +1 -1
  90. package/dist/cjs/utils/typeguards.d.ts +2 -1
  91. package/dist/esm/DayPicker.js +11 -11
  92. package/dist/esm/DayPicker.js.map +1 -1
  93. package/dist/esm/classes/CalendarDay.d.ts +1 -1
  94. package/dist/esm/classes/CalendarDay.js.map +1 -1
  95. package/dist/esm/components/WeekNumber.d.ts +1 -1
  96. package/dist/esm/components/WeekNumber.js +2 -2
  97. package/dist/esm/formatters/formatCaption.d.ts +1 -2
  98. package/dist/esm/formatters/formatCaption.js.map +1 -1
  99. package/dist/esm/formatters/formatDay.d.ts +1 -2
  100. package/dist/esm/formatters/formatDay.js.map +1 -1
  101. package/dist/esm/formatters/formatWeekdayName.d.ts +1 -2
  102. package/dist/esm/formatters/formatWeekdayName.js.map +1 -1
  103. package/dist/esm/helpers/getDateLib.d.ts +2 -1
  104. package/dist/esm/helpers/getDateLib.js.map +1 -1
  105. package/dist/esm/helpers/getDates.d.ts +1 -1
  106. package/dist/esm/helpers/getDates.js +3 -3
  107. package/dist/esm/helpers/getDates.js.map +1 -1
  108. package/dist/esm/helpers/getDisplayMonths.d.ts +2 -1
  109. package/dist/esm/helpers/getDisplayMonths.js.map +1 -1
  110. package/dist/esm/helpers/getFocusableDate.d.ts +2 -1
  111. package/dist/esm/helpers/getInitialMonth.d.ts +1 -1
  112. package/dist/esm/helpers/getInitialMonth.js +6 -1
  113. package/dist/esm/helpers/getInitialMonth.js.map +1 -1
  114. package/dist/esm/helpers/getMonthOptions.d.ts +2 -2
  115. package/dist/esm/helpers/getMonthOptions.js +6 -3
  116. package/dist/esm/helpers/getMonthOptions.js.map +1 -1
  117. package/dist/esm/helpers/getMonths.d.ts +3 -2
  118. package/dist/esm/helpers/getMonths.js.map +1 -1
  119. package/dist/esm/helpers/getNavMonth.d.ts +3 -2
  120. package/dist/esm/helpers/getNavMonth.js +16 -3
  121. package/dist/esm/helpers/getNavMonth.js.map +1 -1
  122. package/dist/esm/helpers/getNextFocus.d.ts +3 -2
  123. package/dist/esm/helpers/getNextFocus.js.map +1 -1
  124. package/dist/esm/helpers/getNextMonth.d.ts +2 -1
  125. package/dist/esm/helpers/getNextMonth.js.map +1 -1
  126. package/dist/esm/helpers/getPreviousMonth.d.ts +2 -1
  127. package/dist/esm/helpers/getPreviousMonth.js.map +1 -1
  128. package/dist/esm/helpers/getWeekdays.d.ts +2 -3
  129. package/dist/esm/helpers/getWeekdays.js +9 -3
  130. package/dist/esm/helpers/getWeekdays.js.map +1 -1
  131. package/dist/esm/helpers/getYearOptions.d.ts +2 -1
  132. package/dist/esm/helpers/getYearOptions.js +6 -5
  133. package/dist/esm/helpers/getYearOptions.js.map +1 -1
  134. package/dist/esm/labels/labelGrid.d.ts +1 -2
  135. package/dist/esm/labels/labelGrid.js.map +1 -1
  136. package/dist/esm/labels/labelWeekday.d.ts +1 -2
  137. package/dist/esm/labels/labelWeekday.js.map +1 -1
  138. package/dist/esm/lib/dateLib.d.ts +66 -3
  139. package/dist/esm/lib/dateLib.js +0 -2
  140. package/dist/esm/lib/dateLib.js.map +1 -1
  141. package/dist/esm/lib/index.d.ts +1 -0
  142. package/dist/esm/lib/index.js +1 -0
  143. package/dist/esm/lib/index.js.map +1 -1
  144. package/dist/esm/locale.d.ts +1 -0
  145. package/dist/esm/locale.js +2 -0
  146. package/dist/esm/locale.js.map +1 -0
  147. package/dist/esm/selection/useMulti.d.ts +2 -1
  148. package/dist/esm/selection/useMulti.js +5 -2
  149. package/dist/esm/selection/useMulti.js.map +1 -1
  150. package/dist/esm/selection/useRange.d.ts +2 -1
  151. package/dist/esm/selection/useRange.js +5 -2
  152. package/dist/esm/selection/useRange.js.map +1 -1
  153. package/dist/esm/selection/useSingle.d.ts +2 -1
  154. package/dist/esm/selection/useSingle.js +5 -2
  155. package/dist/esm/selection/useSingle.js.map +1 -1
  156. package/dist/esm/types/props.d.ts +31 -6
  157. package/dist/esm/types/selection.d.ts +14 -5
  158. package/dist/esm/types/shared.d.ts +17 -8
  159. package/dist/esm/useCalendar.d.ts +2 -2
  160. package/dist/esm/useCalendar.js +6 -0
  161. package/dist/esm/useCalendar.js.map +1 -1
  162. package/dist/esm/useDayPicker.d.ts +30 -6
  163. package/dist/esm/useDayPicker.js +10 -2
  164. package/dist/esm/useDayPicker.js.map +1 -1
  165. package/dist/esm/useFocus.d.ts +2 -1
  166. package/dist/esm/useGetModifiers.d.ts +2 -1
  167. package/dist/esm/useGetModifiers.js +8 -2
  168. package/dist/esm/useGetModifiers.js.map +1 -1
  169. package/dist/esm/useSelection.d.ts +2 -1
  170. package/dist/esm/useSelection.js.map +1 -1
  171. package/dist/esm/utc.js +1 -2
  172. package/dist/esm/utc.js.map +1 -1
  173. package/dist/esm/utils/addToRange.d.ts +2 -1
  174. package/dist/esm/utils/addToRange.js.map +1 -1
  175. package/dist/esm/utils/dateMatchModifiers.d.ts +2 -1
  176. package/dist/esm/utils/dateMatchModifiers.js.map +1 -1
  177. package/dist/esm/utils/rangeIncludesDate.d.ts +2 -1
  178. package/dist/esm/utils/rangeIncludesDate.js.map +1 -1
  179. package/dist/esm/utils/typeguards.d.ts +2 -1
  180. package/examples/Input.test.tsx +1 -1
  181. package/examples/ItalianLabels.tsx +1 -1
  182. package/examples/ModifiersHidden.test.tsx +1 -1
  183. package/examples/NumberingSystem.test.tsx +3 -3
  184. package/examples/PastDatesDisabled.tsx +7 -0
  185. package/examples/Range.test.tsx +1 -1
  186. package/examples/RangeShiftKey.tsx +1 -1
  187. package/examples/SingleControlled.test.tsx +37 -0
  188. package/examples/SingleControlled.tsx +8 -0
  189. package/examples/SingleMockDate.test.tsx +39 -0
  190. package/examples/TimeZone.tsx +23 -0
  191. package/examples/WeekStartsOn.tsx +7 -0
  192. package/examples/Weeknumber.test.tsx +2 -2
  193. package/examples/WeeknumberCustom.tsx +2 -2
  194. package/examples/__snapshots__/Range.test.tsx.snap +84 -100
  195. package/examples/__snapshots__/StylingCssModules.test.tsx.snap +42 -50
  196. package/examples/index.ts +4 -0
  197. package/package.json +19 -3
  198. package/src/DayPicker.test.tsx +13 -0
  199. package/src/DayPicker.tsx +13 -10
  200. package/src/classes/CalendarDay.ts +1 -1
  201. package/src/components/WeekNumber.tsx +3 -3
  202. package/src/formatters/formatCaption.ts +5 -2
  203. package/src/formatters/formatDay.ts +1 -2
  204. package/src/formatters/formatWeekdayName.ts +1 -2
  205. package/src/helpers/getDateLib.ts +2 -2
  206. package/src/helpers/getDates.ts +4 -5
  207. package/src/helpers/getDisplayMonths.ts +2 -1
  208. package/src/helpers/getFocusableDate.ts +1 -1
  209. package/src/helpers/getInitialMonth.ts +8 -1
  210. package/src/helpers/getMonthOptions.ts +8 -5
  211. package/src/helpers/getMonths.ts +3 -1
  212. package/src/helpers/getNavMonth.ts +23 -5
  213. package/src/helpers/getNextFocus.tsx +8 -2
  214. package/src/helpers/getNextMonth.ts +2 -1
  215. package/src/helpers/getPreviousMonth.ts +2 -1
  216. package/src/helpers/getWeekdays.test.ts +1 -1
  217. package/src/helpers/getWeekdays.ts +11 -4
  218. package/src/helpers/getYearOptions.ts +8 -7
  219. package/src/labels/labelGrid.ts +1 -2
  220. package/src/labels/labelWeekday.ts +1 -2
  221. package/src/lib/dateLib.ts +95 -3
  222. package/src/lib/index.ts +1 -0
  223. package/src/locale.ts +1 -0
  224. package/src/selection/useMulti.test.tsx +42 -0
  225. package/src/selection/useMulti.tsx +7 -3
  226. package/src/selection/useRange.test.tsx +41 -0
  227. package/src/selection/useRange.tsx +7 -3
  228. package/src/selection/useSingle.test.tsx +39 -0
  229. package/src/selection/useSingle.tsx +7 -3
  230. package/src/types/props.ts +31 -7
  231. package/src/types/selection.ts +12 -9
  232. package/src/types/shared.ts +17 -9
  233. package/src/useCalendar.ts +10 -3
  234. package/src/useDayPicker.ts +30 -6
  235. package/src/useFocus.ts +1 -1
  236. package/src/useGetModifiers.tsx +14 -3
  237. package/src/useSelection.ts +2 -1
  238. package/src/utc.tsx +1 -3
  239. package/src/utils/addToRange.ts +2 -2
  240. package/src/utils/dateMatchModifiers.ts +2 -2
  241. package/src/utils/rangeIncludesDate.ts +2 -2
  242. package/src/utils/typeguards.ts +1 -1
  243. package/website/docs/development/code-of-conduct.md +5 -7
  244. package/website/docs/development/contributing.md +9 -0
  245. package/website/docs/docs/localization.mdx +71 -85
  246. package/website/docs/docs/selection-modes.mdx +40 -26
  247. package/website/docs/docs/translation.mdx +3 -3
  248. package/website/docs/guides/custom-components.mdx +10 -10
  249. package/website/docs/intro.mdx +1 -1
  250. package/website/docs/start.mdx +1 -1
  251. package/website/docs/development/contributing.mdx +0 -11
@@ -4,37 +4,22 @@ sidebar_position: 5
4
4
 
5
5
  # Localization
6
6
 
7
- Learn how to set the locale, adjust the starting day of the week, and apply ISO Week Dates to enhance the user experience across different regions and languages.
8
-
9
- ## Locale props
10
-
11
- | Prop Name | Type | Description |
12
- | ----------------------- | --------------------------------------------- | ------------------------------------------------------------------ |
13
- | `locale` | [`Locale`](https://date-fns.org/docs/I18n) | Set the locale. Default is `en-US`. |
14
- | `weekStartsOn` | `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` | Display the days falling into the other months. |
15
- | `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year. |
16
- | `ISOWeek` | `boolean` | Use [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date). |
7
+ Learn how to set the locale, changing the time zone, and adjust other calendar options.
17
8
 
18
9
  ## Setting the Locale
19
10
 
20
- ### 1. Install date-fns
21
-
22
- DayPicker uses the [date-fns](https://date-fns.org) library for calendar localization. To set a different locale, install `date-fns`:
23
-
24
- ```bash npm2yarn
25
- npm install date-fns
26
- ```
27
-
28
- ### 2. Set a Different Locale
29
-
30
- By default, the locale is set to English (US). To localize the calendar, pass a [`Locale`](https://date-fns.org/docs/I18n) object to the `locale` prop.
11
+ | Prop Name | Type | Description |
12
+ | --------- | ------------------------------------------ | ----------------------------------- |
13
+ | `locale` | [`Locale`](https://date-fns.org/docs/I18n) | Set the locale. Default is `en-US`. |
31
14
 
32
- 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.
33
16
 
34
17
  ```tsx
35
- import { es } from "date-fns/locale";
18
+ // import the locale object
19
+ import { es } from "react-day-picker/locale";
36
20
 
37
- <DayPicker locale={es} />; // Set the locale to Spanish
21
+ // use the locale object
22
+ <DayPicker locale={es} />;
38
23
  ```
39
24
 
40
25
  <BrowserWindow>
@@ -62,104 +47,105 @@ import { DayPicker, defaultLocale } from "react-day-picker";
62
47
 
63
48
  :::
64
49
 
65
- ## First Date of the Week
50
+ ## Changing the Time Zone {#time-zone}
66
51
 
67
- Use the `weekStartsOn` prop to set the first day of the week.
52
+ :::warning Experimental Feature (since v9.1.1)
53
+
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!
55
+
56
+ :::
57
+
58
+ | Prop Name | Type | Description |
59
+ | ---------- | -------- | ---------------------------------------------- |
60
+ | `timeZone` | `string` | Set a time zone for the dates in the calendar. |
61
+
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)
63
+ for a list of the possible values.
68
64
 
69
65
  ```tsx
70
- <DayPicker locale={es} weekStartsOn={0} /> // Start the week on Domingo
66
+ <DayPicker timeZone="UTC" /> // Use Coordinated Universal Time
67
+ <DayPicker timeZone="Pacific/Kiritimati" /> // Use Line Islands Time
71
68
  ```
72
69
 
73
- <BrowserWindow>
74
- <Examples.SpanishWeekStartsOn />
70
+ <BrowserWindow bodyStyle={{ justifyContent: "start" }}>
71
+ <Examples.TimeZone />
75
72
  </BrowserWindow>
76
73
 
77
- ## First Week Contains Date
74
+ ### Working with Time-Zoned Dates
78
75
 
79
- The `firstWeekContainsDate` prop sets the first day of the year's initial week, which is used to calculate week numbers.
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.
80
77
 
81
- - Acceptable values are `1` for Monday and `4` for Thursday.
82
- - For more information, see [Week Numbering](https://en.wikipedia.org/wiki/Week#Numbering) and the [getWeek function](https://date-fns.org/docs/getWeek).
78
+ - To initialize a date in a specific time zone, create a `new TZDate()` object or the `TZDate.tz`.
83
79
 
84
80
  ```tsx
85
- <DayPicker
86
- showWeekNumber
87
- firstWeekContainsDate={1} // First week must contain Monday
88
- />
81
+ import { DayPicker, TZDate } from "react-day-picker";
82
+
83
+ export function TimeZone() {
84
+ const timeZone = "America/New_York";
85
+ const [selected, setSelected] = useState<Date | undefined>(
86
+ new TZDate(2024, 12, 10, timeZone) // Make sure you use `TZDate` instead of `Date`
87
+ );
88
+ return (
89
+ <DayPicker
90
+ mode="single"
91
+ timeZone={timeZone}
92
+ selected={selected}
93
+ onSelect={setSelected}
94
+ />
95
+ );
96
+ }
89
97
  ```
90
98
 
91
- ## ISO Week Dates
99
+ ## Calendar Options
92
100
 
93
- Use the `ISOWeek` prop to switch to [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date) instead of the locale setting.
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). |
106
+
107
+ ### First Date of the Week
108
+
109
+ Use the `weekStartsOn` prop to set the first day of the week.
94
110
 
95
111
  ```tsx
96
- <DayPicker ISOWeek />
112
+ <DayPicker weekStartsOn={0} /> // Start the week on Sunday
97
113
  ```
98
114
 
99
115
  <BrowserWindow>
100
- <Examples.WeeknumberIso />
116
+ <Examples.WeekStartsOn />
101
117
  </BrowserWindow>
102
118
 
103
- ## UTC Dates
104
-
105
- Since DayPicker works with the native JavaScript `Date`, it uses the local time zone by default. To switch to UTC dates:
106
-
107
- 1. Add [@date-fns/utc](https://www.npmjs.com/package/@date-fns/utc) to your dependencies.
108
- 2. Import `DayPicker` from `react-day-picker/utc`.
109
- 3. Use `new UTCDate()` instead of `new Date()`.
110
-
111
- :::note Experimental feature
112
-
113
- The UTC mode is an experimental feature. If you encounter any issues, please [report them](https://github.com/gpbl/react-day-picker/issues). Thank you!
114
-
115
- :::
116
-
117
- #### 1. Install the `@date-fns/utc` package
119
+ ### First Week Contains Date
118
120
 
119
- ```bash npm2yarn
120
- npm install @date-fns/utc
121
- ```
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.
122
122
 
123
- #### 2. Import `DayPicker` from `react-day-picker/utc`
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`.
124
124
 
125
- ```diff
126
- - import { DayPicker } from 'react-day-picker';
127
- + import { DayPicker } from 'react-day-picker/utc';
125
+ ```tsx
126
+ <DayPicker
127
+ showWeekNumber
128
+ firstWeekContainsDate={1} // First week must contain Monday
129
+ />
128
130
  ```
129
131
 
130
- #### 3. Use DayPicker as usual
132
+ ### ISO Week Dates
131
133
 
132
- Use `new UTCDate()` instead of `new Date()` to ensure dates are always in GMT.
134
+ Use the `ISOWeek` prop to switch to [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date) instead of the locale setting.
133
135
 
134
136
  ```tsx
135
- import { UTCDate } from "@date-fns/utc";
136
- import { DayPicker } from "react-day-picker/utc";
137
-
138
- export function Utc() {
139
- const [selected, setSelected] = React.useState<Date>(new UTCDate());
140
- return (
141
- <DayPicker
142
- mode="single"
143
- required
144
- selected={selected}
145
- onSelect={(date: Date) => {
146
- setSelected(date);
147
- }}
148
- footer={selected ? `Selected: ${selected.toUTCString()}` : null}
149
- />
150
- );
151
- }
137
+ <DayPicker ISOWeek />
152
138
  ```
153
139
 
154
140
  <BrowserWindow>
155
- <Examples.Utc />
141
+ <Examples.WeeknumberIso />
156
142
  </BrowserWindow>
157
143
 
158
144
  ## Jalali Calendar
159
145
 
160
146
  DayPicker supports the Jalali calendar through the [date-fns-jalali](https://www.npmjs.com/package/date-fns-jalali) package. To switch to the Jalali calendar, add `date-fns-jalali` to your dependencies and import `DayPicker` from `react-day-picker/jalali`.
161
147
 
162
- :::note Experimental feature
148
+ :::warning Experimental Feature
163
149
 
164
150
  Support for the Jalali calendar is an experimental feature. [Please report](https://github.com/gpbl/react-day-picker/issues) any issues you encounter. Thank you!
165
151
 
@@ -185,8 +171,8 @@ You can set the right-to-left direction and change the locale as needed.
185
171
  ```tsx title="./JalaliCalendar.jsx"
186
172
  import React from "react";
187
173
 
188
- import { faIR } from "date-fns/locale";
189
174
  import { DayPicker } from "react-day-picker/jalali";
175
+ import { faIR } from "react-day-picker/locale";
190
176
 
191
177
  export function Jalali() {
192
178
  return <DayPicker mode="single" locale={faIR} dir="rtl" />;
@@ -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,22 +34,27 @@ 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
- Use the `selected` and `onSelect` props to manage the selected date:
43
+ ### Controlled Selections
44
+
45
+ Use the `selected` and `onSelect` props to control the selected date:
44
46
 
45
47
  ```tsx
46
48
  export function App() {
47
49
  const [selected, setSelected] = React.useState<Date | undefined>();
48
-
49
50
  return <DayPicker mode="single" selected={selected} onSelect={setSelected} />;
50
51
  }
51
52
  ```
52
53
 
54
+ <BrowserWindow>
55
+ <Examples.SingleControlled />
56
+ </BrowserWindow>
57
+
53
58
  ### Required Selection
54
59
 
55
60
  By setting the `required` prop, DayPicker ensures that the user cannot unselect the selected date.
@@ -76,13 +81,13 @@ Set the `mode` prop to `"multiple"` to enable the selection of multiple days in
76
81
 
77
82
  ### Multiple Mode Props
78
83
 
79
- | Prop Name | Type | Description |
80
- | ---------- | ---------------------------------------- | --------------------------------------- |
81
- | `selected` | `Date[] \| undefined` | The selected dates. |
82
- | `onSelect` | `(selected, date, modifiers, e) => void` | Event callback when a date is selected. |
83
- | `min` | `number` | The minimum dates that can be selected. |
84
- | `max` | `number` | The maximum dates that can be selected. |
85
- | `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. |
86
91
 
87
92
  Use the `selected` and `onSelect` props to manage the selected date:
88
93
 
@@ -134,14 +139,14 @@ Set the `mode` prop to `"range"` to enable the selection of a continuous range o
134
139
 
135
140
  ### Range Mode Props
136
141
 
137
- | Prop Name | Type | Description |
138
- | ----------------- | ----------------------------------------------- | --------------------------------------- |
139
- | `selected` | [`DateRange`](../api/type-aliases/DateRange.md) | The selected range. |
140
- | `onSelect` | `(selected, triggerDate, modifiers, e) => void` | Event callback when a date is selected. |
141
- | `required` | `boolean` | Make the selection required. |
142
- | `min` | `number` | The minimum dates that can be selected. |
143
- | `max` | `number` | The maximum dates that can be selected. |
144
- | `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. |
145
150
 
146
151
  ### Min and Max Dates
147
152
 
@@ -175,10 +180,9 @@ To disable specific days, use the `disabled` prop. Disabled dates cannot be sele
175
180
 
176
181
  The prop accepts a [`Matcher`](../api/type-aliases/Matcher.md) or an array of matchers to specify which days should be disabled.
177
182
 
178
- ```tsx
179
- // disable today
180
- <DayPicker mode="single" disabled={ new Date() } />
183
+ ### Disabling Specific Dates
181
184
 
185
+ ```tsx
182
186
  // disable weekends
183
187
  <DayPicker mode="range" disabled={{ dayOfWeek: [0, 6] }} />
184
188
  ```
@@ -187,6 +191,16 @@ The prop accepts a [`Matcher`](../api/type-aliases/Matcher.md) or an array of ma
187
191
  <Examples.ModifiersDisabled />
188
192
  </BrowserWindow>
189
193
 
194
+ ### Disabling Dates in the Past
195
+
196
+ ```tsx
197
+ <DayPicker mode="single" disabled={{ before: new Date() }} />
198
+ ```
199
+
200
+ <BrowserWindow>
201
+ <Examples.PastDatesDisabled />
202
+ </BrowserWindow>
203
+
190
204
  ### Excluding Disabled Dates from Range {#exclude-disabled}
191
205
 
192
206
  In `range` mode, disabled dates are included in the selected range by default. To exclude disabled dates from the range, use the `excludeDisabled` prop. If a disabled date is selected, the range will reset.
@@ -30,7 +30,7 @@ The `labels` prop allows you to customize the [ARIA labels](./accessibility.mdx)
30
30
 
31
31
  ```tsx
32
32
  import { format } from "date-fns";
33
- import { it } from "date-fns/locale";
33
+ import { it } from "react-day-picker/locale";
34
34
 
35
35
  function ItalianLabels() {
36
36
  return (
@@ -89,7 +89,7 @@ The following labels are optional and should work out of the box in most languag
89
89
  To set the text direction to right-to-left, use the `dir` prop with the value `rtl`.
90
90
 
91
91
  ```tsx
92
- import { arSA } from "date-fns/locale";
92
+ import { arSA } from "react-day-picker/locale";
93
93
 
94
94
  <DayPicker locale={arSA} dir="rtl" />;
95
95
  ```
@@ -130,8 +130,8 @@ For example, to switch to Hindu-Arabic numerals, use the native [`Date.toLocaleS
130
130
 
131
131
  ```tsx
132
132
  import { format } from "date-fns/format";
133
- import { arSA } from "date-fns/locale";
134
133
  import { DayPicker, Formatters } from "react-day-picker";
134
+ import { arSA } from "react-day-picker/locale";
135
135
 
136
136
  const NU_LOCALE = "ar-u-nu-arab";
137
137
 
@@ -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
  | --------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- |
@@ -14,7 +14,7 @@ DayPicker is a [React](https://react.dev) component for creating date pickers, c
14
14
  - 🛠 Extensive set of props for [customizing](./docs/customization.mdx) the calendar.
15
15
  - 🎨 Minimal design that can be [easily styled](./docs/styling.mdx) with CSS or any CSS framework.
16
16
  - 📅 Supports [selections](./docs/selection-modes.mdx) of single days, multiple days, ranges of days, or [custom selections](./guides/custom-selections.mdx).
17
- - 🌍 Can be [localized](./docs/localization.mdx) into any language, supports [ISO 8601 dates](./docs/localization.mdx#iso-week-dates), [UTC dates](./docs/localization.mdx#utc-dates), and the [Jalali calendar](./docs/localization.mdx#jalali-calendar).
17
+ - 🌍 Can be [localized](./docs/localization.mdx) into any language, supports [ISO 8601 dates](./docs/localization.mdx#iso-week-dates), [time zones](./docs/localization.mdx#time-zone), and the [Jalali calendar](./docs/localization.mdx#jalali-calendar).
18
18
  - 🦮 Complies with WCAG 2.1 AA requirements for [accessibility](./docs/accessibility.mdx).
19
19
  - ⚙️ [Customizable components](./guides/custom-components.mdx) to extend the rendered elements.
20
20
  - 🔤 Easy integration [with input fields](./guides/input-fields.mdx).
@@ -18,7 +18,7 @@ To add a simple date picker to your app:
18
18
 
19
19
  1. Import the component and styles from `react-day-picker`.
20
20
  2. Choose a [selection mode](./docs/selection-modes) using the `mode` prop.
21
- 3. Use the `selected` and `onSelect` props to manage the selected date.
21
+ 3. Use the `selected` and `onSelect` props to control the selected date.
22
22
 
23
23
  ```tsx
24
24
  import { useState } from "react";
@@ -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
- :::