react-day-picker 9.6.2 → 9.6.3

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 (177) hide show
  1. package/dist/cjs/DayPicker.js +14 -2
  2. package/dist/cjs/DayPicker.js.map +1 -1
  3. package/dist/cjs/classes/DateLib.js +4 -4
  4. package/dist/cjs/classes/DateLib.js.map +1 -1
  5. package/dist/esm/DayPicker.js +14 -2
  6. package/dist/esm/DayPicker.js.map +1 -1
  7. package/dist/esm/classes/DateLib.js +1 -1
  8. package/dist/esm/classes/DateLib.js.map +1 -1
  9. package/package.json +2 -4
  10. package/src/.eslintignore +1 -0
  11. package/src/.eslintrc.cjs +27 -0
  12. package/src/DayPicker.test.tsx +199 -0
  13. package/src/DayPicker.tsx +629 -0
  14. package/src/UI.ts +365 -0
  15. package/src/classes/CalendarDay.test.ts +17 -0
  16. package/src/classes/CalendarDay.ts +61 -0
  17. package/src/classes/CalendarMonth.test.ts +28 -0
  18. package/src/classes/CalendarMonth.ts +15 -0
  19. package/src/classes/CalendarWeek.test.ts +21 -0
  20. package/src/classes/CalendarWeek.ts +13 -0
  21. package/src/classes/DateLib.ts +615 -0
  22. package/src/classes/index.ts +4 -0
  23. package/src/components/Button.tsx +13 -0
  24. package/src/components/CaptionLabel.tsx +13 -0
  25. package/src/components/Chevron.tsx +42 -0
  26. package/src/components/Day.tsx +28 -0
  27. package/src/components/DayButton.tsx +29 -0
  28. package/src/components/Dropdown.tsx +71 -0
  29. package/src/components/DropdownNav.tsx +13 -0
  30. package/src/components/Footer.tsx +13 -0
  31. package/src/components/Month.tsx +24 -0
  32. package/src/components/MonthCaption.tsx +23 -0
  33. package/src/components/MonthGrid.tsx +13 -0
  34. package/src/components/Months.tsx +13 -0
  35. package/src/components/MonthsDropdown.tsx +16 -0
  36. package/src/components/Nav.tsx +90 -0
  37. package/src/components/NextMonthButton.tsx +18 -0
  38. package/src/components/Option.tsx +13 -0
  39. package/src/components/PreviousMonthButton.tsx +20 -0
  40. package/src/components/Root.tsx +19 -0
  41. package/src/components/Select.tsx +13 -0
  42. package/src/components/Week.tsx +20 -0
  43. package/src/components/WeekNumber.tsx +21 -0
  44. package/src/components/WeekNumberHeader.tsx +15 -0
  45. package/src/components/Weekday.tsx +13 -0
  46. package/src/components/Weekdays.tsx +17 -0
  47. package/src/components/Weeks.tsx +13 -0
  48. package/src/components/YearsDropdown.tsx +16 -0
  49. package/src/components/custom-components.tsx +26 -0
  50. package/src/formatters/formatCaption.test.ts +27 -0
  51. package/src/formatters/formatCaption.ts +23 -0
  52. package/src/formatters/formatDay.test.ts +7 -0
  53. package/src/formatters/formatDay.ts +16 -0
  54. package/src/formatters/formatMonthDropdown.test.ts +19 -0
  55. package/src/formatters/formatMonthDropdown.ts +15 -0
  56. package/src/formatters/formatWeekNumber.test.ts +5 -0
  57. package/src/formatters/formatWeekNumber.ts +13 -0
  58. package/src/formatters/formatWeekNumberHeader.ts +10 -0
  59. package/src/formatters/formatWeekdayName.test.ts +15 -0
  60. package/src/formatters/formatWeekdayName.ts +16 -0
  61. package/src/formatters/formatYearDropdown.test.ts +7 -0
  62. package/src/formatters/formatYearDropdown.ts +21 -0
  63. package/src/formatters/index.ts +7 -0
  64. package/src/helpers/broadcastCalendar.test.ts +43 -0
  65. package/src/helpers/calculateFocusTarget.ts +51 -0
  66. package/src/helpers/endOfBroadcastWeek.test.ts +25 -0
  67. package/src/helpers/endOfBroadcastWeek.ts +16 -0
  68. package/src/helpers/getBroadcastWeeksInMonth.test.ts +23 -0
  69. package/src/helpers/getBroadcastWeeksInMonth.ts +31 -0
  70. package/src/helpers/getClassNamesForModifiers.ts +26 -0
  71. package/src/helpers/getComponents.ts +11 -0
  72. package/src/helpers/getDataAttributes.test.tsx +48 -0
  73. package/src/helpers/getDataAttributes.tsx +21 -0
  74. package/src/helpers/getDates.test.ts +190 -0
  75. package/src/helpers/getDates.ts +64 -0
  76. package/src/helpers/getDays.test.ts +30 -0
  77. package/src/helpers/getDays.ts +16 -0
  78. package/src/helpers/getDefaultClassNames.test.ts +47 -0
  79. package/src/helpers/getDefaultClassNames.ts +33 -0
  80. package/src/helpers/getDisplayMonths.test.ts +44 -0
  81. package/src/helpers/getDisplayMonths.ts +20 -0
  82. package/src/helpers/getFocusableDate.ts +59 -0
  83. package/src/helpers/getFormatters.test.ts +48 -0
  84. package/src/helpers/getFormatters.ts +19 -0
  85. package/src/helpers/getInitialMonth.test.ts +79 -0
  86. package/src/helpers/getInitialMonth.ts +41 -0
  87. package/src/helpers/getLabels.ts +10 -0
  88. package/src/helpers/getMonthOptions.test.ts +226 -0
  89. package/src/helpers/getMonthOptions.ts +37 -0
  90. package/src/helpers/getMonths.test.ts +88 -0
  91. package/src/helpers/getMonths.ts +90 -0
  92. package/src/helpers/getNavMonth.test.ts +253 -0
  93. package/src/helpers/getNavMonth.ts +70 -0
  94. package/src/helpers/getNextFocus.test.tsx +99 -0
  95. package/src/helpers/getNextFocus.tsx +67 -0
  96. package/src/helpers/getNextMonth.test.ts +101 -0
  97. package/src/helpers/getNextMonth.ts +45 -0
  98. package/src/helpers/getPossibleFocusDate.test.ts +144 -0
  99. package/src/helpers/getPreviousMonth.test.ts +77 -0
  100. package/src/helpers/getPreviousMonth.ts +40 -0
  101. package/src/helpers/getStyleForModifiers.test.ts +92 -0
  102. package/src/helpers/getStyleForModifiers.ts +21 -0
  103. package/src/helpers/getWeekdays.test.ts +44 -0
  104. package/src/helpers/getWeekdays.ts +29 -0
  105. package/src/helpers/getWeeks.test.ts +30 -0
  106. package/src/helpers/getWeeks.ts +9 -0
  107. package/src/helpers/getYearOptions.test.ts +46 -0
  108. package/src/helpers/getYearOptions.ts +34 -0
  109. package/src/helpers/index.ts +2 -0
  110. package/src/helpers/startOfBroadcastWeek.test.ts +24 -0
  111. package/src/helpers/startOfBroadcastWeek.ts +19 -0
  112. package/src/helpers/useControlledValue.test.ts +45 -0
  113. package/src/helpers/useControlledValue.ts +33 -0
  114. package/src/index.ts +15 -0
  115. package/src/jalali.tsx +2 -0
  116. package/src/labels/index.ts +12 -0
  117. package/src/labels/labelDayButton.test.ts +41 -0
  118. package/src/labels/labelDayButton.ts +31 -0
  119. package/src/labels/labelGrid.test.ts +7 -0
  120. package/src/labels/labelGrid.ts +23 -0
  121. package/src/labels/labelGridcell.test.ts +7 -0
  122. package/src/labels/labelGridcell.ts +22 -0
  123. package/src/labels/labelMonthDropdown.test.ts +5 -0
  124. package/src/labels/labelMonthDropdown.ts +12 -0
  125. package/src/labels/labelNav.test.ts +5 -0
  126. package/src/labels/labelNav.ts +10 -0
  127. package/src/labels/labelNext.test.ts +5 -0
  128. package/src/labels/labelNext.ts +13 -0
  129. package/src/labels/labelPrevious.test.ts +5 -0
  130. package/src/labels/labelPrevious.ts +13 -0
  131. package/src/labels/labelWeekNumber.test.ts +5 -0
  132. package/src/labels/labelWeekNumber.ts +15 -0
  133. package/src/labels/labelWeekNumberHeader.test.ts +5 -0
  134. package/src/labels/labelWeekNumberHeader.ts +12 -0
  135. package/src/labels/labelWeekday.test.ts +15 -0
  136. package/src/labels/labelWeekday.ts +16 -0
  137. package/src/labels/labelYearDropdown.test.ts +5 -0
  138. package/src/labels/labelYearDropdown.ts +12 -0
  139. package/src/locale.ts +1 -0
  140. package/src/persian.tsx +86 -0
  141. package/src/selection/useMulti.test.tsx +41 -0
  142. package/src/selection/useMulti.tsx +74 -0
  143. package/src/selection/useRange.test.tsx +154 -0
  144. package/src/selection/useRange.tsx +73 -0
  145. package/src/selection/useSingle.test.tsx +38 -0
  146. package/src/selection/useSingle.tsx +69 -0
  147. package/src/types/deprecated.ts +230 -0
  148. package/src/types/index.ts +4 -0
  149. package/src/types/props.test.tsx +71 -0
  150. package/src/types/props.ts +675 -0
  151. package/src/types/selection.ts +57 -0
  152. package/src/types/shared.ts +442 -0
  153. package/src/useAnimation.test.tsx +134 -0
  154. package/src/useAnimation.ts +203 -0
  155. package/src/useCalendar.ts +178 -0
  156. package/src/useDayPicker.test.tsx +142 -0
  157. package/src/useDayPicker.ts +93 -0
  158. package/src/useFocus.ts +87 -0
  159. package/src/useGetModifiers.test.tsx +154 -0
  160. package/src/useGetModifiers.tsx +122 -0
  161. package/src/useSelection.ts +26 -0
  162. package/src/utc.tsx +10 -0
  163. package/src/utils/addToRange.test.ts +117 -0
  164. package/src/utils/addToRange.ts +87 -0
  165. package/src/utils/dateMatchModifiers.test.ts +120 -0
  166. package/src/utils/dateMatchModifiers.ts +88 -0
  167. package/src/utils/index.ts +7 -0
  168. package/src/utils/rangeContainsDayOfWeek.test.ts +48 -0
  169. package/src/utils/rangeContainsDayOfWeek.ts +35 -0
  170. package/src/utils/rangeContainsModifiers.test.ts +230 -0
  171. package/src/utils/rangeContainsModifiers.ts +125 -0
  172. package/src/utils/rangeIncludesDate.test.ts +46 -0
  173. package/src/utils/rangeIncludesDate.ts +43 -0
  174. package/src/utils/rangeOverlaps.test.ts +60 -0
  175. package/src/utils/rangeOverlaps.ts +22 -0
  176. package/src/utils/typeguards.test.ts +83 -0
  177. package/src/utils/typeguards.ts +70 -0
