1
- import { DayPicker , DayPickerProps , DropdownProps } from "react-day-picker" ;
2
- import { cva } from "class-variance-authority" ;
1
+ import {
2
+ dateLib ,
3
+ DayPicker ,
4
+ DayPickerProps ,
5
+ DropdownProps ,
6
+ } from 'react-day-picker' ;
7
+ import { cva } from 'class-variance-authority' ;
3
8
import {
4
9
ChevronRightIcon ,
5
10
ChevronLeftIcon ,
6
11
ChevronUpIcon ,
7
12
ChevronDownIcon ,
8
- } from "@radix-ui/react-icons" ;
9
- import styles from "./calendar.module.css" ;
10
- import { Select } from "~/select" ;
11
- import { ChangeEvent , useEffect , useState } from "react" ;
12
- import { Flex } from "~/flex/flex" ;
13
+ } from '@radix-ui/react-icons' ;
14
+ import styles from './calendar.module.css' ;
15
+ import { Select } from '~/select' ;
16
+ import { ChangeEvent , useEffect , useState } from 'react' ;
17
+ import { Flex } from '~/flex/flex' ;
18
+ import { Tooltip } from '~/tooltip' ;
19
+ import Skeleton from 'react-loading-skeleton' ;
13
20
14
21
interface OnDropdownOpen {
15
22
onDropdownOpen ?: VoidFunction ;
16
23
}
17
24
18
- export type CalendarProps = DayPickerProps & OnDropdownOpen ;
25
+ interface CalendarPropsExtended {
26
+ showTooltip ?: boolean ;
27
+ tooltipMessages ?: { [ key : string ] : any } ;
28
+ loadingData ?: boolean ;
29
+ }
30
+
31
+ export type CalendarProps = DayPickerProps &
32
+ OnDropdownOpen &
33
+ CalendarPropsExtended ;
19
34
20
35
const root = cva ( styles . calendarRoot ) ;
21
36
@@ -54,7 +69,7 @@ function DropDown({
54
69
</ Select . Trigger >
55
70
< Select . Content className = { styles . dropdown_content } >
56
71
< Select . ScrollUpButton asChild >
57
- < Flex justify = { " center" } >
72
+ < Flex justify = { ' center' } >
58
73
< ChevronUpIcon />
59
74
</ Flex >
60
75
</ Select . ScrollUpButton >
@@ -73,7 +88,7 @@ function DropDown({
73
88
) ) }
74
89
</ Select . Viewport >
75
90
< Select . ScrollDownButton asChild >
76
- < Flex justify = { " center" } >
91
+ < Flex justify = { ' center' } >
77
92
< ChevronDownIcon />
78
93
</ Flex >
79
94
</ Select . ScrollDownButton >
@@ -87,21 +102,51 @@ export const Calendar = function ({
87
102
classNames,
88
103
showOutsideDays = true ,
89
104
onDropdownOpen,
105
+ showTooltip = false ,
106
+ tooltipMessages = { } ,
107
+ loadingData = false ,
90
108
...props
91
109
} : CalendarProps ) {
92
110
return (
93
111
< DayPicker
94
112
showOutsideDays = { showOutsideDays }
95
113
components = { {
96
114
Chevron : ( props ) => {
97
- if ( props . orientation === " left" ) {
115
+ if ( props . orientation === ' left' ) {
98
116
return < ChevronLeftIcon { ...props } /> ;
99
117
}
100
118
return < ChevronRightIcon { ...props } /> ;
101
119
} ,
102
120
Dropdown : ( props : DropdownProps ) => (
103
121
< DropDown { ...props } onDropdownOpen = { onDropdownOpen } />
104
122
) ,
123
+ DayButton : ( props ) => {
124
+ const { day, ...buttonProps } = props ;
125
+ const message =
126
+ tooltipMessages [ dateLib . format ( day . date , 'dd-MM-yyyy' ) ] ;
127
+ return (
128
+ < Tooltip
129
+ side = "top"
130
+ disabled = { loadingData || ! showTooltip || ! message }
131
+ message = { message }
132
+ >
133
+ < button { ...buttonProps } />
134
+ </ Tooltip >
135
+ ) ;
136
+ } ,
137
+ MonthGrid : ( props ) =>
138
+ loadingData ? (
139
+ < Skeleton
140
+ count = { 6 }
141
+ height = { '12px' }
142
+ width = { '252px' }
143
+ style = { { marginBottom : 'var(--space-5)' } }
144
+ highlightColor = "var(--background-base)"
145
+ baseColor = "var(--background-base-hover)"
146
+ />
147
+ ) : (
148
+ < table { ...props } />
149
+ ) ,
105
150
} }
106
151
classNames = { {
107
152
caption_label : styles . caption_label ,
0 commit comments