mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import React, { useEffect } from "react";
|
|
import { makeStyles } from "@material-ui/core/styles";
|
|
import { Paper } from "@material-ui/core";
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
root: {
|
|
zIndex: 10,
|
|
background: "#424242",
|
|
marginTop: "15px",
|
|
width: "90%",
|
|
display: "flex",
|
|
flexFlow: "column nowrap",
|
|
position: "absolute",
|
|
top: "80px",
|
|
},
|
|
displayBlock: {
|
|
/*Sets modal to center*/
|
|
display: "flex",
|
|
flexFlow: "column nowrap",
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
position: "relative",
|
|
},
|
|
displayNone: {
|
|
display: "none",
|
|
},
|
|
}));
|
|
|
|
export const Modal = ({ children, visible, handleClose }) => {
|
|
const classes = useStyles();
|
|
|
|
// when the user presses escape we should close the modal
|
|
const _handleEscape = (e) => {
|
|
const isEscapeKey = e.key == "Escape" || e.key == "Esc";
|
|
if (isEscapeKey) {
|
|
e.preventDefault();
|
|
handleClose();
|
|
}
|
|
};
|
|
useEffect(() => {
|
|
const listener = window.addEventListener("keydown", _handleEscape, true);
|
|
return () => window.removeEventListener("keydown", listener);
|
|
}, []);
|
|
|
|
const showHideClassName = visible
|
|
? classes.displayBlock
|
|
: classes.displayNone;
|
|
|
|
return (
|
|
<div className={showHideClassName}>
|
|
<Paper className={classes.root}>{children}</Paper>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Modal;
|