import React, { CSSProperties } from 'react'; import { InputProps } from '../Input'; import { PickerProps } from '../Picker'; import { RadioProps } from '../Radio'; import { TextareaProps } from '../Textarea'; import { UploadProps } from '../Upload'; import { Language } from '../../language'; import { ButtonProps } from '../Button'; import { CheckboxGroupProps } from '../Checkbox'; export declare type ChildElement = React.ReactNode | React.ReactNode[] | FieldProps | FieldProps[] | (FieldProps | React.ReactNode)[][] | React.ReactElement; export { InputProps, PickerProps, RadioProps, TextareaProps, UploadProps, Language, CheckboxGroupProps, ButtonProps }; export declare type FieldType = 'INPUT' | 'PICKER' | 'RADIO' | 'TEXTAREA' | 'UPLOAD' | 'TEXT' | 'CHECKBOX' | undefined; export declare type Value = any; export declare type ObjectDependence = { name: string; value: RegExp; }; export interface FieldTypeDefine { INPUT: InputProps; PICKER: PickerProps; RADIO: RadioProps; TEXTAREA: TextareaProps; UPLOAD: UploadProps; TEXT: { value?: string; style?: React.CSSProperties; className?: string; onChange?: (value: string) => void; }; CHECKBOX: CheckboxGroupProps; } export declare type Keys = keyof FieldTypeDefine; export declare type KeysType = { type?: T; componentProps?: P; }; export declare type Types = { [K in Keys]: KeysType; }; export declare type ChildrenProps = Types[Keys]; export declare type shouldUpdate = ((prevValues: StoreValues, curValues: StoreValues) => boolean) | boolean; export declare type FieldProps = { shouldUpdate?: shouldUpdate; } & ChildrenProps & RenderProps; export interface Rule { required?: (() => boolean) | boolean; message?: string; validator?: (value: Value) => boolean; } export interface RenderProps { name?: string; label?: string; rules?: Rule[]; isShow?: ((props: Pick) => boolean) | boolean; dependences?: ((props: Pick) => boolean) | (string | ObjectDependence)[] | string | ObjectDependence; disabled?: boolean; initialValue?: Value; render?: (formInstance: FormInstance) => React.ReactNode; children?: React.ReactNode | ((formInstance: FormInstance) => React.ReactNode); layout?: Layout; } export declare type FormFieldChildrenProps = { formInstance: FormInstance; } & ChildrenProps & Pick & Pick; export declare type Locale = 'en' | 'zh-cn'; export declare type TextAlign = 'right' | 'left'; export declare type Layout = 'horizontal' | 'vertical'; export declare type Config = { language: Language; } & Pick; export interface YButtonProps extends ButtonProps { text?: React.ReactNode; } export declare type ValidateErrorMessage = { name?: string; label?: string; message: string; }; export declare type FieldsChange = (props: { name: string; value: any; values: T; setFieldsValue: (fieldsValue: { value: any; name: string; }) => void; }) => void; export interface FormProps { filterInitialValues?: boolean; readonly?: boolean; style?: CSSProperties; className?: string; layout?: Layout; onFinish?: Callbacks['onFinish']; onFinishFailed?: Callbacks['onFinishFailed']; onValuesChange?: Callbacks['onValuesChange']; fields?: React.ReactNode | React.ReactNodeArray | FieldProps | FieldProps[] | (FieldProps | React.ReactNode)[][]; disabled?: boolean; validateFirst?: boolean; initialValues?: { [key: string]: any; }; submitter?: ((props: { onSubmit: () => void; onReset: () => void; }) => React.ReactNode) | null | { resetButton?: boolean | YButtonProps; cancelButton?: boolean | YButtonProps; submitButton?: boolean | YButtonProps; render?: (props: { onSubmit: () => void; onReset: () => void; }) => React.ReactNode; }; textAlign?: TextAlign; locale?: Locale; form?: any; children?: React.ReactNode | React.ReactNodeArray | FieldProps | FieldProps[] | (FieldProps | React.ReactNode)[][]; loading?: boolean; loadingIcon?: JSX.Element; } export declare type FieldRule = { rules?: Rule[]; label?: string | null; name: string; }; export interface FormContextProps { readonly?: boolean; disabled?: boolean; validateFirst?: boolean; layout?: Layout; textAlign?: TextAlign; locale?: Locale; language?: Language; formInstance?: FormInstance; } export interface Meta { touched: boolean; validating: boolean; errors: string[]; name: Name; } export interface FieldEntity { touched: boolean; name: Name; label?: string; rules?: Rule[]; initialValue?: StoreValue; shouldUpdate?: shouldUpdate; onStoreChange: (render: any) => void; } export interface FieldData extends FieldEntity { value: StoreValue; } export declare type StoreValue = any; export declare type StoreValues = Record; export declare type Name = string; export interface InternalHooks { registerField: (entity: FieldEntity) => () => void; setInitialValues: (initialValues: StoreValues, init?: boolean) => void; setCallbacks: (callbacks: Callbacks) => void; getFields: (names?: Name[]) => FieldData[]; setConfigs: (config: Config) => void; resetStatus: () => void; } export interface Callbacks { onValuesChange?: (changedValues: T, values: T) => void; onFinish?: (values: T) => void; onFinishFailed?: (errors: ValidateErrorMessage[]) => void; } export declare type RecursivePartial = T extends object ? { [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial[] : T[P] extends object ? RecursivePartial : T[P]; } : any; export interface FormInstance { getFieldValue: (name: Name) => StoreValue; getFieldsValue(): T; getFieldsValue(names: Name[] | true, filterFunc?: (fieldEntity: FieldEntity) => boolean): any; setFieldsValue: (value: RecursivePartial) => void; setInitialValues: (value: RecursivePartial, init?: boolean) => void; useSubscribe: (subscribable: boolean) => void; getFields: () => FieldData[]; getField: (name: Name) => FieldData; getInternalHooks: (key: string) => InternalHooks | null; getFieldsError: () => ValidateErrorMessage[]; submit: () => void; reset: () => void; }