Added proptypes and jsdocs, and color fix

This commit is contained in:
Daniel Cojocea
2024-07-06 14:44:04 -04:00
parent bf62404247
commit 49f8958418
2 changed files with 21 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
import { Box, Stack } from "@mui/material";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
@@ -5,12 +6,25 @@ import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined";
import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined";
import "./index.css";
/**
* Icons mapping for different alert variants.
* @type {Object<string, JSX.Element>}
*/
const icons = {
info: <InfoOutlinedIcon />,
error: <ErrorOutlineOutlinedIcon />,
warning: <WarningAmberOutlinedIcon />,
};
/**
* @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.
* @returns {JSX.Element}
*/
const Alert = ({ variant, title, body }) => {
const theme = useTheme();
const { bg, border, color } = theme.alert[variant];
@@ -37,4 +51,10 @@ const Alert = ({ variant, title, body }) => {
);
};
Alert.propTypes = {
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
title: PropTypes.string,
body: PropTypes.string,
};
export default Alert;

View File

@@ -105,7 +105,7 @@ const theme = createTheme({
},
error: {
color: "#d92d20",
bg: "#fffaef",
bg: "hsla(0, 100%, 52%, 0.03)",
border: "#f04438",
},
warning: {