UNPKG

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