闭社主体 forked from https://github.com/tootsuite/mastodon
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.0 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. padding: `0 ${this.props.size / 2.25}px`,
  25. height: `${this.props.size}px`,
  26. lineHeight: `${this.props.size}px`,
  27. ...this.props.style
  28. };
  29. return (
  30. <button
  31. className={`button ${this.props.secondary ? 'button-secondary' : ''} ${this.props.block ? 'button--block' : ''}`}
  32. disabled={this.props.disabled}
  33. onClick={this.handleClick}
  34. style={style}
  35. >
  36. {this.props.text || this.props.children}
  37. </button>
  38. );
  39. }
  40. }
  41. export default Button;