Components
Calendar
The days of a month in a grid, to pick a date, several dates or a range of dates from.
Introduction
Calendar shows the days of a month in a grid and lets you pick one of them, several of them, or a range from one day to another. Use it on its own for a booking or a schedule, or as the panel of a date picker.
- Built on react-aria's Calendar: the arrow keys, Page Up and Down, Home and End all move as people expect, and screen readers announce each day, its state and the month.
- The month and the names of the days are written in the user's language, and the week starts on the day that language does, unless you set
firstDayOfWeek. - Three ways to pick: one day, several days with
selectionMode="multiple", and arangewhose days join into one band. - Days can be limited with an earliest and a latest date, a list of dates, days of the week, or a function of your own. Unavailable days are struck through.
- One to three months side by side, days from the months around the one shown, a Today button, three sizes, and a card or a plain look for sitting in a popover.
- Today has a dot under its number, and follows the theme in light and dark.
Dates are plain text, "2026-03-15", which is what a form and a database want: a date has no time and no time zone. A range is { start, end } of two of them. It is a Client Component, so a function such as isDateUnavailable must be defined in a client file. The days are drawn in the browser, so a space of the same size holds their place until then.
Installation
centerUI has no CLI or registry yet: components are copied into your project.
# bun
bun add react-aria-components @internationalized/date tailwind-variants tailwind-merge clsx
# pnpm
pnpm add react-aria-components @internationalized/date tailwind-variants tailwind-merge clsx
# npm
npm install react-aria-components @internationalized/date tailwind-variants tailwind-merge clsxManual installation
Copy these files into your project and keep the paths, or adjust the imports. It also uses Button and the arrow icons.
1. Add the styles
src/types/calendar-styles.tsShow code
import { tv } from "tailwind-variants";
// Styles for Calendar. `cell` is the day inside its table cell: the cells touch
// each other, so the days of a range join into one band. react-aria marks the
// state of a day with data attributes (selected, start and end of a range,
// today, outside the month, unavailable, disabled), and the classes below read
// them. The class names are written out in full so Tailwind can find them.
export const calendarStyles = tv({
slots: {
root: "inline-flex max-w-full flex-col gap-3 text-fg",
header: "flex items-center justify-between gap-2",
heading: "m-0 flex-1 text-center text-sm font-medium",
months: "flex flex-wrap gap-x-6 gap-y-4",
grid: "border-collapse",
headerCell: "pb-1 text-center text-xs font-medium text-muted-fg",
cell: [
"relative flex cursor-default items-center justify-center rounded-md text-sm tabular-nums outline-none select-none transition-colors",
"data-hovered:bg-muted data-pressed:bg-muted/70",
"data-focus-visible:z-10 data-focus-visible:ring-2 data-focus-visible:ring-ring data-focus-visible:ring-offset-1 data-focus-visible:ring-offset-bg",
"data-outside-month:text-muted-fg/70",
"data-disabled:pointer-events-none data-disabled:opacity-40",
"data-unavailable:pointer-events-none data-unavailable:text-muted-fg data-unavailable:line-through data-unavailable:opacity-60",
// Today gets a dot under its number.
"data-today:font-semibold data-today:after:absolute data-today:after:bottom-1 data-today:after:size-1 data-today:after:rounded-full data-today:after:bg-primary",
],
footer: "flex flex-wrap items-center justify-center gap-2 border-t pt-2",
// What the picked range is and how long, at the left of the footer.
summary: "mr-auto flex-1 text-left text-sm",
// The ready-made ranges (a range calendar's presets): in a column at the left
// of the days, or in a row above them on a narrow screen.
panel: "flex flex-col gap-3 sm:flex-row",
presets:
"flex shrink-0 flex-row flex-wrap gap-1 border-b pb-3 sm:w-36 sm:flex-col sm:flex-nowrap sm:border-r sm:border-b-0 sm:pr-3 sm:pb-0",
preset: "justify-start",
main: "flex flex-col gap-3",
placeholder: "",
},
variants: {
variant: {
// A card of its own, or nothing around it, to sit in a popover or a panel.
card: { root: "rounded-xl border bg-card p-3 text-card-fg shadow-xs" },
plain: {},
},
size: {
sm: {
cell: "size-8 text-xs",
headerCell: "w-8",
placeholder: "h-72 w-64",
},
md: { cell: "size-9", headerCell: "w-9", placeholder: "h-80 w-72" },
lg: {
cell: "size-11 text-base",
headerCell: "w-11",
placeholder: "h-96 w-[21rem]",
},
},
// One day picked, or a range whose days are joined into a band.
mode: {
single: {
cell: [
"data-selected:bg-primary data-selected:text-primary-fg data-selected:data-hovered:bg-primary/90",
"data-selected:data-today:after:bg-primary-fg",
],
},
range: {
cell: [
"data-selected:rounded-none data-selected:bg-primary/15 data-selected:text-fg data-selected:data-hovered:bg-primary/25",
"data-selected:data-selection-start:rounded-l-md data-selected:data-selection-start:bg-primary data-selected:data-selection-start:text-primary-fg",
"data-selected:data-selection-end:rounded-r-md data-selected:data-selection-end:bg-primary data-selected:data-selection-end:text-primary-fg",
"data-selected:data-selection-start:data-today:after:bg-primary-fg data-selected:data-selection-end:data-today:after:bg-primary-fg",
],
},
},
// Days of the months around the one shown: hidden, or faint.
showOutsideDays: {
true: {},
false: {
cell: "data-outside-month:pointer-events-none data-outside-month:invisible",
},
},
},
defaultVariants: {
variant: "card",
size: "md",
mode: "single",
showOutsideDays: false,
},
});2. Add the Calendar file
src/components/ui/calendar/calendar.tsxShow code
"use client";
import {
type CalendarDate,
type DateValue,
getLocalTimeZone,
parseDate,
today,
} from "@internationalized/date";
import { useContext, useMemo, useSyncExternalStore } from "react";
import {
Calendar as AriaCalendar,
RangeCalendar as AriaRangeCalendar,
CalendarCell,
CalendarGrid,
CalendarGridBody,
CalendarGridHeader,
CalendarHeaderCell,
CalendarStateContext,
Heading,
RangeCalendarStateContext,
} from "react-aria-components";
import { ChevronLeftIcon, ChevronRightIcon } from "@/components/icons";
import { Button } from "@/components/ui/button/button";
import { cn } from "@/lib/cn";
import { calendarStyles } from "@/types/calendar-styles";
import {
type DateRangePresetInput,
resolveDateRangePreset,
} from "@/types/date-range-presets";
/** A date as text, `"2026-03-15"`. */
export type CalendarDateText = string;
/** A range of dates: from the first to the last, as text. */
export interface CalendarRange {
start: CalendarDateText;
end: CalendarDateText;
}
interface BaseProps {
/** Names the calendar for screen readers, such as "Departure date". */
"aria-label"?: string;
/** The earliest date that can be picked, `"2026-03-01"`. Earlier days are dimmed and cannot be reached. */
minValue?: CalendarDateText;
/** The latest date that can be picked. */
maxValue?: CalendarDateText;
/** Dates that cannot be picked, such as days that are booked. They are struck through, but can still be moved onto. */
unavailableDates?: CalendarDateText[];
/** Days of the week that cannot be picked, from 0 (Sunday) to 6 (Saturday). `[0, 6]` is the weekend. */
disabledWeekdays?: number[];
/** Decides for each date if it cannot be picked, for rules the two props above cannot say. Called with `"2026-03-15"`. */
isDateUnavailable?: (date: CalendarDateText) => boolean;
/** The month to show first, as a date of that month, when nothing is picked. Defaults to today. */
defaultFocusedValue?: CalendarDateText;
/** The first day of the week. Defaults to the one of the user's language. */
firstDayOfWeek?: "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat";
/** How many months are shown side by side, from 1 to 3. Defaults to 1. */
visibleMonths?: 1 | 2 | 3;
/** What the arrows move by: every month shown (`visible`), or one month at a time (`single`). Defaults to `visible`. */
pageBehavior?: "visible" | "single";
/** The days of the neighbouring months that fill the first and last week. Defaults to `false`. */
showOutsideDays?: boolean;
/** A "Today" button under the days, which moves to the month of today. Defaults to `false`. */
showTodayButton?: boolean;
/** The text of that button. Defaults to "Today". */
todayLabel?: string;
/** Nothing can be picked or moved. */
isDisabled?: boolean;
/** Days can be looked at and moved between, but not picked. */
isReadOnly?: boolean;
/** Focus a day when it is first shown. */
autoFocus?: boolean;
/** How big the days are. Defaults to `md`. */
size?: "sm" | "md" | "lg";
/** A card with a border and padding, or nothing around the days, to sit in a popover or a panel. Defaults to `card`. */
variant?: "card" | "plain";
className?: string;
}
interface SingleProps {
/** One day (the default), several days, or a range from one day to another. */
selectionMode?: "single";
/** The picked date as text, `"2026-03-15"`, or `null` for none. For a controlled calendar. */
value?: CalendarDateText | null;
/** The date to start with, for an uncontrolled calendar. */
defaultValue?: CalendarDateText | null;
onChange?: (value: CalendarDateText | null) => void;
}
interface MultipleProps {
selectionMode: "multiple";
/** The picked dates as text, in any order. For a controlled calendar. */
value?: CalendarDateText[];
defaultValue?: CalendarDateText[];
onChange?: (value: CalendarDateText[]) => void;
}
interface RangeProps {
selectionMode: "range";
/** Ranges offered in a list beside the days, to pick in one press: the names of ready-made ones, or ranges of your own. Ready-made ranges are worked out from today. */
presets?: DateRangePresetInput[];
/** A line under the days that says the range and how many days it has. Defaults to `false`. */
showSummary?: boolean;
/** A "Clear" button under the days. Defaults to `false`. */
showClearButton?: boolean;
/** The text of that button. Defaults to "Clear". */
clearLabel?: string;
/** Let the range run across days that are unavailable, which stay out of it. Defaults to `false`. */
allowsNonContiguousRanges?: boolean;
/** The picked range, `{ start: "2026-03-10", end: "2026-03-14" }`, or `null` for none. For a controlled calendar. */
value?: CalendarRange | null;
defaultValue?: CalendarRange | null;
onChange?: (value: CalendarRange | null) => void;
}
export type CalendarProps = BaseProps &
(SingleProps | MultipleProps | RangeProps);
function toDate(text: string | null | undefined): CalendarDate | null {
if (!text) return null;
try {
return parseDate(text);
} catch {
return null;
}
}
const toDates = (list: string[] | undefined) =>
(list ?? []).map(toDate).filter((d): d is CalendarDate => d !== null);
function toRange(range: CalendarRange | null | undefined) {
const start = toDate(range?.start);
const end = toDate(range?.end);
return start && end ? { start, end } : null;
}
// Jumps to the month of today. The calendar it is in provides its state.
function TodayButton({ children }: { children: string }) {
const single = useContext(CalendarStateContext);
const range = useContext(RangeCalendarStateContext);
const state = single ?? range;
return (
<Button
// Not one of the arrows: a button of the calendar's own must say so.
slot={null}
variant="ghost"
size="sm"
onPress={() => state?.setFocusedDate(today(getLocalTimeZone()))}
>
{children}
</Button>
);
}
const summaryFormat = new Intl.DateTimeFormat(undefined, {
dateStyle: "medium",
});
// What the range is and how long: "Mar 10, 2026 to Mar 14, 2026 · 5 days".
function RangeSummary({ className }: { className: string }) {
const state = useContext(RangeCalendarStateContext);
const value = state?.value;
if (!value?.start || !value.end) {
return <span className={className}>Pick the first and the last day</span>;
}
const days = value.end.compare(value.start) + 1;
const zone = getLocalTimeZone();
return (
<span className={className}>
{summaryFormat.format(value.start.toDate(zone))} to{" "}
{summaryFormat.format(value.end.toDate(zone))}
<span className="text-muted-fg">
{" "}
· {days} {days === 1 ? "day" : "days"}
</span>
</span>
);
}
// Forgets the picked range.
function ClearButton({ children }: { children: string }) {
const state = useContext(RangeCalendarStateContext);
return (
<Button
// Not one of the arrows: a button of the calendar's own must say so.
slot={null}
variant="ghost"
size="sm"
isDisabled={!state?.value}
onPress={() => state?.setValue(null)}
>
{children}
</Button>
);
}
/**
* A list of ready-made ranges to pick in one press, for a range calendar or a
* range picker. It is given the range now picked, to mark the one that matches,
* and what to do when one is pressed.
*/
export function RangePresetList({
presets,
value,
min,
max,
onPick,
className,
buttonClassName,
}: {
presets: DateRangePresetInput[];
value: { start: DateValue; end: DateValue } | null;
min?: DateValue;
max?: DateValue;
onPick: (range: { start: CalendarDate; end: CalendarDate }) => void;
className: string;
buttonClassName: string;
}) {
const now = today(getLocalTimeZone());
return (
// biome-ignore lint/a11y/useSemanticElements: a fieldset would bring a border and a legend of its own
<div role="group" aria-label="Quick ranges" className={className}>
{presets.map((preset) => {
const { label, start, end } = resolveDateRangePreset(preset, now);
const isOutside =
(min !== undefined && start.compare(min) < 0) ||
(max !== undefined && end.compare(max) > 0);
const isActive =
value !== null &&
value.start.compare(start) === 0 &&
value.end.compare(end) === 0;
return (
<Button
key={label}
// Not one of the arrows, nor the button that opens a picker.
slot={null}
variant={isActive ? "secondary" : "ghost"}
size="sm"
className={buttonClassName}
aria-pressed={isActive}
isDisabled={isOutside}
onPress={() => onPick({ start, end })}
>
{label}
</Button>
);
})}
</div>
);
}
// The presets of a range calendar: they set the calendar it is in.
function CalendarPresets({
presets,
min,
max,
className,
buttonClassName,
}: {
presets: DateRangePresetInput[];
min?: DateValue;
max?: DateValue;
className: string;
buttonClassName: string;
}) {
const state = useContext(RangeCalendarStateContext);
const value = state?.value;
return (
<RangePresetList
presets={presets}
value={
value?.start && value.end
? { start: value.start, end: value.end }
: null
}
min={min}
max={max}
className={className}
buttonClassName={buttonClassName}
onPick={(range) => {
state?.setValue(range);
state?.setFocusedDate(range.start);
}}
/>
);
}
type CalendarStyles = ReturnType<typeof calendarStyles>;
/**
* The inside of a calendar: the header with its arrows, the grids of days, and
* the Today button. `Calendar` and the panel of `DatePicker` both draw it, each
* inside the react-aria calendar it belongs to.
*/
export function CalendarBody({
styles,
visibleMonths,
showTodayButton,
todayLabel,
showSummary = false,
showClearButton = false,
clearLabel = "Clear",
}: {
styles: CalendarStyles;
visibleMonths: number;
showTodayButton: boolean;
todayLabel: string;
showSummary?: boolean;
showClearButton?: boolean;
clearLabel?: string;
}) {
return (
<>
<header className={styles.header()}>
<Button slot="previous" variant="ghost" isIcon size="sm">
<ChevronLeftIcon />
</Button>
<Heading className={styles.heading()} />
<Button slot="next" variant="ghost" isIcon size="sm">
<ChevronRightIcon />
</Button>
</header>
<div className={styles.months()}>
{Array.from({ length: visibleMonths }, (_, i) => (
<CalendarGrid
// biome-ignore lint/suspicious/noArrayIndexKey: the months are the positions
key={i}
offset={{ months: i }}
className={styles.grid()}
>
<CalendarGridHeader>
{(day) => (
<CalendarHeaderCell className={styles.headerCell()}>
{day}
</CalendarHeaderCell>
)}
</CalendarGridHeader>
<CalendarGridBody>
{(date) => <CalendarCell date={date} className={styles.cell()} />}
</CalendarGridBody>
</CalendarGrid>
))}
</div>
{showTodayButton || showSummary || showClearButton ? (
<div className={styles.footer()}>
{showSummary ? <RangeSummary className={styles.summary()} /> : null}
{showClearButton ? <ClearButton>{clearLabel}</ClearButton> : null}
{showTodayButton ? <TodayButton>{todayLabel}</TodayButton> : null}
</div>
) : null}
</>
);
}
/**
* Turns the ways to say that a date is not allowed into one function for
* react-aria: a list of dates, days of the week, and a rule of your own.
*/
export function createUnavailable(
unavailableDates: string[] | undefined,
disabledWeekdays: number[] | undefined,
isDateUnavailable: ((date: string) => boolean) | undefined,
) {
const blocked = new Set(unavailableDates);
return (date: DateValue) => {
const text = date.toString();
return (
blocked.has(text) ||
Boolean(disabledWeekdays?.includes(date.toDate("UTC").getUTCDay())) ||
Boolean(isDateUnavailable?.(text))
);
};
}
/**
* A calendar to pick a date, several dates, or a range of dates from: the days
* of a month in a grid, with arrows to go to the next or the previous. Built on
* react-aria's Calendar, so everything works with the keyboard (arrow keys move
* by a day or a week, Page Up and Down by a month, Home and End to the start and
* end of the week), screen readers announce each day, and the days and months
* are written in the user's language and calendar.
*
* Dates are plain text, `"2026-03-15"`, which is what a form and a database
* want. A date has no time and no time zone.
*
* @example
* <Calendar aria-label="Date of birth" value={date} onChange={setDate} />
* <Calendar selectionMode="range" aria-label="Stay" onChange={setStay} />
*/
export function Calendar(props: CalendarProps) {
const {
minValue,
maxValue,
unavailableDates,
disabledWeekdays,
isDateUnavailable,
defaultFocusedValue,
firstDayOfWeek,
visibleMonths = 1,
pageBehavior,
showOutsideDays = false,
showTodayButton = false,
todayLabel = "Today",
size = "md",
variant,
className,
...rest
} = props;
const isRange = props.selectionMode === "range";
const styles = calendarStyles({
variant,
size,
mode: isRange ? "range" : "single",
showOutsideDays,
});
// False on the server and while the page hydrates, true after. The days and
// their names are written for the user's language and time zone, which the
// server does not know, so they are drawn in the browser only.
const isClient = useSyncExternalStore(
() => () => {},
() => true,
() => false,
);
const min = useMemo(() => toDate(minValue) ?? undefined, [minValue]);
const max = useMemo(() => toDate(maxValue) ?? undefined, [maxValue]);
const focus = useMemo(
() => toDate(defaultFocusedValue) ?? undefined,
[defaultFocusedValue],
);
const unavailable = createUnavailable(
unavailableDates,
disabledWeekdays,
isDateUnavailable,
);
const shared = {
"aria-label": rest["aria-label"],
minValue: min,
maxValue: max,
isDateUnavailable: unavailable,
defaultFocusedValue: focus,
firstDayOfWeek,
visibleDuration: { months: visibleMonths },
pageBehavior,
isDisabled: rest.isDisabled,
isReadOnly: rest.isReadOnly,
autoFocus: rest.autoFocus,
className: cn(styles.root(), className),
};
const body = (
<CalendarBody
styles={styles}
visibleMonths={visibleMonths}
showTodayButton={showTodayButton}
todayLabel={todayLabel}
/>
);
if (!isClient) {
return (
<div
aria-hidden="true"
className={cn(styles.root(), styles.placeholder(), className)}
/>
);
}
if (props.selectionMode === "range") {
return (
<AriaRangeCalendar
{...shared}
{...(props.value !== undefined
? { value: toRange(props.value) }
: { defaultValue: toRange(props.defaultValue) })}
onChange={(next) =>
props.onChange?.(
next
? { start: next.start.toString(), end: next.end.toString() }
: null,
)
}
allowsNonContiguousRanges={props.allowsNonContiguousRanges}
>
<div className={styles.panel()}>
{props.presets?.length ? (
<CalendarPresets
presets={props.presets}
min={min}
max={max}
className={styles.presets()}
buttonClassName={styles.preset()}
/>
) : null}
<div className={styles.main()}>
<CalendarBody
styles={styles}
visibleMonths={visibleMonths}
showTodayButton={showTodayButton}
todayLabel={todayLabel}
showSummary={props.showSummary}
showClearButton={props.showClearButton}
clearLabel={props.clearLabel}
/>
</div>
</div>
</AriaRangeCalendar>
);
}
if (props.selectionMode === "multiple") {
return (
<AriaCalendar
{...shared}
selectionMode="multiple"
{...(props.value !== undefined
? { value: toDates(props.value) }
: { defaultValue: toDates(props.defaultValue) })}
onChange={(next) => props.onChange?.(next.map((d) => d.toString()))}
>
{body}
</AriaCalendar>
);
}
return (
<AriaCalendar
{...shared}
{...(props.value !== undefined
? { value: toDate(props.value) }
: { defaultValue: toDate(props.defaultValue) })}
onChange={(next) => props.onChange?.(next ? next.toString() : null)}
>
{body}
</AriaCalendar>
);
}3. Use it
import { Calendar } from "@/components/ui/calendar/calendar";Anatomy
A header, the names of the weekdays, and a grid of days.
<Calendar
aria-label="Date of birth"
defaultValue="2026-03-15"
onChange={(date) => console.log(date)} // "2026-03-18"
/>| Part | Rendered as | Notes |
|---|---|---|
| Header | header | The arrows to the previous and the next month, and the month and year between them. |
| Weekdays | th | The names of the days of the week, in the user's language. |
| Day | td, div | One per date, with its state: today, picked, in the range, outside the month, unavailable, disabled. |
| Footer | div | The Today button, with showTodayButton. |
Examples
Usage
Uncontrolled: it keeps the picked day itself, and starts on defaultValue.
Controlled
Own the picked day with value and onChange, which gets the date as text, or null when it is cleared.
Picked March 18, 2026
Range
selectionMode="range": press the first day and then the last. The days between are joined into a band, and the ends are marked.
March 10, 2026 to March 14, 2026
Several days
selectionMode="multiple" picks any number of days, one at a time. Press a picked day to drop it.
3 days picked
Earliest and latest
minValue and maxValue dim the days outside them, and the keyboard cannot reach them.
Your own rule
isDateUnavailable is called for each day, with its date as text, for rules the lists cannot say. Here nothing is delivered on the 13th.
More than one month
visibleMonths shows up to three months side by side, which suits a range that crosses a month. The arrows move by all of them, or by one with pageBehavior single.
First day of the week
It follows the user's language, and firstDayOfWeek sets it.
Days around the month
The first and the last week are filled with days of the months around, hidden by default. showOutsideDays shows them faintly.
Today button
showTodayButton adds a button under the days that moves to the month of today, which helps when the calendar was opened far away. It opens here on an older month.
Sizes
The size of the days. Large is easier to press on a touch screen.
Variants
A card with a border and padding, or nothing around the days, to sit inside a popover or a panel that has its own.
Disabled and read only
A disabled calendar cannot be used at all. A read only one can be moved between months and days but not picked from, to show a date that is already set.
Which month to open on
With a day picked it opens on that month, and otherwise on today. defaultFocusedValue sets it without picking anything.
Keyboard
The days are a grid with one place in the tab order, and the keys move inside it.
| Key | Action |
|---|---|
| Arrow keys | Move to the next or the previous day, or the same day of the next or previous week. |
| Page Up, Page Down | Move by a month. With Shift, by a year. |
| Home, End | Move to the start or the end of the week. |
| Enter, Space | Pick the day. In a range, the first press sets the start and the second the end. |
| Escape | In a range, forget the start you pressed and begin again. |
Component API
Calendar takes the props below. The type of value follows selectionMode: text for a day, a list of text for several days, and { start, end } for a range.
| Prop | Type | Default |
|---|---|---|
| selectionMode | "single" | "multiple" | "range" | "single" |
| value | string | null | string[] | { start, end } | null | - |
| defaultValue | same as value | - |
| onChange | (value) => void | - |
| aria-label | string | - |
| minValue | string | - |
| maxValue | string | - |
| unavailableDates | string[] | - |
| disabledWeekdays | number[] | - |
| isDateUnavailable | (date: string) => boolean | - |
| defaultFocusedValue | string | the picked day, or today |
| firstDayOfWeek | "sun" | "mon" | ... | "sat" | the user's language |
| visibleMonths | 1 | 2 | 3 | 1 |
| pageBehavior | "visible" | "single" | "visible" |
| showOutsideDays | boolean | false |
| showTodayButton | boolean | false |
| todayLabel | string | "Today" |
| isDisabled | boolean | false |
| isReadOnly | boolean | false |
| autoFocus | boolean | false |
| size | "sm" | "md" | "lg" | "md" |
| variant | "card" | "plain" | "card" |
| className | string | - |