insomnia/app/ui/components/base/button.js
2017-08-09 18:56:27 -07:00

54 lines
1.1 KiB
JavaScript

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