Date Picker
rivelle/date-pickerFreeComponent
A controlled date field composed from Calendar and Popover.
Live preview
live · rendered by the registry
Rendered by rivelle on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://rivelle.dev/r/date-picker.jsonSource
1"use client";23import * as React from "react";4import { CalendarDays, X } from "lucide-react";56import { 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";1415function DatePicker({16 value,17 defaultValue,18 onValueChange,19 placeholder = "Pick a date",20 locale = "en-US",21 disabled,22 clearable = false,23 className,24}: {25 value?: Date;26 defaultValue?: Date;27 onValueChange?: (date: Date | undefined) => void;28 placeholder?: string;29 locale?: string;30 disabled?: boolean;31 clearable?: boolean;32 className?: string;33}) {34 const [open, setOpen] = React.useState(false);35 const [internalValue, setInternalValue] = React.useState<Date | undefined>(36 defaultValue,37 );38 const selected = value ?? internalValue;3940 function update(next: Date | undefined) {41 if (value === undefined) setInternalValue(next);42 onValueChange?.(next);43 if (next) setOpen(false);44 }4546 return (47 <div data-slot="date-picker" className={cn("relative w-full", className)}>48 <Popover open={open} onOpenChange={setOpen}>49 <PopoverTrigger asChild>50 <Button51 disabled={disabled}52 variant="outline"53 className={cn(54 "h-11.5 w-full justify-start px-4 text-left font-medium hover:-translate-y-0",55 !selected && "text-muted-foreground",56 clearable && selected && "pr-11",57 )}58 >59 <CalendarDays className="text-primary" />60 {selected61 ? new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(62 selected,63 )64 : placeholder}65 </Button>66 </PopoverTrigger>67 <PopoverContent align="start" className="w-auto p-0">68 <Calendar69 mode="single"70 selected={selected}71 onSelect={update}72 autoFocus73 />74 </PopoverContent>75 </Popover>76 {clearable && selected && !disabled && (77 <button78 type="button"79 aria-label="Clear date"80 className="absolute right-2 top-1/2 z-10 grid size-7 -translate-y-1/2 place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/[.055] hover:text-foreground"81 onClick={() => update(undefined)}82 >83 <X className="size-3.5" />84// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from rivelle
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | rivelle | Components | Free | 2 deps | |
| Alertalert | rivelle | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | rivelle | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | rivelle | Components | Free | 1 dep | |
| Avataravatar | rivelle | Components | Free | 1 dep | |
| Badgebadge | rivelle | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | rivelle | Components | Free | 2 deps | |
| Buttonbutton | rivelle | Components | Free | 2 deps |
