Added proptypes and jsdocs, and color fix
This commit is contained in:
1 parent
bf62404247
commit
49f8958418
2 files changed
+21
-1
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import PropTypes from "prop-types";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Box, Stack } from "@mui/material";
|
import { Box, Stack } from "@mui/material";
|
||||||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
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 WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Icons mapping for different alert variants.
|
||||||
|
* @type {Object<string, JSX.Element>}
|
||||||
|
*/
|
||||||
|
|
||||||
const icons = {
|
const icons = {
|
||||||
info: <InfoOutlinedIcon />,
|
info: <InfoOutlinedIcon />,
|
||||||
error: <ErrorOutlineOutlinedIcon />,
|
error: <ErrorOutlineOutlinedIcon />,
|
||||||
warning: <WarningAmberOutlinedIcon />,
|
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 Alert = ({ variant, title, body }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { bg, border, color } = theme.alert[variant];
|
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;
|
export default Alert;
|
||||||
@@ -105,7 +105,7 @@ const theme = createTheme({
|
|||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
color: "#d92d20",
|
color: "#d92d20",
|
||||||
bg: "#fffaef",
|
bg: "hsla(0, 100%, 52%, 0.03)",
|
||||||
border: "#f04438",
|
border: "#f04438",
|
||||||
},
|
},
|
||||||
warning: {
|
warning: {
|
||||||
|
|||||||
Reference in new issue
Block a user