2018-09-03 16:17:36 +02:00
|
|
|
// @flow
|
|
|
|
|
import * as React from "react";
|
2019-02-01 08:47:38 +01:00
|
|
|
import ReactDOM from "react-dom";
|
2018-09-03 16:17:36 +02:00
|
|
|
import "./ConfirmAlert.css";
|
|
|
|
|
|
|
|
|
|
type Button = {
|
|
|
|
|
label: string,
|
|
|
|
|
onClick: () => void | null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
title: string,
|
|
|
|
|
message: string,
|
|
|
|
|
buttons: Button[]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ConfirmAlert extends React.Component<Props> {
|
|
|
|
|
handleClickButton = (button: Button) => {
|
|
|
|
|
if (button.onClick) {
|
|
|
|
|
button.onClick();
|
|
|
|
|
}
|
|
|
|
|
this.close();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
close = () => {
|
2019-02-01 08:47:38 +01:00
|
|
|
ReactDOM.unmountComponentAtNode(document.getElementById("modalRoot"));
|
2018-09-03 16:17:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { title, message, buttons } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
2019-01-31 10:50:15 +01:00
|
|
|
<div className="modal is-active">
|
2019-01-31 11:01:37 +01:00
|
|
|
<div className="modal-background" />
|
2019-01-31 10:50:15 +01:00
|
|
|
<div className="modal-card">
|
|
|
|
|
|
|
|
|
|
<header className="modal-card-head">
|
|
|
|
|
<p className="modal-card-title">
|
|
|
|
|
{title}
|
|
|
|
|
</p>
|
2019-01-31 11:07:54 +01:00
|
|
|
<button
|
|
|
|
|
className="delete"
|
|
|
|
|
aria-label="close"
|
|
|
|
|
onClick={() => this.close()}
|
|
|
|
|
/>
|
2019-01-31 10:50:15 +01:00
|
|
|
</header>
|
|
|
|
|
<section className="modal-card-body">
|
2018-09-03 16:17:36 +02:00
|
|
|
{message}
|
|
|
|
|
<div className="react-confirm-alert-button-group">
|
|
|
|
|
{buttons.map((button, i) => (
|
|
|
|
|
<button
|
|
|
|
|
key={i}
|
|
|
|
|
onClick={() => this.handleClickButton(button)}
|
2019-01-22 16:44:26 +01:00
|
|
|
href="javascript:void(0);"
|
2018-09-03 16:17:36 +02:00
|
|
|
>
|
|
|
|
|
{button.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2019-01-31 10:50:15 +01:00
|
|
|
</section>
|
|
|
|
|
|
2018-09-03 16:17:36 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function confirmAlert(properties: Props) {
|
2019-02-01 08:47:38 +01:00
|
|
|
const root = document.getElementById("modalRoot");
|
|
|
|
|
if(root){
|
|
|
|
|
ReactDOM.render(<ConfirmAlert {...properties}/>, root);
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ConfirmAlert;
|