ZUI

Search documentation

Find a page or a heading.

Calendar

A month's grid of days on which a day, several days or a range is selected.

Installation

bash

The 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

tsx
tsx

API reference

Calendar

Takes every prop of React Native's View except children, and react-day-picker's props below, with the same meaning:

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; locale takes the same date-fns locales.
  • The dropdown caption is the Select item, where upstream lays an invisible HTML select over its caption: React Native has no select element.
  • Several months stack one under another, as upstream's do below its md breakpoint, 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.
  • modifiersClassNames adds to the day's cell, as upstream's does, but a selector into the cell such as upstream's [&>button]:line-through reaches nothing: React Native styles carry no selectors. Style the button from its modifiers in a components.DayButton instead.
  • The cells take the style's size (size-8 in Vega, size-7 in Nova), where upstream's take the --cell-size variable, 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 installed calendar.tsx: the cells' size-8 and the weekday columns' w-8.
  • dir is left out: React Native lays out right to left from I18nManager, for the whole app, not per component.
  • Not ported, though the platform does not stop them: react-day-picker's timeZone, ISOWeek and broadcastCalendar, which change which day a date falls on and which weeks a month draws, and every component but DayButton.