asb_cloud_front/src/components/selectors/Poprompt.tsx

51 lines
1.7 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { memo, ReactNode, useCallback, useState } from 'react'
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)
const onFormFinish = useCallback((values: any) => {
setVisible(false)
onDone?.(values)
}, [onDone])
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}
open={visible}
onOpenChange={(visible) => setVisible(visible)}
>
<Button {...buttonProps}>{text}</Button>
</Popover>
)
})
export default Poprompt