antd-mobile
Version:
<img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*hjjDS5Yy-ooAAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />
38 lines (35 loc) • 1.1 kB
JavaScript
import React from 'react';
import { List as RCList } from 'rc-field-form';
import List from '../list';
export const FormArray = props => {
return React.createElement(RCList, {
name: props.name,
initialValue: props.initialValue
}, (rcFields, operation) => {
const fields = rcFields.map(field => ({
index: field.name,
key: field.key
}));
const children = props.children(fields, operation).map((child, index) => {
var _a;
return React.createElement(List, {
key: fields[index].key,
mode: 'card',
header: (_a = props.renderHeader) === null || _a === void 0 ? void 0 : _a.call(props, fields[index], operation)
}, child);
});
if (props.renderAdd) {
children.push(React.createElement(List, {
key: 'add',
mode: 'card'
}, React.createElement(List.Item, {
className: 'adm-form-list-operation',
onClick: () => {
operation.add();
},
arrow: false
}, props.renderAdd())));
}
return React.createElement(React.Fragment, null, children);
});
};