1
1
"use client" ;
2
2
import 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" ;
9
4
10
5
import {
11
6
ArrowLeftHeadIcon ,
@@ -17,6 +12,9 @@ import { addYears, format } from "date-fns";
17
12
import { Text } from "../../text-elements/Text" ;
18
13
import { NavButton } from "./NavButton" ;
19
14
15
+ export type DayPickerSingleProps = PropsBase & PropsSingle ;
16
+ export type DayPickerRangeProps = PropsBase & PropsRange ;
17
+
20
18
function Calendar < T extends DayPickerSingleProps | DayPickerRangeProps > ( {
21
19
mode,
22
20
defaultMonth,
@@ -34,49 +32,57 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
34
32
showOutsideDays = { true }
35
33
mode = { mode as any }
36
34
defaultMonth = { defaultMonth }
37
- selected = { selected }
35
+ selected = { selected as any }
38
36
onSelect = { onSelect as any }
39
37
locale = { locale }
40
38
disabled = { disabled }
41
39
weekStartsOn = { weekStartsOn }
42
40
classNames = { {
43
41
months : "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0" ,
44
42
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" ,
46
44
caption_label :
47
45
"text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium" ,
48
46
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 :
56
54
"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 :
62
61
"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 :
64
63
"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" ,
66
65
...classNames ,
67
66
} }
68
67
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 ( ) ;
73
77
74
78
return (
75
79
< div className = "flex justify-between items-center" >
76
80
< div className = "flex items-center space-x-1" >
77
81
{ enableYearNavigation && (
78
82
< NavButton
79
- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , - 1 ) ) }
83
+ onClick = { ( ) =>
84
+ calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , - 1 ) )
85
+ }
80
86
icon = { DoubleArrowLeftHeadIcon }
81
87
/>
82
88
) }
@@ -87,7 +93,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
87
93
</ div >
88
94
89
95
< 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 } ) }
91
97
</ Text >
92
98
93
99
< div className = "flex items-center space-x-1" >
@@ -97,7 +103,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
97
103
/>
98
104
{ enableYearNavigation && (
99
105
< NavButton
100
- onClick = { ( ) => currentMonth && goToMonth ( addYears ( currentMonth , 1 ) ) }
106
+ onClick = { ( ) => calendarMonth . date && goToMonth ( addYears ( calendarMonth . date , 1 ) ) }
101
107
icon = { DoubleArrowRightHeadIcon }
102
108
/>
103
109
) }
@@ -107,6 +113,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
107
113
} ,
108
114
} }
109
115
{ ...other }
116
+ hideNavigation
110
117
/>
111
118
) ;
112
119
}
0 commit comments