bitburner-src/src/ui/React/Modal.tsx

76 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-05-29 17:54:14 +02:00
import React from "react";
2021-09-17 01:23:03 +02:00
import { Theme } from "@mui/material";
2021-09-18 19:29:01 +02:00
import Box from "@mui/material/Box";
2023-05-29 17:54:14 +02:00
import IconButton from "@mui/material/IconButton";
2022-05-06 18:35:23 +02:00
import Fade from "@mui/material/Fade";
import M from "@mui/material/Modal";
import createStyles from "@mui/styles/createStyles";
import makeStyles from "@mui/styles/makeStyles";
import { SxProps } from "@mui/system";
2023-05-29 17:54:14 +02:00
import CloseIcon from "@mui/icons-material/Close";
2021-09-15 03:05:49 +02:00
const useStyles = makeStyles((theme: Theme) =>
createStyles({
modal: {
display: "flex",
alignItems: "center",
justifyContent: "center",
},
paper: {
2023-05-29 17:54:14 +02:00
position: "relative",
2021-09-19 06:46:39 +02:00
backgroundColor: theme.palette.background.default,
2021-09-15 03:05:49 +02:00
border: "2px solid " + theme.palette.primary.main,
2021-09-19 06:46:39 +02:00
boxShadow: `0px 3px 5px -1px ${theme.palette.primary.dark},0px 5px 8px 0px ${theme.palette.primary.dark},0px 1px 14px 0px ${theme.palette.primary.dark}`,
2021-09-17 01:23:03 +02:00
padding: 2,
2021-09-15 03:47:42 +02:00
maxWidth: "80%",
maxHeight: "80%",
overflow: "auto",
"&::-webkit-scrollbar": {
// webkit
display: "none",
},
scrollbarWidth: "none", // firefox
2021-09-15 03:05:49 +02:00
},
2023-05-29 17:54:14 +02:00
closeButton: {
position: "absolute",
right: 3,
top: 3,
width: 20,
height: 20,
},
2021-09-15 03:05:49 +02:00
}),
);
interface IProps {
open: boolean;
2021-09-15 03:47:42 +02:00
onClose: () => void;
2021-09-30 23:02:07 +02:00
children: React.ReactNode;
2022-05-06 18:35:23 +02:00
sx?: SxProps<Theme>;
2021-09-15 03:05:49 +02:00
}
export const Modal = (props: IProps): React.ReactElement => {
const classes = useStyles();
return (
2021-09-30 23:02:07 +02:00
<M
disableRestoreFocus
disableScrollLock
2021-10-01 19:08:37 +02:00
disableEnforceFocus
disableAutoFocus
2021-09-30 23:02:07 +02:00
open={props.open}
onClose={props.onClose}
closeAfterTransition
className={classes.modal}
2022-05-06 18:35:23 +02:00
sx={props.sx}
2021-09-30 23:02:07 +02:00
>
2021-09-15 03:05:49 +02:00
<Fade in={props.open}>
2021-09-18 19:29:01 +02:00
<div className={classes.paper}>
2023-05-29 17:54:14 +02:00
<IconButton className={classes.closeButton} onClick={props.onClose}>
<CloseIcon />
</IconButton>
2021-09-18 19:29:01 +02:00
<Box sx={{ m: 2 }}>{props.children}</Box>
</div>
2021-09-15 03:05:49 +02:00
</Fade>
</M>
);
};