import { useCallback, useState } from 'react'; import DateRangeQuickPicker, { DateRangeQuickPickerPresetValue, IDateRangeQuickPickerProps, } from '../../date-range-quick-picker'; import { IFormComponentProps, dateRangeDefaultValueFactory, IFormFieldChildProps, } from '../shared'; import { FormField } from '../Field'; import { $MergeParams } from '../utils'; import { useEventCallbackRef } from '../../utils/hooks/useEventCallbackRef'; import { RangeDate } from '../../date-picker'; export type IFormDateRangeQuickPickerFieldProps = IFormComponentProps< RangeDate, Omit >; const DateRangeQuickPickerField: React.FC<{ childProps: IFormFieldChildProps; props: IFormDateRangeQuickPickerFieldProps; }> = ({ childProps, props }) => { const [chosenDays, setChosenDays] = useState< DateRangeQuickPickerPresetValue | undefined >(undefined); const onChangeRef = useEventCallbackRef(childProps.onChange); const onChange = useCallback( (value: RangeDate, chosenDays: DateRangeQuickPickerPresetValue) => { onChangeRef.current?.(value); setChosenDays(chosenDays); }, [onChangeRef] ); return ( ); }; export const FormDateRangeQuickPickerField: React.FC = props => { return ( ) .defaultValue ?? dateRangeDefaultValueFactory } > {childProps => ( )} ); };