2021-11-29 16:49:22 +05:00
|
|
|
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,
|
|
|
|
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,
|
2021-12-29 12:23:27 +05:00
|
|
|
message: `Это обязательное поле!`,
|
2021-11-29 16:49:22 +05:00
|
|
|
}]}
|
|
|
|
initialValue={initialValue}
|
|
|
|
>
|
|
|
|
{input ?? <Input/>}
|
|
|
|
</Form.Item>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
)
|