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.

49 lines
1.1 KiB

  1. import PropTypes from 'prop-types';
  2. class Button extends React.PureComponent {
  3. constructor (props, context) {
  4. super(props, context);
  5. this.handleClick = this.handleClick.bind(this);
  6. }
  7. handleClick (e) {
  8. if (!this.props.disabled) {
  9. this.props.onClick();
  10. }
  11. }
  12. render () {
  13. const style = {
  14. display: this.props.block ? 'block' : 'inline-block',
  15. width: this.props.block ? '100%' : 'auto',
  16. padding: `0 ${this.props.size / 2.25}px`,
  17. height: `${this.props.size}px`,
  18. lineHeight: `${this.props.size}px`
  19. };
  20. return (
  21. <button className={`button ${this.props.secondary ? 'button-secondary' : ''}`} disabled={this.props.disabled} onClick={this.handleClick} style={{ ...style, ...this.props.style }}>
  22. {this.props.text || this.props.children}
  23. </button>
  24. );
  25. }
  26. }
  27. Button.propTypes = {
  28. text: PropTypes.node,
  29. onClick: PropTypes.func,
  30. disabled: PropTypes.bool,
  31. block: PropTypes.bool,
  32. secondary: PropTypes.bool,
  33. size: PropTypes.number,
  34. style: PropTypes.object,
  35. children: PropTypes.node
  36. };
  37. Button.defaultProps = {
  38. size: 36
  39. };
  40. export default Button;