@@ -6,7 +6,7 @@ import DatePickerPopup from "./DatePickerPopup"
6
6
import DatePickerProvider , { DatePickerContext } from "./DatePickerProvider"
7
7
8
8
export interface IDatePickerProps {
9
- value ?: Date ,
9
+ value ?: Date
10
10
children ?: ReactElement | ReactNode
11
11
options ?: IOptions
12
12
onChange ?: ( date : Date ) => void
@@ -19,12 +19,14 @@ export interface IDatePickerProps {
19
19
const DatePicker = ( { value, children, options, onChange, classNames, show, setShow, selectedDateState } : IDatePickerProps ) => (
20
20
< div className = { twMerge ( "w-full" , classNames ) } >
21
21
< DatePickerProvider options = { options } onChange = { onChange } show = { show } setShow = { setShow } selectedDateState = { selectedDateState } >
22
- < DatePickerMain value = { value } options = { options } > { children } </ DatePickerMain >
22
+ < DatePickerMain value = { value } options = { options } >
23
+ { children }
24
+ </ DatePickerMain >
23
25
</ DatePickerProvider >
24
26
</ div >
25
27
)
26
28
27
- const DatePickerMain = ( { value, options : customOptions , children } : { value ?: Date , options ?: IOptions ; children ?: ReactElement } ) => {
29
+ const DatePickerMain = ( { value, options : customOptions , children } : { value ?: Date ; options ?: IOptions ; children ?: ReactElement } ) => {
28
30
const options = { ...defaultOptions , ...customOptions }
29
31
const { setShow, show } = useContext ( DatePickerContext )
30
32
const InputRef = useRef < HTMLInputElement > ( null )
@@ -57,6 +59,7 @@ const DatePickerMain = ({ value, options: customOptions, children }: { value?: D
57
59
< Input
58
60
ref = { InputRef }
59
61
idProp = { options ?. inputIdProp }
62
+ valueProp = { value }
60
63
nameProp = { options ?. inputNameProp }
61
64
placeholderProp = { options ?. inputPlaceholderProp }
62
65
dateFormat = { options ?. inputDateFormatProp }
@@ -68,16 +71,16 @@ const DatePickerMain = ({ value, options: customOptions, children }: { value?: D
68
71
)
69
72
}
70
73
71
- const Input = forwardRef < HTMLInputElement , { idProp ?: string , valueProp ?: Date , nameProp ?: string , placeholderProp ?: string , dateFormat ?: Intl . DateTimeFormatOptions } > ( ( props , ref ) => {
74
+ const Input = forwardRef < HTMLInputElement , { idProp ?: string ; valueProp ?: Date ; nameProp ?: string ; placeholderProp ?: string ; dateFormat ?: Intl . DateTimeFormatOptions } > ( ( props , ref ) => {
72
75
const { setShow, selectedDate, showSelectedDate, options, getFormattedDate } = useContext ( DatePickerContext )
73
-
74
- const nameProp = props . nameProp || "date" ;
75
- const idProp = props . idProp || nameProp ;
76
- const placeholderProp = props . placeholderProp || "Select Date" ;
77
- const valueProp = props . valueProp ;
78
76
79
- const format = props . dateFormat || null ;
80
-
77
+ const nameProp = props . nameProp || "date"
78
+ const idProp = props . idProp || nameProp
79
+ const placeholderProp = props . placeholderProp || "Select Date"
80
+ const valueProp = props . valueProp
81
+
82
+ const format = props . dateFormat || null
83
+
81
84
return (
82
85
< input
83
86
ref = { ref }
@@ -89,7 +92,7 @@ const Input = forwardRef<HTMLInputElement, { idProp ?: string, valueProp?: Date,
89
92
options ?. theme ?. input
90
93
) }
91
94
placeholder = { placeholderProp }
92
- value = { value ? getFormattedDate ( valueProp , format ) : selectedDate && showSelectedDate ? getFormattedDate ( selectedDate , format ) : "" }
95
+ value = { valueProp ? getFormattedDate ( valueProp , format ) : selectedDate && showSelectedDate ? getFormattedDate ( selectedDate , format ) : "" }
93
96
onFocus = { ( ) => setShow ( true ) }
94
97
readOnly
95
98
/>
0 commit comments