| 1 | import { cn } from "@/lib/utils"; |
| 2 | import { Button } |
| 3 | import { Popover, PopoverContent |
| 4 | import { CalendarIcon } |
| 5 | import { format } |
| 6 | import { Calendar } |
| 7 | |
| 8 | export default function DatePicker |
| 9 | onChange, |
| 10 | value, |
| 11 | disablePastDates = true, |
| 12 | disableFutureDates = false, |
| 13 | }: { |
| 14 | value: Date |
| 15 | onChange: (date |
| 16 | disablePastDates?: boolean |
| 17 | disableFutureDates?: boolean |
| 18 | }) { |
| 19 | return ( |
| 20 | <Popover> |
| 21 | <PopoverTrigger asChild> |
| 22 | <Button |
| 23 | className={cn( |
| 24 | "w-full justify-start text-left font-normal", |
| 25 | !value && "text-muted-foreground |
| 26 | )} |
| 27 | size="lg" |
| 28 | type="button" |
| 29 | variant="outline" |
| 30 | > |
| 31 | <CalendarIcon className=" |
| 32 | {value ? format |
| 33 | </Button> |
| 34 | </PopoverTrigger> |
| 35 | <PopoverContent align=" |
| 36 | <Calendar |
| 37 | disabled={(date) |
| 38 | const today = |
| 39 | today.setHours(0, |
| 40 | if (disablePastDates && date |
| 41 | if (disableFutureDates && date |
| 42 | return false; |
| 43 | }} |
| 44 | mode="single" |
| 45 | onSelect={onChange} |
| 46 | selected={value} |
| 47 | /> |
| 48 | </PopoverContent> |
| 49 | </Popover> |
| 50 | ); |
| 51 | } |