22
33import * as React from "react" ;
44import { ChevronLeftIcon , ChevronRightIcon } from "@radix-ui/react-icons" ;
5- import { DayPicker } from "react-day-picker" ;
5+ import { DayPicker , getDefaultClassNames } from "react-day-picker" ;
6+
7+ import "react-day-picker/style.css" ;
68
79import { cn } from "utils" ;
810
@@ -11,46 +13,80 @@ import { buttonVariants } from "./button";
1113export type CalendarProps = React . ComponentProps < typeof DayPicker > ;
1214
1315function Calendar ( { className, classNames, showOutsideDays = true , ...props } : CalendarProps ) {
16+ const defaultClassNames = getDefaultClassNames ( ) ;
17+
1418 return (
1519 < DayPicker
1620 showOutsideDays = { showOutsideDays }
1721 className = { cn ( "p-3" , className ) }
1822 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 : "text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]" ,
33- row : "flex w-full mt-2" ,
34- cell : cn (
35- "relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md" ,
36- props . mode === "range"
37- ? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
38- : "[&:has([aria-selected])]:rounded-md"
23+ root : cn ( "w-fit" , defaultClassNames . root ) ,
24+ months : cn ( "relative flex flex-col gap-4 md:flex-row" , defaultClassNames . months ) ,
25+ month : cn ( "flex w-full flex-col gap-4" , defaultClassNames . month ) ,
26+ nav : cn (
27+ "absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1" ,
28+ defaultClassNames . nav
3929 ) ,
40- day : cn (
30+ button_previous : cn (
31+ buttonVariants ( { variant : "ghost" } ) ,
32+ "size-(--cell-size) select-none p-0 aria-disabled:opacity-50" ,
33+ defaultClassNames . button_previous
34+ ) ,
35+ button_next : cn (
4136 buttonVariants ( { variant : "ghost" } ) ,
42- "h-8 w-8 p-0 font-normal aria-selected:opacity-100"
43- ) ,
44- day_range_start : "day-range-start" ,
45- day_range_end : "day-range-end" ,
46- day_selected :
47- "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground" ,
48- day_today : "bg-accent text-accent-foreground" ,
49- day_outside :
50- "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30" ,
51- day_disabled : "text-muted-foreground opacity-50" ,
52- day_range_middle : "aria-selected:bg-accent aria-selected:text-accent-foreground" ,
53- day_hidden : "invisible" ,
37+ "size-(--cell-size) select-none p-0 aria-disabled:opacity-50" ,
38+ defaultClassNames . button_next
39+ ) ,
40+ month_caption : cn (
41+ "h-(--cell-size) px-(--cell-size) flex w-full items-center justify-center" ,
42+ defaultClassNames . month_caption
43+ ) ,
44+ dropdowns : cn (
45+ "h-(--cell-size) flex w-full items-center justify-center gap-1.5 text-sm font-medium" ,
46+ defaultClassNames . dropdowns
47+ ) ,
48+ dropdown_root : cn (
49+ "has-focus:border-ring shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border border-input" ,
50+ defaultClassNames . dropdown_root
51+ ) ,
52+ dropdown : cn ( "absolute inset-0 bg-popover opacity-0" , defaultClassNames . dropdown ) ,
53+ caption_label : cn (
54+ "select-none font-medium" ,
55+ "flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground" ,
56+ defaultClassNames . caption_label
57+ ) ,
58+ table : "w-full border-collapse" ,
59+ weekdays : cn ( "flex" , defaultClassNames . weekdays ) ,
60+ weekday : cn (
61+ "flex-1 select-none rounded-md text-[0.8rem] font-normal text-muted-foreground" ,
62+ defaultClassNames . weekday
63+ ) ,
64+ week : cn ( "mt-2 flex w-full" , defaultClassNames . week ) ,
65+ week_number_header : cn (
66+ "w-(--cell-size) select-none" ,
67+ defaultClassNames . week_number_header
68+ ) ,
69+ week_number : cn (
70+ "select-none text-[0.8rem] text-muted-foreground" ,
71+ defaultClassNames . week_number
72+ ) ,
73+ day : cn (
74+ "group/day relative aspect-square h-full w-full select-none p-0 text-center text-sm [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md" ,
75+ defaultClassNames . day
76+ ) ,
77+ range_start : cn ( "rounded-l-md bg-accent" , defaultClassNames . range_start ) ,
78+ range_middle : cn ( "rounded-none" , defaultClassNames . range_middle ) ,
79+ range_end : cn ( "rounded-r-md bg-accent" , defaultClassNames . range_end ) ,
80+ today : cn (
81+ "rounded-md bg-accent text-accent-foreground data-[selected=true]:rounded-none" ,
82+ defaultClassNames . today
83+ ) ,
84+ outside : cn (
85+ "text-muted-foreground aria-selected:text-muted-foreground" ,
86+ defaultClassNames . outside
87+ ) ,
88+ disabled : cn ( "text-muted-foreground opacity-50" , defaultClassNames . disabled ) ,
89+ hidden : cn ( "invisible" , defaultClassNames . hidden ) ,
5490 ...classNames ,
5591 } }
5692 { ...props }
0 commit comments