You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
|
|
||
|
class Button extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
constructor (props, context) {
|
||
|
super(props, context);
|
||
|
this.handleClick = this.handleClick.bind(this);
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleClick (e) {
|
||
8 years ago
|
if (!this.props.disabled) {
|
||
|
this.props.onClick();
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
render () {
|
||
8 years ago
|
const style = {
|
||
|
display: this.props.block ? 'block' : 'inline-block',
|
||
|
width: this.props.block ? '100%' : 'auto',
|
||
8 years ago
|
padding: `0 ${this.props.size / 2.25}px`,
|
||
|
height: `${this.props.size}px`,
|
||
8 years ago
|
lineHeight: `${this.props.size}px`
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<button className={`button ${this.props.secondary ? 'button-secondary' : ''}`} disabled={this.props.disabled} onClick={this.handleClick} style={{ ...style, ...this.props.style }}>
|
||
8 years ago
|
{this.props.text || this.props.children}
|
||
8 years ago
|
</button>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|
||
|
|
||
|
Button.propTypes = {
|
||
|
text: PropTypes.node,
|
||
|
onClick: PropTypes.func,
|
||
|
disabled: PropTypes.bool,
|
||
|
block: PropTypes.bool,
|
||
|
secondary: PropTypes.bool,
|
||
|
size: PropTypes.number,
|
||
|
style: PropTypes.object,
|
||
|
children: PropTypes.node
|
||
|
};
|
||
|
|
||
|
Button.defaultProps = {
|
||
|
size: 36
|
||
|
};
|
||
8 years ago
|
|
||
|
export default Button;
|