Added start and end icon props to buttons to allow for images, made prop type for level more specific, added onClick prop so a function can be passed to onClick

This commit is contained in:
Alex Holliday committed 2024-05-06 13:39:58 -07:00
1 parent e76db0a499
commit f13b64a496
2 files changed
+48 -7

No files matched your search

+16 -3
View File
@@ -24,22 +24,35 @@ const levelConfig = {
* @typedef {Object} Props
* @property {'primary' | 'secondary' | 'tertiary' | 'error'} level - The level of the button
* @property {string} label - The label of the button
* @property {React.ReactNode} [startIcon] - Icon prepended to the label
* @property {React.ReactNode} [endIcon] - Icon appended to the button label
* @property {boolean} [disabled] - Whether the button is disabled
* @property {(event: React.MouseEvent<HTMLButtonElement>) => void} [onClick] - The click handler of the button
*/
const Button = ({ level, label, disabled }) => {
const Button = ({ level, label, disabled, startIcon, endIcon, onClick }) => {
const { variant, color } = levelConfig[level];
return (
<MuiButton variant={variant} color={color} disabled={disabled}>
<MuiButton
variant={variant}
color={color}
disabled={disabled}
startIcon={startIcon}
endIcon={endIcon}
onClick={onClick}
>
{label}
</MuiButton>
);
};
Button.propTypes = {
level: PropTypes.string.isRequired,
level: PropTypes.oneOf(["primary", "secondary", "tertiary", "error"]),
label: PropTypes.string.isRequired,
startIcon: PropTypes.node,
endIcon: PropTypes.node,
disabled: PropTypes.bool,
onClick: PropTypes.func,
};
export default Button;