insomnia/app/ui/components/base/button.js

50 lines
1020 B
JavaScript
Raw Normal View History

import React, {PureComponent, PropTypes} from 'react';
import autobind from 'autobind-decorator';
@autobind
class Button extends PureComponent {
_handleClick (e) {
2017-01-23 22:41:31 +00:00
const {onClick, onDisabledClick, disabled} = this.props;
const fn = disabled ? onDisabledClick : onClick;
if (this.props.hasOwnProperty('value')) {
2017-01-23 22:41:31 +00:00
fn && fn(this.props.value, e);
} else {
2017-01-23 22:41:31 +00:00
fn && fn(e);
}
}
render () {
const {
children,
disabled,
tabIndex,
className
} = this.props;
return (
<button disabled={disabled}
tabIndex={tabIndex}
className={className}
onClick={this._handleClick}>
{children}
</button>
);
}
}
Button.propTypes = {
// Required
children: PropTypes.node.isRequired,
// Optional
value: PropTypes.any,
className: PropTypes.string,
2017-01-23 22:41:31 +00:00
onDisabledClick: PropTypes.func,
onClick: PropTypes.func,
disabled: PropTypes.bool,
tabIndex: PropTypes.number
};
export default Button;