Files
Checkmate/Client/src/Components/Label/BaseLabel.jsx
T

54 lines
1.4 KiB
React
Raw Normal View History

2024-05-06 15:58:51 -07:00
import PropTypes from "prop-types";
import "./BaseLabel.css";
2024-05-06 15:58:51 -07:00
import { useTheme } from "@mui/material";
2024-05-07 14:22:39 -07:00
/**
* @typedef {Object} Styles
* @param {string} [color] - The text color
* @param {string} [backgroundColor] - The background color
* @param {string} [borderColor] - The border color
*/
2024-05-06 15:58:51 -07:00
/**
2024-05-07 14:22:39 -07:00
* @component
* @param {Object} props
* @param {string} props.label - The label of the label
* @param {Styles} props.styles - CSS Styles passed from parent component
2024-05-07 14:30:00 -07:00
* @param {React.ReactNode} children - Children passed from parent component
2024-05-07 14:22:39 -07:00
* @returns {JSX.Element}
2024-05-06 15:58:51 -07:00
*/
2024-05-07 14:22:39 -07:00
const BaseLabel = ({ label, styles, children }) => {
2024-05-06 15:58:51 -07:00
const theme = useTheme();
// Grab the default borderRadius from the theme to match button style
2024-05-06 15:58:51 -07:00
const { borderRadius } = theme.shape;
// Calculate padding for the label to mimic button. Appears to scale correctly, not 100% sure though.
const padding = theme.spacing(1 * 0.75, 2);
2024-05-06 15:58:51 -07:00
return (
<div
className="label"
style={{
borderRadius: borderRadius,
2024-05-07 14:22:39 -07:00
borderColor: theme.palette.tertiary.main,
color: theme.palette.tertiary.main,
padding: padding,
2024-05-07 14:22:39 -07:00
...styles,
2024-05-06 15:58:51 -07:00
}}
>
2024-05-07 14:22:39 -07:00
{children}
2024-05-06 15:58:51 -07:00
{label}
</div>
);
};
2024-05-07 14:22:39 -07:00
BaseLabel.propTypes = {
2024-05-06 15:58:51 -07:00
label: PropTypes.string.isRequired,
2024-05-07 14:22:39 -07:00
styles: PropTypes.shape({
color: PropTypes.string,
backgroundColor: PropTypes.string,
}),
children: PropTypes.node,
2024-05-06 15:58:51 -07:00
};
2024-05-07 14:22:39 -07:00
export default BaseLabel;