@@ -16,17 +16,20 @@ import InputRange from './input/Range';
1616
1717interface IProps {
1818 // initValue?: Date | null;
19+ initStartValue ?: Date | null ;
20+ initEndValue ?: Date | null ;
1921 useClearButton ?: boolean ;
2022 showsMultipleCalendar ?: boolean ;
2123 valueFormat ?: string ;
2224 labelFormat ?: string ;
2325 closesAfterChange ?: boolean ;
2426 weekdayLabels ?: string [ ] ;
25- onChange ?: ( activeDate : Date | null ) => void ;
27+ onChange ?: ( startDate : Date | null , endDate : Date | null ) => void ;
2628}
2729
2830function Rangepicker ( {
29- // initValue = null,
31+ initStartValue = null ,
32+ initEndValue = null ,
3033 useClearButton = false ,
3134 showsMultipleCalendar = false ,
3235 valueFormat = 'YYYY-MM-DD' ,
@@ -37,8 +40,8 @@ function Rangepicker({
3740} : IProps ) {
3841 // 인수가 없을 땐 LOCAL 기준 현재 시간을 반환한다.
3942 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 ) ;
4245 const [ hoverValue , setHoverValue ] = useState < Date | null > ( null ) ;
4346 const [ viewDate , setViewDate ] = useState < string > (
4447 formatDate ( startValue || NEW_DATE , 'YYYY-MM-DD' )
@@ -64,6 +67,12 @@ function Rangepicker({
6467 // eslint-disable-next-line react-hooks/exhaustive-deps
6568 } , [ endValue , onChange , setViewDate ] ) ;
6669
70+ useEffect ( ( ) => {
71+ if ( onChange ) {
72+ onChange ( startValue , endValue ) ;
73+ }
74+ } , [ startValue , endValue , onChange ] ) ;
75+
6776 return (
6877 < div className = { `${ NAME_SPACE } __wrapper` } >
6978 < InputRange
0 commit comments