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

105 lines
2.3 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";
2024-07-30 19:36:37 -04:00
import "./index.css";
2024-05-06 12:24:03 -07:00
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
};
/**
* @component
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-06-12 13:49:38 -07:00
* @param {string} props.type - The type 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 {function} props.onClick - Function to run when the button is clicked
* @param {Object} props.sx - Styles for the button
2024-05-07 14:30:00 -07:00
* @returns {JSX.Element}
* @example
* // Render an error button
2024-06-12 13:49:38 -07:00
* <Button type="submit" level="error" label="Error" disabled sx={{marginTop: "1rem"}}/>
2024-05-06 12:24:03 -07:00
*/
2024-07-30 19:36:37 -04:00
const Button = ({
id,
animate,
type,
level,
label,
disabled,
img,
onClick,
sx,
}) => {
2024-05-06 12:24:03 -07:00
const { variant, color } = levelConfig[level];
return (
<MuiButton
2024-06-26 21:56:56 +03:30
id={id}
2024-07-30 19:36:37 -04:00
className={`button-${animate}`}
2024-06-12 13:49:38 -07:00
type={type}
variant={variant}
color={color}
disabled={disabled}
onClick={onClick}
2024-07-19 13:27:00 -04:00
disableRipple
sx={{
lineHeight: 1.5,
fontWeight: 400,
boxShadow: "none",
textTransform: "none",
"&:focus": {
outline: "none",
},
"&:hover": {
boxShadow: "none",
},
...sx,
}}
>
{img && img}
2024-07-30 19:36:37 -04:00
<span>{label}</span>
2024-05-06 12:24:03 -07:00
</MuiButton>
);
};
Button.propTypes = {
2024-06-26 21:56:56 +03:30
id: PropTypes.string,
2024-06-12 13:49:38 -07:00
type: PropTypes.string,
2024-05-06 12:24:03 -07:00
level: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
img: PropTypes.node,
onClick: PropTypes.func,
sx: PropTypes.object,
2024-05-06 12:24:03 -07:00
disabled: PropTypes.bool,
};
export default Button;