From 9db259ca9e92cb4296304209e1ddc2ea291738ba Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Sun, 8 Sep 2024 08:19:02 -0500 Subject: [PATCH] feat(types): add OnSelectHandler --- src/types/props.ts | 50 +++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/src/types/props.ts b/src/types/props.ts index 0d0b8c2dd..28e125b79 100644 --- a/src/types/props.ts +++ b/src/types/props.ts @@ -470,6 +470,14 @@ export interface PropsBase { onDayTouchStart?: DayEventHandler; } +/** Shared handler type for onSelect events */ +export type OnSelectHandler = ( + selected: T, + triggerDate: Date, + modifiers: Modifiers, + e: React.MouseEvent | React.KeyboardEvent +) => void; + /** * The props when the single selection is required. * @@ -481,12 +489,7 @@ export interface PropsSingleRequired { /** The selected date. */ selected: Date | undefined; /** Event handler when a day is selected. */ - onSelect?: ( - selected: Date, - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void | undefined; + onSelect?: OnSelectHandler; } /** @@ -500,12 +503,7 @@ export interface PropsSingle { /** The selected date. */ selected?: Date | undefined; /** Event handler when a day is selected. */ - onSelect?: ( - selected: Date | undefined, - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void; + onSelect?: OnSelectHandler; } /** @@ -519,12 +517,7 @@ export interface PropsMultiRequired { /** The selected dates. */ selected: Date[] | undefined; /** Event handler when days are selected. */ - onSelect?: ( - selected: Date[], - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void; + onSelect?: OnSelectHandler; /** The minimum number of selectable days. */ min?: number; /** The maximum number of selectable days. */ @@ -542,12 +535,7 @@ export interface PropsMulti { /** The selected dates. */ selected?: Date[] | undefined; /** Event handler when days are selected. */ - onSelect?: ( - selected: Date[] | undefined, - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void; + onSelect?: OnSelectHandler; /** The minimum number of selectable days. */ min?: number; /** The maximum number of selectable days. */ @@ -571,12 +559,7 @@ export interface PropsRangeRequired { /** The selected range. */ selected: DateRange | undefined; /** Event handler when a range is selected. */ - onSelect?: ( - selected: DateRange, - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void; + onSelect?: OnSelectHandler; /** The minimum number of days to include in the range. */ min?: number; /** The maximum number of days to include in the range. */ @@ -600,12 +583,7 @@ export interface PropsRange { /** The selected range. */ selected?: DateRange | undefined; /** Event handler when the selection changes. */ - onSelect?: ( - selected: DateRange | undefined, - triggerDate: Date, - modifiers: Modifiers, - e: React.MouseEvent | React.KeyboardEvent - ) => void | undefined; + onSelect?: OnSelectHandler; /** The minimum number of days to include in the range. */ min?: number; /** The maximum number of days to include in the range. */