| 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 | disabled = false, |
| 14 | }: { |
| 15 | value: Date |
| 16 | onChange: (date |
| 17 | disablePastDates?: boolean |
| 18 | disableFutureDates?: boolean |
| 19 | disabled?: boolean |
| 20 | }) { |
| 21 | return ( |
| 22 | <Popover> |
| 23 | <PopoverTrigger asChild> |
| 24 | <Button |
| 25 | className={cn( |
| 26 | "w-full justify-start text-left font-normal", |
| 27 | !value && "text-muted-foreground |
| 28 | )} |
| 29 | disabled={disabled} |
| 30 | size="lg" |
| 31 | type="button" |
| 32 | variant="outline" |
| 33 | > |
| 34 | <CalendarIcon className=" |
| 35 | {value ? format |
| 36 | </Button> |
| 37 | </PopoverTrigger> |
| 38 | <PopoverContent align=" |
| 39 | <Calendar |
| 40 | disabled={(date) |
| 41 | const today = |
| 42 | today.setHours(0, |
| 43 | if (disablePastDates && date |
| 44 | if (disableFutureDates && date |
| 45 | return false; |
| 46 | }} |
| 47 | mode="single" |
| 48 | onSelect={onChange} |
| 49 | selected={value} |
| 50 | /> |
| 51 | </PopoverContent> |
| 52 | </Popover> |
| 53 | ); |
| 54 | } |