Last active
March 6, 2020 05:38
-
-
Save alexdisdier/e50564b17bf6c300d64b351ff7ca6a44 to your computer and use it in GitHub Desktop.
A simple react button in typescript using react-jss for styling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import useStyles from './button.style'; | |
export type Props = { | |
children: React.ReactNode; | |
onClick?: () => void; | |
color?: string; | |
type?: string; | |
disabled?: boolean; | |
dataTestId?: string; | |
} & React.ButtonHTMLAttributes<HTMLButtonElement>; | |
const Button: React.FC<Props> = ({ | |
children, | |
onClick = () => {}, | |
disabled = false, | |
type = 'submit', | |
color = '', | |
dataTestId = 'button' | |
}) => { | |
const classes = useStyles({ color }); | |
const handleClick = () => { | |
if (!disabled && onClick) onClick(); | |
}; | |
const rootProps = { | |
className: classes.root, | |
type, | |
onClick: handleClick, | |
disabled, | |
'data-testid': dataTestId | |
}; | |
return ( | |
<button {...rootProps}> | |
<span className={classes.label}>{children}</span> | |
</button> | |
); | |
}; | |
export default Button; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment