11'use client' ;
22
33import * as React from 'react' ;
4- import { useMemo } from 'react' ;
54import { NAME_SPACE } from '../constants/core' ;
65import {
76 setCenturyPage ,
@@ -19,6 +18,7 @@ interface IProps {
1918 setViewType : ( value : TviewType ) => void ;
2019 viewDate : string ;
2120 labelFormat : string ;
21+ isMultipleCalendar : boolean ;
2222 setViewDateByType : (
2323 value : string | number ,
2424 type : 'year' | 'month' | 'date'
@@ -30,8 +30,17 @@ function Controller({
3030 viewType,
3131 labelFormat,
3232 setViewType,
33+ isMultipleCalendar,
3334 setViewDateByType,
3435} : IProps ) {
36+ const setMonthLabel = ( date : string , addMonth = 0 ) => {
37+ const monthPage = setMonthPage ( date ) ;
38+ const year = Math . ceil ( ( monthPage + addMonth ) / 12 ) ;
39+ const month = addLeadingZero ( ( monthPage + addMonth ) % 12 || 12 ) ;
40+
41+ return formatLabel ( `${ year } -${ month } ` , labelFormat ) ;
42+ } ;
43+
3544 const setLabel = ( date : string , type : TviewType ) : string => {
3645 if ( type === 'century' ) {
3746 const centuryPage = setCenturyPage ( date ) ;
@@ -53,20 +62,11 @@ function Controller({
5362 return `${ yearPage } ` ;
5463 }
5564 if ( type === 'month' ) {
56- const monthPage = setMonthPage ( date ) ;
57- const year = Math . ceil ( monthPage / 12 ) ;
58- const month = addLeadingZero ( monthPage % 12 || 12 ) ;
59-
60- return formatLabel ( `${ year } -${ month } ` , labelFormat ) ;
65+ return setMonthLabel ( date ) ;
6166 }
6267 return '' ;
6368 } ;
6469
65- const label = useMemo (
66- ( ) => setLabel ( viewDate , viewType ) ,
67- [ viewDate , viewType ]
68- ) ;
69-
7070 const handleLabelClick = ( ) => {
7171 if ( viewType === 'decade' ) {
7272 setViewType ( 'century' ) ;
@@ -111,14 +111,14 @@ function Controller({
111111
112112 return (
113113 < div className = { `${ NAME_SPACE } __controller` } >
114- { viewType !== 'century' && (
114+ { /* { viewType !== 'century' && (
115115 <button
116116 className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-extra-prev` }
117117 onClick={() => handleControl('extraPrev')}
118118 >
119119 Extra Previous
120120 </button>
121- ) }
121+ )} */ }
122122 < button
123123 className = { `${ NAME_SPACE } __controller-arrow ${ NAME_SPACE } __controller-prev` }
124124 onClick = { ( ) => handleControl ( 'prev' ) }
@@ -131,22 +131,31 @@ function Controller({
131131 onClick = { handleLabelClick }
132132 disabled = { viewType === 'century' }
133133 >
134- { label }
134+ { setLabel ( viewDate , viewType ) }
135135 </ button >
136+ { isMultipleCalendar && viewType === 'month' && (
137+ < button
138+ type = "button"
139+ className = { `${ NAME_SPACE } __label` }
140+ onClick = { handleLabelClick }
141+ >
142+ { setMonthLabel ( viewDate , 1 ) }
143+ </ button >
144+ ) }
136145 < button
137146 className = { `${ NAME_SPACE } __controller-arrow ${ NAME_SPACE } __controller-next` }
138147 onClick = { ( ) => handleControl ( 'next' ) }
139148 >
140149 Next
141150 </ button >
142- { viewType !== 'century' && (
151+ { /* { viewType !== 'century' && (
143152 <button
144153 className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-extra-next` }
145154 onClick={() => handleControl('extraNext')}
146155 >
147156 Extra Next
148157 </button>
149- ) }
158+ )} */ }
150159 </ div >
151160 ) ;
152161}
0 commit comments