Calendar

A month-grid date picker built on React DayPicker that supports single, multiple, and range selection, with a caption that opens a month and year picker. It also exports optional CalendarPresets and CalendarPreset shortcut components for placing beside the grid.

Calendar
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://www.cubby-ui.dev/r/style.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @cubby-ui/calendar

Requires @cubby-ui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { Calendar } from '@/components/ui/cubby-ui/calendar/calendar'<Calendar mode='single' selected={date} onSelect={setDate} />
  • Letting users pick one date, several dates, or a start and end date range in a form or booking flow
  • Showing a month view with fast month and year navigation for dates far from today
  • Adding one-click shortcuts such as 'Today' or 'Last 7 days' next to a range calendar
  • Displaying a two-month side-by-side range picker inside a popover or dialog where the card is already provided (set framed to false)

Examples

Single date

A controlled single-date picker. Clicking a day selects it, and the caption opens the month and year picker.

single-date.tsx
import * as React from 'react'import { Calendar } from '@/components/ui/cubby-ui/calendar/calendar'export function SingleDate() {  const [date, setDate] = React.useState<Date | undefined>(new Date())  return <Calendar mode='single' selected={date} onSelect={setDate} />}

Range with presets

A range picker with a rail of one-click presets. Each preset sets the range directly.

range-with-presets.tsx
import * as React from 'react'import type { DateRange } from 'react-day-picker'import {  Calendar,  CalendarPreset,  CalendarPresets,} from '@/components/ui/cubby-ui/calendar/calendar'export function RangeWithPresets() {  const [range, setRange] = React.useState<DateRange | undefined>()  const today = new Date()  const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 6)  return (    <div className='flex flex-col gap-2 sm:flex-row'>      <CalendarPresets>        <CalendarPreset onClick={() => setRange({ from: today, to: today })}>          Today        </CalendarPreset>        <CalendarPreset onClick={() => setRange({ from: lastWeek, to: today })}>          Last 7 days        </CalendarPreset>      </CalendarPresets>      <Calendar mode='range' selected={range} onSelect={setRange} />    </div>  )}

Two months with footer

Two months shown side by side in range mode, with a status footer that reports the selection.

two-months-with-footer.tsx
import * as React from 'react'import type { DateRange } from 'react-day-picker'import { Calendar } from '@/components/ui/cubby-ui/calendar/calendar'export function TwoMonthRange() {  const [range, setRange] = React.useState<DateRange | undefined>()  return (    <Calendar      mode='range'      numberOfMonths={2}      selected={range}      onSelect={setRange}      footer={range?.from ? 'Picked from ' + range.from.toLocaleDateString() : 'Pick a start date'}    />  )}

Localised labels

Overrides the screen-reader labels for the month and year picker in a single calendar.

localised-labels.tsx
import * as React from 'react'import { Calendar } from '@/components/ui/cubby-ui/calendar/calendar'export function LocalisedLabels() {  const [date, setDate] = React.useState<Date | undefined>()  return (    <Calendar      mode='single'      selected={date}      onSelect={setDate}      labels={{        labelMonthYearPicker: '月と年を選択',        labelYears: '年',      }}    />  )}

API reference

PropTypeDefaultDescription
mode'single' | 'multiple' | 'range' | ...DayPicker mode—Selection mode, passed through to React DayPicker. Required by DayPicker when selection is used.
selectedDate | Date[] | DateRange | undefined—Controlled selection, passed through to React DayPicker.
onSelect(value, day, modifiers, event) => void—Called when the selection changes, passed through to React DayPicker.
numberOfMonthsnumber1Number of months shown side by side. Outside days and fixed weeks are hidden when more than one month is shown unless overridden.
framedbooleantrueDraws the card background, padding, and shadow. Turn off when the container already is a card, such as a popover.
captionLayoutDayPicker captionLayout | undefined—When set to any value, the built-in month and year picker is disabled and DayPicker's own caption layout is used instead.
showOutsideDaysbooleannumberOfMonths === 1Shows days from neighbouring months in the first and last weeks.
fixedWeeksbooleannumberOfMonths === 1Always renders six weeks so the calendar height stays constant.
animatebooleantrueAnimates month changes via DayPicker and the calendar's CSS.
monthDate—Controlled displayed month. Pair with onMonthChange.
defaultMonthDate—Initial displayed month when uncontrolled. Falls back to the first selected date, then today.
onMonthChange(month: Date) => void—Called when the displayed month changes.
footerReact.ReactNode—Content rendered below the grid inside a polite live region.
labelsPartial<Labels> & Partial<CalendarLabels>—DayPicker labels plus labelCaptionTrigger(caption), labelMonthYearPicker, and labelYears for the built-in picker.
classNamestring—Merged onto the root calendar element.
CalendarPresets propsReact.ComponentProps<'div'>—Rendered as a role=group wrapper inside a horizontal or vertical ScrollArea. className applies to the outer scroll area.
CalendarPreset propsReact.ComponentProps<'button'> & { active?: boolean }falseA preset button. active marks the preset matching the current selection with aria-pressed and a highlighted style.

Accessibility

  • Caption button has an aria-label built from the formatted month and year plus 'choose month and year', with aria-expanded and aria-controls linking to the picker panel
  • The month and year picker is a labelled group; its year column and month grid are separate labelled groups and support arrow keys, Home, End, and PageUp/PageDown
  • Pressing Escape inside the picker closes it and returns focus to the caption button
  • While the picker is open the underlying day grid is inert, so focus and screen readers stay in the picker
  • Day buttons are focusable with roving tabindex from DayPicker, and arrow keys move between days, skipping disabled cells
  • Month names are announced in full via aria-label on picker months, while the visible label is abbreviated
  • The DayPicker caption live region is kept as sr-only text so month changes are announced
  • The optional footer is a role=status polite live region
  • Preset buttons expose aria-pressed based on the active prop
  • Disabled days are conveyed with line-through and reduced opacity, not colour alone; focus rings use outline with offset
  • Motion is removed under prefers-reduced-motion, leaving simple crossfades

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Calendar" component (cubby-ui/calendar) from its shadcn registry.1. Install it with: npx shadcn@latest add @cubby-ui/calendar2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: mode, selected, onSelect, numberOfMonths, framed, captionLayout, showOutsideDays, fixedWeeks, animate, month, defaultMonth, onMonthChange, footer, labels, className, CalendarPresets props, CalendarPreset props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Calendar } from '@/components/ui/cubby-ui/calendar/calendar'<Calendar mode='single' selected={date} onSelect={setDate} />```

Files & dependencies

  • registry/default/calendar/calendar.tsx→ components/ui/cubby-ui/calendar/calendar.tsx
  • registry/default/calendar/calendar-picker.tsx→ components/ui/cubby-ui/calendar/calendar-picker.tsx
  • registry/default/calendar/calendar.css→ components/ui/cubby-ui/calendar/calendar.css
dependenciesreact-day-picker@hugeicons/react@hugeicons/core-free-icons
registryDependencies@cubby-ui/button@cubby-ui/scroll-area@cubby-ui/text-morph@cubby-ui/use-controllable-state@cubby-ui/date-utils@cubby-ui/elevated

Looks similar, elsewhere