Skip to content

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

UIComponentsReact

Year Range Picker

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

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

Rendered by React 19.3.1

year-range-picker.tsx

Installation

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

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

Usage

The parts are the Year Picker's with a start and an end: put two YearRangePickerInputs in the YearRangePickerControl, type="start" and type="end", with a YearRangePickerSeparator between them (an en dash by default), then YearRangePickerClear and YearRangePickerTrigger. The popup is a YearRangePickerPortal, YearRangePickerPositioner, YearRangePickerPopup and YearRangePickerCalendar, which picks the range in two presses. The value is { start, end }, '2026' strings, or null. 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 Year Range Picker's.

import {
  YearRangePicker,
  YearRangePickerCalendar,
  YearRangePickerClear,
  YearRangePickerClose,
  YearRangePickerControl,
  YearRangePickerInput,
  YearRangePickerPopup,
  YearRangePickerPortal,
  YearRangePickerPositioner,
  YearRangePickerPreset,
  YearRangePickerSegment,
  YearRangePickerSeparator,
  YearRangePickerTrigger,
} from '@/components/ui/year-range-picker'

Examples

Default

Two inputs with a dash between them and a page of years.

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

This item follows the Date Range Picker's composition. It takes the Year Picker's control, segment, trigger, popup, preset and close classes, so the item requires it; the calendar is the Year 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 Year Range Picker's API reference.