Guest User

Untitled

a guest
Jun 23rd, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. "use client";
  2.  
  3. import * as React from "react";
  4. import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
  5. import { DayPicker } from "react-day-picker";
  6.  
  7. import { cn } from "@/lib/utils";
  8. import { buttonVariants } from "@/components/ui/button";
  9.  
  10. function Calendar({
  11. className,
  12. classNames,
  13. showOutsideDays = true,
  14. components: userComponents,
  15. ...props
  16. }: React.ComponentProps<typeof DayPicker>) {
  17. const defaultClassNames = {
  18. months: "relative flex flex-col sm:flex-row gap-4",
  19. month: "w-full",
  20. month_caption:
  21. "relative mx-10 mb-1 flex h-9 items-center justify-center z-20",
  22. caption_label: "text-sm font-medium",
  23. nav: "absolute top-0 flex w-full justify-between z-10",
  24. button_previous: cn(
  25. buttonVariants({ variant: "ghost" }),
  26. "size-9 text-muted-foreground/80 hover:text-foreground p-0"
  27. ),
  28. button_next: cn(
  29. buttonVariants({ variant: "ghost" }),
  30. "size-9 text-muted-foreground/80 hover:text-foreground p-0"
  31. ),
  32. weekday: "size-9 p-0 text-xs font-medium text-muted-foreground/80",
  33. day_button:
  34. "relative flex size-9 items-center justify-center whitespace-nowrap rounded-md p-0 text-foreground group-[[data-selected]:not(.range-middle)]:[transition-property:color,background-color,border-radius,box-shadow] group-[[data-selected]:not(.range-middle)]:duration-150 group-data-disabled:pointer-events-none focus-visible:z-10 hover:not-in-data-selected:bg-accent group-data-selected:bg-primary hover:not-in-data-selected:text-foreground group-data-selected:text-primary-foreground group-data-disabled:text-foreground/30 group-data-disabled:line-through group-data-outside:text-foreground/30 group-data-selected:group-data-outside:text-primary-foreground outline-none focus-visible:ring-ring/50 focus-visible:ring-[3px] group-[.range-start:not(.range-end)]:rounded-e-none group-[.range-end:not(.range-start)]:rounded-s-none group-[.range-middle]:rounded-none group-[.range-middle]:group-data-selected:bg-accent group-[.range-middle]:group-data-selected:text-foreground",
  35. day: "group size-9 px-0 py-px text-sm",
  36. range_start: "range-start",
  37. range_end: "range-end",
  38. range_middle: "range-middle",
  39. today:
  40. "*:after:pointer-events-none *:after:absolute *:after:bottom-1 *:after:start-1/2 *:after:z-10 *:after:size-[3px] *:after:-translate-x-1/2 *:after:rounded-full *:after:bg-primary [&[data-selected]:not(.range-middle)>*]:after:bg-background [&[data-disabled]>*]:after:bg-foreground/30 *:after:transition-colors",
  41. outside:
  42. "text-muted-foreground data-selected:bg-accent/50 data-selected:text-muted-foreground",
  43. hidden: "invisible",
  44. week_number: "size-9 p-0 text-xs font-medium text-muted-foreground/80",
  45. };
  46.  
  47. const mergedClassNames: typeof defaultClassNames = Object.keys(
  48. defaultClassNames
  49. ).reduce(
  50. (acc, key) => ({
  51. ...acc,
  52. [key]: classNames?.[key as keyof typeof classNames]
  53. ? cn(
  54. defaultClassNames[key as keyof typeof defaultClassNames],
  55. classNames[key as keyof typeof classNames]
  56. )
  57. : defaultClassNames[key as keyof typeof defaultClassNames],
  58. }),
  59. {} as typeof defaultClassNames
  60. );
  61.  
  62. const defaultComponents = {
  63. Chevron: (props: {
  64. className?: string;
  65. size?: number;
  66. disabled?: boolean;
  67. orientation?: "left" | "right" | "up" | "down";
  68. }) => {
  69. if (props.orientation === "left") {
  70. return <ChevronLeftIcon size={16} {...props} aria-hidden="true" />;
  71. }
  72. return <ChevronRightIcon size={16} {...props} aria-hidden="true" />;
  73. },
  74. };
  75.  
  76. const mergedComponents = {
  77. ...defaultComponents,
  78. ...userComponents,
  79. };
  80.  
  81. return (
  82. <DayPicker
  83. showOutsideDays={showOutsideDays}
  84. className={cn("w-fit", className)}
  85. classNames={mergedClassNames}
  86. {...props}
  87. />
  88. );
  89. }
  90.  
  91. export { Calendar };
  92.  
Advertisement
Add Comment
Please, Sign In to add comment