Skip to main content

API Reference

Complete API reference for @gentleduck/calendar hooks, core functions, and types.

Hooks

ExportDescription
useCalendarMain calendar hook - state, actions, and prop getters
useTimePickerTime picker hook - spinbutton fields and keyboard input
useDateTimeCombined date + time hook
useAnnouncerScreen reader announcement hook
useKeyboardKeyboard navigation hook

Core functions

ExportDescription
GridGrid builder functions - buildCalendarMonth, buildMultiMonth, etc.
SelectionSelection logic - selectDay, applySelection
NavigationNavigation functions - navigate, canNavigate
isDateDisabledCheck if a date is disabled by the current constraints
isInRangeCheck if a date falls within a range
clampTimeClamp a time value to min/max bounds
formatTimeFieldFormat a single time field for display
getAmPmGet the AM/PM value from a time
incrementFieldIncrement or decrement a time field by step
isValidTimeValidate a time value against constraints
parseTimeInputParse raw keyboard input into a time field value
to12HourConvert a 24-hour value to 12-hour format
to24HourConvert a 12-hour value to 24-hour format

Types

These types are exported from @gentleduck/calendar and used across the API:

TypeDescription
Adapter.IDateAdapter<TDate>Interface for pluggable date backends
Calendar.ICalendarConfig<TDate, M>Full calendar configuration
Calendar.ICalendarLocaleConfigLocale settings (locale tag, week start day, direction, numbering system, calendar)
Selection.CalendarValue<TDate, M>Conditional type resolving per selection mode
Grid.ICalendarDay<TDate>Day cell with selection/state flags
Grid.ICalendarWeek<TDate>Week with weekNumber + 7 days
Grid.ICalendarMonth<TDate>Month grid with weeks
Selection.SelectionMode'single' | 'range' | 'multi' | 'multi-range'
Selection.ISelectionConstraints<TDate>Disabled dates and date bounds
Selection.DateRange<TDate>{ from: TDate, to: TDate | null }
Navigation.Direction'prev' | 'next'
Navigation.Unit'month' | 'year' | 'decade'
UseCalendar.IDayPropsProps returned by getDayProps
UseCalendar.IGridPropsProps returned by getGridProps
UseCalendar.INavPropsProps returned by getNavProps
UseCalendar.IHeaderPropsProps returned by getHeaderProps
UseAnnouncer.IAnnouncerReturnReturn type of useAnnouncer
UseKeyboard.IKeyboardConfig<TDate>Configuration for the keyboard navigation hook
UseKeyboard.IKeyboardReturnReturn type of useKeyboard
UseTimePicker.ITimeFieldPropsProps returned by getFieldProps
Time.ITimeValue{ hour, minute, second? }
Time.TimeField'hour' | 'minute' | 'second' | 'ampm'
Time.HourCycle'12' | '24'
Time.ITimePickerConfigConfiguration for the time picker
UseCalendar.IUseCalendarConfig<TDate, M>Configuration accepted by useCalendar
UseCalendar.IUseCalendarReturn<TDate, M>Return type of useCalendar
UseTimePicker.IUseTimePickerConfigConfiguration accepted by useTimePicker
UseTimePicker.IUseTimePickerReturnReturn type of useTimePicker
UseDateTime.IUseDateTimeConfig<TDate>Configuration accepted by useDateTime
UseDateTime.IUseDateTimeReturn<TDate>Return type of useDateTime
Calendar.ViewMode'days' | 'months' | 'years'
Adapter.WeekStartDayNumeric day used as the first day of the week
Grid.IDecadeEntryEntry in the decade view grid
Grid.IYearEntryEntry in the year view grid