1 | import type { DayPickerProps } from "./props.js";
|
2 | import type { DateRange, Mode, Modifiers } from "./shared.js";
|
3 | export type Selection<T extends DayPickerProps> = {
|
4 |
|
5 | selected: SelectedValue<T> | undefined;
|
6 |
|
7 | select: SelectHandler<T> | undefined;
|
8 |
|
9 | isSelected: (date: Date) => boolean;
|
10 | };
|
11 | export type SelectedSingle<T extends {
|
12 | required?: boolean;
|
13 | }> = T["required"] extends true ? Date : Date | undefined;
|
14 | export type SelectedMulti<T extends {
|
15 | required?: boolean;
|
16 | }> = T["required"] extends true ? Date[] : Date[] | undefined;
|
17 | export type SelectedRange<T extends {
|
18 | required?: boolean;
|
19 | }> = T["required"] extends true ? DateRange : DateRange | undefined;
|
20 | export 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;
|
30 | export 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;
|
33 | export 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;
|
36 | export 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;
|
39 | export 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;
|