2022-02-25 16:57:08 +05:00
|
|
|
|
import { memo, ReactNode, useCallback, useState } from 'react'
|
2022-02-22 15:29:50 +05:00
|
|
|
|
import { Button, ButtonProps, Form, FormProps, Popover, PopoverProps } from 'antd'
|
|
|
|
|
|
|
|
|
|
export type PopromptProps = PopoverProps & {
|
|
|
|
|
children?: ReactNode
|
|
|
|
|
footer?: ReactNode
|
|
|
|
|
text?: string
|
|
|
|
|
onDone?: (values: any) => void
|
|
|
|
|
formProps?: FormProps
|
|
|
|
|
buttonProps?: ButtonProps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Poprompt = memo<PopromptProps>(({ formProps, buttonProps, footer, children, onDone, text, ...other }) => {
|
|
|
|
|
const [visible, setVisible] = useState<boolean>(false)
|
|
|
|
|
|
2022-02-25 16:57:08 +05:00
|
|
|
|
const onFormFinish = useCallback((values: any) => {
|
2022-02-22 15:29:50 +05:00
|
|
|
|
setVisible(false)
|
|
|
|
|
onDone?.(values)
|
2022-02-25 16:57:08 +05:00
|
|
|
|
}, [onDone])
|
2022-02-22 15:29:50 +05:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Popover
|
|
|
|
|
content={(
|
|
|
|
|
<Form
|
|
|
|
|
onFinish={onFormFinish}
|
|
|
|
|
autoComplete={'off'}
|
|
|
|
|
{...formProps}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
<Form.Item style={{ marginBottom: 0 }}>
|
|
|
|
|
{footer ?? (
|
|
|
|
|
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
|
|
|
<Button htmlType={'reset'} onClick={() => setVisible(false)}>Отмена</Button>
|
|
|
|
|
<Button type={'primary'} htmlType={'submit'} style={{ marginLeft: '8px' }}>ОК</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
trigger={'click'}
|
|
|
|
|
{...other}
|
|
|
|
|
visible={visible}
|
|
|
|
|
onVisibleChange={(visible) => setVisible(visible)}
|
|
|
|
|
>
|
|
|
|
|
<Button {...buttonProps}>{text}</Button>
|
|
|
|
|
</Popover>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default Poprompt
|