Calendar
A date picker calendar built on react-day-picker v9 with OKLCH theming
The Calendar component wraps react-day-picker v9 with nim-ui's OKLCH tokens, dark-mode support, and focus-visible rings. It supports single-date, range, and multiple-date selection, plus full keyboard navigation and i18n through react-day-picker's built-in features.
Import
import { Calendar } from '@nim-ui/components';You'll also need to import react-day-picker's styles once in your app's root entry — typically import 'react-day-picker/style.css'; — so the default layout ships alongside nim-ui's overrides.
Single Date
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Code
<Calendar
mode="single"
selected={date}
onSelect={setDate}
/>import { useState } from 'react';
import { Calendar } from '@nim-ui/components';
export function SingleDateExample() {
const [date, setDate] = useState<Date | undefined>(new Date());
return (
<Calendar
mode="single"
selected={date}
onSelect={setDate}
/>
);
}Range Selection
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Code
<Calendar
mode="range"
selected={range}
onSelect={setRange}
numberOfMonths={2}
/>import { useState } from 'react';
import { Calendar } from '@nim-ui/components';
import type { DateRange } from 'react-day-picker';
export function RangeExample() {
const [range, setRange] = useState<DateRange | undefined>();
return (
<Calendar
mode="range"
selected={range}
onSelect={setRange}
numberOfMonths={2}
/>
);
}Multiple Dates
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Code
<Calendar
mode="multiple"
selected={dates}
onSelect={(value) => setDates(value ?? [])}
/>import { useState } from 'react';
import { Calendar } from '@nim-ui/components';
export function MultipleExample() {
const [dates, setDates] = useState<Date[]>([]);
return (
<Calendar
mode="multiple"
selected={dates}
onSelect={(value) => setDates(value ?? [])}
/>
);
}Buddhist Era
Set calendar="buddhist" to display Buddhist Era years in the calendar UI. Selection values are still JavaScript Date objects, so forms and APIs can keep using Gregorian ISO values.
| อา. | จ. | อ. | พ. | พฤ. | ศ. | ส. |
|---|---|---|---|---|---|---|
Code
<Calendar
calendar="buddhist"
mode="single"
selected={date}
onSelect={setDate}
/>Disabled Dates
Pass a matcher to disable specific dates — a single date, an array, a range, or a predicate function.
<Calendar
mode="single"
selected={date}
onSelect={setDate}
disabled={[
{ before: new Date() }, // disable past dates
{ dayOfWeek: [0, 6] }, // disable weekends
]}
/>Props
Calendar passes through all react-day-picker props. The most common are listed below.
| Name | Type | Default | Description |
|---|---|---|---|
mode | 'single' | 'multiple' | 'range' | 'single' | Selection mode |
calendar | 'gregory' | 'buddhist' | 'gregory' | Display Gregorian CE or Buddhist Era years while keeping Date values unchanged |
selected | Date | Date[] | DateRange | undefined | - | Currently selected date(s). Shape depends on mode |
onSelect | (selected) => void | - | Callback fired when selection changes. Signature depends on mode |
numberOfMonths | number | 1 | Number of months to display side by side |
showOutsideDays | boolean | true | Show days from the previous/next month at the edges of the grid |
disabled | Matcher | Matcher[] | - | Dates that cannot be selected (see react-day-picker Matcher docs) |
autoFocus | boolean | false | Focus the first day of the calendar on mount |
classNames | Partial<ClassNames> | - | Override individual element class names (merged with the default nim-ui theme) |
Accessibility
- Implements the ARIA date picker pattern via react-day-picker
- Full keyboard navigation: arrow keys move day-by-day, Page Up/Down move month-by-month, Home/End jump to the start/end of the week
- Today cell gets a visual indicator (neutral background) and the selected cell uses the
primary-600token - Outside days (from prev/next month) dimmed with
opacity-50and can be hidden viashowOutsideDays={false} - Focus-visible rings from
buttonVariantsapply to day buttons and nav arrows aria-selectedreflects selection state;aria-disabledreflects disabled dates
Keyboard Support
| Key | Action |
|---|---|
| Arrow Left / Right | Move one day |
| Arrow Up / Down | Move one week |
| Page Up / Down | Move one month |
| Shift + Page Up / Down | Move one year |
| Home | Start of the week |
| End | End of the week |
| Enter / Space | Select the focused day |
Related Components
- DatePicker — Calendar composed with Popover for form inputs