- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/calendarThe CLI writes components/ui/calendar.tsx, installs Direction, Button,
Icon, Select,
Text and Utils, and adds date-fns and lucide-react-native. The
dropdown caption opens a Select, which draws in the app's PortalHost; see Add a portal
host.
Usage#
import { Calendar } from '@/components/ui/calendar';const [date, setDate] = useState<Date | undefined>(new Date());
<Calendar mode="single" selected={date} onSelect={setDate} />;API reference#
Calendar#
Takes every prop of React Native's View except children, and react-day-picker's props below, with the same
meaning:
| Prop | Type | Default |
|---|---|---|
mode | 'single' | 'multiple' | 'range' | - |
selected | Date, Date[] or DateRange, by mode | - |
onSelect | (selected, triggerDate: Date) => void | - |
required | boolean | false |
min, max | number (multiple and range) | - |
month | Date | - |
defaultMonth | Date | today's month |
onMonthChange | (month: Date) => void | - |
startMonth | Date | - |
endMonth | Date | - |
numberOfMonths | number | 1 |
pagedNavigation | boolean | false |
disableNavigation | boolean | false |
hideNavigation | boolean | false |
captionLayout | 'label' | 'dropdown' | 'dropdown-months' | 'dropdown-years' | 'label' |
reverseYears | boolean | false |
showOutsideDays | boolean | true |
fixedWeeks | boolean | false |
showWeekNumber | boolean | false |
weekStartsOn | 0 to 6 | the locale's |
locale | a date-fns Locale | English (US) |
today | Date | the device's today |
disabled | Matcher | Matcher[] | - |
hidden | Matcher | Matcher[] | - |
modifiers | Record<string, Matcher | Matcher[]> | - |
modifiersClassNames | Record<string, string> | - |
modifiersStyles | Record<string, StyleProp<ViewStyle>> | - |
onDayClick | (date: Date, modifiers, event) => void | - |
footer | ReactNode | - |
formatters | Partial<Formatters> | - |
labels | Partial<Labels> | - |
components | { DayButton?: ComponentType<CalendarDayButtonProps> } | - |
buttonVariant | the Button's variant | 'ghost' |
With onSelect the calendar follows selected; without it the calendar holds its own selection, starting from
selected. In single mode a press on the selected day clears it unless required. In range mode the first
press starts a range of that day and the next one ends it; a press before its start moves the start.
A Matcher is a Date, a Date[], a DateRange, { before }, { after }, { before, after },
{ dayOfWeek }, a function of the day, or true. A disabled day takes no press and is announced disabled; a
hidden one is blank space.
modifiers names days of your own, such as booked ones, and each day's modifiers then carries that name as
true or false. modifiersClassNames and modifiersStyles add to the cell of each day a modifier, built in
or your own, is true for. onDayClick is called on every press of a day, after the selection changes; with it
the days are buttons even without a mode. footer is drawn under the months in a polite live region.
Each day is a button announced by its full date, with "Today" before it and "selected" after it, and the
previous and next buttons are named "Go to the Previous Month" and "Go to the Next Month"; labels changes
them. When the month changes, iOS announces the new caption, and Android and the web read it from the caption's
polite live region. On the web each month is a grid named by its month, one day is the tab stop, and the arrow
keys move a day or a week, Page Up and Page Down a month (with Shift, a year), and Home and End to the start and
end of the week, moving to another month when the day is not drawn.
captionLayout="dropdown" writes the caption as a Select of the months and a Select of the years, from a
hundred years ago to this year unless startMonth and endMonth say otherwise.
CalendarDayButton#
The button each day is drawn as, which a components.DayButton can build on. Takes every prop of React
Native's Pressable, plus day ({ date, displayMonth, outside }), modifiers (today, selected,
disabled, hidden, outside, focused, range_start, range_middle, range_end, and each of
modifiers by name) and locale.
Right to left#
When Direction says text reads right to left, the month buttons'
chevrons are mirrored, as upstream's rtl: rotation of them does, and the left and right arrow keys move to the
day drawn on that side: the left arrow to the next day, as react-day-picker does in text read right to left.
Differences from upstream#
- Built on React Native views with date-fns, where upstream is react-day-picker, which draws HTML tables. Its
props, labels and selection rules are kept;
localetakes the same date-fns locales. - The dropdown caption is the Select item, where upstream lays an invisible HTML
selectover its caption: React Native has noselectelement. - Several months stack one under another, as upstream's do below its
mdbreakpoint, which a phone is under. - Inside a Card or a Popover upstream's calendar drops its background by a CSS selector on its parent. React
Native has no such selector, so pass
className="bg-transparent"there. - The grid, row and cell roles are written on the web only: iOS has no grid role, and a device reads each day's button by its full date.
- A day's selected state is in its name only ("..., selected"), where upstream also marks its cell selected: a
device reads a button's name and then its state, so a day marked both would be read "selected, selected". The
web's grid cells still carry
aria-selected. modifiersClassNamesadds to the day's cell, as upstream's does, but a selector into the cell such as upstream's[&>button]:line-throughreaches nothing: React Native styles carry no selectors. Style the button from itsmodifiersin acomponents.DayButtoninstead.- The cells take the style's size (
size-8in Vega,size-7in Nova), where upstream's take the--cell-sizevariable, which a class such as[--cell-size:--spacing(10)]on the calendar changes. A React Native view reads no CSS variable its parent sets, so change the size in the installedcalendar.tsx: the cells'size-8and the weekday columns'w-8. diris left out: React Native lays out right to left fromI18nManager, for the whole app, not per component.- Not ported, though the platform does not stop them: react-day-picker's
timeZone,ISOWeekandbroadcastCalendar, which change which day a date falls on and which weeks a month draws, and every component butDayButton.