@@ -16,17 +16,20 @@ import InputRange from './input/Range';
16
16
17
17
interface IProps {
18
18
// initValue?: Date | null;
19
+ initStartValue ?: Date | null ;
20
+ initEndValue ?: Date | null ;
19
21
useClearButton ?: boolean ;
20
22
showsMultipleCalendar ?: boolean ;
21
23
valueFormat ?: string ;
22
24
labelFormat ?: string ;
23
25
closesAfterChange ?: boolean ;
24
26
weekdayLabels ?: string [ ] ;
25
- onChange ?: ( activeDate : Date | null ) => void ;
27
+ onChange ?: ( startDate : Date | null , endDate : Date | null ) => void ;
26
28
}
27
29
28
30
function Rangepicker ( {
29
- // initValue = null,
31
+ initStartValue = null ,
32
+ initEndValue = null ,
30
33
useClearButton = false ,
31
34
showsMultipleCalendar = false ,
32
35
valueFormat = 'YYYY-MM-DD' ,
@@ -37,8 +40,8 @@ function Rangepicker({
37
40
} : IProps ) {
38
41
// 인수가 없을 땐 LOCAL 기준 현재 시간을 반환한다.
39
42
const NEW_DATE = new Date ( ) ;
40
- const [ startValue , setStartValue ] = useState < Date | null > ( null ) ;
41
- const [ endValue , setEndValue ] = useState < Date | null > ( null ) ;
43
+ const [ startValue , setStartValue ] = useState < Date | null > ( initStartValue ) ;
44
+ const [ endValue , setEndValue ] = useState < Date | null > ( initEndValue ) ;
42
45
const [ hoverValue , setHoverValue ] = useState < Date | null > ( null ) ;
43
46
const [ viewDate , setViewDate ] = useState < string > (
44
47
formatDate ( startValue || NEW_DATE , 'YYYY-MM-DD' )
@@ -64,6 +67,12 @@ function Rangepicker({
64
67
// eslint-disable-next-line react-hooks/exhaustive-deps
65
68
} , [ endValue , onChange , setViewDate ] ) ;
66
69
70
+ useEffect ( ( ) => {
71
+ if ( onChange ) {
72
+ onChange ( startValue , endValue ) ;
73
+ }
74
+ } , [ startValue , endValue , onChange ] ) ;
75
+
67
76
return (
68
77
< div className = { `${ NAME_SPACE } __wrapper` } >
69
78
< InputRange
0 commit comments