9
9
* OF ANY KIND, either express or implied. See the License for the specific language
10
10
* governing permissions and limitations under the License.
11
11
*/
12
- import { Button } from " @react-spectrum/button" ;
12
+ import { Button } from ' @react-spectrum/button' ;
13
13
import {
14
14
CalendarState ,
15
15
RangeCalendarState ,
16
- useCalendarState ,
17
- } from " @react-stately/calendar" ;
16
+ useCalendarState
17
+ } from ' @react-stately/calendar' ;
18
18
import {
19
19
createCalendar ,
20
20
DateDuration ,
21
- startOfWeek ,
22
- } from " @internationalized/date" ;
23
- import React , { ReactElement , useMemo , useRef } from " react" ;
24
- import { useCalendar , useCalendarCell , useCalendarGrid } from " ../src" ;
25
- import { useDateFormatter , useLocale } from " @react-aria-nutrient/i18n" ;
21
+ startOfWeek
22
+ } from ' @internationalized/date' ;
23
+ import React , { ReactElement , useMemo , useRef } from ' react' ;
24
+ import { useCalendar , useCalendarCell , useCalendarGrid } from ' ../src' ;
25
+ import { useDateFormatter , useLocale } from ' @react-aria-nutrient/i18n' ;
26
26
27
27
export function Example ( props ) {
28
- let { locale } = useLocale ( ) ;
29
- const { visibleDuration } = props ;
28
+ let { locale} = useLocale ( ) ;
29
+ const { visibleDuration} = props ;
30
30
31
31
let state = useCalendarState ( {
32
32
createCalendar,
33
33
...props ,
34
- locale,
34
+ locale
35
35
} ) ;
36
36
37
- let { calendarProps, prevButtonProps, nextButtonProps } = useCalendar (
37
+ let { calendarProps, prevButtonProps, nextButtonProps} = useCalendar (
38
38
props ,
39
39
state
40
40
) ;
@@ -52,8 +52,7 @@ export function Example(props) {
52
52
key = { i }
53
53
state = { state }
54
54
visibleDuration = { visibleDuration }
55
- offset = { { months : i } }
56
- />
55
+ offset = { { months : i } } />
57
56
) ;
58
57
}
59
58
@@ -62,23 +61,22 @@ export function Example(props) {
62
61
63
62
return (
64
63
< div { ...calendarProps } >
65
- < div style = { { textAlign : " center" } } data-testid = { " range" } >
66
- { calendarProps [ " aria-label" ] }
64
+ < div style = { { textAlign : ' center' } } data-testid = { ' range' } >
65
+ { calendarProps [ ' aria-label' ] }
67
66
</ div >
68
67
< div
69
68
style = { {
70
- display : " grid" ,
69
+ display : ' grid' ,
71
70
gridTemplateColumns : `repeat(${ grids . length } , 1fr)` ,
72
- gap : "1em" ,
73
- } }
74
- >
71
+ gap : '1em'
72
+ } } >
75
73
{ grids }
76
74
</ div >
77
75
< div >
78
- < Button variant = { " secondary" } { ...prevButtonProps } >
76
+ < Button variant = { ' secondary' } { ...prevButtonProps } >
79
77
prev
80
78
</ Button >
81
- < Button variant = { " secondary" } { ...nextButtonProps } >
79
+ < Button variant = { ' secondary' } { ...nextButtonProps } >
82
80
next
83
81
</ Button >
84
82
</ div >
@@ -89,14 +87,14 @@ export function Example(props) {
89
87
function CalendarGrid ( {
90
88
state,
91
89
visibleDuration,
92
- offset = { } ,
90
+ offset = { }
93
91
} : {
94
- state : CalendarState | RangeCalendarState ;
95
- visibleDuration : DateDuration ;
96
- offset ?: DateDuration ;
92
+ state : CalendarState | RangeCalendarState ,
93
+ visibleDuration : DateDuration ,
94
+ offset ?: DateDuration
97
95
} ) {
98
- let { locale } = useLocale ( ) ;
99
- let { gridProps, weeksInMonth } = useCalendarGrid ( { } , state ) ;
96
+ let { locale} = useLocale ( ) ;
97
+ let { gridProps, weeksInMonth} = useCalendarGrid ( { } , state ) ;
100
98
101
99
let weeks = visibleDuration . weeks ?? 1 ;
102
100
let startDate = state . visibleRange . start . add ( offset ) ;
@@ -112,8 +110,7 @@ function CalendarGrid({
112
110
< Cell
113
111
key = { dayIndex }
114
112
state = { state }
115
- date = { startDate . add ( { weeks : weekIndex , days : dayIndex } ) }
116
- />
113
+ date = { startDate . add ( { weeks : weekIndex , days : dayIndex } ) } />
117
114
) ) }
118
115
</ div >
119
116
) ) }
@@ -123,69 +120,66 @@ function CalendarGrid({
123
120
124
121
function Cell ( props ) {
125
122
let ref = useRef < HTMLSpanElement | null > ( null ) ;
126
- let { cellProps, buttonProps } = useCalendarCell ( props , props . state , ref ) ;
123
+ let { cellProps, buttonProps} = useCalendarCell ( props , props . state , ref ) ;
127
124
128
125
let dateFormatter = useDateFormatter ( {
129
- day : " numeric" ,
126
+ day : ' numeric' ,
130
127
timeZone : props . state . timeZone ,
131
- calendar : props . date . calendar . identifier ,
128
+ calendar : props . date . calendar . identifier
132
129
} ) ;
133
130
134
131
return (
135
- < div { ...cellProps } style = { { display : " inline-block" } } >
132
+ < div { ...cellProps } style = { { display : ' inline-block' } } >
136
133
< span
137
134
ref = { ref }
138
135
{ ...buttonProps }
139
136
style = { {
140
- display : " block" ,
137
+ display : ' block' ,
141
138
width : 42 ,
142
139
height : 42 ,
143
- background : props . state . isSelected ( props . date ) ? "blue" : "" ,
144
- } }
145
- >
140
+ background : props . state . isSelected ( props . date ) ? 'blue' : ''
141
+ } } >
146
142
{ dateFormatter . format ( props . date . toDate ( props . state . timeZone ) ) }
147
143
</ span >
148
144
</ div >
149
145
) ;
150
146
}
151
147
152
148
export function ExampleCustomFirstDay ( props ) {
153
- let { locale } = useLocale ( ) ;
154
- const { firstDayOfWeek } = props ;
149
+ let { locale} = useLocale ( ) ;
150
+ const { firstDayOfWeek} = props ;
155
151
156
152
let state = useCalendarState ( {
157
153
createCalendar,
158
154
...props ,
159
- locale,
155
+ locale
160
156
} ) ;
161
157
162
- let { calendarProps, prevButtonProps, nextButtonProps } = useCalendar (
158
+ let { calendarProps, prevButtonProps, nextButtonProps} = useCalendar (
163
159
props ,
164
160
state
165
161
) ;
166
162
167
163
return (
168
164
< div { ...calendarProps } >
169
- < div style = { { textAlign : " center" } } data-testid = { " range" } >
170
- { calendarProps [ " aria-label" ] }
165
+ < div style = { { textAlign : ' center' } } data-testid = { ' range' } >
166
+ { calendarProps [ ' aria-label' ] }
171
167
</ div >
172
168
< div
173
169
style = { {
174
- display : "grid" ,
175
- gridTemplateColumns : "repeat(1, 1fr)" ,
176
- gap : "1em" ,
177
- } }
178
- >
170
+ display : 'grid' ,
171
+ gridTemplateColumns : 'repeat(1, 1fr)' ,
172
+ gap : '1em'
173
+ } } >
179
174
< ExampleFirstDayCalendarGrid
180
175
state = { state }
181
- firstDayOfWeek = { firstDayOfWeek }
182
- />
176
+ firstDayOfWeek = { firstDayOfWeek } />
183
177
</ div >
184
178
< div >
185
- < Button variant = { " secondary" } { ...prevButtonProps } >
179
+ < Button variant = { ' secondary' } { ...prevButtonProps } >
186
180
prev
187
181
</ Button >
188
- < Button variant = { " secondary" } { ...nextButtonProps } >
182
+ < Button variant = { ' secondary' } { ...nextButtonProps } >
189
183
next
190
184
</ Button >
191
185
</ div >
@@ -195,12 +189,12 @@ export function ExampleCustomFirstDay(props) {
195
189
196
190
function ExampleFirstDayCalendarGrid ( {
197
191
state,
198
- firstDayOfWeek,
192
+ firstDayOfWeek
199
193
} : {
200
- state : CalendarState | RangeCalendarState ;
201
- firstDayOfWeek ?: " sun" | " mon" | " tue" | " wed" | " thu" | " fri" | " sat" ;
194
+ state : CalendarState | RangeCalendarState ,
195
+ firstDayOfWeek ?: ' sun' | ' mon' | ' tue' | ' wed' | ' thu' | ' fri' | ' sat'
202
196
} ) {
203
- let { gridProps, weeksInMonth } = useCalendarGrid ( { firstDayOfWeek } , state ) ;
197
+ let { gridProps, weeksInMonth} = useCalendarGrid ( { firstDayOfWeek} , state ) ;
204
198
let startDate = state . visibleRange . start ;
205
199
return (
206
200
< div { ...gridProps } >
0 commit comments