1 | import type { DayPickerProps } from "./props.js";
|
2 | import type { DateRange, 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 DayPickerProps> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? Date : Date | undefined;
|
31 | export type SelectHandlerMulti<T extends DayPickerProps> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? Date[] : Date[] | undefined;
|
32 | export type SelectHandlerRange<T extends DayPickerProps> = (triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => T["required"] extends true ? DateRange : DateRange | undefined;
|
33 | export type SelectHandler<T extends DayPickerProps> = T extends {
|
34 | mode: "single";
|
35 | } ? SelectHandlerSingle<T> : T extends {
|
36 | mode: "multiple";
|
37 | } ? SelectHandlerMulti<T> : T extends {
|
38 | mode: "range";
|
39 | } ? SelectHandlerRange<T> : undefined;
|