import type { DateFrameworkType, Timezone } from "@salt-ds/date-adapters"; import { type Context, type Ref, type SyntheticEvent } from "react"; import type { DateRangeSelection, SingleDateSelection } from "../calendar"; import type { DateInputRangeDetails, DateInputSingleDetails } from "../date-input"; /** * Interface representing the base state for a DatePicker. * @template TDate - The type of the date object. */ interface DatePickerBaseState { /** * The state properties of the DatePicker. */ state: { /** * If `true`, the DatePicker is disabled. */ disabled?: boolean; /** * If `true`, the DatePicker is read-only. */ readOnly?: boolean; /** * If `true`, the DatePicker has been cancelled. */ cancelled?: boolean; /** * If `true`, the apply action is enabled. */ enableApply?: boolean; /** * The minimum selectable date. */ minDate?: TDate; /** * The maximum selectable date. */ maxDate?: TDate; /** * Reference to the container element. */ containerRef: Ref; /** * Specifies the timezone behavior: * - If undefined, the timezone will be derived from the passed date, or from `defaultSelectedDate`/`selectedDate`. * - If set to "default", the default timezone of the date library will be used. * - If set to "system", the local system's timezone will be applied. * - If set to "UTC", the time will be returned in UTC. * - If set to a valid IANA timezone identifier, the time will be returned for that specific timezone. */ timezone?: Timezone; }; /** * Helper functions for managing the DatePicker state. */ helpers: { /** * Cancels the DatePicker action. * @param event - event that triggered the state change */ cancel: (event?: Event) => void; /** * Function to determine if a day is highlighted. * @param date - The date to check. * @returns A string reason if the day is highlighted, otherwise `false` or `undefined`. */ isDayHighlighted?: (date: TDate) => string | false | undefined; /** * Function to determine if a day is unselectable. * @param date - The date to check. * @returns A string reason if the day is unselectable, otherwise `false` or `undefined`. */ isDayUnselectable?: (date: TDate) => string | false | undefined; /** * Sets the enableApply state. * @param newEnableApply - The new value for enableApply. */ setEnableApply: (newEnableApply: boolean) => void; }; } /** * Interface representing the state for a single date picker. */ export interface SingleDatePickerState extends DatePickerBaseState { /** * The state properties of the single date picker. */ state: DatePickerBaseState["state"] & { /** * The selected date. */ selectedDate: SingleDateSelection | null; /** * The default selected date. */ defaultSelectedDate?: SingleDateSelection; }; /** * Helper functions for managing the single date picker state. */ helpers: DatePickerBaseState["helpers"] & { /** * Apply the selected single date. * @param event - The synthetic event. * @param date - The new applied date. */ apply: (event: SyntheticEvent, date: SingleDateSelection | null) => void; /** * Select a single date. * @param event - The synthetic event. * @param date - The selected date or null. * @param details - Details of selection, such as errors and original value. */ select: (event: SyntheticEvent, date: SingleDateSelection | null, details?: DateInputSingleDetails) => void; }; } /** * Interface representing the state for a range date picker. */ export interface RangeDatePickerState extends DatePickerBaseState { /** * The state properties of the range date picker. */ state: DatePickerBaseState["state"] & { /** * The selected date range. */ selectedDate: DateRangeSelection | null; /** * The default selected date range. */ defaultSelectedDate?: DateRangeSelection; }; /** * Helper functions for managing the range date picker state. */ helpers: DatePickerBaseState["helpers"] & { /** * Apply the selected date range. * @param event - The synthetic event. * @param date - The new applied date range */ apply: (event: SyntheticEvent, date: DateRangeSelection | null) => void; /** * Select a date range. * @param event - The synthetic event. * @param date - The selected date. * @param details - Details of selection, such as errors and original value. */ select: (event: SyntheticEvent, date: DateRangeSelection | null, details?: DateInputRangeDetails) => void; }; } /** * Type representing the state of a date picker, either single or range. */ export type DatePickerState = SingleDatePickerState | RangeDatePickerState; /** * Context for single date selection. */ export declare const SingleDateSelectionContext: Context | undefined>; /** * Context for date range selection. */ export declare const DateRangeSelectionContext: Context | undefined>; /** * Props for using the date picker context. */ export interface UseDatePickerContextProps { /** * The selection variant, either "single" or "range". */ selectionVariant: "single" | "range"; } /** * Hook to use the date picker context for single date selection. * @param props - The props for the hook. * @returns The state of the single date picker. */ export declare function useDatePickerContext(props: { selectionVariant: "single"; }): SingleDatePickerState; /** * Hook to use the date picker context for range date selection. * @param props - The props for the hook. * @returns The state of the range date picker. */ export declare function useDatePickerContext(props: { selectionVariant: "range"; }): RangeDatePickerState; export {};