PeakUI

Calendar

Month grid for choosing dates

Usage

import {Calendar} from "@peakui/react";

Anatomy

import {Calendar} from "@peakui/react";

export default () => (
  <Calendar>
    <Calendar.Header>
      <Calendar.Heading />
      <Calendar.NavButton slot="previous" />
      <Calendar.NavButton slot="next" />
    </Calendar.Header>
    <Calendar.Grid>
      <Calendar.GridHeader>
        {(day) => <Calendar.HeaderCell>{day}</Calendar.HeaderCell>}
      </Calendar.GridHeader>
      <Calendar.GridBody>
        {(date) => (
          <Calendar.Cell date={date}>
            <Calendar.CellIndicator />
          </Calendar.Cell>
        )}
      </Calendar.GridBody>
    </Calendar.Grid>
    <Calendar.YearPickerGrid>
      <Calendar.YearPickerGridBody>
        {({year}) => <Calendar.YearPickerCell year={year} />}
      </Calendar.YearPickerGridBody>
    </Calendar.YearPickerGrid>
  </Calendar>
);

Examples

Default Value

Controlled

With Year Picker

Calendar.YearPickerTrigger replaces Calendar.Heading and opens the year grid.

Min and Max Dates

Unavailable Dates

Multiple Selection

Disabled

Read Only

With Indicators

Multiple Months

Day View

Week View

International Calendar

The locale sets the calendar system and the first weekday.

Custom Nav Icons

Customization

Tailwind CSS

<Calendar className="w-80 max-w-80" aria-label="Appointment date">
  {/* ... */}
</Calendar>

Global CSS

