1 | import { Component, ComponentType } from "react";
|
2 | import { Validator } from "../index";
|
3 |
|
4 | interface _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 |
|
13 | export type BaseFieldArrayProps<P = {}, FieldValue = any> = (P | { props?: P }) & _BaseFieldArrayProps<P, FieldValue>;
|
14 |
|
15 | export interface GenericFieldArray<FieldValue = any, P = {}> extends Component<BaseFieldArrayProps<P, FieldValue>> {
|
16 | name: string;
|
17 | valid: boolean;
|
18 | getRenderedComponent(): Component<WrappedFieldArrayProps<FieldValue> & P>;
|
19 | }
|
20 |
|
21 | export 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 |
|
29 | export interface WrappedFieldArrayProps<FieldValue = any> {
|
30 | fields: FieldArrayFieldsProps<FieldValue>;
|
31 | meta: FieldArrayMetaProps;
|
32 | }
|
33 |
|
34 | export type FieldIterate<FieldValue, R = void> = (
|
35 | name: string,
|
36 | index: number,
|
37 | fields: FieldArrayFieldsProps<FieldValue>,
|
38 | ) => R;
|
39 |
|
40 | export 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 |
|
60 | export 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 | }
|