UNPKG

1.14 kBJavaScriptView Raw
1import React from 'react';
2import { List as RCList } from 'rc-field-form';
3import List from '../list';
4export const FormArray = props => {
5 return React.createElement(RCList, {
6 name: props.name,
7 initialValue: props.initialValue
8 }, (rcFields, operation) => {
9 const fields = rcFields.map(field => ({
10 index: field.name,
11 key: field.key
12 }));
13 const children = props.children(fields, operation).map((child, index) => {
14 var _a;
15 return React.createElement(List, {
16 key: fields[index].key,
17 mode: 'card',
18 header: (_a = props.renderHeader) === null || _a === void 0 ? void 0 : _a.call(props, fields[index], operation)
19 }, child);
20 });
21 if (props.renderAdd) {
22 children.push(React.createElement(List, {
23 key: 'add',
24 mode: 'card'
25 }, React.createElement(List.Item, {
26 className: 'adm-form-list-operation',
27 onClick: () => {
28 props.onAdd ? props.onAdd(operation) : operation.add();
29 },
30 arrow: false
31 }, props.renderAdd())));
32 }
33 return React.createElement(React.Fragment, null, children);
34 });
35};
\No newline at end of file