File size: 927 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import type { ComponentType } from 'react';
import { createElement } from 'react';
import { useForm } from 'uniforms';
import AutoField from './AutoField';
export type AutoFieldsProps = {
autoField?: ComponentType<{ name: string }>;
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};
export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
return createElement(
element,
props,
(fields ?? schema.getSubfields())
.filter((field) => !omitFields.includes(field))
.map((field) =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError }
)
)
)
);
}
|