2
2
import React from "react" ;
3
3
import {
4
4
DayPicker ,
5
- DayPickerRangeProps ,
6
- DayPickerSingleProps ,
7
- useNavigation ,
5
+ useDayPicker ,
6
+ type PropsSingle ,
7
+ type PropsRange ,
8
+ type PropsBase ,
8
9
} from "react-day-picker" ;
9
10
10
11
import {
@@ -17,7 +18,7 @@ import { addYears, format } from "date-fns";
17
18
import { Text } from "../../text-elements/Text" ;
18
19
import { NavButton } from "./NavButton" ;
19
20
20
- function Calendar < T extends DayPickerSingleProps | DayPickerRangeProps > ( {
21
+ function Calendar < T extends ( PropsSingle | PropsRange ) & PropsBase > ( {
21
22
mode,
22
23
defaultMonth,
23
24
selected,
@@ -34,49 +35,57 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
34
35
showOutsideDays = { true }
35
36
mode = { mode as any }
36
37
defaultMonth = { defaultMonth }
37
- selected = { selected }
38
+ selected = { selected as any }
38
39
onSelect = { onSelect as any }
39
40
locale = { locale }
40
41
disabled = { disabled }
41
42
weekStartsOn = { weekStartsOn }
42
43
classNames = { {
43
44
months : "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0" ,
44
45
month : "space-y-4" ,
45
- caption : "flex justify-center pt-2 relative items-center" ,
46
+ month_caption : "flex justify-center pt-2 relative items-center" ,
46
47
caption_label :
47
48
"text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium" ,
48
49
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 :
50
+ button_previous :
51
+ "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 " ,
52
+ button_next :
53
+ "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",
54
+ month_grid : "w-full border-collapse space-y-1" ,
55
+ weekdays : "flex" ,
56
+ weekday :
56
57
"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 :
58
+ week : "flex w-full mt-0.5" ,
59
+ day : "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis" ,
60
+ day_button :
61
+ "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" ,
62
+ today : "font-bold" ,
63
+ selected :
62
64
"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 :
65
+ disabled :
64
66
"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" ,
67
+ outside : "text-tremor-content-subtle dark:text-dark-tremor-content-subtle" ,
66
68
...classNames ,
67
69
} }
68
70
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 ( ) ;
71
+ Chevron : ( props ) => {
72
+ if ( props . orientation === "left" ) {
73
+ return < ArrowLeftHeadIcon className = "h-4 w-4" { ...props } /> ;
74
+ }
75
+
76
+ return < ArrowRightHeadIcon className = "h-4 w-4" { ...props } /> ;
77
+ } ,
78
+ MonthCaption : ( { calendarMonth } ) => {
79
+ const { goToMonth, nextMonth, previousMonth } = useDayPicker ( ) ;
73
80
74
81
return (
75
82
< div className = "flex justify-between items-center" >
76
83
< div className = "flex items-center space-x-1" >
77
84
{ enableYearNavigation && (
78
85
< NavButton
79
- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , - 1 ) ) }
86
+ onClick = { ( ) =>
87
+ calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , - 1 ) )
88
+ }
80
89
icon = { DoubleArrowLeftHeadIcon }
81
90
/>
82
91
) }
@@ -87,7 +96,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
87
96
</ div >
88
97
89
98
< 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 } ) }
99
+ { format ( calendarMonth . date , "LLLL yyy" , { locale } ) }
91
100
</ Text >
92
101
93
102
< div className = "flex items-center space-x-1" >
@@ -97,7 +106,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
97
106
/>
98
107
{ enableYearNavigation && (
99
108
< NavButton
100
- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , 1 ) ) }
109
+ onClick = { ( ) => calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , 1 ) ) }
101
110
icon = { DoubleArrowRightHeadIcon }
102
111
/>
103
112
) }
@@ -107,6 +116,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
107
116
} ,
108
117
} }
109
118
{ ...other }
119
+ hideNavigation
110
120
/>
111
121
) ;
112
122
}
0 commit comments