2019-07-03 20:14:39 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import { List } from 'rc-field-form';
|
2020-03-10 15:46:13 +08:00
|
|
|
import { StoreValue } from 'rc-field-form/lib/interface';
|
2020-05-14 15:57:04 +08:00
|
|
|
import devWarning from '../_util/devWarning';
|
2019-07-03 20:14:39 +08:00
|
|
|
|
|
|
|
interface FieldData {
|
|
|
|
name: number;
|
|
|
|
key: number;
|
|
|
|
fieldKey: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Operation {
|
2020-03-10 15:46:13 +08:00
|
|
|
add: (defaultValue?: StoreValue) => void;
|
2019-07-03 20:14:39 +08:00
|
|
|
remove: (index: number) => void;
|
2019-12-24 20:36:27 +08:00
|
|
|
move: (from: number, to: number) => void;
|
2019-07-03 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface FormListProps {
|
|
|
|
name: string | number | (string | number)[];
|
|
|
|
children: (fields: FieldData[], operation: Operation) => React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FormList: React.FC<FormListProps> = ({ children, ...props }) => {
|
2020-05-14 15:57:04 +08:00
|
|
|
devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');
|
2019-07-03 20:14:39 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<List {...props}>
|
|
|
|
{(fields, operation) => {
|
2020-05-14 15:57:04 +08:00
|
|
|
return children(
|
|
|
|
fields.map(field => ({ ...field, fieldKey: field.key })),
|
|
|
|
operation,
|
|
|
|
);
|
2019-07-03 20:14:39 +08:00
|
|
|
}}
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FormList;
|