@@ -5,7 +5,7 @@ import Calendar from "../components/Calendar";
55import Footer from "../components/Footer" ;
66import Input from "../components/Input" ;
77import Shortcuts from "../components/Shortcuts" ;
8- import { COLORS , DEFAULT_COLOR } from "../constants" ;
8+ import { COLORS , DATE_FORMAT , DEFAULT_COLOR , LANGUAGE } from "../constants" ;
99import DatepickerContext from "../contexts/DatepickerContext" ;
1010import { formatDate , nextMonth , previousMonth } from "../helpers" ;
1111import useOnClickOutside from "../hooks" ;
@@ -66,13 +66,13 @@ const Datepicker: React.FC<Props> = ({
6666 placeholder = null ,
6767 separator = "~" ,
6868 startFrom = null ,
69- i18n = "en" ,
69+ i18n = LANGUAGE ,
7070 disabled = false ,
7171 inputClassName = null ,
7272 containerClassName = null ,
7373 toggleClassName = null ,
7474 toggleIcon = undefined ,
75- displayFormat = "YYYY-MM-DD" ,
75+ displayFormat = DATE_FORMAT ,
7676 readOnly = false ,
7777 minDate = null ,
7878 maxDate = null ,
@@ -91,14 +91,13 @@ const Datepicker: React.FC<Props> = ({
9191 const [ firstDate , setFirstDate ] = useState < dayjs . Dayjs > (
9292 startFrom && dayjs ( startFrom ) . isValid ( ) ? dayjs ( startFrom ) : dayjs ( )
9393 ) ;
94+ const [ secondDate , setSecondDate ] = useState < dayjs . Dayjs > ( nextMonth ( firstDate ) ) ;
9495 const [ period , setPeriod ] = useState < Period > ( {
9596 start : null ,
9697 end : null
9798 } ) ;
98- const [ secondDate , setSecondDate ] = useState < dayjs . Dayjs > ( nextMonth ( firstDate ) ) ;
9999 const [ dayHover , setDayHover ] = useState < string | null > ( null ) ;
100100 const [ inputText , setInputText ] = useState < string > ( "" ) ;
101-
102101 const [ inputRef , setInputRef ] = useState ( React . createRef < HTMLInputElement > ( ) ) ;
103102
104103 // Custom Hooks use
@@ -133,6 +132,7 @@ const Datepicker: React.FC<Props> = ({
133132 }
134133 } , [ ] ) ;
135134
135+ /* Start First */
136136 const firstGotoDate = useCallback (
137137 ( date : dayjs . Dayjs ) => {
138138 const newDate = dayjs ( formatDate ( date ) ) ;
@@ -153,6 +153,22 @@ const Datepicker: React.FC<Props> = ({
153153 firstGotoDate ( nextMonth ( firstDate ) ) ;
154154 } , [ firstDate , firstGotoDate ] ) ;
155155
156+ const changeFirstMonth = useCallback (
157+ ( month : number ) => {
158+ firstGotoDate ( dayjs ( `${ firstDate . year ( ) } -${ month < 10 ? "0" : "" } ${ month } -01` ) ) ;
159+ } ,
160+ [ firstDate , firstGotoDate ]
161+ ) ;
162+
163+ const changeFirstYear = useCallback (
164+ ( year : number ) => {
165+ firstGotoDate ( dayjs ( `${ year } -${ firstDate . month ( ) + 1 } -01` ) ) ;
166+ } ,
167+ [ firstDate , firstGotoDate ]
168+ ) ;
169+ /* End First */
170+
171+ /* Start Second */
156172 const secondGotoDate = useCallback (
157173 ( date : dayjs . Dayjs ) => {
158174 const newDate = dayjs ( formatDate ( date , displayFormat ) ) ;
@@ -173,33 +189,20 @@ const Datepicker: React.FC<Props> = ({
173189 setSecondDate ( nextMonth ( secondDate ) ) ;
174190 } , [ secondDate ] ) ;
175191
176- const changeFirstMonth = useCallback (
177- ( month : number ) => {
178- firstGotoDate ( dayjs ( `${ firstDate . year ( ) } -${ month < 10 ? "0" : "" } ${ month } -01` ) ) ;
179- } ,
180- [ firstDate , firstGotoDate ]
181- ) ;
182-
183192 const changeSecondMonth = useCallback (
184193 ( month : number ) => {
185194 secondGotoDate ( dayjs ( `${ secondDate . year ( ) } -${ month < 10 ? "0" : "" } ${ month } -01` ) ) ;
186195 } ,
187196 [ secondDate , secondGotoDate ]
188197 ) ;
189198
190- const changeFirstYear = useCallback (
191- ( year : number ) => {
192- firstGotoDate ( dayjs ( `${ year } -${ firstDate . month ( ) + 1 } -01` ) ) ;
193- } ,
194- [ firstDate , firstGotoDate ]
195- ) ;
196-
197199 const changeSecondYear = useCallback (
198200 ( year : number ) => {
199201 secondGotoDate ( dayjs ( `${ year } -${ secondDate . month ( ) + 1 } -01` ) ) ;
200202 } ,
201203 [ secondDate , secondGotoDate ]
202204 ) ;
205+ /* End Second */
203206
204207 // UseEffects & UseLayoutEffect
205208 useEffect ( ( ) => {
@@ -251,7 +254,7 @@ const Datepicker: React.FC<Props> = ({
251254
252255 useEffect ( ( ) => {
253256 if ( startFrom && dayjs ( startFrom ) . isValid ( ) ) {
254- if ( value != null && value . startDate != null ) {
257+ if ( value ? .startDate != null ) {
255258 setFirstDate ( dayjs ( value . startDate ) ) ;
256259 setSecondDate ( nextMonth ( dayjs ( value . startDate ) ) ) ;
257260 } else {
@@ -261,7 +264,7 @@ const Datepicker: React.FC<Props> = ({
261264 }
262265 } , [ startFrom , value ] ) ;
263266
264- // Variable
267+ // Variables
265268 const colorPrimary = useMemo ( ( ) => {
266269 if ( COLORS . includes ( primaryColor ) ) {
267270 return primaryColor ;
0 commit comments