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.

59 lines
1.4 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. const Button = React.createClass({
  3. propTypes: {
  4. text: React.PropTypes.node,
  5. onClick: React.PropTypes.func,
  6. disabled: React.PropTypes.bool,
  7. block: React.PropTypes.bool,
  8. secondary: React.PropTypes.bool,
  9. size: React.PropTypes.number,
  10. style: React.PropTypes.object,
  11. children: React.PropTypes.node
  12. },
  13. getDefaultProps () {
  14. return {
  15. size: 36
  16. };
  17. },
  18. mixins: [PureRenderMixin],
  19. handleClick (e) {
  20. if (!this.props.disabled) {
  21. this.props.onClick();
  22. }
  23. },
  24. render () {
  25. const style = {
  26. fontFamily: 'inherit',
  27. display: this.props.block ? 'block' : 'inline-block',
  28. width: this.props.block ? '100%' : 'auto',
  29. position: 'relative',
  30. boxSizing: 'border-box',
  31. textAlign: 'center',
  32. border: '10px none',
  33. fontSize: '14px',
  34. fontWeight: '500',
  35. letterSpacing: '0',
  36. padding: `0 ${this.props.size / 2.25}px`,
  37. height: `${this.props.size}px`,
  38. cursor: 'pointer',
  39. lineHeight: `${this.props.size}px`,
  40. borderRadius: '4px',
  41. textDecoration: 'none'
  42. };
  43. return (
  44. <button className={`button ${this.props.secondary ? 'button-secondary' : ''}`} disabled={this.props.disabled} onClick={this.handleClick} style={{ ...style, ...this.props.style }}>
  45. {this.props.text || this.props.children}
  46. </button>
  47. );
  48. }
  49. });
  50. export default Button;