Date Picker
A button that opens a calendar in a popover to pick a date.
Installation
Date Picker isn't a separate component. It combines Calendar, Popover, and Button. Install all three:
npx shadcn@latest add @columbus/calendar @columbus/popover @columbus/buttonUsage
"use client";
import { CalendarIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import { Popover, PopoverPopup, PopoverTrigger } from "@/components/ui/popover";
export function DatePicker() {
const [date, setDate] = useState<Date | undefined>();
return (
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>
<CalendarIcon aria-hidden="true" />
{date ? date.toLocaleDateString() : "Pick a date"}
</PopoverTrigger>
<PopoverPopup align="start">
<Calendar mode="single" selected={date} onSelect={setDate} />
</PopoverPopup>
</Popover>
);
}Control the popover with open and onOpenChange to close it once a date is
picked, as the demo above does.
Format dates with
Intl.DateTimeFormat
or toLocaleDateString, so they follow the user's locale.
Date range
Presets
Add buttons for common dates. Control the calendar's month so it jumps to the
picked date.