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

81 lines
1.9 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
};
/**
* @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-06-12 13:49:38 -07:00
const Button = ({ type, level, label, disabled, img, onClick, sx }) => {
2024-05-06 12:24:03 -07:00
const { variant, color } = levelConfig[level];
return (
<MuiButton
2024-06-12 13:49:38 -07:00
type={type}
variant={variant}
color={color}
disabled={disabled}
onClick={onClick}
sx={{
textTransform: "none",
...sx,
}}
>
{img && img}
{label}
2024-05-06 12:24:03 -07:00
</MuiButton>
);
};
Button.propTypes = {
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;