UNPKG

@uiw/react-form

Version:
59 lines (58 loc) 2.2 kB
import React from 'react'; import { IProps } from '@uiw/utils'; import { FormItemProps } from './FormItem'; import './style/form.less'; export interface FormProps<T> extends IProps, Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onChange' | 'onSubmit' | 'children'> { prefixCls?: string; fields?: Record<string, FormFieldsProps<T>>; onSubmit?: (state: FormSubmitProps, event: React.FormEvent) => any; afterSubmit?: (result: FormAfterSubmitProps) => any; onChange?: (state: FormState) => void; onSubmitError?: (evn: any) => any; resetOnSubmit?: boolean; children?: (handle: FormChildrenProps) => JSX.Element; } export interface FormState { submitting: boolean; initial: Record<string, any>; current: FormState['initial']; errors: Record<string, any>; } export interface FormFieldsProps<T> extends Omit<FormItemProps<T>, 'children'> { name?: string; children?: ((handle: FormChildrenProps) => JSX.Element) | JSX.Element; help?: React.ReactNode; labelFor?: string; inline?: boolean; checked?: boolean; initialValue?: string | number | T; required?: boolean; validator?: (currentValue: any) => any; } export interface FormSubmitProps { initial: FormState['initial']; current: FormState['current']; } export interface FormAfterSubmitProps { state: FormState; response: any; reset: () => void; } export interface FormChildrenProps { onChange?: (env: React.BaseSyntheticEvent<HTMLInputElement>, list?: string[]) => void; onSubmit?: (env: React.FormEvent) => void; fields?: Record<string, React.ReactElement>; resetForm?: () => void; canSubmit?: () => boolean; state?: FormState; } export type FormElementProps = { id?: string; name?: string; value?: string | boolean; checked?: boolean; onChange?: (env: React.BaseSyntheticEvent<HTMLInputElement>, list?: string[]) => void; }; export type FormRefType = Record<'onSubmit' | 'resetForm' | 'getFieldValues' | 'setFields' | 'getError' | 'setFieldValue', Function>; declare const _default: React.ForwardRefExoticComponent<FormProps<{}> & React.RefAttributes<FormRefType | undefined>>; export default _default;