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