Files
Checkmate/Client/src/Components/Button/Button.jsx
T

74 lines
1.6 KiB
React
Raw Normal View History

2024-05-06 12:24:03 -07:00
import { Button as MuiButton } from "@mui/material";
import PropTypes from "prop-types";
const levelConfig = {
primary: {
variant: "contained",
color: "primary",
},
secondary: {
variant: "outlined",
color: "secondary",
},
tertiary: {
variant: "text",
color: "tertiary",
},
error: {
variant: "contained",
color: "error",
},
imagePrimary: {
color: "primary",
variant: "text",
},
imageSecondary: {
color: "secondary",
variant: "text",
},
imageTertiary: {
color: "tertiary",
variant: "text",
},
2024-05-06 12:24:03 -07:00
};
/**
2024-05-07 14:30:00 -07:00
* @param {Object} props
* @param {'primary' | 'secondary' | 'tertiary' | 'error' | 'imagePrimary' | 'imageSecondary' | 'imageTertiary'} props.level - The level of the button
2024-05-07 14:30:00 -07:00
* @param {string} props.label - The label of the button
* @param {React.ReactNode} props.img - Image for button
2024-05-07 14:30:00 -07:00
* @param {boolean} [props.disabled] - Whether the button is disabled
* @param {Object} prps.sx - Styles for the button
2024-05-07 14:30:00 -07:00
* @returns {JSX.Element}
* @example
* // Render an error button
* <Button level="error" label="Error" disabled sx={{marginTop: "1rem"}}/>
2024-05-06 12:24:03 -07:00
*/
const Button = ({ level, label, disabled, img, sx }) => {
2024-05-06 12:24:03 -07:00
const { variant, color } = levelConfig[level];
return (
<MuiButton
variant={variant}
color={color}
disabled={disabled}
sx={{
textTransform: "none",
...sx,
}}
>
{img && img}
{label}
2024-05-06 12:24:03 -07:00
</MuiButton>
);
};
Button.propTypes = {
level: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
img: PropTypes.node,
sx: PropTypes.object,
2024-05-06 12:24:03 -07:00
disabled: PropTypes.bool,
};
export default Button;