From 616927d388c9a77517c2fff45b82458698d14c5c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 16 Jul 2025 10:32:19 -0700 Subject: [PATCH] Add new toast component --- client/src/Components/Toast/body.jsx | 34 +++++++++++ client/src/Components/Toast/index.jsx | 83 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 client/src/Components/Toast/body.jsx create mode 100644 client/src/Components/Toast/index.jsx diff --git a/client/src/Components/Toast/body.jsx b/client/src/Components/Toast/body.jsx new file mode 100644 index 000000000..04d5aee99 --- /dev/null +++ b/client/src/Components/Toast/body.jsx @@ -0,0 +1,34 @@ +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; + +import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; + +const ToastBody = ({ body }) => { + const theme = useTheme(); + + if (Array.isArray(body)) { + return ( + + {body.map((item, idx) => ( + + {item} + + ))} + + ); + } else if (typeof body === "string") { + return {body}; + } + + return null; +}; + +ToastBody.propTypes = { + body: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), +}; + +export default ToastBody; diff --git a/client/src/Components/Toast/index.jsx b/client/src/Components/Toast/index.jsx new file mode 100644 index 000000000..4505b758b --- /dev/null +++ b/client/src/Components/Toast/index.jsx @@ -0,0 +1,83 @@ +import Stack from "@mui/material/Stack"; +import IconButton from "@mui/material/IconButton"; +import Typography from "@mui/material/Typography"; +import Button from "@mui/material/Button"; +import ToastBody from "./body"; +import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; +import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined"; +import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined"; +import CloseIcon from "@mui/icons-material/Close"; + +// Utils +import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; + +const icons = { + info: , + error: , + warning: , +}; + +const Toast = ({ variant, title, body, onClick, hasDismiss, hasIcon }) => { + const theme = useTheme(); + const icon = icons[variant]; + + return ( + + + {hasIcon && icon} + {title && ( + + {title} + + )} + + + + + + + {hasDismiss && ( + + )} + + ); +}; + +export default Toast; + +Toast.propTypes = { + variant: PropTypes.string.isRequired, + title: PropTypes.string, + body: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), + hasDismiss: PropTypes.bool, + hasIcon: PropTypes.bool, + onClick: PropTypes.func, +};