web-base/react/shared/elements/dialog.jsx

45 lines
1.4 KiB
React
Raw Normal View History

2023-01-14 09:51:46 +01:00
import React from "react";
import clsx from "clsx";
2023-01-15 00:32:17 +01:00
import {Box, Modal} from "@mui/material";
import {Button, Typography} from "@material-ui/core";
import "./dialog.css";
2023-01-14 09:51:46 +01:00
export default function Dialog(props) {
const show = props.show;
const onClose = props.onClose || function() { };
const onOption = props.onOption || function() { };
const options = props.options || ["Close"];
2023-01-15 00:32:17 +01:00
const type = props.type || "default";
2023-01-14 09:51:46 +01:00
let buttons = [];
for (let name of options) {
let type = "default";
if (name === "Yes") type = "warning";
else if(name === "No") type = "danger";
buttons.push(
2023-01-15 00:32:17 +01:00
<Button variant={"outlined"} size={"small"} type="button" key={"button-" + name}
2023-01-14 09:51:46 +01:00
data-dismiss={"modal"} onClick={() => { onClose(); onOption(name); }}>
{name}
2023-01-15 00:32:17 +01:00
</Button>
2023-01-14 09:51:46 +01:00
)
}
2023-01-15 00:32:17 +01:00
return <Modal
open={show}
onClose={onClose}
aria-labelledby="modal-title"
aria-describedby="modal-description"
>
<Box className={clsx("modal-dialog", props.className)}>
<Typography id="modal-title" variant="h6" component="h2">
{props.title}
</Typography>
<Typography id="modal-description" sx={{ mt: 2 }}>
{props.message}
</Typography>
{ buttons }
</Box>
</Modal>
2023-01-14 09:51:46 +01:00
}