2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
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 {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleClick (e) {
|
2017-01-23 22:41:31 +00:00
|
|
|
const {onClick, onDisabledClick, disabled} = this.props;
|
|
|
|
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
|
|
|
|
|
|
|
render () {
|
2017-03-03 20:09:08 +00:00
|
|
|
const {
|
|
|
|
children,
|
2017-03-09 06:23:23 +00:00
|
|
|
disabled,
|
|
|
|
tabIndex,
|
2017-03-28 22:45:23 +00:00
|
|
|
className,
|
|
|
|
type
|
2017-03-03 20:09:08 +00:00
|
|
|
} = this.props;
|
2017-03-08 05:52:17 +00:00
|
|
|
|
2017-01-20 21:54:03 +00:00
|
|
|
return (
|
2017-03-09 06:23:23 +00:00
|
|
|
<button disabled={disabled}
|
2017-03-28 22:45:23 +00:00
|
|
|
type={type}
|
2017-03-09 06:23:23 +00:00
|
|
|
tabIndex={tabIndex}
|
|
|
|
className={className}
|
|
|
|
onClick={this._handleClick}>
|
|
|
|
{children}
|
|
|
|
</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,
|
|
|
|
type: PropTypes.string
|
2017-01-20 21:54:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Button;
|