11"use client" ;
22import React from "react" ;
3- import {
4- DayPicker ,
5- DayPickerRangeProps ,
6- DayPickerSingleProps ,
7- useNavigation ,
8- } from "react-day-picker" ;
3+ import { DayPicker , useDayPicker , PropsSingle , PropsRange , PropsBase } from "react-day-picker" ;
94
105import {
116 ArrowLeftHeadIcon ,
@@ -17,6 +12,9 @@ import { addYears, format } from "date-fns";
1712import { Text } from "../../text-elements/Text" ;
1813import { NavButton } from "./NavButton" ;
1914
15+ export type DayPickerSingleProps = PropsBase & PropsSingle ;
16+ export type DayPickerRangeProps = PropsBase & PropsRange ;
17+
2018function Calendar < T extends DayPickerSingleProps | DayPickerRangeProps > ( {
2119 mode,
2220 defaultMonth,
@@ -34,49 +32,57 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
3432 showOutsideDays = { true }
3533 mode = { mode as any }
3634 defaultMonth = { defaultMonth }
37- selected = { selected }
35+ selected = { selected as any }
3836 onSelect = { onSelect as any }
3937 locale = { locale }
4038 disabled = { disabled }
4139 weekStartsOn = { weekStartsOn }
4240 classNames = { {
4341 months : "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0" ,
4442 month : "space-y-4" ,
45- caption : "flex justify-center pt-2 relative items-center" ,
43+ month_caption : "flex justify-center pt-2 relative items-center" ,
4644 caption_label :
4745 "text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium" ,
4846 nav : "space-x-1 flex items-center" ,
49- nav_button :
50- "flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content" ,
51- nav_button_previous : "absolute left-1" ,
52- nav_button_next : " absolute right-1",
53- table : "w-full border-collapse space-y-1" ,
54- head_row : "flex" ,
55- head_cell :
47+ button_previous :
48+ "flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content absolute left-1 " ,
49+ button_next :
50+ "flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content absolute right-1",
51+ month_grid : "w-full border-collapse space-y-1" ,
52+ weekdays : "flex" ,
53+ weekday :
5654 "w-9 font-normal text-center text-tremor-content-subtle dark:text-dark-tremor-content-subtle" ,
57- row : "flex w-full mt-0.5" ,
58- cell : "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis" ,
59- day : "h-9 w-9 p-0 hover:bg-tremor-background-subtle dark:hover:bg-dark-tremor-background-subtle outline-tremor-brand dark:outline-dark-tremor-brand rounded-tremor-default" ,
60- day_today : "font-bold" ,
61- day_selected :
55+ week : "flex w-full mt-0.5" ,
56+ day : "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis hover:bg-tremor-background-subtle dark:hover:bg-dark-tremor-background-subtle rounded-tremor-default" ,
57+ day_button :
58+ "h-9 w-9 p-0 outline-tremor-brand dark:outline-dark-tremor-brand rounded-tremor-default" ,
59+ today : "font-bold" ,
60+ selected :
6261 "aria-selected:bg-tremor-background-emphasis aria-selected:text-tremor-content-inverted dark:aria-selected:bg-dark-tremor-background-emphasis dark:aria-selected:text-dark-tremor-content-inverted " ,
63- day_disabled :
62+ disabled :
6463 "text-tremor-content-subtle dark:text-dark-tremor-content-subtle disabled:hover:bg-transparent" ,
65- day_outside : "text-tremor-content-subtle dark:text-dark-tremor-content-subtle" ,
64+ outside : "text-tremor-content-subtle dark:text-dark-tremor-content-subtle" ,
6665 ...classNames ,
6766 } }
6867 components = { {
69- IconLeft : ( { ...props } ) => < ArrowLeftHeadIcon className = "h-4 w-4" { ...props } /> ,
70- IconRight : ( { ...props } ) => < ArrowRightHeadIcon className = "h-4 w-4" { ...props } /> ,
71- Caption : ( { ...props } ) => {
72- const { goToMonth, nextMonth, previousMonth, currentMonth } = useNavigation ( ) ;
68+ Chevron : ( props ) => {
69+ if ( props . orientation === "left" ) {
70+ return < ArrowLeftHeadIcon className = "h-4 w-4" { ...props } /> ;
71+ }
72+
73+ return < ArrowRightHeadIcon className = "h-4 w-4" { ...props } /> ;
74+ } ,
75+ MonthCaption : ( { calendarMonth } ) => {
76+ const { goToMonth, nextMonth, previousMonth } = useDayPicker ( ) ;
7377
7478 return (
7579 < div className = "flex justify-between items-center" >
7680 < div className = "flex items-center space-x-1" >
7781 { enableYearNavigation && (
7882 < NavButton
79- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , - 1 ) ) }
83+ onClick = { ( ) =>
84+ calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , - 1 ) )
85+ }
8086 icon = { DoubleArrowLeftHeadIcon }
8187 />
8288 ) }
@@ -87,7 +93,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
8793 </ div >
8894
8995 < Text className = "text-tremor-default tabular-nums capitalize text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium" >
90- { format ( props . displayMonth , "LLLL yyy" , { locale } ) }
96+ { format ( calendarMonth . date , "LLLL yyy" , { locale : locale as any } ) }
9197 </ Text >
9298
9399 < div className = "flex items-center space-x-1" >
@@ -97,7 +103,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
97103 />
98104 { enableYearNavigation && (
99105 < NavButton
100- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , 1 ) ) }
106+ onClick = { ( ) => calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , 1 ) ) }
101107 icon = { DoubleArrowRightHeadIcon }
102108 />
103109 ) }
@@ -107,6 +113,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
107113 } ,
108114 } }
109115 { ...other }
116+ hideNavigation
110117 />
111118 ) ;
112119}
0 commit comments