@layer components {
  .calendar {
    --calendar-width: calc(var(--spacing) * 80);
  }

  .calendar__cell[data-selected="true"] {
    --calendar-cell-bg-selected: var(--color-success);
    --calendar-cell-fg-selected: var(--color-success-foreground);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Calendar component uses these CSS classes (view source styles):

Base Classes

  • .calendar - Root container, 252px wide
  • .calendar__header - Heading and navigation row
  • .calendar__heading - Month and year text
  • .calendar__nav-button - Previous and next buttons
  • .calendar__nav-button-icon - Default chevron in a nav button
  • .calendar__grid - Month grid
  • .calendar__grid-header - Weekday row
  • .calendar__header-cell - Weekday name
  • .calendar__grid-body - Date rows
  • .calendar__grid-row - Hook for custom row styling
  • .calendar__cell - Date cell
  • .calendar__cell-indicator - Dot at the bottom of a cell

Modifier Classes

  • .calendar--week-view - Set when visibleDuration is in weeks
  • .calendar--day-view - Set when visibleDuration is in days

Year Picker Classes

  • .calendar-year-picker__trigger - Button that replaces the heading
  • .calendar-year-picker__trigger-heading - Month and year text
  • .calendar-year-picker__trigger-indicator - Chevron, turned while open
  • .calendar-year-picker__year-grid - Three-column grid laid over the date grid
  • .calendar-year-picker__year-cell - Year button

Slots

  • [data-slot="calendar"]
  • [data-slot="calendar-header"]
  • [data-slot="calendar-heading"]
  • [data-slot="calendar-nav-button"]
  • [data-slot="calendar-nav-button-icon"]
  • [data-slot="calendar-grid"]
  • [data-slot="calendar-grid-header"]
  • [data-slot="calendar-header-cell"]
  • [data-slot="calendar-grid-body"]
  • [data-slot="calendar-cell"]
  • [data-slot="calendar-cell-indicator"]
  • [data-slot="calendar-year-picker-trigger"]
  • [data-slot="calendar-year-picker-trigger-heading"]
  • [data-slot="calendar-year-picker-trigger-indicator"]
  • [data-slot="calendar-year-picker-grid"]
  • [data-slot="calendar-year-picker-year-cell"]

CSS Variables

VariablePurpose
--calendar-widthWidth and maximum width of the calendar
--calendar-cell-bg-hoverHovered cell background
--calendar-cell-bg-todayToday's cell background
--calendar-cell-bg-today-hoverHovered today's cell background
--calendar-cell-bg-selectedSelected cell background
--calendar-cell-fg-selectedSelected cell text color

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered="true"]
  • Pressed: :active or [data-pressed="true"]
  • Focus: :focus-visible or [data-focus-visible="true"]
  • Disabled: :disabled or [data-disabled="true"]
  • Selected: [data-selected="true"] on a cell or a year cell
  • Today: [data-today="true"] on a cell
  • Outside month: [data-outside-month="true"] on a cell
  • Unavailable: [data-unavailable="true"] on a cell
  • Open: [data-open="true"] on the year picker trigger and grid

API Reference

Calendar

PropTypeDefaultDescription
valueDateValue | null-The selected date (controlled)
defaultValueDateValue | null-The initial selected date (uncontrolled)
onChange(value: DateValue) => void-Called when the selection changes
selectionMode"single" | "multiple""single"Whether one date or several can be selected
minValueDateValue1 Jan 1900The earliest selectable date, in the locale's calendar
maxValueDateValue31 Dec 2099The latest selectable date, in the locale's calendar
isDateUnavailable(date: DateValue) => boolean-Marks a date as unavailable
isDisabledbooleanfalseDisables the whole calendar
isReadOnlybooleanfalseAllows focus and navigation but not selection
isInvalidboolean-Marks the selection as invalid
visibleDurationDateDuration{months: 1}The span shown at once: months, weeks or days
firstDayOfWeek"sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat"localeThe first day of the week
focusedValueDateValue-The focused date (controlled)
defaultFocusedValueDateValue-The initially focused date
onFocusChange(date: CalendarDate) => void-Called when the focused date changes
isYearPickerOpenboolean-Whether the year picker is open (controlled)
defaultYearPickerOpenbooleanfalseWhether the year picker starts open
onYearPickerOpenChange(isYearPickerOpen: boolean) => void-Called when the year picker opens or closes
classNamestring | ((values: CalendarRenderProps) => string)-Additional classes, or a function of the render props
childrenReactNode | ((values: CalendarRenderProps) => ReactNode)-The parts, or a function of the render props
...restEvery React Aria Calendar prop, including aria-label

Calendar.Header

PropTypeDefaultDescription
renderDOMRenderFunction<"header", undefined>-Replaces the default <header> element
classNamestring-Additional classes
...restEvery <header> attribute

Calendar.Heading

PropTypeDefaultDescription
classNamestring-Additional classes
...restEvery React Aria Heading prop, including offset

Calendar.NavButton

PropTypeDefaultDescription
slot"previous" | "next"-The direction; picks the default chevron
childrenReactNodechevronReplaces the default icon
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Button prop

Calendar.Grid

PropTypeDefaultDescription
weekdayStyle"narrow" | "short" | "long""short"The format of the weekday names
offsetDateDuration-Shifts the grid, for showing several months side by side
classNamestring-Additional classes
...restEvery React Aria CalendarGrid prop

Calendar.GridHeader

PropTypeDefaultDescription
children(day: string) => ReactElement-Renders one weekday name
classNamestring-Additional classes
...restEvery React Aria CalendarGridHeader prop

Calendar.GridBody

PropTypeDefaultDescription
children(date: CalendarDate) => ReactElement-Renders one date. From seven visible days up, rows follow the week
classNamestring-Additional classes
...restEvery React Aria CalendarGridBody prop

Calendar.HeaderCell

PropTypeDefaultDescription
classNamestring-Additional classes
...restEvery React Aria CalendarHeaderCell prop

Calendar.Cell

PropTypeDefaultDescription
dateCalendarDate-The date the cell stands for
childrenReactNode | ((values: CalendarCellRenderProps) => ReactNode)formattedDateCell content, or a function of the render props
classNamestring | ((values: CalendarCellRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria CalendarCell prop

Calendar.CellIndicator

PropTypeDefaultDescription
renderDOMRenderFunction<"span", undefined>-Replaces the default <span> element
classNamestring-Additional classes
...restEvery <span> attribute

Calendar.YearPickerTrigger

PropTypeDefaultDescription
childrenReactNode | ((values: CalendarYearPickerTriggerRenderProps) => ReactNode)-Trigger content, or a function of the render props
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Button prop; aria-label defaults to "Month Year, year selector"

Calendar.YearPickerTriggerHeading

PropTypeDefaultDescription
formatIntl.DateTimeFormatOptions-The format of the month and year
offsetDateDuration-Shows a month other than the first visible one
childrenReactNode | ((values: CalendarYearPickerTriggerRenderProps) => ReactNode)month and yearReplaces the text
renderDOMRenderFunction<"span", undefined>-Replaces the default <span> element
classNamestring-Additional classes
...restEvery <span> attribute

Calendar.YearPickerTriggerIndicator

PropTypeDefaultDescription
childrenReactNode | ((values: CalendarYearPickerTriggerRenderProps) => ReactNode)chevronReplaces the chevron
renderDOMRenderFunction<"span", undefined>-Replaces the default <span> element
classNamestring-Additional classes
...restEvery <span> attribute

Calendar.YearPickerGrid

PropTypeDefaultDescription
visibleYearsnumberyears between the boundsHow many years the grid lists
formatIntl.DateTimeFormatOptions-The format of the year labels
renderDOMRenderFunction<"div", undefined>-Replaces the default <div> element
classNamestring-Additional classes
...restEvery <div> attribute

Calendar.YearPickerGridBody

PropTypeDefaultDescription
children(values: CalendarYearPickerCellRenderProps) => ReactNodea YearPickerCellRenders one year

Calendar.YearPickerCell

PropTypeDefaultDescription
yearnumber-The year the button stands for
childrenReactNode | ((values: CalendarYearPickerCellRenderProps) => ReactNode)formattedYearCell content, or a function of the render props
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Button prop

Render Props

Calendar and Calendar.Cell pass the React Aria render props to children and className functions:

PartValues
Calendarstate, isDisabled, isInvalid
Calendar.Celldate, formattedDate, isSelected, isFocused, isHovered, isPressed, isUnavailable, isOutsideMonth, isDisabled

Calendar.YearPickerTrigger, Calendar.YearPickerTriggerHeading and Calendar.YearPickerTriggerIndicator children receive:

PropTypeDescription
isOpenbooleanWhether the year picker is open
monthYearstringThe formatted month and year
toggle() => voidOpens or closes the year picker

Calendar.YearPickerGridBody children and Calendar.YearPickerCell children receive:

PropTypeDescription
yearnumberThe year
formattedYearstringThe year formatted for the locale and calendar
isSelectedbooleanWhether the calendar is showing this year
isCurrentYearbooleanWhether this is the present calendar year
isOpenbooleanWhether the year picker is open
selectYear() => voidShows this year and closes the picker

On this page