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'
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'
DayPropsProps returned by getDayProps
GridPropsProps returned by getGridProps
NavPropsProps returned by getNavProps
HeaderPropsProps returned by getHeaderProps
AnnouncerReturnReturn type of useAnnouncer
KeyboardConfigConfiguration for the keyboard navigation hook
KeyboardReturnReturn type of useKeyboard
TimeFieldPropsProps returned by getFieldProps
Time.ITimeValue{ hour, minute, second? }
Time.ITimeField'hour' | 'minute' | 'second' | 'ampm'
Time.IHourCycle'12' | '24'
Time.ITimePickerConfigConfiguration for the time picker
UseCalendarConfigConfiguration accepted by useCalendar
UseCalendarReturnReturn type of useCalendar
UseTimePickerConfigConfiguration accepted by useTimePicker
UseTimePickerReturnReturn type of useTimePicker
UseDateTimeConfigConfiguration accepted by useDateTime
UseDateTimeReturnReturn 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