mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-11 23:00:20 +08:00
775d1800bb
* chore(deps-dev): bump eslint-config-prettier from 6.15.0 to 7.0.0 Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.15.0 to 7.0.0. - [Release notes](https://github.com/prettier/eslint-config-prettier/releases) - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-config-prettier/compare/v6.15.0...v7.0.0) Signed-off-by: dependabot[bot] <support@github.com> * chore: fix eslint style * chore: prettier code style Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import * as React from 'react';
|
|
import { List } from 'rc-field-form';
|
|
import { ValidatorRule, StoreValue } from 'rc-field-form/lib/interface';
|
|
import devWarning from '../_util/devWarning';
|
|
import { ConfigContext } from '../config-provider';
|
|
import { FormItemPrefixContext } from './context';
|
|
|
|
export interface FormListFieldData {
|
|
name: number;
|
|
key: number;
|
|
fieldKey: number;
|
|
}
|
|
|
|
export interface FormListOperation {
|
|
add: (defaultValue?: StoreValue, insertIndex?: number) => void;
|
|
remove: (index: number | number[]) => void;
|
|
move: (from: number, to: number) => void;
|
|
}
|
|
|
|
export interface FormListProps {
|
|
prefixCls?: string;
|
|
name: string | number | (string | number)[];
|
|
rules?: ValidatorRule[];
|
|
initialValue?: any[];
|
|
children: (
|
|
fields: FormListFieldData[],
|
|
operation: FormListOperation,
|
|
meta: { errors: React.ReactNode[] },
|
|
) => React.ReactNode;
|
|
}
|
|
|
|
const FormList: React.FC<FormListProps> = ({
|
|
prefixCls: customizePrefixCls,
|
|
children,
|
|
...props
|
|
}) => {
|
|
devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
const prefixCls = getPrefixCls('form', customizePrefixCls);
|
|
|
|
return (
|
|
<List {...props}>
|
|
{(fields, operation, meta) => (
|
|
<FormItemPrefixContext.Provider value={{ prefixCls, status: 'error' }}>
|
|
{children(
|
|
fields.map(field => ({ ...field, fieldKey: field.key })),
|
|
operation,
|
|
{
|
|
errors: meta.errors,
|
|
},
|
|
)}
|
|
</FormItemPrefixContext.Provider>
|
|
)}
|
|
</List>
|
|
);
|
|
};
|
|
|
|
export default FormList;
|