1 | import { INPUT_VALIDATION_RULES } from '../constants';
|
2 | import { Message } from './errors';
|
3 | import { FieldValues } from './fields';
|
4 | import { FieldPath, FieldPathValue } from './path';
|
5 | export type ValidationValue = boolean | number | string | RegExp;
|
6 | export type ValidationRule<TValidationValue extends ValidationValue = ValidationValue> = TValidationValue | ValidationValueMessage<TValidationValue>;
|
7 | export type ValidationValueMessage<TValidationValue extends ValidationValue = ValidationValue> = {
|
8 | value: TValidationValue;
|
9 | message: Message;
|
10 | };
|
11 | export type ValidateResult = Message | Message[] | boolean | undefined;
|
12 | export type Validate<TFieldValue, TFormValues> = (value: TFieldValue, formValues: TFormValues) => ValidateResult | Promise<ValidateResult>;
|
13 | export type RegisterOptions<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{
|
14 | required: Message | ValidationRule<boolean>;
|
15 | min: ValidationRule<number | string>;
|
16 | max: ValidationRule<number | string>;
|
17 | maxLength: ValidationRule<number>;
|
18 | minLength: ValidationRule<number>;
|
19 | validate: Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues> | Record<string, Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues>>;
|
20 | value: FieldPathValue<TFieldValues, TFieldName>;
|
21 | setValueAs: (value: any) => any;
|
22 | shouldUnregister?: boolean;
|
23 | onChange?: (event: any) => void;
|
24 | onBlur?: (event: any) => void;
|
25 | disabled: boolean;
|
26 | deps: FieldPath<TFieldValues> | FieldPath<TFieldValues>[];
|
27 | }> & ({
|
28 | pattern?: ValidationRule<RegExp>;
|
29 | valueAsNumber?: false;
|
30 | valueAsDate?: false;
|
31 | } | {
|
32 | pattern?: undefined;
|
33 | valueAsNumber?: false;
|
34 | valueAsDate?: true;
|
35 | } | {
|
36 | pattern?: undefined;
|
37 | valueAsNumber?: true;
|
38 | valueAsDate?: false;
|
39 | });
|
40 | export type InputValidationRules = typeof INPUT_VALIDATION_RULES;
|
41 | export type MaxType = InputValidationRules['max'] | InputValidationRules['maxLength'];
|
42 | export type MinType = InputValidationRules['min'] | InputValidationRules['minLength'];
|
43 |
|
\ | No newline at end of file |