@@ -14,43 +14,48 @@ import { ColorKeys, DatepickerType, Period, PeriodDay } from "../types";
1414import Time from "./Time" ;
1515import { Arrow , VerticalDash } from "./utils" ;
1616
17- const Datepicker : React . FC < DatepickerType > = ( {
18- primaryColor = "blue" ,
19- value = null ,
20- onChange,
21- useRange = true ,
22- showFooter = false ,
23- showShortcuts = false ,
24- configs = undefined ,
25- asSingle = false ,
26- asTimePicker = false ,
27- placeholder = null ,
28- separator = "~" ,
29- startFrom = null ,
30- i18n = LANGUAGE ,
31- disabled = false ,
32- inputClassName = null ,
33- containerClassName = null ,
34- toggleClassName = null ,
35- toggleIcon = undefined ,
36- displayFormat = DATE_FORMAT ,
37- readOnly = false ,
38- minDate = null ,
39- maxDate = null ,
40- dateLooking = "forward" ,
41- disabledDates = null ,
42- inputId,
43- inputName,
44- startWeekOn = "sun" ,
45- classNames = undefined ,
46- popoverDirection = undefined
47- } ) => {
48- // Ref
17+ const Datepicker = ( props : DatepickerType ) => {
18+ // Props
19+ const {
20+ primaryColor = "blue" ,
21+ value = null ,
22+ onChange,
23+ useRange = true ,
24+ showFooter = false ,
25+ showShortcuts = false ,
26+ configs = undefined ,
27+ asSingle = false ,
28+ placeholder = null ,
29+ separator = "~" ,
30+ startFrom = null ,
31+ asTimePicker = false ,
32+ i18n = LANGUAGE ,
33+ disabled = false ,
34+ inputClassName = null ,
35+ containerClassName = null ,
36+ toggleClassName = null ,
37+ popupClassName = null ,
38+ toggleIcon = undefined ,
39+ displayFormat = DATE_FORMAT ,
40+ readOnly = false ,
41+ minDate = null ,
42+ maxDate = null ,
43+ dateLooking = "forward" ,
44+ disabledDates = null ,
45+ inputId,
46+ inputName,
47+ startWeekOn = "sun" ,
48+ classNames = undefined ,
49+ popoverDirection = undefined ,
50+ required = false
51+ } = props ;
52+
53+ // Refs
4954 const containerRef = useRef < HTMLDivElement | null > ( null ) ;
5055 const calendarContainerRef = useRef < HTMLDivElement | null > ( null ) ;
5156 const arrowRef = useRef < HTMLDivElement | null > ( null ) ;
5257
53- // State
58+ // States
5459 const [ firstDate , setFirstDate ] = useState < dayjs . Dayjs > (
5560 startFrom && dayjs ( startFrom ) . isValid ( ) ? dayjs ( startFrom ) : dayjs ( )
5661 ) ;
@@ -258,6 +263,7 @@ const Datepicker: React.FC<DatepickerType> = ({
258263 }
259264 return DEFAULT_COLOR ;
260265 } , [ primaryColor ] ) ;
266+
261267 const contextValues = useMemo ( ( ) => {
262268 return {
263269 asSingle,
@@ -303,7 +309,8 @@ const Datepicker: React.FC<DatepickerType> = ({
303309 classNames,
304310 onChange,
305311 input : inputRef ,
306- popoverDirection
312+ popoverDirection,
313+ required
307314 } ;
308315 } , [
309316 asSingle ,
@@ -343,6 +350,7 @@ const Datepicker: React.FC<DatepickerType> = ({
343350 classNames ,
344351 inputRef ,
345352 popoverDirection ,
353+ required ,
346354 firstGotoDate
347355 ] ) ;
348356
@@ -355,15 +363,22 @@ const Datepicker: React.FC<DatepickerType> = ({
355363 : defaultContainerClassName ;
356364 } , [ containerClassName ] ) ;
357365
366+ const popupClassNameOverload = useMemo ( ( ) => {
367+ const defaultPopupClassName =
368+ "transition-all ease-out duration-300 absolute z-10 mt-[1px] text-sm lg:text-xs 2xl:text-sm translate-y-4 opacity-0 hidden" ;
369+ return typeof popupClassName === "function"
370+ ? popupClassName ( defaultPopupClassName )
371+ : typeof popupClassName === "string" && popupClassName !== ""
372+ ? popupClassName
373+ : defaultPopupClassName ;
374+ } , [ popupClassName ] ) ;
375+
358376 return (
359377 < DatepickerContext . Provider value = { contextValues } >
360378 < div className = { containerClassNameOverload } ref = { containerRef } >
361379 < Input setContextRef = { setInputRef } />
362380
363- < div
364- className = "absolute z-10 mt-[1px] hidden translate-y-4 text-sm opacity-0 transition-all duration-300 ease-out lg:text-xs 2xl:text-sm"
365- ref = { calendarContainerRef }
366- >
381+ < div className = { popupClassNameOverload } ref = { calendarContainerRef } >
367382 < Arrow ref = { arrowRef } />
368383
369384 < 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" >
0 commit comments