1 | import * as React from 'react';
|
2 | import type { ColProps } from 'antd/lib/grid/col';
|
3 | import FormItem from './FormItem';
|
4 | import type { FormLabelAlign } from './FormItem';
|
5 | import type { FormWrappedProps } from './interface';
|
6 | type FormCreateOptionMessagesCallback = (...args: any[]) => string;
|
7 | interface FormCreateOptionMessages {
|
8 | [messageId: string]: string | FormCreateOptionMessagesCallback | FormCreateOptionMessages;
|
9 | }
|
10 | export interface FormCreateOption<T> {
|
11 | onFieldsChange?: (props: T, fields: any, allFields: any) => void;
|
12 | onValuesChange?: (props: T, changedValues: any, allValues: any) => void;
|
13 | mapPropsToFields?: (props: T) => void;
|
14 | validateMessages?: FormCreateOptionMessages;
|
15 | withRef?: boolean;
|
16 | name?: string;
|
17 | }
|
18 | declare const FormLayouts: ["horizontal", "inline", "vertical"];
|
19 | export type FormLayout = typeof FormLayouts[number];
|
20 | export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
|
21 | layout?: FormLayout;
|
22 | form?: WrappedFormUtils;
|
23 | onSubmit?: React.FormEventHandler<HTMLFormElement>;
|
24 | style?: React.CSSProperties;
|
25 | className?: string;
|
26 | prefixCls?: string;
|
27 | hideRequiredMark?: boolean;
|
28 | |
29 |
|
30 |
|
31 | wrapperCol?: ColProps;
|
32 | labelCol?: ColProps;
|
33 | |
34 |
|
35 |
|
36 | colon?: boolean;
|
37 | labelAlign?: FormLabelAlign;
|
38 | }
|
39 | export interface ValidationRule {
|
40 |
|
41 | message?: React.ReactNode;
|
42 |
|
43 | type?: string;
|
44 |
|
45 | required?: boolean;
|
46 |
|
47 | whitespace?: boolean;
|
48 |
|
49 | len?: number;
|
50 |
|
51 | min?: number;
|
52 |
|
53 | max?: number;
|
54 |
|
55 | enum?: string | string[];
|
56 |
|
57 | pattern?: RegExp;
|
58 |
|
59 | transform?: (value: any) => any;
|
60 |
|
61 | validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any;
|
62 | }
|
63 | export type ValidateCallback<V> = (errors: any, values: V) => void;
|
64 | export interface GetFieldDecoratorOptions {
|
65 |
|
66 | valuePropName?: string;
|
67 |
|
68 | initialValue?: any;
|
69 |
|
70 | trigger?: string;
|
71 |
|
72 | getValueFromEvent?: (...args: any[]) => any;
|
73 |
|
74 | getValueProps?: (value: any) => any;
|
75 |
|
76 | validateTrigger?: string | string[];
|
77 |
|
78 | rules?: ValidationRule[];
|
79 |
|
80 | exclusive?: boolean;
|
81 |
|
82 | normalize?: (value: any, prevValue: any, allValues: any) => any;
|
83 |
|
84 | validateFirst?: boolean;
|
85 |
|
86 | preserve?: boolean;
|
87 | }
|
88 |
|
89 | export interface DomScrollIntoViewConfig {
|
90 |
|
91 | alignWithLeft?: boolean;
|
92 |
|
93 | alignWithTop?: boolean;
|
94 |
|
95 | offsetTop?: number;
|
96 |
|
97 | offsetLeft?: number;
|
98 |
|
99 | offsetBottom?: number;
|
100 |
|
101 | offsetRight?: number;
|
102 |
|
103 | allowHorizontalScroll?: boolean;
|
104 |
|
105 | onlyScrollIfNeeded?: boolean;
|
106 | }
|
107 | export interface ValidateFieldsOptions {
|
108 |
|
109 | first?: boolean;
|
110 |
|
111 | firstFields?: string[];
|
112 |
|
113 | force?: boolean;
|
114 |
|
115 | scroll?: DomScrollIntoViewConfig;
|
116 | }
|
117 | export interface WrappedFormUtils<V = any> {
|
118 |
|
119 | getFieldsValue(fieldNames?: string[]): Record<string, any>;
|
120 |
|
121 | getFieldValue(fieldName: string): any;
|
122 |
|
123 | setFieldsValue(obj: Object, callback?: Function): void;
|
124 |
|
125 | setFields(obj: Object): void;
|
126 |
|
127 | validateFields(fieldNames: string[], options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
|
128 | validateFields(options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
|
129 | validateFields(fieldNames: string[], callback: ValidateCallback<V>): void;
|
130 | validateFields(fieldNames: string[], options: ValidateFieldsOptions): void;
|
131 | validateFields(fieldNames: string[]): void;
|
132 | validateFields(callback: ValidateCallback<V>): void;
|
133 | validateFields(options: ValidateFieldsOptions): void;
|
134 | validateFields(): void;
|
135 |
|
136 | validateFieldsAndScroll(fieldNames: string[], options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
|
137 | validateFieldsAndScroll(options: ValidateFieldsOptions, callback: ValidateCallback<V>): void;
|
138 | validateFieldsAndScroll(fieldNames: string[], callback: ValidateCallback<V>): void;
|
139 | validateFieldsAndScroll(fieldNames: string[], options: ValidateFieldsOptions): void;
|
140 | validateFieldsAndScroll(fieldNames: string[]): void;
|
141 | validateFieldsAndScroll(callback: ValidateCallback<V>): void;
|
142 | validateFieldsAndScroll(options: ValidateFieldsOptions): void;
|
143 | validateFieldsAndScroll(): void;
|
144 |
|
145 | getFieldError(name: string): string[] | undefined;
|
146 | getFieldsError(names?: string[]): Record<string, string[] | undefined>;
|
147 |
|
148 | isFieldValidating(name: string): boolean;
|
149 | isFieldTouched(name: string): boolean;
|
150 | isFieldsTouched(names?: string[]): boolean;
|
151 |
|
152 | resetFields(names?: string[]): void;
|
153 | getFieldDecorator<T extends Object = {}>(id: keyof T, options?: GetFieldDecoratorOptions): (node: React.ReactNode) => React.ReactNode;
|
154 | }
|
155 | export interface WrappedFormInternalProps<V = any> {
|
156 | form: WrappedFormUtils<V>;
|
157 | }
|
158 | export interface RcBaseFormProps {
|
159 | wrappedComponentRef?: any;
|
160 | }
|
161 | export interface FormComponentProps<V = any> extends WrappedFormInternalProps<V>, RcBaseFormProps {
|
162 | form: WrappedFormUtils<V>;
|
163 | }
|
164 | declare const FormFC: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<any>> & {
|
165 | Item: typeof FormItem;
|
166 | createFormField: any;
|
167 | create: typeof create;
|
168 | };
|
169 | declare function create<TOwnProps extends FormComponentProps>(options?: FormCreateOption<TOwnProps>): FormWrappedProps<TOwnProps>;
|
170 | export default FormFC;
|