@@ -9,8 +9,9 @@ import { COLORS, DATE_FORMAT, DEFAULT_COLOR, LANGUAGE } from "../constants";
9
9
import DatepickerContext from "../contexts/DatepickerContext" ;
10
10
import { formatDate , nextMonth , previousMonth } from "../helpers" ;
11
11
import useOnClickOutside from "../hooks" ;
12
- import { Period , DatepickerType , ColorKeys } from "../types" ;
12
+ import { ColorKeys , DatepickerType , Period , PeriodDay } from "../types" ;
13
13
14
+ import Time from "./Time" ;
14
15
import { Arrow , VerticalDash } from "./utils" ;
15
16
16
17
const Datepicker = ( props : DatepickerType ) => {
@@ -27,6 +28,7 @@ const Datepicker = (props: DatepickerType) => {
27
28
placeholder = null ,
28
29
separator = "~" ,
29
30
startFrom = null ,
31
+ asTimePicker = false ,
30
32
i18n = LANGUAGE ,
31
33
disabled = false ,
32
34
inputClassName = null ,
@@ -66,6 +68,10 @@ const Datepicker = (props: DatepickerType) => {
66
68
const [ inputText , setInputText ] = useState < string > ( "" ) ;
67
69
const [ inputRef , setInputRef ] = useState ( React . createRef < HTMLInputElement > ( ) ) ;
68
70
71
+ const [ hour , setHour ] = useState < string > ( "8" ) ;
72
+ const [ minute , setMinute ] = useState < string > ( "00" ) ;
73
+ const [ periodDay , setPeriodDay ] = useState < PeriodDay > ( "AM" ) ;
74
+
69
75
// Custom Hooks use
70
76
useOnClickOutside ( containerRef , ( ) => {
71
77
const container = containerRef . current ;
@@ -98,6 +104,14 @@ const Datepicker = (props: DatepickerType) => {
98
104
}
99
105
} , [ ] ) ;
100
106
107
+ /* Start Time */
108
+ const changeHour = useCallback ( ( hour : string ) => setHour ( hour ) , [ ] ) ;
109
+
110
+ const changeMinute = useCallback ( ( minute : string ) => setMinute ( minute ) , [ ] ) ;
111
+
112
+ const changePeriodDay = useCallback ( ( periodDay : PeriodDay ) => setPeriodDay ( periodDay ) , [ ] ) ;
113
+ /* End Time */
114
+
101
115
/* Start First */
102
116
const firstGotoDate = useCallback (
103
117
( date : dayjs . Dayjs ) => {
@@ -253,6 +267,7 @@ const Datepicker = (props: DatepickerType) => {
253
267
const contextValues = useMemo ( ( ) => {
254
268
return {
255
269
asSingle,
270
+ asTimePicker,
256
271
primaryColor : safePrimaryColor ,
257
272
configs,
258
273
calendarContainer : calendarContainerRef ,
@@ -266,6 +281,12 @@ const Datepicker = (props: DatepickerType) => {
266
281
changeInputText : ( newText : string ) => setInputText ( newText ) ,
267
282
updateFirstDate : ( newDate : dayjs . Dayjs ) => firstGotoDate ( newDate ) ,
268
283
changeDatepickerValue : onChange ,
284
+ hour,
285
+ minute,
286
+ periodDay,
287
+ changeHour,
288
+ changeMinute,
289
+ changePeriodDay,
269
290
showFooter,
270
291
placeholder,
271
292
separator,
@@ -293,13 +314,20 @@ const Datepicker = (props: DatepickerType) => {
293
314
} ;
294
315
} , [
295
316
asSingle ,
317
+ asTimePicker ,
296
318
safePrimaryColor ,
297
319
configs ,
298
320
hideDatepicker ,
299
321
period ,
300
322
dayHover ,
301
323
inputText ,
302
324
onChange ,
325
+ hour ,
326
+ minute ,
327
+ periodDay ,
328
+ changeHour ,
329
+ changeMinute ,
330
+ changePeriodDay ,
303
331
showFooter ,
304
332
placeholder ,
305
333
separator ,
@@ -353,31 +381,33 @@ const Datepicker = (props: DatepickerType) => {
353
381
< div className = { popupClassNameOverload } ref = { calendarContainerRef } >
354
382
< Arrow ref = { arrowRef } />
355
383
356
- < div className = "mt-2.5 shadow-sm border border-gray-300 px-1 py-0.5 bg-white dark:bg -slate-800 dark:text-white dark:border-slate-600 rounded-lg " >
357
- < div className = "flex flex-col lg:flex-row py-2 " >
384
+ < div className = "mt-2.5 rounded-lg border border-gray-300 bg-white px-1 py-0.5 shadow-sm dark:border -slate-600 dark:bg-slate-800 dark:text-white " >
385
+ < div className = "flex flex-col py-2 lg:flex-row" >
358
386
{ showShortcuts && < Shortcuts /> }
359
387
360
388
< div
361
- className = { `flex items-stretch flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-1.5 ${
389
+ className = { `flex flex-col items-stretch space-y-4 md:flex-row md:space-x-1.5 md:space-y-0 ${
362
390
showShortcuts ? "md:pl-2" : "md:pl-1"
363
391
} pr-2 lg:pr-1`}
364
392
>
365
- < Calendar
366
- date = { firstDate }
367
- onClickPrevious = { previousMonthFirst }
368
- onClickNext = { nextMonthFirst }
369
- changeMonth = { changeFirstMonth }
370
- changeYear = { changeFirstYear }
371
- minDate = { minDate }
372
- maxDate = { maxDate }
373
- />
393
+ < div >
394
+ < Calendar
395
+ date = { firstDate }
396
+ onClickPrevious = { previousMonthFirst }
397
+ onClickNext = { nextMonthFirst }
398
+ changeMonth = { changeFirstMonth }
399
+ changeYear = { changeFirstYear }
400
+ minDate = { minDate }
401
+ maxDate = { maxDate }
402
+ />
403
+ { asSingle && asTimePicker && < Time /> }
404
+ </ div >
374
405
375
406
{ useRange && (
376
407
< >
377
408
< div className = "flex items-center" >
378
409
< VerticalDash />
379
410
</ div >
380
-
381
411
< Calendar
382
412
date = { secondDate }
383
413
onClickPrevious = { previousMonthSecond }
@@ -391,7 +421,6 @@ const Datepicker = (props: DatepickerType) => {
391
421
) }
392
422
</ div >
393
423
</ div >
394
-
395
424
{ showFooter && < Footer /> }
396
425
</ div >
397
426
</ div >
0 commit comments