asb_cloud_front/src/components/Table/EditableCell.tsx

44 lines
952 B
TypeScript
Raw Normal View History

import { Form, Input } from 'antd'
import { NamePath, Rule } from 'rc-field-form/lib/interface'
type EditableCellProps = {
editing?: boolean
dataIndex?: NamePath
input?: React.Component
isRequired?: boolean
title: string
formItemClass?: string
formItemRules?: Rule[]
children: React.ReactNode
initialValue: any
}
export const EditableCell = ({
editing,
dataIndex,
input,
isRequired,
title,
formItemClass,
formItemRules,
children,
initialValue,
}: EditableCellProps) => (
<td style={editing ? { padding: 0 } : undefined}>
{!editing ? children : (
<Form.Item
name={dataIndex}
style={{ margin: 0 }}
className={formItemClass}
rules={formItemRules ?? [{
required: isRequired,
message: `Пожалуйста, введите ${title}!`,
}]}
initialValue={initialValue}
>
{input ?? <Input/>}
</Form.Item>
)}
</td>
)