Files
persionalBrand/apps/admin/src/components/TemplateListField.tsx
T

42 lines
1.4 KiB
TypeScript

import { Button, Form, Input, Space } from "antd";
import type { TemplateAdminField } from "@personal-brand/api-client";
export function TemplateListField({
field,
name,
}: {
field: TemplateAdminField;
name: string | (string | number)[];
}) {
return (
<Form.Item label={field.label} help={field.help}>
<Form.List name={name}>
{(rows, { add, remove }) => (
<Space direction="vertical" style={{ width: "100%" }}>
{rows.map((row, index) => (
<Space key={row.key} align="start" wrap>
{field.itemFields?.map((itemField) => (
<Form.Item
key={itemField.key}
name={[row.name, itemField.key]}
label={`${index + 1}. ${itemField.label}`}
rules={
itemField.required === false
? []
: [{ required: true, message: `请填写${itemField.label}` }]
}
>
{itemField.input === "textarea" ? <Input.TextArea rows={2} /> : <Input />}
</Form.Item>
))}
<Button onClick={() => remove(row.name)}>删除</Button>
</Space>
))}
<Button onClick={() => add()}>新增{field.label}</Button>
</Space>
)}
</Form.List>
</Form.Item>
);
}