|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import * as React from "react"; |
| 4 | +import { DayPicker } from "react-day-picker"; |
| 5 | + |
| 6 | +import { cn } from "@/lib/utils"; |
| 7 | +import { buttonVariants } from "@/components/ui/button"; |
| 8 | +import { |
| 9 | + ChevronLeft16Regular, |
| 10 | + ChevronRight16Regular, |
| 11 | +} from "@fluentui/react-icons"; |
| 12 | + |
| 13 | +export type CalendarProps = React.ComponentProps<typeof DayPicker>; |
| 14 | + |
| 15 | +function Calendar({ |
| 16 | + className, |
| 17 | + classNames, |
| 18 | + showOutsideDays = true, |
| 19 | + ...props |
| 20 | +}: CalendarProps) { |
| 21 | + return ( |
| 22 | + <DayPicker |
| 23 | + showOutsideDays={showOutsideDays} |
| 24 | + className={cn("p-3", className)} |
| 25 | + classNames={{ |
| 26 | + months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0", |
| 27 | + month: "space-y-4", |
| 28 | + caption: "flex justify-center pt-1 relative items-center", |
| 29 | + caption_label: "text-sm font-medium", |
| 30 | + nav: "space-x-1 flex items-center", |
| 31 | + nav_button: cn( |
| 32 | + buttonVariants({ variant: "outline" }), |
| 33 | + "h-7 w-7 bg-transparent p-0 flex justify-center opacity-50 hover:opacity-100", |
| 34 | + ), |
| 35 | + nav_button_previous: "absolute left-1", |
| 36 | + nav_button_next: "absolute right-1", |
| 37 | + table: "w-full border-collapse space-y-1", |
| 38 | + head_row: "flex", |
| 39 | + head_cell: |
| 40 | + "text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]", |
| 41 | + row: "flex w-full mt-2", |
| 42 | + cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20", |
| 43 | + day: cn( |
| 44 | + buttonVariants({ variant: "ghost" }), |
| 45 | + "h-9 w-9 p-0 flex justify-center font-normal hover:bg-slate-100 dark:hover:bg-slate-800 aria-selected:bg-accent-color aria-selected:text-white aria-selected:opacity-100", |
| 46 | + ), |
| 47 | + day_range_end: "day-range-end", |
| 48 | + day_selected: "bg-primary text-white hover:bg-primary hover:text-white", |
| 49 | + day_today: "bg-accent-color/20 text-accent-foreground", |
| 50 | + day_outside: |
| 51 | + "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30", |
| 52 | + day_disabled: "text-muted-foreground opacity-50", |
| 53 | + day_range_middle: |
| 54 | + "aria-selected:bg-accent aria-selected:text-accent-foreground", |
| 55 | + day_hidden: "invisible", |
| 56 | + ...classNames, |
| 57 | + }} |
| 58 | + components={{ |
| 59 | + IconLeft: ({ ...props }) => ( |
| 60 | + <ChevronLeft16Regular className="h-4 w-4" /> |
| 61 | + ), |
| 62 | + IconRight: ({ ...props }) => ( |
| 63 | + <ChevronRight16Regular className="h-4 w-4" /> |
| 64 | + ), |
| 65 | + }} |
| 66 | + {...props} |
| 67 | + /> |
| 68 | + ); |
| 69 | +} |
| 70 | +Calendar.displayName = "Calendar"; |
| 71 | + |
| 72 | +export { Calendar }; |
0 commit comments