UNPKG

2.96 kBTypeScriptView Raw
1import { CalendarDay } from "./classes/CalendarDay.js";
2import { CalendarMonth } from "./classes/CalendarMonth.js";
3import { DayPickerProps } from "./types/props.js";
4import type { SelectedValue, SelectHandler } from "./types/selection.js";
5import { ClassNames, CustomComponents, Formatters, Labels, Mode, Modifiers, Styles } from "./types/shared.js";
6/** @ignore */
7export declare const dayPickerContext: import("react").Context<DayPickerContext<{
8 mode?: Mode | undefined;
9 required?: boolean | undefined;
10}> | undefined>;
11/**
12 * Represents the context for the DayPicker component, providing various
13 * properties and methods to interact with the calendar.
14 *
15 * @template T - The type of the DayPicker props, which must optionally include
16 * `mode` and `required` properties. This type can be used to refine the type
17 * returned by the hook.
18 */
19export type DayPickerContext<T extends {
20 mode?: Mode | undefined;
21 required?: boolean | undefined;
22}> = {
23 /** The months displayed in the calendar. */
24 months: CalendarMonth[];
25 /** The next month to display. */
26 nextMonth: Date | undefined;
27 /** The previous month to display. */
28 previousMonth: Date | undefined;
29 /** Navigate to the specified month. Will fire the `onMonthChange` callback. */
30 goToMonth: (month: Date) => void;
31 /** Returns the modifiers for the given day. */
32 getModifiers: (day: CalendarDay) => Modifiers;
33 /** The selected date(s). */
34 selected: SelectedValue<T> | undefined;
35 /** Set a selection. */
36 select: SelectHandler<T> | undefined;
37 /** Whether the given date is selected. */
38 isSelected: ((date: Date) => boolean) | undefined;
39 /** The components used internally by DayPicker. */
40 components: CustomComponents;
41 /** The class names for the UI elements. */
42 classNames: ClassNames;
43 /** The styles for the UI elements. */
44 styles: Partial<Styles> | undefined;
45 /** The labels used in the user interface. */
46 labels: Labels;
47 /** The formatters used to format the UI elements. */
48 formatters: Formatters;
49 /**
50 * The props as passed to the DayPicker component.
51 *
52 * @since 9.3.0
53 */
54 dayPickerProps: DayPickerProps;
55};
56/**
57 * Returns the context to work with `<DayPicker />` inside custom components.
58 *
59 * This hook provides access to the DayPicker context, which includes various
60 * properties and methods to interact with the DayPicker component. It must be
61 * used within a custom component.
62 *
63 * @template T - Use this type to refine the returned context type with a
64 * specific selection mode.
65 * @returns {DayPickerContext<T>} The context to work with DayPicker.
66 * @throws {Error} If the hook is used outside of a DayPicker provider.
67 * @group Hooks
68 * @see https://daypicker.dev/guides/custom-components
69 */
70export declare function useDayPicker<T extends {
71 mode?: Mode | undefined;
72 required?: boolean | undefined;
73}>(): DayPickerContext<T>;
74
\No newline at end of file