1 | import React from "react";
|
2 | import type { Locale } from "../lib/dateLib.js";
|
3 | import type { ClassNames, ModifiersClassNames, Styles, ModifiersStyles, CustomComponents, Matcher, Labels, Formatters, MonthChangeEventHandler, DayEventHandler, Modifiers, DateRange, Mode, DateLib } from "./shared.js";
|
4 | /**
|
5 | * The props for the `<DayPicker />` component.
|
6 | *
|
7 | * @group DayPicker
|
8 | */
|
9 | export type DayPickerProps = PropsBase & (PropsSingle | PropsSingleRequired | PropsMulti | PropsMultiRequired | PropsRange | PropsRangeRequired | {
|
10 | mode?: undefined;
|
11 | required?: undefined;
|
12 | });
|
13 | /**
|
14 | * Props used for customization of the calendar, localization, and event
|
15 | * handling.
|
16 | */
|
17 | export interface PropsBase {
|
18 | /**
|
19 | * Enable the selection of single day, multiple days or a range of days.
|
20 | *
|
21 | * @see https://daypicker.dev/docs/selection-modes
|
22 | */
|
23 | mode?: Mode | undefined;
|
24 | /**
|
25 | * Whether the selection is required.
|
26 | *
|
27 | * @see https://daypicker.dev/docs/selection-modes
|
28 | */
|
29 | required?: boolean | undefined;
|
30 | /** Class name to add to the root element */
|
31 | className?: string;
|
32 | /**
|
33 | * Change the class names used by DayPicker.
|
34 | *
|
35 | * Use this prop when you need to change the default class names — for example
|
36 | * when importing the style via CSS modules or when using a CSS framework.
|
37 | *
|
38 | * @see https://daypicker.dev/docs/styling
|
39 | */
|
40 | classNames?: Partial<ClassNames>;
|
41 | /**
|
42 | * Change the class name for the day matching the `modifiers`.
|
43 | *
|
44 | * @see https://daypicker.dev/guides/custom-modifiers
|
45 | */
|
46 | modifiersClassNames?: ModifiersClassNames;
|
47 | /** Style to apply to the root element. */
|
48 | style?: React.CSSProperties;
|
49 | /**
|
50 | * Change the inline styles of the HTML elements.
|
51 | *
|
52 | * @see https://daypicker.dev/docs/styling
|
53 | */
|
54 | styles?: Partial<Styles>;
|
55 | /**
|
56 | * Change the class name for the day matching the {@link modifiers}.
|
57 | *
|
58 | * @see https://daypicker.dev/guides/custom-modifiers
|
59 | */
|
60 | modifiersStyles?: ModifiersStyles;
|
61 | /** A unique id to add to the root element. */
|
62 | id?: string;
|
63 | /**
|
64 | * The initial month to show in the calendar.
|
65 | *
|
66 | * Use this prop to let DayPicker control the current month. If you need to
|
67 | * set the month programmatically, use {@link month} and {@link onMonthChange}.
|
68 | *
|
69 | * @defaultValue The current month
|
70 | * @see https://daypicker.dev/docs/navigation
|
71 | */
|
72 | defaultMonth?: Date;
|
73 | /**
|
74 | * The month displayed in the calendar.
|
75 | *
|
76 | * As opposed to `defaultMonth`, use this prop with `onMonthChange` to change
|
77 | * the month programmatically.
|
78 | *
|
79 | * @see https://daypicker.dev/docs/navigation
|
80 | */
|
81 | month?: Date;
|
82 | /**
|
83 | * The number of displayed months.
|
84 | *
|
85 | * @defaultValue 1
|
86 | * @see https://daypicker.dev/docs/customization#multiplemonths
|
87 | */
|
88 | numberOfMonths?: number;
|
89 | /**
|
90 | * The earliest month to start the month navigation.
|
91 | *
|
92 | * @since 9.0.0
|
93 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
94 | */
|
95 | startMonth?: Date | undefined;
|
96 | /**
|
97 | * @private
|
98 | * @deprecated This prop has been removed. Use `hidden={{ before: date }}`
|
99 | * instead.
|
100 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
101 | */
|
102 | fromDate?: Date | undefined;
|
103 | /**
|
104 | * @private
|
105 | * @deprecated This prop has been renamed to `startMonth`.
|
106 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
107 | */
|
108 | fromMonth?: Date | undefined;
|
109 | /**
|
110 | * @private
|
111 | * @deprecated Use `startMonth` instead. E.g. `startMonth={new Date(year,
|
112 | * 0)}`.
|
113 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
114 | */
|
115 | fromYear?: number | undefined;
|
116 | /**
|
117 | * The latest month to end the month navigation.
|
118 | *
|
119 | * @since 9.0.0
|
120 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
121 | */
|
122 | endMonth?: Date;
|
123 | /**
|
124 | * @private
|
125 | * @deprecated This prop has been removed. Use `hidden={{ after: date }}`
|
126 | * instead.
|
127 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
128 | */
|
129 | toDate?: Date;
|
130 | /**
|
131 | * @private
|
132 | * @deprecated This prop has been renamed to `endMonth`.
|
133 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
134 | */
|
135 | toMonth?: Date;
|
136 | /**
|
137 | * @private
|
138 | * @deprecated Use `endMonth` instead. E.g. `endMonth={new Date(year, 0)}`.
|
139 | * @see https://daypicker.dev/docs/navigation#start-and-end-dates
|
140 | */
|
141 | toYear?: number;
|
142 | /**
|
143 | * Paginate the month navigation displaying the `numberOfMonths` at time.
|
144 | *
|
145 | * @see https://daypicker.dev/docs/customization#multiplemonths
|
146 | */
|
147 | pagedNavigation?: boolean;
|
148 | /**
|
149 | * Render the months in reversed order (when {@link numberOfMonths} is set) to
|
150 | * display the most recent month first.
|
151 | *
|
152 | * @see https://daypicker.dev/docs/customization#multiplemonths
|
153 | */
|
154 | reverseMonths?: boolean;
|
155 | /**
|
156 | * Hide the navigation buttons. This prop won't disable the navigation: to
|
157 | * disable the navigation, use {@link disableNavigation}.
|
158 | *
|
159 | * @since 9.0.0
|
160 | * @see https://daypicker.dev/docs/navigation#hidenavigation
|
161 | */
|
162 | hideNavigation?: boolean;
|
163 | /**
|
164 | * Disable the navigation between months. This prop won't hide the navigation:
|
165 | * to hide the navigation, use {@link hideNavigation}.
|
166 | *
|
167 | * @see https://daypicker.dev/docs/navigation#disablenavigation
|
168 | */
|
169 | disableNavigation?: boolean;
|
170 | /**
|
171 | * Show dropdowns to navigate between months or years.
|
172 | *
|
173 | * - `true`: display the dropdowns for both month and year
|
174 | * - `label`: display the month and the year as a label. Change the label with
|
175 | * the `formatCaption` formatter.
|
176 | * - `month`: display only the dropdown for the months
|
177 | * - `year`: display only the dropdown for the years
|
178 | *
|
179 | * **Note:** showing the dropdown will set the start/end months
|
180 | * {@link fromYear} to the 100 years ago, and {@link toYear} to the current
|
181 | * year.
|
182 | *
|
183 | * @see https://daypicker.dev/docs/customization#caption-layouts
|
184 | */
|
185 | captionLayout?: "label" | "dropdown" | "dropdown-months" | "dropdown-years";
|
186 | /**
|
187 | * Display always 6 weeks per each month, regardless the month’s number of
|
188 | * weeks. Weeks will be filled with the days from the next month.
|
189 | *
|
190 | * @see https://daypicker.dev/docs/customization#fixed-weeks
|
191 | */
|
192 | fixedWeeks?: boolean;
|
193 | /**
|
194 | * Hide the row displaying the weekday row header.
|
195 | *
|
196 | * @since 9.0.0
|
197 | */
|
198 | hideWeekdays?: boolean;
|
199 | /**
|
200 | * Show the outside days (days falling in the next or the previous month).
|
201 | *
|
202 | * @see https://daypicker.dev/docs/customization#outside-days
|
203 | */
|
204 | showOutsideDays?: boolean;
|
205 | /**
|
206 | * Show the week numbers column. Weeks are numbered according to the local
|
207 | * week index.
|
208 | *
|
209 | * - To use ISO week numbering, use the `ISOWeek` prop.
|
210 | * - To change how the week numbers are displayed, use the `formatters` prop.
|
211 | *
|
212 | * @see https://daypicker.dev/docs/customization#showweeknumber
|
213 | */
|
214 | showWeekNumber?: boolean;
|
215 | /**
|
216 | * Use ISO week dates instead of the locale setting. Setting this prop will
|
217 | * ignore `weekStartsOn` and `firstWeekContainsDate`.
|
218 | *
|
219 | * Use the
|
220 | * [react-day-picker/utc](https://daypicker.dev/docs/localization#utc-dates)
|
221 | * to set the calendar to UTC.
|
222 | *
|
223 | * @see https://daypicker.dev/docs/localization#iso-week-dates
|
224 | * @see https://en.wikipedia.org/wiki/ISO_week_date
|
225 | */
|
226 | ISOWeek?: boolean;
|
227 | /**
|
228 | * Change the components used for rendering the calendar elements.
|
229 | *
|
230 | * @see https://daypicker.dev/guides/custom-components
|
231 | */
|
232 | components?: Partial<CustomComponents>;
|
233 | /**
|
234 | * Add a footer to the calendar, acting as live region.
|
235 | *
|
236 | * Use this prop to communicate the calendar's status to screen readers.
|
237 | * Prefer strings over complex UI elements.
|
238 | *
|
239 | * @see https://daypicker.dev/docs/accessibility#footer
|
240 | */
|
241 | footer?: React.ReactNode | string;
|
242 | /**
|
243 | * When a selection mode is set, DayPicker will focus the first selected day
|
244 | * (if set) or the today's date (if not disabled).
|
245 | *
|
246 | * Use this prop when you need to focus DayPicker after a user actions, for
|
247 | * improved accessibility.
|
248 | *
|
249 | * @see https://daypicker.dev/docs/accessibility#autofocus
|
250 | */
|
251 | autoFocus?: boolean;
|
252 | /**
|
253 | * Apply the `disabled` modifier to the matching days.
|
254 | *
|
255 | * @see https://daypicker.dev/docs/selection-modes#disabling-dates
|
256 | */
|
257 | disabled?: Matcher | Matcher[] | undefined;
|
258 | /**
|
259 | * Apply the `hidden` modifier to the matching days. Will hide them from the
|
260 | * calendar.
|
261 | *
|
262 | * @see https://daypicker.dev/guides/custom-modifiers#hidden-modifier
|
263 | */
|
264 | hidden?: Matcher | Matcher[] | undefined;
|
265 | /**
|
266 | * The today’s date. Default is the current date. This date will get the
|
267 | * `today` modifier to style the day.
|
268 | *
|
269 | * @see https://daypicker.dev/guides/custom-modifiers#today-modifier
|
270 | */
|
271 | today?: Date;
|
272 | /**
|
273 | * Add modifiers to the matching days.
|
274 | *
|
275 | * @see https://daypicker.dev/guides/custom-modifiers
|
276 | */
|
277 | modifiers?: Record<string, Matcher | Matcher[] | undefined> | undefined;
|
278 | /**
|
279 | * Labels creators to override the defaults. Use this prop to customize the
|
280 | * aria-label attributes in DayPicker.
|
281 | *
|
282 | * @see https://daypicker.dev/docs/translation#aria-labels
|
283 | */
|
284 | labels?: Partial<Labels>;
|
285 | /**
|
286 | * Formatters used to format dates to strings. Use this prop to override the
|
287 | * default functions.
|
288 | *
|
289 | * @see https://daypicker.dev/docs/translation#custom-formatters
|
290 | */
|
291 | formatters?: Partial<Formatters>;
|
292 | /**
|
293 | * The text direction of the calendar. Use `ltr` for left-to-right (default)
|
294 | * or `rtl` for right-to-left.
|
295 | *
|
296 | * @see https://daypicker.dev/docs/translation#rtl-text-direction
|
297 | */
|
298 | dir?: HTMLDivElement["dir"];
|
299 | /**
|
300 | * A cryptographic nonce ("number used once") which can be used by Content
|
301 | * Security Policy for the inline `style` attributes.
|
302 | */
|
303 | nonce?: HTMLDivElement["nonce"];
|
304 | /** Add a `title` attribute to the container element. */
|
305 | title?: HTMLDivElement["title"];
|
306 | /** Add the language tag to the container element. */
|
307 | lang?: HTMLDivElement["lang"];
|
308 | /**
|
309 | * The date-fns locale object used to localize dates.
|
310 | *
|
311 | * @defaultValue en-US
|
312 | * @see https://daypicker.dev/docs/localization
|
313 | */
|
314 | locale?: Locale | undefined;
|
315 | /**
|
316 | * The index of the first day of the week (0 - Sunday). Overrides the locale's
|
317 | * one.
|
318 | *
|
319 | * @see https://daypicker.dev/docs/localization#first-date-of-the-week
|
320 | */
|
321 | weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
322 | /**
|
323 | * The day of January, which is always in the first week of the year.
|
324 | *
|
325 | * @see https://daypicker.dev/docs/localization#first-week-contains-date
|
326 | */
|
327 | firstWeekContainsDate?: 1 | 4;
|
328 | /**
|
329 | * Enable `DD` and `DDDD` for week year tokens when formatting or parsing
|
330 | * dates.
|
331 | *
|
332 | * @see https://date-fns.org/docs/Unicode-Tokens
|
333 | */
|
334 | useAdditionalWeekYearTokens?: boolean | undefined;
|
335 | /**
|
336 | * Enable `YY` and `YYYY` for day of year tokens when formatting or parsing
|
337 | * dates.
|
338 | *
|
339 | * @see https://date-fns.org/docs/Unicode-Tokens
|
340 | */
|
341 | useAdditionalDayOfYearTokens?: boolean | undefined;
|
342 | /**
|
343 | * Event fired when the user navigates between months.
|
344 | *
|
345 | * @see https://daypicker.dev/docs/navigation#onmonthchange
|
346 | */
|
347 | onMonthChange?: MonthChangeEventHandler;
|
348 | /**
|
349 | * Event handler when the next month button is clicked.
|
350 | *
|
351 | * @see https://daypicker.dev/docs/navigation
|
352 | */
|
353 | onNextClick?: MonthChangeEventHandler;
|
354 | /**
|
355 | * Event handler when the previous month button is clicked.
|
356 | *
|
357 | * @see https://daypicker.dev/docs/navigation
|
358 | */
|
359 | onPrevClick?: MonthChangeEventHandler;
|
360 | /**
|
361 | * Event handler when a week number is clicked
|
362 | *
|
363 | * @private
|
364 | * @deprecated Use a custom `WeekNumber` component instead.
|
365 | * @see https://daypicker.dev/docs/customization#showweeknumber
|
366 | */
|
367 | onWeekNumberClick?: any;
|
368 | /** Event handler when a day is clicked. */
|
369 | onDayClick?: DayEventHandler<React.MouseEvent>;
|
370 | /** Event handler when a day is focused. */
|
371 | onDayFocus?: DayEventHandler<React.FocusEvent>;
|
372 | /** Event handler when a day is blurred. */
|
373 | onDayBlur?: DayEventHandler<React.FocusEvent>;
|
374 | /** Event handler when a key is pressed on a day. */
|
375 | onDayKeyDown?: DayEventHandler<React.KeyboardEvent>;
|
376 | /**
|
377 | * Replace the default date library with a custom one.
|
378 | *
|
379 | * @private
|
380 | * @since 9.0.0
|
381 | * @experimental
|
382 | */
|
383 | dateLib?: Partial<DateLib> | undefined;
|
384 | /**
|
385 | * @private
|
386 | * @deprecated Use a custom `DayButton` component instead.
|
387 | */
|
388 | onDayKeyUp?: DayEventHandler<React.KeyboardEvent>;
|
389 | /**
|
390 | * @private
|
391 | * @deprecated Use a custom `DayButton` component instead.
|
392 | */
|
393 | onDayKeyPress?: DayEventHandler<React.KeyboardEvent>;
|
394 | /**
|
395 | * @private
|
396 | * @deprecated Use a custom `DayButton` component instead.
|
397 | */
|
398 | onDayPointerEnter?: DayEventHandler<React.PointerEvent>;
|
399 | /**
|
400 | * @private
|
401 | * @deprecated Use a custom `DayButton` component instead.
|
402 | */
|
403 | onDayPointerLeave?: DayEventHandler<React.PointerEvent>;
|
404 | /**
|
405 | * @private
|
406 | * @deprecated Use a custom `DayButton` component instead.
|
407 | */
|
408 | onDayTouchCancel?: DayEventHandler<React.TouchEvent>;
|
409 | /**
|
410 | * @private
|
411 | * @deprecated Use a custom `DayButton` component instead.
|
412 | */
|
413 | onDayTouchEnd?: DayEventHandler<React.TouchEvent>;
|
414 | /**
|
415 | * @private
|
416 | * @deprecated Use a custom `DayButton` component instead.
|
417 | */
|
418 | onDayTouchMove?: DayEventHandler<React.TouchEvent>;
|
419 | /**
|
420 | * @private
|
421 | * @deprecated Use a custom `DayButton` component instead.
|
422 | */
|
423 | onDayTouchStart?: DayEventHandler<React.TouchEvent>;
|
424 | }
|
425 | /**
|
426 | * The props when the single selection is required.
|
427 | *
|
428 | * @see https://daypicker.dev/docs/selection-modes#single-mode
|
429 | */
|
430 | export interface PropsSingleRequired {
|
431 | mode: "single";
|
432 | required: true;
|
433 | selected: Date;
|
434 | onSelect?: (selected: Date, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void | undefined;
|
435 | }
|
436 | /**
|
437 | * The props when the single selection is optional.
|
438 | *
|
439 | * @see https://daypicker.dev/docs/selection-modes#single-mode
|
440 | */
|
441 | export interface PropsSingle {
|
442 | mode: "single";
|
443 | required?: false | undefined;
|
444 | selected?: Date | undefined;
|
445 | onSelect?: (selected: Date | undefined, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void;
|
446 | }
|
447 | /**
|
448 | * The props when the multiple selection is required.
|
449 | *
|
450 | * @see https://daypicker.dev/docs/selection-modes#multiple-mode
|
451 | */
|
452 | export interface PropsMultiRequired {
|
453 | mode: "multiple";
|
454 | required: true;
|
455 | selected: Date[];
|
456 | onSelect?: (selected: Date[], triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void;
|
457 | min?: number;
|
458 | max?: number;
|
459 | }
|
460 | /**
|
461 | * The props when the multiple selection is optional.
|
462 | *
|
463 | * @see https://daypicker.dev/docs/selection-modes#multiple-mode
|
464 | */
|
465 | export interface PropsMulti {
|
466 | mode: "multiple";
|
467 | required?: false | undefined;
|
468 | selected?: Date[] | undefined;
|
469 | onSelect?: (selected: Date[] | undefined, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void;
|
470 | min?: number;
|
471 | max?: number;
|
472 | }
|
473 | /**
|
474 | * The props when the range selection is required.
|
475 | *
|
476 | * @see https://daypicker.dev/docs/selection-modes#range-mode
|
477 | */
|
478 | export interface PropsRangeRequired {
|
479 | mode: "range";
|
480 | required: true;
|
481 | selected: DateRange;
|
482 | onSelect?: (selected: DateRange, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void;
|
483 | min?: number;
|
484 | max?: number;
|
485 | }
|
486 | /**
|
487 | * The props when the range selection is optional.
|
488 | *
|
489 | * @see https://daypicker.dev/docs/selection-modes#range-mode
|
490 | */
|
491 | export interface PropsRange {
|
492 | mode: "range";
|
493 | required?: false | undefined;
|
494 | selected?: DateRange | undefined;
|
495 | disabled?: Matcher | Matcher[] | undefined;
|
496 | onSelect?: (selected: DateRange | undefined, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void | undefined;
|
497 | min?: number;
|
498 | max?: number;
|
499 | }
|