fix shadcn calendar component

This commit is contained in:
Josh Hawkins 2025-05-15 10:16:05 -05:00
parent 5e3d0c20bd
commit d567740e5c

View File

@ -17,45 +17,59 @@ function Calendar({
return ( return (
<DayPicker <DayPicker
locale={locale} locale={locale}
navLayout={"around"}
showOutsideDays={showOutsideDays} showOutsideDays={showOutsideDays}
className={cn("p-3", className)} className={cn("p-3", className)}
classNames={{ classNames={{
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0", months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
month: "space-y-4", month: "relative",
caption: "flex justify-center pt-1 relative items-center", month_caption: "flex justify-center pt-1 relative items-center",
month_grid: "w-full border-collapse space-y-1 mt-4",
caption_label: "text-sm font-medium", caption_label: "text-sm font-medium",
nav: "space-x-1 flex items-center", nav: "flex items-center justify-between",
nav_button: cn( button_previous: cn(
buttonVariants({ variant: "outline" }), buttonVariants({ variant: "outline" }),
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100", "h-7 w-7 absolute top-0 left-1 bg-transparent fill-primary p-0 opacity-50 hover:opacity-100 z-10",
), ),
nav_button_previous: "absolute left-1", button_next: cn(
nav_button_next: "absolute right-1", buttonVariants({ variant: "outline" }),
table: "w-full border-collapse space-y-1", "h-7 w-7 absolute top-0 right-1 bg-transparent fill-primary p-0 opacity-50 hover:opacity-100 z-10",
head_row: "flex justify-center", ),
head_cell: weeks: "w-full border-collapse",
weekdays: "flex justify-center",
weekday:
"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]", "text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]",
row: "flex w-full mt-2 justify-center", week: "flex w-full mt-2 justify-center",
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", day: "h-9 w-9 text-center text-sm p-0 relative aria-selected:opacity-100 first:aria-selected:rounded-l-md last:aria-selected:rounded-r-md",
day: cn( day_button: cn(
buttonVariants({ variant: "ghost" }), buttonVariants({ variant: "ghost" }),
"h-9 w-9 p-0 font-normal aria-selected:opacity-100", "h-9 w-9 p-0 font-normal text-muted-foreground focus-within:relative focus-within:z-20",
), ),
day_range_end: "day-range-end", range_start:
day_selected: "day-range-start !bg-accent rounded-l-md [&>button]:bg-selected [&>button]:text-white [&>button]:hover:bg-selected [&>button]:hover:text-white",
"bg-selected text-white hover:bg-selected hover:text-white focus:bg-selected focus:text-white", range_end:
day_today: "bg-muted text-muted-foreground", "day-range-end !bg-accent rounded-r-md [&>button]:bg-selected [&>button]:text-white [&>button]:hover:bg-selected [&>button]:hover:text-white",
day_outside: selected: cn(
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30", props.mode === "range"
day_disabled: "text-muted-foreground opacity-50", ? " [&>button]:hover:bg-selected [&>button]:hover:text-white focus:bg-selected focus:text-white [&>button]:aria-selected:text-primary"
day_range_middle: : " [&>button]:bg-selected [&>button]:text-white [&>button]:hover:bg-selected [&>button]:hover:text-white focus:bg-selected focus:text-white rounded-md",
),
today: "bg-muted text-muted-foreground !rounded-md",
outside:
"day-outside text-muted-foreground opacity-50 !aria-selected:bg-accent/50 !aria-selected:text-muted-foreground !aria-selected:opacity-30",
disabled: "text-muted-foreground opacity-50",
range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground", "aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible", hidden: "invisible",
...classNames, ...classNames,
}} }}
components={{ components={{
IconLeft: () => <ChevronLeft className="h-4 w-4" />, Chevron: ({ ...props }) =>
IconRight: () => <ChevronRight className="h-4 w-4" />, props.orientation === "left" ? (
<ChevronLeft {...props} className="h-4 w-4" />
) : (
<ChevronRight {...props} className="h-4 w-4" />
),
}} }}
{...props} {...props}
/> />