Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Date Range Picker

Two fields the reader types a start date and an end date into, with a button that opens a calendar in a popup to pick the range from.

Built on the headless Date Range Picker.See its API in Docs

Rendered by React 19.3.1

date-range-picker.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/date-range-picker.json

It also adds utils, button, calendar, date-picker, popover. The app needs its setup first: Installation.

Usage

The parts are the Date Picker's with a start and an end: put two DateRangePickerInputs in the DateRangePickerControl, type="start" and type="end", with a DateRangePickerSeparator between them (an en dash by default), then DateRangePickerClear and DateRangePickerTrigger. The popup is a DateRangePickerPortal, DateRangePickerPositioner, DateRangePickerPopup and DateRangePickerCalendar, which picks the range in two presses. The value is { start, end }, ISO date strings, or null. visibleMonths on the root and months on the calendar show more than one month; DateRangePickerPreset takes a function of today that returns a range, and DateRangePickerClose closes the popup. An end typed before the start is not swapped: the end field is marked invalid and the picker's value is null until it is fixed. The rest is the headless Date Range Picker's.

import {
  DateRangePicker,
  DateRangePickerCalendar,
  DateRangePickerClear,
  DateRangePickerClose,
  DateRangePickerControl,
  DateRangePickerInput,
  DateRangePickerPopup,
  DateRangePickerPortal,
  DateRangePickerPositioner,
  DateRangePickerPreset,
  DateRangePickerSegment,
  DateRangePickerSeparator,
  DateRangePickerTrigger,
} from '@/components/ui/date-range-picker'

Examples

Default

Two inputs with a dash between them and two months.

Its preview and code are at the top of the page.

shadcn has no date range picker item: its page composes a Popover and a Calendar with mode="range" around an outline button. This item follows the Date Picker's composition, so it differs from shadcn's in the same places, and the value is { start, end } strings, not { from, to } dates. It takes the Date Picker's control, segment, trigger, popup, preset and close classes, so the item requires it; the calendar is the Calendar's markup on the range Root.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Date Range Picker's API reference.