DateRangePicker.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { FC, useRef, forwardRef } from 'react';
  2. import DatePicker from 'react-datepicker';
  3. import 'react-datepicker/dist/react-datepicker.css';
  4. type CustomInputProps = {
  5. buttonRef: React.Ref<HTMLButtonElement>
  6. onClick?: () => void;
  7. }
  8. const CustomInput = forwardRef<HTMLButtonElement, CustomInputProps>((props: CustomInputProps) => {
  9. return (
  10. <button
  11. type="button"
  12. className="btn btn-outline-secondary dropdown-toggle"
  13. ref={props.buttonRef}
  14. onClick={props.onClick}
  15. >
  16. <i className="fa fa-fw fa-calendar" /> Date
  17. </button>
  18. );
  19. });
  20. type DateRangePickerProps = {
  21. startDate: Date | null
  22. endDate: Date | null
  23. onChangeDate: (dateList: Date[] | null[]) => void
  24. }
  25. export const DateRangePicker: FC<DateRangePickerProps> = (props: DateRangePickerProps) => {
  26. const { startDate, endDate } = props;
  27. const buttonRef = useRef(null);
  28. return (
  29. <div className="btn-group mr-2 mb-3">
  30. <DatePicker
  31. selectsRange
  32. startDate={startDate}
  33. endDate={endDate}
  34. onChange={props.onChangeDate}
  35. customInput={<CustomInput buttonRef={buttonRef} />}
  36. />
  37. </div>
  38. );
  39. };