mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 05:29:37 +08:00
2e284aa017
* update warning * rm warning * replace with dev warning * fix test * fix site * Update webpack.config.js Co-authored-by: 偏右 <afc163@gmail.com> * Update webpack.config.js * fix sytax * adjust * move into function Co-authored-by: 偏右 <afc163@gmail.com>
39 lines
931 B
TypeScript
39 lines
931 B
TypeScript
import * as React from 'react';
|
|
import { List } from 'rc-field-form';
|
|
import { StoreValue } from 'rc-field-form/lib/interface';
|
|
import devWarning from '../_util/devWarning';
|
|
|
|
interface FieldData {
|
|
name: number;
|
|
key: number;
|
|
fieldKey: number;
|
|
}
|
|
|
|
interface Operation {
|
|
add: (defaultValue?: StoreValue) => void;
|
|
remove: (index: number) => void;
|
|
move: (from: number, to: number) => void;
|
|
}
|
|
|
|
interface FormListProps {
|
|
name: string | number | (string | number)[];
|
|
children: (fields: FieldData[], operation: Operation) => React.ReactNode;
|
|
}
|
|
|
|
const FormList: React.FC<FormListProps> = ({ children, ...props }) => {
|
|
devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');
|
|
|
|
return (
|
|
<List {...props}>
|
|
{(fields, operation) => {
|
|
return children(
|
|
fields.map(field => ({ ...field, fieldKey: field.key })),
|
|
operation,
|
|
);
|
|
}}
|
|
</List>
|
|
);
|
|
};
|
|
|
|
export default FormList;
|