import { CSSProperties, ReactNode } from 'react'; import { FormValidator } from '../../services/formValidation/index.js'; import { HtmlProps, SlotClassNames, SlotStyles } from '../types/slots.types.js'; import { Weekday } from '../utils/weekStart.js'; export type DatePickerSlots = 'root' | 'input' | 'header' | 'monthDropdown' | 'yearDropdown' | 'calendar' | 'clearButton'; /** Text DatePicker renders of its own, for translating it. Month and weekday names come from `locale`. */ export interface DatePickerLabels { /** The arrow to the previous month, read out by screen readers. */ previousMonth?: string; /** The arrow to the next month, read out by screen readers. */ nextMonth?: string; /** The button `showClearButton` adds. */ clear?: string; /** The month dropdown, read out by screen readers. */ month?: string; /** The year dropdown, read out by screen readers. */ year?: string; } /** * `onChange` and `onSelect` report a day rather than a DOM event, so the native * handlers of those names are dropped instead of being widened to accept both. * * Every day is a `'YYYY-MM-DD'` string, never a `Date`: see docs/DatePicker.md. */ export interface DatePickerProps extends Omit, 'onChange' | 'onSelect'> { /** Class on the root element. */ className?: string; style?: CSSProperties; classNames?: SlotClassNames; styles?: SlotStyles; /** Selected day, `'YYYY-MM-DD'`, controlled. Ignored while a `formValidator` owns the value. */ selected?: string | null; /** Floating label on the input. */ label?: string; /** * Called when a day is picked in the calendar, after `onChange`. Picking also * closes the picker. */ onSelect?: (day: string | null) => void; /** * Called whenever the value changes, whether picked in the calendar or typed * into the input. `null` when the field was cleared or holds no valid day. */ onChange?: (day: string | null) => void; /** * Hands the value to a validator, which then owns it. See docs/FormValidator.md. The three * forms are what TypeScript infers for `new FormValidator(null)`, * `new FormValidator(null)` and `new FormValidator('')`; a `Date` validator fits none of them. */ formValidator?: FormValidator | FormValidator | FormValidator | null; /** Earliest selectable day, `'YYYY-MM-DD'`. Also bounds the year dropdown. */ minDate?: string | null; /** Latest selectable day, `'YYYY-MM-DD'`. Also bounds the year dropdown. */ maxDate?: string | null; /** * Start of a highlighted range. Defaults to the selected date, so two pickers * sharing a start and an end highlight the span between them. */ startDate?: string | null; /** End of the highlighted range. */ endDate?: string | null; /** Render the calendar in place instead of in a popover. */ isInline?: boolean; /** Open the calendar in a modal, with the input read-only. */ isModal?: boolean; /** Drop the text input and show the calendar alone. */ noInput?: boolean; /** Drop the month and year navigation above the calendar. */ noHeader?: boolean; /** Show a button that clears the value. */ showClearButton?: boolean; /** Rendered under the calendar, inside the popover or modal. */ children?: ReactNode; /** Marks the field invalid. A `formValidator` decides this for itself. */ isValid?: boolean; /** Message for the error tooltip, shown while the field is focused or hovered. */ errorMessage?: string; /** Appends ` *` to the label. Implied by a `required` validator on `formValidator`. */ isRequired?: boolean; /** * BCP 47 tag for the month and weekday names and the first day of the week (default the app's * `locale`, else the browser's). The field is typed as `dd.mm.yyyy` in every locale. */ locale?: string; /** Overrides the locale's first day of the week: 0 is Sunday, 1 is Monday. */ weekStartsOn?: Weekday; /** Overrides the text DatePicker renders of its own. Merged per key. */ labels?: DatePickerLabels; }