2018-06-25 17:42:50 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-08-10 01:56:27 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-01-20 21:54:03 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class Button extends PureComponent {
|
2018-06-25 17:42:50 +00:00
|
|
|
_handleClick(e) {
|
|
|
|
const { onClick, onDisabledClick, disabled } = this.props;
|
2017-01-23 22:41:31 +00:00
|
|
|
const fn = disabled ? onDisabledClick : onClick;
|
2017-01-20 21:54:03 +00:00
|
|
|
|
|
|
|
if (this.props.hasOwnProperty('value')) {
|
2017-01-23 22:41:31 +00:00
|
|
|
fn && fn(this.props.value, e);
|
2017-01-20 21:54:03 +00:00
|
|
|
} else {
|
2017-01-23 22:41:31 +00:00
|
|
|
fn && fn(e);
|
2017-01-20 21:54:03 +00:00
|
|
|
}
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2017-01-20 21:54:03 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
render() {
|
|
|
|
const { children, disabled, tabIndex, className, type, id } = this.props;
|
2017-03-08 05:52:17 +00:00
|
|
|
|
2017-01-20 21:54:03 +00:00
|
|
|
return (
|
2018-06-25 17:42:50 +00:00
|
|
|
<button
|
|
|
|
disabled={disabled}
|
|
|
|
id={id}
|
|
|
|
type={type}
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
className={className}
|
|
|
|
onClick={this._handleClick}>
|
2017-03-09 06:23:23 +00:00
|
|
|
{children}
|
2018-06-25 17:42:50 +00:00
|
|
|
</button>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-01-20 21:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button.propTypes = {
|
2017-03-08 05:52:17 +00:00
|
|
|
// Required
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2017-01-20 21:54:03 +00:00
|
|
|
value: PropTypes.any,
|
2017-03-09 06:23:23 +00:00
|
|
|
className: PropTypes.string,
|
2017-01-23 22:41:31 +00:00
|
|
|
onDisabledClick: PropTypes.func,
|
2017-03-08 05:52:17 +00:00
|
|
|
onClick: PropTypes.func,
|
2017-03-09 06:23:23 +00:00
|
|
|
disabled: PropTypes.bool,
|
2017-03-28 22:45:23 +00:00
|
|
|
tabIndex: PropTypes.number,
|
2018-01-29 03:41:02 +00:00
|
|
|
type: PropTypes.string,
|
2018-12-12 17:36:11 +00:00
|
|
|
id: PropTypes.string,
|
2017-01-20 21:54:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Button;
|