@arteneo/forge
Version:
32 lines (31 loc) • 2.5 kB
TypeScript
import React from "react";
import { FormikValues, FormikTouched, FormikErrors } from "formik";
import FieldInterface from "../../../components/Form/definitions/FieldInterface";
import FieldsInterface from "../../../components/Form/definitions/FieldsInterface";
type IndexedCollectionRowsKey = string | number;
interface IndexedCollectionRowsInterface {
[key: IndexedCollectionRowsKey]: FormikValues;
}
interface IndexedCollectionSpecificProps {
fields: FieldsInterface;
disableAddRow?: ((value: FormikValues, values: FormikValues, path: string, touched: FormikTouched<FormikValues>, errors: FormikErrors<FormikValues>, name: string) => boolean) | boolean;
disableDeleteRow?: ((value: FormikValues, values: FormikValues, path: string, touched: FormikTouched<FormikValues>, errors: FormikErrors<FormikValues>, name: string) => boolean) | boolean;
onAddRow?: (setFieldValue: (field: string, value: any, shouldValidate?: boolean) => void, values: FormikValues, path: string, defaultAddRow: () => void, name: string, touched: FormikTouched<FormikValues>, errors: FormikErrors<FormikValues>) => void;
onDeleteRow?: (key: IndexedCollectionRowsKey, setFieldValue: (field: string, value: any, shouldValidate?: boolean) => void, values: FormikValues, path: string, defaultDeleteRow: () => void, name: string, touched: FormikTouched<FormikValues>, errors: FormikErrors<FormikValues>) => void;
initialValues?: ((values: FormikValues, path: string, name: string, touched: FormikTouched<FormikValues>, errors: FormikErrors<FormikValues>) => FormikValues) | FormikValues;
}
type IndexedCollectionProps = IndexedCollectionSpecificProps & FieldInterface;
/**
* This is a similar component to <Collection />, but it assumes that collection values are indexed by ID.
*
* Collection values are indexed by ID when transformed by filterInitialValues and transformInitialValues functions in default props.
*/
declare const IndexedCollection: {
({ fields, disableAddRow: disableAddRowProp, disableDeleteRow: disableDeleteRowProp, onAddRow, onDeleteRow, initialValues, validate: fieldValidate, ...field }: IndexedCollectionProps): React.JSX.Element | null;
defaultProps: {
filterInitialValues: (values: any) => any;
transformInitialValue: (values: any, fields?: FieldsInterface) => FormikValues;
};
};
export default IndexedCollection;
export { IndexedCollectionRowsInterface, IndexedCollectionRowsKey, IndexedCollectionProps, IndexedCollectionSpecificProps, };