mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
cffa9af09b
close #24487 close #25835
39 lines
995 B
TypeScript
39 lines
995 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';
|
|
|
|
export interface FormListFieldData {
|
|
name: number;
|
|
key: number;
|
|
fieldKey: number;
|
|
}
|
|
|
|
export interface FormListOperation {
|
|
add: (defaultValue?: StoreValue) => void;
|
|
remove: (index: number | number[]) => void;
|
|
move: (from: number, to: number) => void;
|
|
}
|
|
|
|
export interface FormListProps {
|
|
name: string | number | (string | number)[];
|
|
children: (fields: FormListFieldData[], operation: FormListOperation) => 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;
|