@@ -9,8 +9,9 @@ import { COLORS, DATE_FORMAT, DEFAULT_COLOR, LANGUAGE } from "../constants";
99import DatepickerContext from "../contexts/DatepickerContext" ;
1010import { formatDate , nextMonth , previousMonth } from "../helpers" ;
1111import useOnClickOutside from "../hooks" ;
12- import { Period , DatepickerType , ColorKeys } from "../types" ;
12+ import { ColorKeys , DatepickerType , Period , PeriodDay } from "../types" ;
1313
14+ import Time from "./Time" ;
1415import { Arrow , VerticalDash } from "./utils" ;
1516
1617const Datepicker = ( props : DatepickerType ) => {
@@ -27,6 +28,7 @@ const Datepicker = (props: DatepickerType) => {
2728 placeholder = null ,
2829 separator = "~" ,
2930 startFrom = null ,
31+ asTimePicker = false ,
3032 i18n = LANGUAGE ,
3133 disabled = false ,
3234 inputClassName = null ,
@@ -66,6 +68,10 @@ const Datepicker = (props: DatepickerType) => {
6668 const [ inputText , setInputText ] = useState < string > ( "" ) ;
6769 const [ inputRef , setInputRef ] = useState ( React . createRef < HTMLInputElement > ( ) ) ;
6870
71+ const [ hour , setHour ] = useState < string > ( "8" ) ;
72+ const [ minute , setMinute ] = useState < string > ( "00" ) ;
73+ const [ periodDay , setPeriodDay ] = useState < PeriodDay > ( "AM" ) ;
74+
6975 // Custom Hooks use
7076 useOnClickOutside ( containerRef , ( ) => {
7177 const container = containerRef . current ;
@@ -98,6 +104,14 @@ const Datepicker = (props: DatepickerType) => {
98104 }
99105 } , [ ] ) ;
100106
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+
101115 /* Start First */
102116 const firstGotoDate = useCallback (
103117 ( date : dayjs . Dayjs ) => {
@@ -253,6 +267,7 @@ const Datepicker = (props: DatepickerType) => {
253267 const contextValues = useMemo ( ( ) => {
254268 return {
255269 asSingle,
270+ asTimePicker,
256271 primaryColor : safePrimaryColor ,
257272 configs,
258273 calendarContainer : calendarContainerRef ,
@@ -266,6 +281,12 @@ const Datepicker = (props: DatepickerType) => {
266281 changeInputText : ( newText : string ) => setInputText ( newText ) ,
267282 updateFirstDate : ( newDate : dayjs . Dayjs ) => firstGotoDate ( newDate ) ,
268283 changeDatepickerValue : onChange ,
284+ hour,
285+ minute,
286+ periodDay,
287+ changeHour,
288+ changeMinute,
289+ changePeriodDay,
269290 showFooter,
270291 placeholder,
271292 separator,
@@ -293,13 +314,20 @@ const Datepicker = (props: DatepickerType) => {
293314 } ;
294315 } , [
295316 asSingle ,
317+ asTimePicker ,
296318 safePrimaryColor ,
297319 configs ,
298320 hideDatepicker ,
299321 period ,
300322 dayHover ,
301323 inputText ,
302324 onChange ,
325+ hour ,
326+ minute ,
327+ periodDay ,
328+ changeHour ,
329+ changeMinute ,
330+ changePeriodDay ,
303331 showFooter ,
304332 placeholder ,
305333 separator ,
@@ -353,31 +381,33 @@ const Datepicker = (props: DatepickerType) => {
353381 < div className = { popupClassNameOverload } ref = { calendarContainerRef } >
354382 < Arrow ref = { arrowRef } />
355383
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" >
358386 { showShortcuts && < Shortcuts /> }
359387
360388 < 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 ${
362390 showShortcuts ? "md:pl-2" : "md:pl-1"
363391 } pr-2 lg:pr-1`}
364392 >
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 >
374405
375406 { useRange && (
376407 < >
377408 < div className = "flex items-center" >
378409 < VerticalDash />
379410 </ div >
380-
381411 < Calendar
382412 date = { secondDate }
383413 onClickPrevious = { previousMonthSecond }
@@ -391,7 +421,6 @@ const Datepicker = (props: DatepickerType) => {
391421 ) }
392422 </ div >
393423 </ div >
394-
395424 { showFooter && < Footer /> }
396425 </ div >
397426 </ div >
0 commit comments