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

51 lines
1.1 KiB
JavaScript
Raw Normal View History

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';
import autobind from 'autobind-decorator';
@autobind
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;
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);
}
}
2018-06-25 17:42:50 +00:00
render() {
const { children, disabled, tabIndex, className, type, id } = this.props;
return (
2018-06-25 17:42:50 +00:00
<button
disabled={disabled}
id={id}
type={type}
tabIndex={tabIndex}
className={className}
onClick={this._handleClick}>
{children}
2018-06-25 17:42:50 +00:00
</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,
2018-01-29 03:41:02 +00:00
type: PropTypes.string,
id: PropTypes.string,
};
export default Button;