-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathForm.d.ts
274 lines (259 loc) · 6.61 KB
/
Form.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
*
* Form provides validation functionality and manages form state.
*
* [Live Demo](https://www.primevue.org/forms/)
*
* @module form
*
*/
import type { DefineComponent, DesignToken, EmitFn, PassThrough } from '@primevue/core';
import type { ComponentHooks } from '@primevue/core/basecomponent';
import { VNode } from 'vue';
import type { PassThroughOptions } from '../types';
export declare type FormPassThroughOptionType = FormPassThroughAttributes | ((options: FormPassThroughMethodOptions) => FormPassThroughAttributes | string) | string | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface FormPassThroughMethodOptions {
/**
* Defines instance.
*/
instance: any;
/**
* Defines valid properties.
*/
props: FormProps;
/**
* Defines valid attributes.
*/
attrs: any;
/**
* Defines parent options.
*/
parent: any;
/**
* Defines passthrough(pt) options in global config.
*/
global: object | undefined;
}
/**
* Custom passthrough(pt) options.
* @see {@link FormProps.pt}
*/
export interface FormPassThroughOptions {
/**
* Used to pass attributes to the root's DOM element.
*/
root?: FormPassThroughOptionType;
/**
* Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks}
*/
hooks?: ComponentHooks;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface FormPassThroughAttributes {
[key: string]: any;
}
/**
* Resolver options for Form component.
*/
export interface FormResolverOptions {
/**
* The values of the form fields.
*/
values: Record<string, any>;
/**
* The names of the form fields.
*/
names: string[] | undefined;
}
/**
* Submit events
*/
export interface FormSubmitEvent {
/**
* The original DOM event.
*/
originalEvent: Event;
/**
* The form values.
*/
values: Record<string, any>;
/**
* The form state.
*/
states: Record<string, FormFieldState>;
/**
* Whether the form is valid.
*/
valid: boolean;
/**
* The form errors.
*/
errors: any[];
/**
* Resets the form.
*/
reset: () => void;
}
/**
* The state of a form field.
*/
export interface FormFieldState {
/**
* The value of the form field.
*/
value: any;
/**
* Whether the form field has been touched.
* @defaultValue false
*/
touched: boolean;
/**
* Whether the form field has been modified.
* @defaultValue false
*/
dirty: boolean;
/**
* Whether the form field has not been modified.
* @defaultValue true
*/
pristine: boolean;
/**
* Whether the form field is valid.
* @defaultValue true
*/
valid: boolean;
/**
* Whether the form field is invalid.
* @defaultValue false
*/
invalid: boolean;
/**
* The first error message of the form field.
*/
error: any;
/**
* All error messages of the form field.
* @defaultValue []
*/
errors: any[];
}
/**
* Defines valid properties in Form component.
*/
export interface FormProps {
/**
* A function that resolves validation logic.
* @param {FormResolverOptions} e - Resolver options
*/
resolver?: (e: FormResolverOptions) => Promise<Record<string, any>> | Record<string, any> | undefined;
/**
* The initial values for the form fields.
*/
initialValues?: Record<string, any> | undefined;
/**
* Whether to validate the form fields when the values change.
* @defaultValue true
*/
validateOnValueUpdate?: boolean | string[] | undefined;
/**
* Whether to validate the form fields when they lose focus (on blur).
* @defaultValue false
*/
validateOnBlur?: boolean | string[] | undefined;
/**
* Whether to validate the form fields immediately after the form is mounted.
* @defaultValue false
*/
validateOnMount?: boolean | string[] | undefined;
/**
* Whether to validate the form fields when the form is submitted.
* @defaultValue true
*/
validateOnSubmit?: boolean | string[] | undefined;
/**
* It generates scoped CSS variables using design tokens for the component.
*/
dt?: DesignToken<any>;
/**
* Used to pass attributes to DOM elements inside the component.
* @type {FormPassThroughOptions}
*/
pt?: PassThrough<FormPassThroughOptions>;
/**
* Used to configure passthrough(pt) options of the component.
* @type {PassThroughOptions}
*/
ptOptions?: PassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**
* Defines valid slots in Form component.
*/
export interface FormSlots {
/**
* Default content slot.
* @param {Object} scope - default slot's params.
*/
default: (
scope: {
/**
* Registers a form field for validation and tracking.
* @param field - The name of the form field to register.
* @param options - Configuration options for the field, such as validation rules.
* @returns - Returns an object or value representing the registered field.
*/
register: (field: string, options: any) => any;
/**
* Resets the entire form state, clearing values and validation statuses.
*/
reset: () => void;
/**
* Indicates whether the form is valid, returning `true` if all fields pass validation.
*/
valid: boolean;
/**
* Index signature for dynamically added form fields.
*/
} & Record<string, FormFieldState>
) => VNode[];
}
/**
* Defines valid emits in Form component.
*/
export interface FormEmitsOptions {
/**
* Emitted when the form is submitted.
* @param {FormSubmitEvent} event - Custom submit event.
*/
submit: (event: FormSubmitEvent) => void;
}
export declare type FormEmits = EmitFn<FormEmitsOptions>;
/**
* **PrimeVue - Form**
*
* _Form provides validation functionality and manages form state._
*
* [Live Demo](https://www.primevue.org/forms/)
* --- ---
* 
*
* @group Component
*
*/
declare const Form: DefineComponent<FormProps, FormSlots, FormEmits>;
declare module 'vue' {
export interface GlobalComponents {
Form: DefineComponent<FormProps, FormSlots, FormEmits>;
}
}
export default Form;