tianji/src/client/components/ModalButton.tsx
2023-10-21 00:19:12 +08:00

27 lines
698 B
TypeScript

import { Button, ButtonProps, Modal, ModalProps } from 'antd';
import React, { useState } from 'react';
interface ModalButtonProps {
buttonProps: Omit<ButtonProps, 'onClick'>;
modalProps: Omit<ModalProps, 'open' | 'onCancel'>;
}
export const ModalButton: React.FC<ModalButtonProps> = React.memo((props) => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button
{...props.buttonProps}
onClick={() => setIsOpen((state) => !state)}
/>
<Modal
onOk={() => setIsOpen(false)}
{...props.modalProps}
open={isOpen}
onCancel={() => setIsOpen(false)}
/>
</>
);
});
ModalButton.displayName = 'ModalButton';