80 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-13 19:40:04 -05:00
import { NavLink } from 'react-router-dom'
2020-02-05 17:45:48 -05:00
import classNames from 'classnames/bind'
export default class Button extends PureComponent {
static propTypes = {
2020-02-13 19:40:04 -05:00
children: PropTypes.node,
text: PropTypes.node,
2020-02-13 19:40:04 -05:00
to: PropTypes.string,
2020-02-05 17:45:48 -05:00
href: PropTypes.string,
onClick: PropTypes.func,
disabled: PropTypes.bool,
block: PropTypes.bool,
secondary: PropTypes.bool,
2020-02-05 17:45:48 -05:00
className: PropTypes.string,
}
handleClick = (e) => {
if (!this.props.disabled && this.props.onClick) {
2020-02-05 17:45:48 -05:00
this.props.onClick(e)
}
}
setRef = (c) => {
2020-02-05 17:45:48 -05:00
this.node = c
}
focus() {
2020-02-05 17:45:48 -05:00
this.node.focus()
}
render () {
2020-02-13 19:40:04 -05:00
const { block, className, disabled, text, to, children, href } = this.props
2020-02-05 17:45:48 -05:00
const cx = classNames.bind(styles)
const classes = cx(className, {
default: 1,
noUnderline: 1,
font: 1,
colorWhite: 1,
circle: 1,
cursorPointer: 1,
textAlignCenter: 1,
paddingVertical10PX: 1,
paddingHorizontal15PX: 1,
2020-02-08 01:12:01 -05:00
width100PC: block,
2020-02-13 19:40:04 -05:00
backgroundColorBrand: 1,
backgroundColorBrandDark_onHover: 1,
2020-02-05 17:45:48 -05:00
})
if (href) {
return (
2020-02-13 19:40:04 -05:00
<a className={classes} href={href}>
2020-02-05 17:45:48 -05:00
{text || children}
</a>
)
2020-02-13 19:40:04 -05:00
} else if (to) {
return (
<NavLink className={classes} to={to}>
{text || children}
</NavLink>
)
2020-02-05 17:45:48 -05:00
}
return (
<button
ref={this.setRef}
2020-02-05 17:45:48 -05:00
disabled={disabled}
onClick={this.handleClick}
className={classes}
>
2020-02-05 17:45:48 -05:00
{text || children}
</button>
);
}
}