import type { FC } from 'react'; import React, { forwardRef, useCallback } from 'react'; import { addDays, format } from 'date-fns'; import DatePicker from 'react-datepicker'; import 'react-datepicker/dist/react-datepicker.css'; type CustomInputProps = { value?: string onChange?: () => void onFocus?: () => void } const CustomInput = forwardRef((props: CustomInputProps, ref) => { const dateFormat = 'MM/dd/yyyy'; const date = new Date(); const placeholder = `${format(date, dateFormat)} - ${format(addDays(date, 1), dateFormat)}`; return (
calendar_month
); }); CustomInput.displayName = 'CustomInput'; type DateRangePickerProps = { startDate: Date | null endDate: Date | null onChange: (dateList: Date[] | null[]) => void } export const DateRangePicker: FC = (props: DateRangePickerProps) => { const { startDate, endDate, onChange } = props; const changeHandler = useCallback((dateList: Date[] | null[]) => { if (onChange != null) { const [start, end] = dateList; const isSameTime = (start != null && end != null) && (start.getTime() === end.getTime()); if (isSameTime) { onChange([null, null]); } else { onChange(dateList); } } }, [onChange]); return (
} />
); };