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",
|
|
|
|
|
},
|
2024-05-10 11:41:16 -07:00
|
|
|
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
|
2024-05-10 11:41:16 -07:00
|
|
|
* @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
|
2024-05-10 11:41:16 -07:00
|
|
|
* @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
|
2024-05-10 11:41:16 -07:00
|
|
|
* @param {Object} prps.sx - Styles for the button
|
2024-05-07 14:30:00 -07:00
|
|
|
* @returns {JSX.Element}
|
|
|
|
|
* @example
|
|
|
|
|
* // Render an error button
|
2024-05-10 11:41:16 -07:00
|
|
|
* <Button level="error" label="Error" disabled sx={{marginTop: "1rem"}}/>
|
2024-05-06 12:24:03 -07:00
|
|
|
*/
|
|
|
|
|
|
2024-05-10 11:41:16 -07:00
|
|
|
const Button = ({ level, label, disabled, img, sx }) => {
|
2024-05-06 12:24:03 -07:00
|
|
|
const { variant, color } = levelConfig[level];
|
|
|
|
|
return (
|
2024-05-10 11:41:16 -07:00
|
|
|
<MuiButton
|
|
|
|
|
variant={variant}
|
|
|
|
|
color={color}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
sx={{
|
|
|
|
|
textTransform: "none",
|
|
|
|
|
...sx,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{img && img}
|
2024-05-06 12:34:36 -07:00
|
|
|
{label}
|
2024-05-06 12:24:03 -07:00
|
|
|
</MuiButton>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Button.propTypes = {
|
|
|
|
|
level: PropTypes.string.isRequired,
|
2024-05-06 12:34:36 -07:00
|
|
|
label: PropTypes.string.isRequired,
|
2024-05-10 11:41:16 -07:00
|
|
|
img: PropTypes.node,
|
|
|
|
|
sx: PropTypes.object,
|
2024-05-06 12:24:03 -07:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Button;
|