UNPKG

@payfit/unity-components

Version:

68 lines (67 loc) 3.21 kB
import { CalendarDate } from '@internationalized/date'; import { DatePickerProps as AriaDatePickerProps } from 'react-aria-components/DatePicker'; export interface DatePickerProps extends Pick<AriaDatePickerProps<CalendarDate>, 'id' | 'firstDayOfWeek' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-details'> { /** The currently selected date */ value?: CalendarDate | null; /** The default selected date (uncontrolled) */ defaultValue?: CalendarDate | null; /** The minimum allowed date */ minValue?: CalendarDate; /** The maximum allowed date */ maxValue?: CalendarDate; /** Callback fired when the date value changes */ onChange?: (value: CalendarDate | null) => void; /** Callback fired when the clear button is clicked */ onClearButtonPress?: () => void; /** Callback fired when the picker loses focus */ onBlur?: () => void; /** Callback fired when the picker gains focus */ onFocus?: () => void; /** Callback fired when the calendar overlay's open state changes */ onOpenChange?: (isOpen: boolean) => void; /** Whether the picker is in an invalid state */ isInvalid?: boolean; /** Whether the picker is in a loading state */ isLoading?: boolean; /** Whether the picker is disabled */ isDisabled?: boolean; /** Whether the picker is read-only */ isReadOnly?: boolean; /** Function to determine if a date should be disabled */ isDateUnavailable?: (date: CalendarDate) => boolean; /** Whether to force leading zeros for days and months */ shouldForceLeadingZeros?: boolean; /** Whether to close the calendar after a date is selected */ shouldCloseOnSelect?: boolean; /** Whether to open the calendar by default */ defaultOpen?: boolean; } /** * The DatePicker component allows users to select a date either by typing it in directly or choosing from a calendar overlay, providing a standardized way to handle date selection across the application. * @param {DatePickerProps} props - Props for configuring the DatePicker's behavior and appearance * @see {@link DatePickerProps} for all available props * @example * ```tsx * import { DatePicker } from '@payfit/unity-components' * import { parseDate } from '@internationalized/date' * * function Example() { * const [selectedDate, setSelectedDate] = useState<CalendarDate>() * * return ( * <DatePicker * value={selectedDate} * onChange={setSelectedDate} * minValue={parseDate('2024-01-01')} // Restrict dates before Jan 1, 2024 * isDateUnavailable={(date) => date.dayOfWeek === 0} // Disable Sundays * /> * ) * } * ``` * @remarks * [API & Docs](https://master--66fe6715241b661107117e47.chromatic.com/?path=/docs/inputs-datepicker--docs) • [Design Guidelines](https://www.payfit.design/24f360409/p/719ac2-date-picker) * @note * This component requires `@internationalized/date` as a peer dependency. Make sure to install it in your project: `yarn add @internationalized/date` */ declare const DatePicker: import('react').ForwardRefExoticComponent<DatePickerProps & import('react').RefAttributes<HTMLDivElement>>; export { DatePicker };