import { Button, Modal, ModalDialog } from "@mui/joy"; import { createRoot } from "react-dom/client"; import Icon from "./Icon"; type AlertStyle = "primary" | "warning" | "danger"; interface Props { title: string; content: string; style?: AlertStyle; closeBtnText?: string; confirmBtnText?: string; onClose?: () => void; onConfirm?: () => void; } const defaultProps: Props = { title: "", content: "", style: "primary", closeBtnText: "Close", confirmBtnText: "Confirm", onClose: () => null, onConfirm: () => null, }; const Alert: React.FC = (props: Props) => { const { title, content, closeBtnText, confirmBtnText, onClose, onConfirm, style } = { ...defaultProps, ...props, }; const handleCloseBtnClick = () => { if (onClose) { onClose(); } }; const handleConfirmBtnClick = async () => { if (onConfirm) { onConfirm(); } }; return (
{title}

{content}

); }; export const showCommonDialog = (props: Props) => { const tempDiv = document.createElement("div"); const dialog = createRoot(tempDiv); document.body.append(tempDiv); const destory = () => { dialog.unmount(); tempDiv.remove(); }; const onClose = () => { if (props.onClose) { props.onClose(); } destory(); }; const onConfirm = () => { if (props.onConfirm) { props.onConfirm(); } destory(); }; dialog.render(); };