UNPKG

2.24 kBTypeScriptView Raw
1import { Component, ComponentType } from "react";
2import { Validator } from "../index";
3
4interface _BaseFieldArrayProps<P = {}, FieldValue = any> {
5 name: string;
6 component: ComponentType<WrappedFieldArrayProps<FieldValue> & P>;
7 validate?: Validator | Validator[] | undefined;
8 warn?: Validator | Validator[] | undefined;
9 withRef?: boolean | undefined;
10 rerenderOnEveryChange?: boolean | undefined;
11}
12
13export type BaseFieldArrayProps<P = {}, FieldValue = any> = (P | { props?: P }) & _BaseFieldArrayProps<P, FieldValue>;
14
15export interface GenericFieldArray<FieldValue = any, P = {}> extends Component<BaseFieldArrayProps<P, FieldValue>> {
16 name: string;
17 valid: boolean;
18 getRenderedComponent(): Component<WrappedFieldArrayProps<FieldValue> & P>;
19}
20
21export class FieldArray<P = {}, FieldValue = any> extends Component<BaseFieldArrayProps<P, FieldValue>>
22 implements GenericFieldArray<FieldValue, P>
23{
24 name: string;
25 valid: boolean;
26 getRenderedComponent(): Component<WrappedFieldArrayProps<FieldValue> & P>;
27}
28
29export interface WrappedFieldArrayProps<FieldValue = any> {
30 fields: FieldArrayFieldsProps<FieldValue>;
31 meta: FieldArrayMetaProps;
32}
33
34export type FieldIterate<FieldValue, R = void> = (
35 name: string,
36 index: number,
37 fields: FieldArrayFieldsProps<FieldValue>,
38) => R;
39
40export interface FieldArrayFieldsProps<FieldValue> {
41 forEach(callback: FieldIterate<FieldValue>): void;
42 get(index: number): FieldValue;
43 getAll(): FieldValue[];
44 removeAll(): void;
45
46 insert(index: number, value: FieldValue): void;
47 name: string;
48 length: number;
49 map<R>(callback: FieldIterate<FieldValue, R>): R[];
50 pop(): FieldValue;
51 push(value: FieldValue): void;
52 remove(index: number): void;
53 shift(): FieldValue;
54 splice(index: number, removeNum: number | null, value: FieldValue): void;
55 swap(indexA: number, indexB: number): void;
56 move(from: number, to: number): void;
57 unshift(value: FieldValue): void;
58}
59
60export interface FieldArrayMetaProps {
61 dirty: boolean;
62 error?: any;
63 form: string;
64 invalid: boolean;
65 pristine: boolean;
66 submitFailed: boolean;
67 submitting: boolean;
68 valid: boolean;
69 warning?: any;
70}