UNPKG

2.06 kBTypeScriptView Raw
1import type { DayPickerProps } from "./props.js";
2import type { DateRange, Mode, Modifiers } from "./shared.js";
3export type Selection<T extends DayPickerProps> = {
4 /** The selected date(s). */
5 selected: SelectedValue<T> | undefined;
6 /** Set a selection. */
7 select: SelectHandler<T> | undefined;
8 /** Whether the given date is selected. */
9 isSelected: (date: Date) => boolean;
10};
11export type SelectedSingle<T extends {
12 required?: boolean;
13}> = T["required"] extends true ? Date : Date | undefined;
14export type SelectedMulti<T extends {
15 required?: boolean;
16}> = T["required"] extends true ? Date[] : Date[] | undefined;
17export type SelectedRange<T extends {
18 required?: boolean;
19}> = T["required"] extends true ? DateRange : DateRange | undefined;
20export type SelectedValue<T> = T extends {
21 mode: "single";
22 required?: boolean;
23} ? SelectedSingle<T> : T extends {
24 mode: "multiple";
25 required?: boolean;
26} ? SelectedMulti<T> : T extends {
27 mode: "range";
28 required?: boolean;
29} ? SelectedRange<T> : undefined;
30export type SelectHandlerSingle<T extends {
31 required?: boolean | undefined;
32}> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? Date : Date | undefined;
33export type SelectHandlerMulti<T extends {
34 required?: boolean | undefined;
35}> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? Date[] : Date[] | undefined;
36export type SelectHandlerRange<T extends {
37 required?: boolean | undefined;
38}> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? DateRange : DateRange | undefined;
39export type SelectHandler<T extends {
40 mode?: Mode | undefined;
41 required?: boolean | undefined;
42}> = T extends {
43 mode: "single";
44} ? SelectHandlerSingle<T> : T extends {
45 mode: "multiple";
46} ? SelectHandlerMulti<T> : T extends {
47 mode: "range";
48} ? SelectHandlerRange<T> : undefined;