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.

45 lines
1.1 KiB

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