import type { HTMLAttributes, ReactNode } from 'react'; import type { SxProp } from '../Layout/sx.js'; import type { WeekDay } from './dateUtils.js'; export type DatePickerSize = 'sm' | 'md' | 'lg'; export type DatePickerColor = 'primary' | 'danger' | 'warning' | 'success'; export type DatePickerMode = 'date' | 'month' | 'year' | 'time' | 'datetime'; /** * Declarative date-window constraint. * - `'any'` (default): no restriction * - `'future'`: today and later * - `'past'`: today and earlier * - `'current'`: today only * * Combines with explicit `min` / `max` — the stricter of the two always wins. */ export type DatePickerAllow = 'any' | 'future' | 'past' | 'current'; export interface DatePickerPreset { /** Button text, e.g. `'Today'` or `'Next week'`. */ label: string; /** The date to select — a `Date`, a parseable string, or a function returning one (evaluated on click). */ value: Date | string | (() => Date); } export interface DatePickerProps extends Omit, 'onChange' | 'defaultValue' | 'children'> { /** Which picker to show. */ mode?: DatePickerMode; /** Controlled value. `null` means cleared. */ value?: Date | string | null; /** Uncontrolled initial value. */ defaultValue?: Date | string; /** Fires on selection and clear. */ onChange?: (date: Date | null) => void; /** Earliest selectable date (inclusive). */ min?: Date | string; /** Latest selectable date (inclusive). */ max?: Date | string; /** Declarative date-window constraint. Combines with `min`/`max` (stricter wins). */ allow?: DatePickerAllow; /** Predicate to disable arbitrary dates (ignored for time-only mode). */ disabledDate?: (date: Date) => boolean; /** Predicate to disable specific times (hour/minute/second combos). */ disabledTime?: (date: Date) => boolean; /** Text shown when empty. */ placeholder?: string; /** Trigger size. */ size?: DatePickerSize; /** Validation color on the trigger. Auto-flips to `'danger'` on validation errors. */ color?: DatePickerColor; /** Disable the trigger. */ disabled?: boolean; /** Quick-pick shortcuts rendered above the calendar (ignored in `time` mode). Disabled when the date is out of range. */ presets?: DatePickerPreset[]; /** Add a text field to the panel for typing a date as `yyyy-mm-dd` (`date` / `datetime` modes). Enter applies it. */ typeable?: boolean; /** Show a clear button when a value is selected. */ clearable?: boolean; /** BCP-47 locale tag. Defaults to the browser's. */ locale?: string; /** 0 = Sunday, 1 = Monday, …, 6 = Saturday. Defaults to 0. */ weekStartsOn?: WeekDay; /** Use 12-hour clock with AM/PM for time / datetime. Default: inferred from locale. */ hour12?: boolean; /** Show a seconds column in time / datetime. */ showSeconds?: boolean; /** Minute granularity (1–30). Default 1. */ minuteStep?: number; /** Second granularity (1–30). Default 1. */ secondStep?: number; /** Custom display formatter for the selected value. */ format?: (date: Date, mode: DatePickerMode) => string; /** Replace the trigger icon. */ icon?: ReactNode; /** Required — empty value is treated as invalid. */ required?: boolean; /** Custom validator. Returns an error message or null/undefined if valid. */ validate?: (date: Date | null) => string | null | undefined; /** Explicit error message. When set, forces danger state and renders below the trigger. */ error?: ReactNode; /** Fires whenever the internal validation state changes. */ onValidate?: (error: string | null) => void; /** id forwarded to the trigger (for Field integration). */ id?: string; /** aria-invalid forwarded to the trigger. */ 'aria-invalid'?: boolean; /** aria-describedby forwarded to the trigger. */ 'aria-describedby'?: string; /** Accessible label for the dialog. */ dialogLabel?: string; /** Name for form submission. */ name?: string; /** Controlled open state. */ open?: boolean; /** Called when open state changes. */ onOpenChange?: (open: boolean) => void; /** * One-off CSS, same as `Box`'s `sx`: each value may be a scalar or a * responsive breakpoint map (`{ base, sm, md, lg, xl }`). Applied to the * outer field wrapper (not the popover calendar). Scalar-only sx merges into * inline style; responsive sx injects a scoped class. */ sx?: SxProp; }