Date Range Picker
boldkit/date-range-pickerFreeComponent
Date range picker with presets, dual calendars, and customizable options
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/date-range-picker.jsonSource
1/* eslint-disable react-refresh/only-export-components */2import * as React from 'react'3import { format, subDays, startOfMonth, endOfMonth, subMonths, isSameDay } from 'date-fns'4import { CalendarIcon } from 'lucide-react'5import type { DateRange } from 'react-day-picker'6import { cn } from '@/lib/utils'7import { Button } from '@/components/ui/button'8import { Calendar } from '@/components/ui/calendar'9import {10 Popover,11 PopoverContent,12 PopoverTrigger,13} from '@/components/ui/popover'1415export interface DateRangePickerPreset {16 label: string17 value: DateRange18}1920export interface DateRangePickerProps {21 value?: DateRange22 defaultValue?: DateRange23 onChange?: (range: DateRange | undefined) => void24 numberOfMonths?: 1 | 225 presets?: DateRangePickerPreset[]26 showPresets?: boolean27 minDate?: Date28 maxDate?: Date29 disabled?: boolean30 placeholder?: string31 align?: 'start' | 'center' | 'end'32 className?: string33}3435const getDefaultPresets = (): DateRangePickerPreset[] => {36 const today = new Date()37 const lastMonth = subMonths(today, 1)3839 return [40 {41 label: 'Today',42 value: { from: today, to: today },43 },44 {45 label: 'Last 7 days',46 value: { from: subDays(today, 6), to: today },47 },48 {49 label: 'Last 30 days',50 value: { from: subDays(today, 29), to: today },51 },52 {53 label: 'This month',54 value: { from: startOfMonth(today), to: today },55 },56 {57 label: 'Last month',58 value: { from: startOfMonth(lastMonth), to: endOfMonth(lastMonth) },59 },60 ]61}6263const DateRangePicker = React.forwardRef<HTMLButtonElement, DateRangePickerProps>(64 (65 {66 value: controlledValue,67 defaultValue,68 onChange,69 numberOfMonths = 2,70 presets,71 showPresets = true,72 minDate,73 maxDate,74 disabled = false,75 placeholder = 'Pick a date range',76 align = 'start',77 className,78 },79 ref80 ) => {81 const [open, setOpen] = React.useState(false)82 const [uncontrolledValue, setUncontrolledValue] = React.useState<DateRange | undefined>(defaultValue)8384 const isControlled = controlledValue !== undefined85 const selectedRange = isControlled ? controlledValue : uncontrolledValue8687 const resolvedPresets = presets ?? getDefaultPresets()8889 const handleSelect = (range: DateRange | undefined) => {90 if (!isControlled) {91 setUncontrolledValue(range)92 }93 onChange?.(range)94 }9596// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
