// @flow //modified from https://github.com/GA-MO/react-confirm-alert import * as React from "react"; import { render, unmountComponentAtNode } from "react-dom"; import "./ConfirmAlert.css"; type Button = { label: string, onClick: () => void | null }; type Props = { title: string, message: string, buttons: Button[] }; class ConfirmAlert extends React.Component { handleClickButton = (button: Button) => { if (button.onClick) { button.onClick(); } this.close(); }; close = () => { removeElementReconfirm(); }; render() { const { title, message, buttons } = this.props; return (
{
{title &&

{title}

} {message}
{buttons.map((button, i) => ( ))}
}
); } } function createElementReconfirm(properties: Props) { const divTarget = document.createElement("div"); divTarget.id = "react-confirm-alert"; if (document.body) { document.body.appendChild(divTarget); render(, divTarget); } } function removeElementReconfirm() { const target = document.getElementById("react-confirm-alert"); if (target) { unmountComponentAtNode(target); if (target.parentNode) { target.parentNode.removeChild(target); } } } export function confirmAlert(properties: Props) { createElementReconfirm(properties); } export default ConfirmAlert;