import { useCallback } from 'react'; import Input, { IInputProps, IInputClearEvent, IInputCoreProps, ITextAreaProps, } from '../../input'; import { FormField, IFormFieldChildProps } from '../Field'; import { IFormComponentProps, TouchWhen, ValidateOccasion } from '../shared'; import { $MergeParams, warningDefaultValueProp } from '../utils'; import { useEventCallbackRef } from '../../utils/hooks/useEventCallbackRef'; import * as React from 'react'; /** * `Omit`无法得到正确的类型提示,因此每个类型单独Omit一次再联合 */ export type IFormInputFieldProps = IFormComponentProps< string, | Omit | Omit >; const InputField: React.FC<{ childProps: IFormFieldChildProps; props: IFormInputFieldProps; }> = ({ childProps, props }) => { const onChangeRef = useEventCallbackRef(childProps.onChange); const onChange = useCallback( ( e: | IInputClearEvent | React.ChangeEvent ) => { onChangeRef.current?.(e.target.value); }, [onChangeRef] ); return ( ); }; export const FormInputField: React.FunctionComponent = props => { const { validateOccasion = ValidateOccasion.Blur } = props; React.useEffect(() => { // warning for use 'props.defaultValue' in Form Input Field warningDefaultValueProp( !('defaultValue' in (props.props ?? {})), 'defaultValue', 'FormInputField' ); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( ).defaultValue || '' } touchWhen={TouchWhen.Blur} validateOccasion={validateOccasion} > {childProps => } ); };