compacto-ui

Search documentation

Jump to a page or a component.

Calendar

Month grid, slot column, or both — date, time and datetime pickers.

peer: react-day-picker

Preview

November 2026

Installation

No install — ask an AI agent to copy this component from registry.json, then pnpm add react-day-picker.

import { Calendar, CalendarDayButton, CalendarGranularity, getCalendarTime, setCalendarTime } from "@/components/ui/calendar";

Notes

  • Optional peer: react-day-picker.
  • granularity picks the fields: "date" (grid only, the default), "time" (a lone time field — every DayPicker prop is ignored) or "datetime" (both, field on a hairline under the grid).
  • Time is a "HH:mm" string, not part of selected. DayPicker types selected/onSelect as a closed union keyed on mode, so a Date there would mean one thing under mode="single" and nothing under mode="range". getCalendarTime / setCalendarTime bridge the two so a datetime calendar still drives one Date in state.
  • setCalendarTime returns the date untouched when the field is cleared, and undefined when no date is picked yet — a time with no day is not a moment.
  • Run onSelect through setCalendarTime too: DayPicker deals in days and hands back midnight, so a bare onSelect={setDate} resets the time to 00:00 whenever a different day is picked. onSelect={(day) => setWhen(setCalendarTime(day, getCalendarTime(when)))}.
  • Time is a column of slots beside the grid, not a field you type into: one row per timeStep minutes from timeStart to timeEnd, the chosen one a solid accent block like the chosen day. That is the only form that can show which times are unavailable — timeDisabled greys them out in place.
  • timeStep is minutes (default 30), timeStart/timeEnd bound the generated list, and timeSlots replaces it outright for an irregular set.
  • Rows are labelled through the calendar's own locale, so the list reads 9:30 AM under en-US and 09:30 under de-DE with no hour12 prop to get wrong. Override with formatTime.
  • The column brings the selected row into view when it is off screen, by setting its own scrollTop rather than calling scrollIntoView — the latter would also scroll the page behind an open popover. A row already in view is left alone, so clicking never yanks the list.
  • The rows are a labelled group of aria-pressed buttons, like OptionList's, not a listbox of options — a listbox promises arrow-key roving and aria-activedescendant, and announcing that without implementing it is worse than plain toggles that tab.
  • A time that is not one of the slots leaves the column with nothing selected — getCalendarTime(new Date()) is almost never on a boundary, so seed state with a slot value.
  • Below the sm breakpoint the column stacks under the grid, four rows tall, with the hairline on top — a grid plus a column is wider than a phone in portrait. The panel is capped at max-w-full, so it is safe in a full-width sheet.
  • Uncontrolled unless time is given, like the day selection above it.
  • Under time/datetime the outermost element is the panel, so className and data-testid land there rather than on the grid.
  • Every DayPicker prop passes through, and className / classNames merge on top of the defaults so you can tweak one slot without redeclaring the rest.
  • locale also drives the month dropdown's own labels, so a localized calendar does not end up with English month abbreviations in its caption.
  • Day test ids are ISO (${testId}-day-2026-09-19) and built from local date parts, not toISOString — the latter converts to UTC and would label the cell with the previous day east of Greenwich.

Props

The props worth knowing. Everything else passes straight through to the underlying element, including className, which is merged last so it always wins.

PropTypeDefaultDescription
granularity"date" | "time" | "datetime""date"Which fields show: the month grid, a time field, or both.
time / defaultTimestring—Controlled / initial selection, "HH:mm".
onTimeChange(time: string) => void—Called with the row's "HH:mm" value when it is clicked.
timeStepnumber30Minutes between generated slots.
timeStart / timeEndstring"00:00" / "23:30"Bounds of the generated list, both inclusive.
timeSlotsstring[]—Explicit "HH:mm" list, for an irregular set of times.
timeDisabled(time: string) => boolean—Greys a row out and makes it unclickable.
formatTime(time: string) => stringlocale hour/minuteRow label from a 24-hour value.
timeLabelstring"Time"Accessible name for the column. Pass a translated string.
mode"single" | "multiple" | "range"—Selection behaviour. Passed through to DayPicker.
captionLayout"label" | "dropdown" | …"label"Month caption style.
buttonVariantButton variant"ghost"Variant for the prev/next arrows.
showOutsideDaysbooleantrueRender neighbouring months' leading/trailing days.