PeakUI

Range Calendar

Month grid for choosing a date range

Usage

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

Anatomy

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

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

Examples

Default Value

Controlled

With Year Picker

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

Min and Max Dates

Unavailable Dates

Anchor Unavailable Dates

isDateUnavailable receives the first chosen date as its second argument.

Non-Contiguous Ranges

Disabled

Read Only

With Indicators

Multiple Months

Day View

Week View

International Calendar

The locale sets the calendar system and the first weekday.

Customization

Tailwind CSS

<RangeCalendar className="w-80 max-w-80" aria-label="Booking dates">
  {/* ... */}
</RangeCalendar>

Global CSS

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

  .range-calendar__cell {
    --range-calendar-cell-bg-range: var(--color-success-soft);
    --range-calendar-cell-bg-cap: var(--color-success);
    --range-calendar-cell-fg-cap: 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 RangeCalendar component uses these CSS classes (view source styles):

Base Classes

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

Modifier Classes

  • .range-calendar--week-view - Set when visibleDuration is in weeks
  • .range-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="range-calendar"]
  • [data-slot="range-calendar-header"]
  • [data-slot="range-calendar-heading"]
  • [data-slot="range-calendar-nav-button"]
  • [data-slot="range-calendar-nav-button-icon"]
  • [data-slot="range-calendar-grid"]
  • [data-slot="range-calendar-grid-header"]
  • [data-slot="range-calendar-header-cell"]
  • [data-slot="range-calendar-grid-body"]
  • [data-slot="range-calendar-cell"]
  • [data-slot="range-calendar-cell-button"]
  • [data-slot="range-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
--range-calendar-widthWidth and maximum width of the calendar
--range-calendar-cell-bg-hoverHovered day background
--range-calendar-cell-bg-todayToday's day background
--range-calendar-cell-bg-today-hoverHovered today's day background
--range-calendar-cell-bg-rangeBackground of the range track
--range-calendar-cell-bg-capBackground of the first and last day
--range-calendar-cell-fg-capText color of the first and last day

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 every cell in the range
  • Range start: [data-selection-start="true"] on a cell
  • Range end: [data-selection-end="true"] on a 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

RangeCalendar

PropTypeDefaultDescription
valueRangeValue<DateValue> | null-The selected range (controlled)
defaultValueRangeValue<DateValue> | null-The initial selected range (uncontrolled)
onChange(value: RangeValue<MappedDateValue<DateValue>>) => void-Called when a range is completed
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, anchorDate: CalendarDate | null) => boolean-Marks a date as unavailable; anchorDate is the first chosen date
allowsNonContiguousRangesbooleanfalseWith isDateUnavailable, lets a range contain unavailable dates
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: RangeCalendarRenderProps) => string)-Additional classes, or a function of the render props
childrenReactNode | ((values: RangeCalendarRenderProps) => ReactNode)-The parts, or a function of the render props
...restEvery React Aria RangeCalendar prop, including aria-label

RangeCalendar.Header

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

RangeCalendar.Heading

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

RangeCalendar.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

RangeCalendar.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

RangeCalendar.GridHeader

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

RangeCalendar.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

RangeCalendar.HeaderCell

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

RangeCalendar.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

RangeCalendar.CellIndicator

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

RangeCalendar.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"

RangeCalendar.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

RangeCalendar.YearPickerTriggerIndicator

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

RangeCalendar.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

RangeCalendar.YearPickerGridBody

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

RangeCalendar.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

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

PartValues
RangeCalendarstate, isDisabled, isInvalid
RangeCalendar.Celldate, formattedDate, isSelected, isSelectionStart, isSelectionEnd, isFocused, isHovered, isPressed, isUnavailable, isOutsideMonth, isDisabled

The year picker parts share the render props of Calendar:

PropTypeDescription
isOpenbooleanWhether the year picker is open (trigger parts)
monthYearstringThe formatted month and year (trigger parts)
toggle() => voidOpens or closes the year picker (trigger parts)
yearnumberThe year (grid body and cell)
formattedYearstringThe year formatted for the locale and calendar (grid body and cell)
isSelectedbooleanWhether the calendar is showing this year (grid body and cell)
isCurrentYearbooleanWhether this is the present calendar year (grid body and cell)
selectYear() => voidShows this year and closes the picker (grid body and cell)

On this page