1 | import type { CSSProperties } from "react";
|
2 | import { UI, DayFlag, SelectionState } from "../UI.js";
|
3 | import * as components from "../components/custom-components.js";
|
4 | import { formatCaption, formatDay, formatMonthCaption, formatMonthDropdown, formatWeekdayName, formatWeekNumber, formatWeekNumberHeader, formatYearCaption, formatYearDropdown } from "../formatters/index.js";
|
5 | import { labelDayButton, labelNav, labelGrid, labelGridcell, labelMonthDropdown, labelNext, labelPrevious, labelWeekday, labelWeekNumber, labelWeekNumberHeader, labelYearDropdown } from "../labels/index.js";
|
6 | /**
|
7 | * Selection modes supported by DayPicker.
|
8 | *
|
9 | * - `single`: use DayPicker to select single days.
|
10 | * - `multiple`: allow selecting multiple days.
|
11 | * - `range`: use DayPicker to select a range of days.
|
12 | *
|
13 | * @see https://daypicker.dev/docs/selection-modes
|
14 | */
|
15 | export type Mode = "single" | "multiple" | "range";
|
16 | /**
|
17 | * The components that can be changed using the `components` prop.
|
18 | *
|
19 | * @see https://daypicker.dev/guides/custom-components
|
20 | */
|
21 | export type CustomComponents = {
|
22 | /**
|
23 | * Render any button element in DayPicker.
|
24 | *
|
25 | * @deprecated Use {@link CustomComponents.NextMonthButton} or
|
26 | * {@link CustomComponents.PreviousMonthButton} instead.
|
27 | */
|
28 | Button: typeof components.Button;
|
29 | /** Render the chevron icon used in the navigation buttons and dropdowns. */
|
30 | Chevron: typeof components.Chevron;
|
31 | /** Render the caption label of the month grid. */
|
32 | CaptionLabel: typeof components.CaptionLabel;
|
33 | /** Render the day cell in the month grid. */
|
34 | Day: typeof components.Day;
|
35 | /** Render the button containing the day in the day cell. */
|
36 | DayButton: typeof components.DayButton;
|
37 | /** Render the dropdown element to select years and months. */
|
38 | Dropdown: typeof components.Dropdown;
|
39 | /** Render the container of the dropdowns. */
|
40 | DropdownNav: typeof components.DropdownNav;
|
41 | /** Render the footer element announced by screen readers. */
|
42 | Footer: typeof components.Footer;
|
43 | /** Render the container of the MonthGrid. */
|
44 | Month: typeof components.Month;
|
45 | /** Render the caption of the month grid. */
|
46 | MonthCaption: typeof components.MonthCaption;
|
47 | /** Render the grid of days in a month. */
|
48 | MonthGrid: typeof components.MonthGrid;
|
49 | /** Wrapper of the month grids. */
|
50 | Months: typeof components.Months;
|
51 | /** Render the navigation element with the next and previous buttons. */
|
52 | Nav: typeof components.Nav;
|
53 | /** Render the `<option>` HTML element in the dropdown. */
|
54 | Option: typeof components.Option;
|
55 | /** Render the previous month button element in the navigation. */
|
56 | PreviousMonthButton: typeof components.PreviousMonthButton;
|
57 | /** Render the next month button element in the navigation. */
|
58 | NextMonthButton: typeof components.NextMonthButton;
|
59 | /** Render the root element of the calendar. */
|
60 | Root: typeof components.Root;
|
61 | /** Render the select element in the dropdowns. */
|
62 | Select: typeof components.Select;
|
63 | /** Render the weeks section in the month grid. */
|
64 | Weeks: typeof components.Weeks;
|
65 | /** Render the week rows. */
|
66 | Week: typeof components.Week;
|
67 | /** Render the weekday name in the header. */
|
68 | Weekday: typeof components.Weekday;
|
69 | /** Render the row containing the week days. */
|
70 | Weekdays: typeof components.Weekdays;
|
71 | /** Render the cell with the number of the week. */
|
72 | WeekNumber: typeof components.WeekNumber;
|
73 | /** Render the header of the week number column. */
|
74 | WeekNumberHeader: typeof components.WeekNumberHeader;
|
75 | /** Render the dropdown with the months. */
|
76 | MonthsDropdown: typeof components.MonthsDropdown;
|
77 | /** Render the dropdown with the years. */
|
78 | YearsDropdown: typeof components.YearsDropdown;
|
79 | };
|
80 | /** Represent a map of formatters used to render localized content. */
|
81 | export type Formatters = {
|
82 | /** Format the caption of a month grid. */
|
83 | formatCaption: typeof formatCaption;
|
84 | /** Format the day in the day cell. */
|
85 | formatDay: typeof formatDay;
|
86 | /** Format the label in the month dropdown. */
|
87 | formatMonthDropdown: typeof formatMonthDropdown;
|
88 | /**
|
89 | * @ignore
|
90 | * @deprecated Use {@link Formatters.formatCaption} instead.
|
91 | */
|
92 | formatMonthCaption: typeof formatMonthCaption;
|
93 | /** Format the week number. */
|
94 | formatWeekNumber: typeof formatWeekNumber;
|
95 | /** Format the header of the week number column. */
|
96 | formatWeekNumberHeader: typeof formatWeekNumberHeader;
|
97 | /** Format the week day name in the header. */
|
98 | formatWeekdayName: typeof formatWeekdayName;
|
99 | /** Format the label in the year dropdown. */
|
100 | formatYearDropdown: typeof formatYearDropdown;
|
101 | /**
|
102 | * @ignore
|
103 | * @deprecated Use {@link Formatters.formatYearDropdown} instead.
|
104 | */
|
105 | formatYearCaption: typeof formatYearCaption;
|
106 | };
|
107 | /** Map of functions to translate ARIA labels for the relative elements. */
|
108 | export type Labels = {
|
109 | /** The label for the navigation toolbar. */
|
110 | labelNav: typeof labelNav;
|
111 | /** The label for the month grid. */
|
112 | labelGrid: typeof labelGrid;
|
113 | /** The label for the gridcell, when the calendar is not interactive. */
|
114 | labelGridcell: typeof labelGridcell;
|
115 | /** The label for the month dropdown. */
|
116 | labelMonthDropdown: typeof labelMonthDropdown;
|
117 | /** The label for the year dropdown. */
|
118 | labelYearDropdown: typeof labelYearDropdown;
|
119 | /** The label for the "next month" button. */
|
120 | labelNext: typeof labelNext;
|
121 | /** The label for the "previous month" button. */
|
122 | labelPrevious: typeof labelPrevious;
|
123 | /** The label for the day button. */
|
124 | labelDayButton: typeof labelDayButton;
|
125 | /**
|
126 | * @ignore
|
127 | * @deprecated Use {@link labelDayButton} instead.
|
128 | */
|
129 | labelDay: typeof labelDayButton;
|
130 | /** The label for the weekday. */
|
131 | labelWeekday: typeof labelWeekday;
|
132 | /** The label for the week number. */
|
133 | labelWeekNumber: typeof labelWeekNumber;
|
134 | /**
|
135 | * Return the label for the column of the week number.
|
136 | *
|
137 | * @since 9.0.0
|
138 | */
|
139 | labelWeekNumberHeader: typeof labelWeekNumberHeader;
|
140 | };
|
141 | /**
|
142 | * A value or a function that matches a specific day.
|
143 | *
|
144 | * @example
|
145 | * // will always match the day
|
146 | * const booleanMatcher: Matcher = true;
|
147 | *
|
148 | * // will match the today's date
|
149 | * const dateMatcher: Matcher = new Date();
|
150 | *
|
151 | * // will match the days in the array
|
152 | * const arrayMatcher: Matcher = [
|
153 | * new Date(2019, 1, 2),
|
154 | * new Date(2019, 1, 4)
|
155 | * ];
|
156 | *
|
157 | * // will match days after the 2nd of February 2019
|
158 | * const afterMatcher: DateAfter = { after: new Date(2019, 1, 2) };
|
159 | *
|
160 | * // will match days before the 2nd of February 2019 }
|
161 | * const beforeMatcher: DateBefore = { before: new Date(2019, 1, 2) };
|
162 | *
|
163 | * // will match Sundays
|
164 | * const dayOfWeekMatcher: DayOfWeek = {
|
165 | * dayOfWeek: 0
|
166 | * };
|
167 | *
|
168 | * // will match the included days, except the two dates
|
169 | * const intervalMatcher: DateInterval = {
|
170 | * after: new Date(2019, 1, 2),
|
171 | * before: new Date(2019, 1, 5)
|
172 | * };
|
173 | *
|
174 | * // will match the included days, including the two dates
|
175 | * const rangeMatcher: DateRange = {
|
176 | * from: new Date(2019, 1, 2),
|
177 | * to: new Date(2019, 1, 5)
|
178 | * };
|
179 | *
|
180 | * // will match when the function return true
|
181 | * const functionMatcher: Matcher = (day: Date) => {
|
182 | * return day.getMonth() === 2; // match when month is March
|
183 | * };
|
184 | */
|
185 | export type Matcher = boolean | ((date: Date) => boolean) | Date | Date[] | DateRange | DateBefore | DateAfter | DateInterval | DayOfWeek;
|
186 | /**
|
187 | * Match a day falling after the specified date, with the date not included.
|
188 | *
|
189 | * @example
|
190 | * // Match days after the 2nd of February 2019
|
191 | * const matcher: DateAfter = { after: new Date(2019, 1, 2) };
|
192 | */
|
193 | export type DateAfter = {
|
194 | after: Date;
|
195 | };
|
196 | /**
|
197 | * Match a day falling before the specified date, with the date not included.
|
198 | *
|
199 | * @example
|
200 | * // Match days before the 2nd of February 2019
|
201 | * const matcher: DateBefore = { before: new Date(2019, 1, 2) };
|
202 | */
|
203 | export type DateBefore = {
|
204 | before: Date;
|
205 | };
|
206 | /**
|
207 | * An interval of dates. Differently from {@link DateRange}, the range ends here
|
208 | * are not included.
|
209 | *
|
210 | * @example
|
211 | * // Match the days between the 2nd and the 5th of February 2019
|
212 | * const matcher: DateInterval = {
|
213 | * after: new Date(2019, 1, 2),
|
214 | * before: new Date(2019, 1, 5)
|
215 | * };
|
216 | */
|
217 | export type DateInterval = {
|
218 | before: Date;
|
219 | after: Date;
|
220 | };
|
221 | /**
|
222 | * A range of dates. The range can be open. Differently from
|
223 | * {@link DateInterval}, the range ends here are included.
|
224 | *
|
225 | * @example
|
226 | * // Match the days between the 2nd and the 5th of February 2019
|
227 | * const matcher: DateRange = {
|
228 | * from: new Date(2019, 1, 2),
|
229 | * to: new Date(2019, 1, 5)
|
230 | * };
|
231 | */
|
232 | export type DateRange = {
|
233 | from: Date | undefined;
|
234 | to?: Date | undefined;
|
235 | };
|
236 | /**
|
237 | * Match dates being one of the specified days of the week (`0-6`, where `0` is
|
238 | * Sunday).
|
239 | *
|
240 | * @example
|
241 | * // Match Sundays
|
242 | * const matcher: DayOfWeek = { dayOfWeek: 0 };
|
243 | * // Match weekends
|
244 | * const matcher: DayOfWeek = { dayOfWeek: [0, 6] };
|
245 | */
|
246 | export type DayOfWeek = {
|
247 | dayOfWeek: number | number[];
|
248 | };
|
249 | /**
|
250 | * The event handler triggered when clicking or interacting with a day.
|
251 | *
|
252 | * @template EventType - The event type that triggered the event (e.g.
|
253 | * `React.MouseEvent`, `React.KeyboardEvent`, etc.).
|
254 | * @param date - The date that has triggered the event.
|
255 | * @param modifiers - The modifiers belonging to the date.
|
256 | * @param e - The DOM event that triggered the event.
|
257 | */
|
258 | export type DayEventHandler<EventType> = (date: Date, modifiers: Modifiers, e: EventType) => void;
|
259 | /**
|
260 | * The event handler when a month is changed in the calendar.
|
261 | *
|
262 | * ```tsx
|
263 | * <DayPicker onMonthChange={(month) => console.log(month)} />
|
264 | * ```
|
265 | *
|
266 | * @see https://daypicker.dev/docs/navigation
|
267 | */
|
268 | export type MonthChangeEventHandler = (month: Date) => void;
|
269 | /**
|
270 | * The CSS classnames to use for the {@link UI} elements, the
|
271 | * {@link SelectionState} and the {@link DayFlag}.
|
272 | *
|
273 | * @example
|
274 | * const classNames: ClassNames = {
|
275 | * [UI.Root]: "root",
|
276 | * [UI.Outside]: "outside",
|
277 | * [UI.Nav]: "nav"
|
278 | * // etc.
|
279 | * };
|
280 | */
|
281 | export type ClassNames = {
|
282 | [key in UI | SelectionState | DayFlag]: string;
|
283 | };
|
284 | /**
|
285 | * The CSS styles to use for the {@link UI} elements, the {@link SelectionState}
|
286 | * and the {@link DayFlag}.
|
287 | */
|
288 | export type Styles = {
|
289 | [key in UI | SelectionState | DayFlag]: CSSProperties | undefined;
|
290 | };
|
291 | /**
|
292 | * Represents the modifiers that match a specific day in the calendar.
|
293 | *
|
294 | * - Retrieve modifiers using the {@link OnSelectHandler} via the `onSelect` prop,
|
295 | * or within custom components using the {@link useDayPicker} hook.
|
296 | * - Includes built-in modifiers from {@link DayFlag} and {@link SelectionState}.
|
297 | * - Add custom modifiers using the `modifiers` prop.
|
298 | *
|
299 | * @example
|
300 | * const modifiers: Modifiers = {
|
301 | * today: false, // the day is not today
|
302 | * selected: true, // the day is selected
|
303 | * disabled: false, // the day is not disabled
|
304 | * outside: false, // the day is not outside the month
|
305 | * focused: false, // the day is not focused
|
306 | *
|
307 | * weekend: false // custom modifier example for matching a weekend
|
308 | * booked: true // custom modifier example for matching a booked day
|
309 | * available: false // custom modifier example for matching an available day
|
310 | * };
|
311 | *
|
312 | * @see https://daypicker.dev/guides/custom-modifiers
|
313 | */
|
314 | export type Modifiers = Record<string, boolean>;
|
315 | /**
|
316 | * The style to apply to each day element matching a modifier.
|
317 | *
|
318 | * @example
|
319 | * const modifiersStyles: ModifiersStyles = {
|
320 | * today: { color: "red" },
|
321 | * selected: { backgroundColor: "blue" },
|
322 | * weekend: { color: "green" }
|
323 | * };
|
324 | */
|
325 | export type ModifiersStyles = Record<string, CSSProperties>;
|
326 | /**
|
327 | * The classnames to assign to each day element matching a modifier.
|
328 | *
|
329 | * @example
|
330 | * const modifiersClassNames: ModifiersClassNames = {
|
331 | * today: "today", // Use the "today" class for the today's day
|
332 | * selected: "highlight", // Use the "highlight" class for the selected day
|
333 | * weekend: "weekend" // Use the "weekend" class for the weekend days
|
334 | * };
|
335 | */
|
336 | export type ModifiersClassNames = Record<string, string>;
|
337 | /**
|
338 | * The props that have been deprecated since version 9.0.0.
|
339 | *
|
340 | * @private
|
341 | * @since 9.0.0
|
342 | * @see https://daypicker.dev/upgrading
|
343 | */
|
344 | export type V9DeprecatedProps =
|
345 | /** Use `hidden` prop instead. */
|
346 | "fromDate"
|
347 | /** Use `hidden` prop instead. */
|
348 | | "toDate"
|
349 | /** Use `startMonth` instead. */
|
350 | | "fromMonth"
|
351 | /** Use `endMonth` instead. */
|
352 | | "toMonth"
|
353 | /** Use `startMonth` instead. */
|
354 | | "fromYear"
|
355 | /** Use `endMonth` instead. */
|
356 | | "toYear";
|
357 | /** The direction to move the focus relative to the current focused date. */
|
358 | export type MoveFocusDir = "after" | "before";
|
359 | /** The temporal unit to move the focus by. */
|
360 | export type MoveFocusBy = "day" | "week" | "startOfWeek" | "endOfWeek" | "month" | "year";
|