11import dayjs from "dayjs" ;
22import React , { useCallback , useContext , useEffect , useMemo , useState } from "react" ;
33
4+ import { CALENDAR_SIZE } from "../../constants" ;
45import DatepickerContext from "../../contexts/DatepickerContext" ;
56import {
67 formatDate ,
@@ -64,9 +65,9 @@ const Calendar: React.FC<Props> = ({
6465 const previous = useCallback ( ( ) => {
6566 return getLastDaysInMonth (
6667 previousMonth ( date ) ,
67- getNumberOfDay ( getFirstDayInMonth ( date ) . ddd , i18n , startWeekOn )
68+ getNumberOfDay ( getFirstDayInMonth ( date ) . ddd , startWeekOn )
6869 ) ;
69- } , [ date , i18n , startWeekOn ] ) ;
70+ } , [ date , startWeekOn ] ) ;
7071
7172 const current = useCallback ( ( ) => {
7273 return getDaysInMonth ( formatDate ( date ) ) ;
@@ -75,20 +76,16 @@ const Calendar: React.FC<Props> = ({
7576 const next = useCallback ( ( ) => {
7677 return getFirstDaysInMonth (
7778 previousMonth ( date ) ,
78- 42 - ( previous ( ) . length + current ( ) . length )
79+ CALENDAR_SIZE - ( previous ( ) . length + current ( ) . length )
7980 ) ;
8081 } , [ current , date , previous ] ) ;
8182
8283 const hideMonths = useCallback ( ( ) => {
83- if ( showMonths ) {
84- setShowMonths ( false ) ;
85- }
84+ showMonths && setShowMonths ( false ) ;
8685 } , [ showMonths ] ) ;
8786
8887 const hideYears = useCallback ( ( ) => {
89- if ( showYears ) {
90- setShowYears ( false ) ;
91- }
88+ showYears && setShowYears ( false ) ;
9289 } , [ showYears ] ) ;
9390
9491 const clickMonth = useCallback (
@@ -278,14 +275,6 @@ const Calendar: React.FC<Props> = ({
278275 </ div >
279276 </ div >
280277
281- { ! showMonths && ! showYears && (
282- < div className = "flex-none" >
283- < RoundedButton roundedFull = { true } onClick = { onClickNext } >
284- < ChevronRightIcon className = "h-5 w-5" />
285- </ RoundedButton >
286- </ div >
287- ) }
288-
289278 { showYears && (
290279 < div className = "flex-none" >
291280 < RoundedButton
@@ -298,6 +287,14 @@ const Calendar: React.FC<Props> = ({
298287 </ RoundedButton >
299288 </ div >
300289 ) }
290+
291+ { ! showMonths && ! showYears && (
292+ < div className = "flex-none" >
293+ < RoundedButton roundedFull = { true } onClick = { onClickNext } >
294+ < ChevronRightIcon className = "h-5 w-5" />
295+ </ RoundedButton >
296+ </ div >
297+ ) }
301298 </ div >
302299
303300 < div className = "px-0.5 sm:px-2 mt-0.5 min-h-[285px]" >
0 commit comments