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

46 lines
1.5 KiB
React
Raw Normal View History

2023-01-18 14:37:34 +01:00
import React, {useContext} from "react";
import {Dialog as MuiDialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from "@mui/material";
import {Button} from "@material-ui/core";
import {LocaleContext} from "../locale";
2023-01-15 00:32:17 +01:00
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-18 14:37:34 +01:00
const {translate: L} = useContext(LocaleContext);
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-18 14:37:34 +01:00
return <MuiDialog
2023-01-15 00:32:17 +01:00
open={show}
onClose={onClose}
2023-01-18 14:37:34 +01:00
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description">
<DialogTitle>{ props.title }</DialogTitle>
<DialogContent>
<DialogContentText>
{ props.message }
</DialogContentText>
</DialogContent>
<DialogActions>
{buttons}
</DialogActions>
</MuiDialog>
2023-01-14 09:51:46 +01:00
}