import type { FC } from 'react'; import { forwardRef, useCallback } from 'react'; import { addDays } from 'date-fns/addDays'; import { format } from 'date-fns/format'; import DatePicker from 'react-datepicker'; import './DateRangePicker.vendor-styles.prebuilt'; 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 (
} />
); };