Date Picker
A date picker component with range and presets.
Installation
Date Picker is built using a composition of the <Popover />
and <Calendar />
components. Follow installation for Popover and Calendar.
Usage
"use client";
import { useState } from "react";
import { CalendarIcon } from "lucide-react";
import { format } from "date-fns";
import { cn } from "~/utils/tailwind";
import { Button } from "~/components/ui/Button";
import { Calendar } from "~/components/ui/Calendar";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "~/components/ui/Popover";
export default function DatePickerDemo() {
const [date, setDate] = useState<Date>();
return (
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
subject="icon-text"
size="md"
className={cn("w-48 justify-start", !date && "text-muted-foreground")}
>
<CalendarIcon />
{date ? format(date, "PPP") : <span>Pick a date</span>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto overflow-hidden p-0" align="start">
<Calendar mode="single" selected={date} onSelect={setDate} autoFocus />
</PopoverContent>
</Popover>
);
}