Date Range Picker
A button showing a range of days, opening a calendar and optional presets.
<DateRangePicker onValueChange={setValue} value={value} />Installation
$ npx shadcn@latest add @constella/date-range-pickerUsage
import { DateRangePicker } from "@/components/primitives/date-range-picker";const [value, setValue] = useState({ from: start, to: end });
<DateRangePicker onValueChange={setValue} value={value} />;Composition
DateRangePicker├── Button└── Popover ├── Button (each preset) └── CalendarPresets
Pass presets to list ranges beside the calendar. A preset whose range matches value is pressed. Picking one closes the picker.
const presets = [ { label: "Last 7 days", range: { from: sevenDaysAgo, to: today } }, { label: "Last 30 days", range: { from: thirtyDaysAgo, to: today } }, { label: "This month", range: { from: startOfMonth, to: today } }, { label: "Last month", range: { from: startOfLastMonth, to: endOfLastMonth }, },];
<DateRangePicker onValueChange={setValue} presets={presets} value={value} />;Time Zone
Pass timeZone to label and select days in that zone, such as "UTC", instead of the browser's.
<DateRangePicker onValueChange={setValue} timeZone="UTC" value={value} />Disabled
Use disabled to block days and startMonth or endMonth to limit how far the arrows go.
<DateRangePicker disabled={{ after: today }} endMonth={today} onValueChange={setValue} value={value}/>API Reference
It also takes disabled, startMonth, endMonth, locale, timeZone and weekStartsOn from react-day-picker. The first day picked waits for a second to end the range.