Files
SCM-Manager/scm-ui-components/packages/ui-components/src/modals/ConfirmAlert.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

// @flow
import * as React from "react";
2019-02-01 08:47:38 +01:00
import ReactDOM from "react-dom";
2019-02-01 10:02:19 +01:00
import Modal from "./Modal";
2019-02-01 09:43:14 +01:00
type ButtonType = {
label: string,
onClick: () => void | null
};
type Props = {
title: string,
message: string,
2019-02-01 09:43:14 +01:00
buttons: ButtonType[]
};
class ConfirmAlert extends React.Component<Props> {
2019-02-01 09:43:14 +01:00
handleClickButton = (button: ButtonType) => {
if (button.onClick) {
button.onClick();
}
this.close();
};
close = () => {
2019-02-01 08:47:38 +01:00
ReactDOM.unmountComponentAtNode(document.getElementById("modalRoot"));
};
render() {
const { title, message, buttons } = this.props;
2019-02-01 10:02:19 +01:00
const closeButton = (
<button
className="delete"
aria-label="close"
onClick={() => this.close()}
/>
);
const body= (
<>
{message}
<div className="buttons is-right">
{buttons.map((button, i) => (
<a className="button is-info is-right"
key={i}
onClick={() => this.handleClickButton(button)}
>
{button.label}
</a>
))}
</div>
</>
);
2019-01-31 10:50:15 +01:00
2019-02-01 10:02:19 +01:00
return (
<Modal title={title} closeButton={closeButton} body={body} active={true}/>
);
}
}
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);
}
}
export default ConfirmAlert;