import PropTypes from "prop-types"; import { useTheme } from "@emotion/react"; import { Box, Button, IconButton, Stack, Typography } from "@mui/material"; 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"; import "./index.css"; /** * Icons mapping for different alert variants. * @type {Object} */ const icons = { info: , error: , warning: , }; /** * @param {Object} props * @param {'info' | 'error' | 'warning'} props.variant - The type of alert. * @param {string} [props.title] - The title of the alert. * @param {string} [props.body] - The body text of the alert. * @param {boolean} [props.isToast] - Indicates if the alert is used as a toast notification. * @param {boolean} [props.hasIcon] - Whether to display an icon in the alert. * @param {function} props.onClick - Toast dismiss function. * @returns {JSX.Element} */ const Alert = ({ variant, title, body, isToast, hasIcon = true, onClick }) => { const theme = useTheme(); /* TODO Do we need other variants for alert? */ const text = theme.palette.secondary.contrastText; const bg = theme.palette.secondary.main; const border = theme.palette.secondary.contrastText; const icon = icons[variant]; return ( {hasIcon && {icon}} {title && ( {title} )} {body && ( {body} )} {hasIcon && isToast && ( )} {isToast && ( )} ); }; Alert.propTypes = { variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired, title: PropTypes.string, body: PropTypes.string, isToast: PropTypes.bool, hasIcon: PropTypes.bool, onClick: function (props, propName, componentName) { if (props.isToast && !props[propName]) { return new Error( `Prop '${propName}' is required when 'isToast' is true in '${componentName}'.` ); } return null; }, }; export default Alert;