Date Range Picker
Popover calendar for selecting a start and end date. Install Date Range Picker from the VLLNT UI registry with the shadcn CLI.
Popover calendar for selecting a start and end date. Part of the form family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Date Range Picker to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/date-range-picker.jsonSource
"use client";
import * as React from "react";
import { CalendarIcon } from "lucide-react";
import type { DateRange } from "react-day-picker";
import { cn } from "../../lib/utils";
import { Button } from "../button/button";
import { Calendar } from "../calendar";
import { Popover, PopoverContent, PopoverTrigger } from "../popover";
const rangeFormatter = new Intl.DateTimeFormat("en-US", {
day: "numeric",
month: "short",
year: "numeric",
});
function formatRange(range: DateRange | undefined): string | undefined {
if (!range?.from) {
return undefined;
}
if (!range.to) {
return rangeFormatter.format(range.from);
}
return `${rangeFormatter.format(range.from)} – ${rangeFormatter.format(range.to)}`;
}
/** Popover date-range picker built on the range calendar. */
export type DateRangePickerProps = {
buttonClassName?: string;
className?: string;
defaultValue?: DateRange;
numberOfMonths?: number;
onValueChange?: (range?: DateRange) => void;
placeholder?: string;
value?: DateRange;
};
const DateRangePicker = ({
buttonClassName,
className,
defaultValue,
numberOfMonths = 2,
onValueChange,
placeholder = "Pick a date range",
ref,
value,
}: DateRangePickerProps & { ref?: React.Ref<HTMLButtonElement> }) => {
const [internalValue, setInternalValue] = React.useState<
DateRange | undefined
>(defaultValue);
const selected = value ?? internalValue;
const label = formatRange(selected);
const handleSelect = (range: DateRange | undefined) => {
if (value === undefined) {
setInternalValue(range);
}
onValueChange?.(range);
};
return (
<Popover>
<PopoverTrigger asChild>
<Button
className={cn(
"w-full justify-start text-left font-normal",
!label && "text-muted-foreground",
buttonClassName,
)}
ref={ref}
variant="outline"
>
<CalendarIcon className="mr-2 size-4" />
{label ?? placeholder}
</Button>
</PopoverTrigger>
<PopoverContent align="start" className={cn("w-auto p-0", className)}>
<Calendar
mode="range"
numberOfMonths={numberOfMonths}
onSelect={handleSelect}
selected={selected}
/>
</PopoverContent>
</Popover>
);
};
DateRangePicker.displayName = "DateRangePicker";
export { DateRangePicker };
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.