GitHub

Reference machines

calendar

interface 2 type 4 function 2
interface Interfaces 2

# CalendarContext

Reactive context surfaced to consumers.

Members

focusedDate
focusedDate: CalendarDate

Currently focused day cell. Mirrors tabindex="0" on its grid cell.

isDateUnavailable
isDateUnavailable: IsDateUnavailable | null

Disable predicate. Returns true if the given date should be marked unavailable in the grid (e.g. a public holiday). Pure function — must not capture mutable external state if you want predictable transitions.

maxValue
maxValue: CalendarDate | null

Inclusive upper bound for selectable dates. null = no ceiling.

minValue
minValue: CalendarDate | null

Inclusive lower bound for selectable dates. null = no floor.

selectedDate
selectedDate: CalendarDate | null

Currently selected date, or null if nothing is selected yet.

selections
selections: number

Number of user-initiated selections since construction (telemetry hook).

# CreateCalendarInput

Construction input.

Members

disabled?
optional disabled?: boolean

Construct in the disabled state. Defaults to false.

focusedDate
focusedDate: CalendarDate

Date to focus initially. Required — the grid must always have a focused cell.

isDateUnavailable?
optional isDateUnavailable?: IsDateUnavailable | null

Disable predicate.

maxValue?
optional maxValue?: CalendarDate | null

Inclusive upper bound for selectable dates.

minValue?
optional minValue?: CalendarDate | null

Inclusive lower bound for selectable dates.

selectedDate?
optional selectedDate?: CalendarDate | null

Initial selection. Defaults to null (no selection).

type Type Aliases 4

# CalendarEvent

CalendarEvent = { date: CalendarDate; type: "FOCUS_DATE"; } | { days: number; type: "FOCUS_DAY_DELTA"; } | { months: number; type: "FOCUS_MONTH_DELTA"; } | { type: "FOCUS_YEAR_DELTA"; years: number; } | { date: CalendarDate; type: "SELECT"; } | { date: CalendarDate | null; type: "SET_VALUE"; } | { type: "DISABLE"; } | { type: "ENABLE"; }

Calendar machine events.

# IsDateUnavailable

IsDateUnavailable = (date) => boolean

Predicate for marking individual dates as unavailable (e.g. holidays).

Parameters

date
CalendarDate

Returns

boolean
function Functions 2

# createCalendarMachine ( )

createCalendarMachine(input): CalendarMachine

Construct a fresh Calendar machine.

Parameters

Returns

CalendarMachine

# isCalendarDateSelectable ( )

isCalendarDateSelectable(date, ctx): boolean

Pure helper: is a given date selectable given the constraints in ctx? Exported so the headless / component layers can render aria-disabled without round-tripping through the machine.

Parameters

date
CalendarDate
ctx
Pick<CalendarContext, "minValue" | "maxValue" | "isDateUnavailable">

Returns

boolean