Spaces:
Sleeping
Sleeping
| import * as React from "react"; | |
| import { format } from "date-fns"; | |
| import { Calendar as CalendarIcon } from "lucide-react"; | |
| import { cn } from "@/lib/utils"; | |
| import { Button } from "@/components/ui/button"; | |
| import { Calendar } from "@/components/ui/calendar"; | |
| import { | |
| Popover, | |
| PopoverContent, | |
| PopoverTrigger, | |
| } from "@/components/ui/popover"; | |
| interface DatePickerProps { | |
| date: Date; | |
| setDate: React.Dispatch<React.SetStateAction<Date>>; | |
| className?: string; | |
| disabled?: (date: Date) => boolean; | |
| placeholder?: string; | |
| } | |
| export function DatePicker({ | |
| date, | |
| setDate, | |
| className, | |
| disabled, | |
| placeholder = "Pick a date", | |
| }: DatePickerProps) { | |
| return ( | |
| <div className={cn("grid gap-2", className)}> | |
| <Popover> | |
| <PopoverTrigger asChild> | |
| <Button | |
| id="date" | |
| variant={"outline"} | |
| className={cn( | |
| "w-full justify-start text-left font-normal", | |
| !date && "text-muted-foreground" | |
| )} | |
| > | |
| <CalendarIcon className="mr-2 h-4 w-4" /> | |
| {date ? format(date, "PPP") : <span>{placeholder}</span>} | |
| </Button> | |
| </PopoverTrigger> | |
| <PopoverContent className="w-auto p-0" align="start"> | |
| <Calendar | |
| mode="single" | |
| selected={date} | |
| onSelect={(newDate) => newDate && setDate(newDate)} | |
| disabled={disabled} | |
| initialFocus | |
| /> | |
| </PopoverContent> | |
| </Popover> | |
| </div> | |
| ); | |
| } |