From d49fe64f8f55f7856a9f3a6fbfc98f6ea004954e Mon Sep 17 00:00:00 2001 From: Himanshu Aggarwal <aggarwah@mcmaster.ca> Date: Wed, 16 Mar 2022 23:58:14 -0400 Subject: [PATCH] Add a way to disable button --- src/cryptometrics/components/button/Button.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cryptometrics/components/button/Button.js b/src/cryptometrics/components/button/Button.js index 3e625e1..882cc5c 100644 --- a/src/cryptometrics/components/button/Button.js +++ b/src/cryptometrics/components/button/Button.js @@ -13,11 +13,13 @@ import classNames from "classnames"; * </Button> * ) */ -function Button({ children, className, onClick, type }) { +function Button({ children, className, onClick, type, disabled }) { return ( <button - className={classNames("py-2 px-5 rounded-xl", className)} - onClick={onClick} + className={classNames("py-2 px-5 rounded-xl", className, { + "brightness-50 cursor-default": disabled, + })} + onClick={disabled ? undefined : onClick} type={type ? type : "button"} > {children} @@ -38,6 +40,18 @@ Button.propTypes = { * The function to run when button is pressed */ onClick: PropTypes.func, + /** + * The type of button + */ + type: PropTypes.string, + /** + * Whether the button is disabled + */ + disabled: PropTypes.bool, +}; + +Button.defaultProps = { + type: "button", }; export default Button; -- GitLab