|
@@ -28,23 +28,23 @@ const CustomInput = forwardRef<HTMLButtonElement, CustomInputProps>((props: Cust
|
|
|
type DateRangePickerProps = {
|
|
type DateRangePickerProps = {
|
|
|
startDate: Date | null
|
|
startDate: Date | null
|
|
|
endDate: Date | null
|
|
endDate: Date | null
|
|
|
- onChangeDatePicker: (dateList: Date[] | null[]) => void
|
|
|
|
|
|
|
+ onChange: (dateList: Date[] | null[]) => void
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePickerProps) => {
|
|
export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePickerProps) => {
|
|
|
- const { startDate, endDate } = props;
|
|
|
|
|
|
|
+ const { startDate, endDate, onChange } = props;
|
|
|
|
|
|
|
|
const buttonRef = useRef(null);
|
|
const buttonRef = useRef(null);
|
|
|
|
|
|
|
|
- const datePickerChangedHandler = useCallback((dateList: Date[] | null[]) => {
|
|
|
|
|
- if (props.onChangeDatePicker != null) {
|
|
|
|
|
|
|
+ const changeHandler = useCallback((dateList: Date[] | null[]) => {
|
|
|
|
|
+ if (onChange != null) {
|
|
|
const [start, end] = dateList;
|
|
const [start, end] = dateList;
|
|
|
const isSameTime = (start != null && end != null) && (start.getTime() === end.getTime());
|
|
const isSameTime = (start != null && end != null) && (start.getTime() === end.getTime());
|
|
|
if (isSameTime) {
|
|
if (isSameTime) {
|
|
|
- props.onChangeDatePicker([null, null]);
|
|
|
|
|
|
|
+ onChange([null, null]);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- props.onChangeDatePicker(dateList);
|
|
|
|
|
|
|
+ onChange(dateList);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}, []);
|
|
}, []);
|
|
@@ -55,7 +55,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePicker
|
|
|
selectsRange
|
|
selectsRange
|
|
|
startDate={startDate}
|
|
startDate={startDate}
|
|
|
endDate={endDate}
|
|
endDate={endDate}
|
|
|
- onChange={datePickerChangedHandler}
|
|
|
|
|
|
|
+ onChange={changeHandler}
|
|
|
customInput={<CustomInput buttonRef={buttonRef} />}
|
|
customInput={<CustomInput buttonRef={buttonRef} />}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|