Date Picker

Single-date picker built with the shared calendar and popover primitives. Install Date Picker from the VLLNT UI registry with the shadcn CLI.

Report a bug

Single-date picker built with the shared calendar and popover primitives. 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 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-picker.json

Source

"use client"; import * as React from "react"; import { CalendarIcon } from "lucide-react"; import { cn } from "../../lib/utils"; import { Button } from "../button/button"; import { Calendar, type CalendarProps } from "../calendar/calendar"; import { Popover, PopoverContent, PopoverTrigger } from "../popover/popover"; const defaultDateFormatter = new Intl.DateTimeFormat("en-US", { day: "numeric", month: "long", year: "numeric", }); export type DatePickerProps = { buttonClassName?: string; calendarProps?: Omit<CalendarProps, "mode" | "onSelect" | "selected">; className?: string; onValueChange?: (date?: Date) => void; placeholder?: string; value?: Date; }; const DatePicker = ({ buttonClassName, calendarProps, className, onValueChange, placeholder = "Pick a date", ref: reference, value, }: DatePickerProps & { ref?: React.Ref<HTMLButtonElement> }) => { const [open, setOpen] = React.useState(false); const [internalValue, setInternalValue] = React.useState<Date | undefined>( () => value, ); const selectedDate = value ?? internalValue; const handleSelect = (nextDate: Date | undefined) => { if (value === undefined) { setInternalValue(nextDate); } onValueChange?.(nextDate); if (nextDate) { setOpen(false); } }; return ( <Popover onOpenChange={setOpen} open={open}> <PopoverTrigger asChild> <Button className={cn( "w-full justify-start text-left font-normal", !selectedDate && "text-muted-foreground", buttonClassName, )} ref={reference} variant="outline" > <CalendarIcon className="mr-2 size-4" /> {selectedDate ? defaultDateFormatter.format(selectedDate) : placeholder} </Button> </PopoverTrigger> <PopoverContent align="start" className={cn("w-auto p-0", className)}> <Calendar mode="single" onSelect={handleSelect} selected={selectedDate} {...calendarProps} /> </PopoverContent> </Popover> ); }; DatePicker.displayName = "DatePicker"; export { DatePicker };

Stories

Explore every variant and state in the interactive Storybook:

Preview

Switch between light and dark to inspect the embedded Storybook preview.

Dependencies

  • @vllnt/ui@^0.3.0