Newer
Older
import React from "react";
import PropTypes from "prop-types";
import MuiAlert from "@mui/material/Alert";
import Snackbar from "@mui/material/Snackbar";
import Slide from "@mui/material/Slide";
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://stackoverflow.com/a/67961603
const Alert = React.forwardRef(function Alert(props, ref) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});
const SlideTransition = React.forwardRef(function SlideTransition(props, ref) {
return <Slide ref={ref} {...props} direction="left" />;
});
export default function BlueprintSnackbar({ snackbar, setSnackbar }) {
const snackbarRef = React.createRef(null);
const handleClose = () => {
setSnackbar((state) => ({ ...state, open: false }));
};
return (
<Snackbar
ref={snackbarRef}
TransitionComponent={SlideTransition}
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
open={snackbar.open}
onClose={handleClose}
message={snackbar.message}
key={"bottomright"}
>
<Alert onClose={handleClose} severity={snackbar.severity}>
{snackbar.message}
</Alert>
</Snackbar>
);
}
BlueprintSnackbar.propTypes = {
snackbar: PropTypes.object,
setSnackbar: PropTypes.func,
};