calendar.tsx 2.5 KB

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