@@ -0,0 +1,615 @@
1
+ import { TZDate } from "@date-fns/tz";
2
+ import {
3
+ addDays,
4
+ addMonths,
5
+ addWeeks,
6
+ addYears,
7
+ differenceInCalendarDays,
8
+ differenceInCalendarMonths,
9
+ eachMonthOfInterval,
10
+ endOfISOWeek,
11
+ endOfMonth,
12
+ endOfWeek,
13
+ endOfYear,
14
+ format,
15
+ getISOWeek,
16
+ getMonth,
17
+ getWeek,
18
+ getYear,
19
+ isAfter,
20
+ isBefore,
21
+ isDate,
22
+ isSameDay,
23
+ isSameMonth,
24
+ isSameYear,
25
+ max,
26
+ min,
27
+ setMonth,
28
+ setYear,
29
+ startOfDay,
30
+ startOfISOWeek,
31
+ startOfMonth,
32
+ startOfWeek,
33
+ startOfYear
34
+ } from "date-fns";
35
+ import type {
36
+ EndOfWeekOptions,
37
+ StartOfWeekOptions,
38
+ FormatOptions as DateFnsFormatOptions,
39
+ GetWeekOptions,
40
+ Interval
41
+ } from "date-fns";
42
+ import type { Locale } from "date-fns/locale";
43
+ import { enUS } from "date-fns/locale/en-US";
44
+
45
+ import { endOfBroadcastWeek } from "../helpers/endOfBroadcastWeek.js";
46
+ import { startOfBroadcastWeek } from "../helpers/startOfBroadcastWeek.js";
47
+ import { Numerals } from "../types/shared.js";
48
+
49
+ export type { Locale } from "date-fns/locale";
50
+ export type { Month as DateFnsMonth } from "date-fns";
51
+
52
+ /**
53
+ * @ignore
54
+ * @deprecated Use {@link DateLibOptions} instead.
55
+ */
56
+ export type FormatOptions = DateLibOptions;
57
+ /**
58
+ * @ignore
59
+ * @deprecated Use {@link DateLibOptions} instead.
60
+ */
61
+ export type LabelOptions = DateLibOptions;
62
+
63
+ /**
64
+ * The options for the `DateLib` class.
65
+ *
66
+ * Extends `date-fns` [format](https://date-fns.org/docs/format),
67
+ * [startOfWeek](https://date-fns.org/docs/startOfWeek) and
68
+ * [endOfWeek](https://date-fns.org/docs/endOfWeek) options.
69
+ *
70
+ * @since 9.2.0
71
+ */
72
+ export interface DateLibOptions
73
+ extends DateFnsFormatOptions,
74
+ StartOfWeekOptions,
75
+ EndOfWeekOptions {
76
+ /** A constructor for the `Date` object. */
77
+ Date?: typeof Date;
78
+ /** A locale to use for formatting dates. */
79
+ locale?: Locale;
80
+ /**
81
+ * A time zone to use for dates.
82
+ *
83
+ * @since 9.5.0
84
+ */
85
+ timeZone?: string;
86
+ /**
87
+ * The numbering system to use for formatting numbers.
88
+ *
89
+ * @since 9.5.0
90
+ */
91
+ numerals?: Numerals;
92
+ }
93
+
94
+ /**
95
+ * A wrapper class around [date-fns](http://date-fns.org) sharing the same
96
+ * options.
97
+ *
98
+ * @since 9.2.0
99
+ * @example
100
+ * const dateLib = new DateLib({ locale: es });
101
+ * const newDate = dateLib.addDays(new Date(), 5);
102
+ */
103
+ export class DateLib {
104
+ /** The options for the date library. */
105
+ readonly options: DateLibOptions;
106
+
107
+ /** Overrides for the date library functions. */
108
+ readonly overrides?: Partial<typeof DateLib.prototype>;
109
+
110
+ /**
111
+ * Creates an instance of DateLib.
112
+ *
113
+ * @param options The options for the date library.
114
+ * @param overrides Overrides for the date library functions.
115
+ */
116
+ constructor(
117
+ options?: DateLibOptions,
118
+ overrides?: Partial<typeof DateLib.prototype>
119
+ ) {
120
+ this.options = { locale: enUS, ...options };
121
+ this.overrides = overrides;
122
+ }
123
+
124
+ /**
125
+ * Generate digit map dynamically using Intl.NumberFormat.
126
+ *
127
+ * @since 9.5.0
128
+ */
129
+ private getDigitMap(): Record<string, string> {
130
+ const { numerals = "latn" } = this.options;
131
+
132
+ // Use Intl.NumberFormat to create a formatter with the specified numbering system
133
+ const formatter = new Intl.NumberFormat("en-US", {
134
+ numberingSystem: numerals
135
+ });
136
+
137
+ // Map Arabic digits (0-9) to the target numerals
138
+ const digitMap: Record<string, string> = {};
139
+ for (let i = 0; i < 10; i++) {
140
+ digitMap[i.toString()] = formatter.format(i);
141
+ }
142
+
143
+ return digitMap;
144
+ }
145
+
146
+ /**
147
+ * Replace Arabic digits with the target numbering system digits.
148
+ *
149
+ * @since 9.5.0
150
+ */
151
+ private replaceDigits(input: string): string {
152
+ const digitMap = this.getDigitMap();
153
+ return input.replace(/\d/g, (digit) => digitMap[digit] || digit);
154
+ }
155
+
156
+ /**
157
+ * Format number using the custom numbering system.
158
+ *
159
+ * @since 9.5.0
160
+ * @param value The number to format.
161
+ * @returns The formatted number.
162
+ */
163
+ formatNumber(value: number): string {
164
+ return this.replaceDigits(value.toString());
165
+ }
166
+
167
+ /**
168
+ * Reference to the built-in Date constructor.
169
+ *
170
+ * @deprecated Use `newDate()` or `today()`.
171
+ */
172
+ Date: typeof Date = Date;
173
+
174
+ /**
175
+ * Creates a new date object to the today's date.
176
+ *
177
+ * @since 9.5.0
178
+ * @returns The new date object.
179
+ */
180
+ today = (): Date => {
181
+ if (this.overrides?.today) {
182
+ return this.overrides.today();
183
+ }
184
+ if (this.options.timeZone) {
185
+ return TZDate.tz(this.options.timeZone);
186
+ }
187
+ return new this.Date();
188
+ };
189
+
190
+ /**
191
+ * Creates a new date object with the specified year, month and date.
192
+ *
193
+ * @since 9.5.0
194
+ * @param year The year.
195
+ * @param monthIndex The month (0-11).
196
+ * @param date The day of the month.
197
+ * @returns The new date object.
198
+ */
199
+ newDate = (year: number, monthIndex: number, date: number): Date => {
200
+ if (this.overrides?.newDate) {
201
+ return this.overrides.newDate(year, monthIndex, date);
202
+ }
203
+ if (this.options.timeZone) {
204
+ return new TZDate(year, monthIndex, date, this.options.timeZone);
205
+ }
206
+ return new Date(year, monthIndex, date);
207
+ };
208
+
209
+ /**
210
+ * Adds the specified number of days to the given date.
211
+ *
212
+ * @param date The date to add days to.
213
+ * @param amount The number of days to add.
214
+ * @returns The new date with the days added.
215
+ */
216
+ addDays = (date: Date, amount: number): Date => {
217
+ return this.overrides?.addDays?.(date, amount) ?? addDays(date, amount);
218
+ };
219
+
220
+ /**
221
+ * Adds the specified number of months to the given date.
222
+ *
223
+ * @param date The date to add months to.
224
+ * @param amount The number of months to add.
225
+ * @returns The new date with the months added.
226
+ */
227
+ addMonths = (date: Date, amount: number): Date => {
228
+ return this.overrides?.addMonths?.(date, amount) ?? addMonths(date, amount);
229
+ };
230
+
231
+ /**
232
+ * Adds the specified number of weeks to the given date.
233
+ *
234
+ * @param date The date to add weeks to.
235
+ * @param amount The number of weeks to add.
236
+ * @returns The new date with the weeks added.
237
+ */
238
+ addWeeks = (date: Date, amount: number): Date => {
239
+ return this.overrides?.addWeeks?.(date, amount) ?? addWeeks(date, amount);
240
+ };
241
+
242
+ /**
243
+ * Adds the specified number of years to the given date.
244
+ *
245
+ * @param date The date to add years to.
246
+ * @param amount The number of years to add.
247
+ * @returns The new date with the years added.
248
+ */
249
+ addYears = (date: Date, amount: number): Date => {
250
+ return this.overrides?.addYears?.(date, amount) ?? addYears(date, amount);
251
+ };
252
+
253
+ /**
254
+ * Returns the number of calendar days between the given dates.
255
+ *
256
+ * @param dateLeft The later date.
257
+ * @param dateRight The earlier date.
258
+ * @returns The number of calendar days between the dates.
259
+ */
260
+ differenceInCalendarDays = (dateLeft: Date, dateRight: Date): number => {
261
+ return (
262
+ this.overrides?.differenceInCalendarDays?.(dateLeft, dateRight) ??
263
+ differenceInCalendarDays(dateLeft, dateRight)
264
+ );
265
+ };
266
+
267
+ /**
268
+ * Returns the number of calendar months between the given dates.
269
+ *
270
+ * @param dateLeft The later date.
271
+ * @param dateRight The earlier date.
272
+ * @returns The number of calendar months between the dates.
273
+ */
274
+ differenceInCalendarMonths = (dateLeft: Date, dateRight: Date): number => {
275
+ return (
276
+ this.overrides?.differenceInCalendarMonths?.(dateLeft, dateRight) ??
277
+ differenceInCalendarMonths(dateLeft, dateRight)
278
+ );
279
+ };
280
+
281
+ /**
282
+ * Returns the months between the given dates.
283
+ *
284
+ * @param interval The interval to get the months for.
285
+ */
286
+ eachMonthOfInterval = (interval: Interval<Date>): Date[] => {
287
+ return (
288
+ this.overrides?.eachMonthOfInterval?.(interval) ??
289
+ eachMonthOfInterval(interval)
290
+ );
291
+ };
292
+
293
+ /**
294
+ * Returns the end of the broadcast week for the given date.
295
+ *
296
+ * @param date The original date.
297
+ * @returns The end of the broadcast week.
298
+ */
299
+ endOfBroadcastWeek = (date: Date, dateLib?: DateLib): Date => {
300
+ return (
301
+ this.overrides?.endOfBroadcastWeek?.(date, dateLib) ??
302
+ endOfBroadcastWeek(date, this)
303
+ );
304
+ };
305
+
306
+ /**
307
+ * Returns the end of the ISO week for the given date.
308
+ *
309
+ * @param date The original date.
310
+ * @returns The end of the ISO week.
311
+ */
312
+ endOfISOWeek = (date: Date): Date => {
313
+ return this.overrides?.endOfISOWeek?.(date) ?? endOfISOWeek(date);
314
+ };
315
+
316
+ /**
317
+ * Returns the end of the month for the given date.
318
+ *
319
+ * @param date The original date.
320
+ * @returns The end of the month.
321
+ */
322
+ endOfMonth = (date: Date): Date => {
323
+ return this.overrides?.endOfMonth?.(date) ?? endOfMonth(date);
324
+ };
325
+
326
+ /**
327
+ * Returns the end of the week for the given date.
328
+ *
329
+ * @param date The original date.
330
+ * @returns The end of the week.
331
+ */
332
+ endOfWeek = (date: Date, options?: EndOfWeekOptions<Date>): Date => {
333
+ return (
334
+ this.overrides?.endOfWeek?.(date, options ?? this.options) ??
335
+ endOfWeek(date, options ?? this.options)
336
+ );
337
+ };
338
+
339
+ /**
340
+ * Returns the end of the year for the given date.
341
+ *
342
+ * @param date The original date.
343
+ * @returns The end of the year.
344
+ */
345
+ endOfYear = (date: Date): Date => {
346
+ return this.overrides?.endOfYear?.(date) ?? endOfYear(date);
347
+ };
348
+
349
+ /**
350
+ * Formats the given date using the specified format string.
351
+ *
352
+ * @param date The date to format.
353
+ * @param formatStr The format string.
354
+ * @returns The formatted date string.
355
+ */
356
+ format = (
357
+ date: Date,
358
+ formatStr: string,
359
+ options?: DateFnsFormatOptions
360
+ ): string => {
361
+ const formatted =
362
+ this.overrides?.format?.(date, formatStr, options ?? this.options) ??
363
+ format(date, formatStr, options ?? this.options);
364
+
365
+ if (this.options.numerals && this.options.numerals !== "latn") {
366
+ return this.replaceDigits(formatted);
367
+ }
368
+ return formatted;
369
+ };
370
+
371
+ /**
372
+ * Returns the ISO week number for the given date.
373
+ *
374
+ * @param date The date to get the ISO week number for.
375
+ * @returns The ISO week number.
376
+ */
377
+ getISOWeek = (date: Date): number => {
378
+ return this.overrides?.getISOWeek?.(date) ?? getISOWeek(date);
379
+ };
380
+
381
+ /**
382
+ * Returns the month of the given date.
383
+ *
384
+ * @param date The date to get the month for.
385
+ * @returns The month.
386
+ */
387
+ getMonth = (date: Date): number => {
388
+ return this.overrides?.getMonth?.(date) ?? getMonth(date);
389
+ };
390
+
391
+ /**
392
+ * Returns the year of the given date.
393
+ *
394
+ * @param date The date to get the year for.
395
+ * @returns The year.
396
+ */
397
+ getYear = (date: Date): number => {
398
+ return this.overrides?.getYear?.(date) ?? getYear(date);
399
+ };
400
+
401
+ /**
402
+ * Returns the local week number for the given date.
403
+ *
404
+ * @param date The date to get the week number for.
405
+ * @returns The week number.
406
+ */
407
+ getWeek = (date: Date, options?: GetWeekOptions): number => {
408
+ return (
409
+ this.overrides?.getWeek?.(date, options ?? this.options) ??
410
+ getWeek(date, options ?? this.options)
411
+ );
412
+ };
413
+
414
+ /**
415
+ * Checks if the first date is after the second date.
416
+ *
417
+ * @param date The date to compare.
418
+ * @param dateToCompare The date to compare with.
419
+ * @returns True if the first date is after the second date.
420
+ */
421
+ isAfter = (date: Date, dateToCompare: Date): boolean => {
422
+ return (
423
+ this.overrides?.isAfter?.(date, dateToCompare) ??
424
+ isAfter(date, dateToCompare)
425
+ );
426
+ };
427
+
428
+ /**
429
+ * Checks if the first date is before the second date.
430
+ *
431
+ * @param date The date to compare.
432
+ * @param dateToCompare The date to compare with.
433
+ * @returns True if the first date is before the second date.
434
+ */
435
+ isBefore = (date: Date, dateToCompare: Date): boolean => {
436
+ return (
437
+ this.overrides?.isBefore?.(date, dateToCompare) ??
438
+ isBefore(date, dateToCompare)
439
+ );
440
+ };
441
+
442
+ /**
443
+ * Checks if the given value is a Date object.
444
+ *
445
+ * @param value The value to check.
446
+ * @returns True if the value is a Date object.
447
+ */
448
+ isDate: (value: unknown) => value is Date = (value): value is Date => {
449
+ return this.overrides?.isDate?.(value) ?? isDate(value);
450
+ };
451
+
452
+ /**
453
+ * Checks if the given dates are on the same day.
454
+ *
455
+ * @param dateLeft The first date to compare.
456
+ * @param dateRight The second date to compare.
457
+ * @returns True if the dates are on the same day.
458
+ */
459
+ isSameDay = (dateLeft: Date, dateRight: Date): boolean => {
460
+ return (
461
+ this.overrides?.isSameDay?.(dateLeft, dateRight) ??
462
+ isSameDay(dateLeft, dateRight)
463
+ );
464
+ };
465
+
466
+ /**
467
+ * Checks if the given dates are in the same month.
468
+ *
469
+ * @param dateLeft The first date to compare.
470
+ * @param dateRight The second date to compare.
471
+ * @returns True if the dates are in the same month.
472
+ */
473
+ isSameMonth = (dateLeft: Date, dateRight: Date): boolean => {
474
+ return (
475
+ this.overrides?.isSameMonth?.(dateLeft, dateRight) ??
476
+ isSameMonth(dateLeft, dateRight)
477
+ );
478
+ };
479
+
480
+ /**
481
+ * Checks if the given dates are in the same year.
482
+ *
483
+ * @param dateLeft The first date to compare.
484
+ * @param dateRight The second date to compare.
485
+ * @returns True if the dates are in the same year.
486
+ */
487
+ isSameYear = (dateLeft: Date, dateRight: Date): boolean => {
488
+ return (
489
+ this.overrides?.isSameYear?.(dateLeft, dateRight) ??
490
+ isSameYear(dateLeft, dateRight)
491
+ );
492
+ };
493
+
494
+ /**
495
+ * Returns the latest date in the given array of dates.
496
+ *
497
+ * @param dates The array of dates to compare.
498
+ * @returns The latest date.
499
+ */
500
+ max = (dates: Date[]): Date => {
501
+ return this.overrides?.max?.(dates) ?? max(dates);
502
+ };
503
+
504
+ /**
505
+ * Returns the earliest date in the given array of dates.
506
+ *
507
+ * @param dates The array of dates to compare.
508
+ * @returns The earliest date.
509
+ */
510
+ min = (dates: Date[]): Date => {
511
+ return this.overrides?.min?.(dates) ?? min(dates);
512
+ };
513
+
514
+ /**
515
+ * Sets the month of the given date.
516
+ *
517
+ * @param date The date to set the month on.
518
+ * @param month The month to set (0-11).
519
+ * @returns The new date with the month set.
520
+ */
521
+ setMonth = (date: Date, month: number): Date => {
522
+ return this.overrides?.setMonth?.(date, month) ?? setMonth(date, month);
523
+ };
524
+
525
+ /**
526
+ * Sets the year of the given date.
527
+ *
528
+ * @param date The date to set the year on.
529
+ * @param year The year to set.
530
+ * @returns The new date with the year set.
531
+ */
532
+ setYear = (date: Date, year: number): Date => {
533
+ return this.overrides?.setYear?.(date, year) ?? setYear(date, year);
534
+ };
535
+
536
+ /**
537
+ * Returns the start of the broadcast week for the given date.
538
+ *
539
+ * @param date The original date.
540
+ * @returns The start of the broadcast week.
541
+ */
542
+ startOfBroadcastWeek = (date: Date, dateLib?: DateLib): Date => {
543
+ return (
544
+ this.overrides?.startOfBroadcastWeek?.(date, dateLib ?? this) ??
545
+ startOfBroadcastWeek(date, dateLib ?? this)
546
+ );
547
+ };
548
+
549
+ /**
550
+ * Returns the start of the day for the given date.
551
+ *
552
+ * @param date The original date.
553
+ * @returns The start of the day.
554
+ */
555
+ startOfDay = (date: Date): Date => {
556
+ return this.overrides?.startOfDay?.(date) ?? startOfDay(date);
557
+ };
558
+
559
+ /**
560
+ * Returns the start of the ISO week for the given date.
561
+ *
562
+ * @param date The original date.
563
+ * @returns The start of the ISO week.
564
+ */
565
+ startOfISOWeek = (date: Date): Date => {
566
+ return this.overrides?.startOfISOWeek?.(date) ?? startOfISOWeek(date);
567
+ };
568
+
569
+ /**
570
+ * Returns the start of the month for the given date.
571
+ *
572
+ * @param date The original date.
573
+ * @returns The start of the month.
574
+ */
575
+ startOfMonth = (date: Date): Date => {
576
+ return this.overrides?.startOfMonth?.(date) ?? startOfMonth(date);
577
+ };
578
+
579
+ /**
580
+ * Returns the start of the week for the given date.
581
+ *
582
+ * @param date The original date.
583
+ * @returns The start of the week.
584
+ */
585
+ startOfWeek = (date: Date): Date => {
586
+ return (
587
+ this.overrides?.startOfWeek?.(date) ?? startOfWeek(date, this.options)
588
+ );
589
+ };
590
+
591
+ /**
592
+ * Returns the start of the year for the given date.
593
+ *
594
+ * @param date The original date.
595
+ * @returns The start of the year.
596
+ */
597
+ startOfYear = (date: Date): Date => {
598
+ return this.overrides?.startOfYear?.(date) ?? startOfYear(date);
599
+ };
600
+ }
601
+ /** The default locale (English). */
602
+ export { enUS as defaultLocale } from "date-fns/locale/en-US";
603
+
604
+ /**
605
+ * The default date library with English locale.
606
+ *
607
+ * @since 9.2.0
608
+ */
609
+ export const defaultDateLib = new DateLib();
610
+
611
+ /**
612
+ * @ignore
613
+ * @deprecated Use `defaultDateLib`.
614
+ */
615
+ export const dateLib = defaultDateLib;
@@ -0,0 +1,4 @@
1
+ export * from "./CalendarDay.js";
2
+ export * from "./CalendarMonth.js";
3
+ export * from "./CalendarWeek.js";
4
+ export * from "./DateLib.js";
@@ -0,0 +1,13 @@
1
+ import React, { type ButtonHTMLAttributes } from "react";
2
+
3
+ /**
4
+ * Render the button elements in the calendar.
5
+ *
6
+ * @private
7
+ * @deprecated Use `PreviousMonthButton` or `@link NextMonthButton` instead.
8
+ */
9
+ export function Button(props: ButtonHTMLAttributes<HTMLButtonElement>) {
10
+ return <button {...props} />;
11
+ }
12
+
13
+ export type ButtonProps = Parameters<typeof Button>[0];
@@ -0,0 +1,13 @@
1
+ import React, { type HTMLAttributes } from "react";
2
+
3
+ /**
4
+ * Render the label in the month caption.
5
+ *
6
+ * @group Components
7
+ * @see https://daypicker.dev/guides/custom-components
8
+ */
9
+ export function CaptionLabel(props: HTMLAttributes<HTMLSpanElement>) {
10
+ return <span {...props} />;
11
+ }
12
+
13
+ export type CaptionLabelProps = Parameters<typeof CaptionLabel>[0];
@@ -0,0 +1,42 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * Render the chevron icon used in the navigation buttons and dropdowns.
5
+ *
6
+ * @group Components
7
+ * @see https://daypicker.dev/guides/custom-components
8
+ */
9
+ export function Chevron(props: {
10
+ className?: string;
11
+ /**
12
+ * The size of the chevron.
13
+ *
14
+ * @defaultValue 24
15
+ */
16
+ size?: number;
17
+ /** Set to `true` to disable the chevron. */
18
+ disabled?: boolean;
19
+ /** The orientation of the chevron. */
20
+ orientation?: "up" | "down" | "left" | "right";
21
+ }) {
22
+ const { size = 24, orientation = "left", className } = props;
23
+
24
+ return (
25
+ <svg className={className} width={size} height={size} viewBox="0 0 24 24">
26
+ {orientation === "up" && (
27
+ <polygon points="6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" />
28
+ )}
29
+ {orientation === "down" && (
30
+ <polygon points="6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72" />
31
+ )}
32
+ {orientation === "left" && (
33
+ <polygon points="16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" />
34
+ )}
35
+ {orientation === "right" && (
36
+ <polygon points="8 18.612 14.1888889 12.5 8 6.37733333 9.91111111 4.5 18 12.5 9.91111111 20.5"></polygon>
37
+ )}
38
+ </svg>
39
+ );
40
+ }
41
+
42
+ export type ChevronProps = Parameters<typeof Chevron>[0];
@@ -0,0 +1,28 @@
1
+ import React, { type HTMLAttributes } from "react";
2
+
3
+ import type { CalendarDay } from "../classes/index.js";
4
+ import type { Modifiers } from "../types/index.js";
5
+
6
+ /**
7
+ * Render the gridcell of a day in the calendar and handle the interaction and
8
+ * the focus with they day.
9
+ *
10
+ * If you need to just change the content of the day cell, consider swapping the
11
+ * `DayButton` component instead.
12
+ *
13
+ * @group Components
14
+ * @see https://daypicker.dev/guides/custom-components
15
+ */
16
+ export function Day(
17
+ props: {
18
+ /** The day to render. */
19
+ day: CalendarDay;
20
+ /** The modifiers to apply to the day. */
21
+ modifiers: Modifiers;
22
+ } & HTMLAttributes<HTMLDivElement>
23
+ ) {
24
+ const { day, modifiers, ...tdProps } = props;
25
+ return <td {...tdProps} />;
26
+ }
27
+
28
+ export type DayProps = Parameters<typeof Day>[0];