The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

66 line
1.3 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import classNames from 'classnames';
  4. export default class Button extends React.PureComponent {
  5. static propTypes = {
  6. text: PropTypes.node,
  7. onClick: PropTypes.func,
  8. disabled: PropTypes.bool,
  9. block: PropTypes.bool,
  10. secondary: PropTypes.bool,
  11. size: PropTypes.number,
  12. className: PropTypes.string,
  13. title: PropTypes.string,
  14. style: PropTypes.object,
  15. children: PropTypes.node,
  16. };
  17. static defaultProps = {
  18. size: 36,
  19. };
  20. handleClick = (e) => {
  21. if (!this.props.disabled) {
  22. this.props.onClick(e);
  23. }
  24. }
  25. setRef = (c) => {
  26. this.node = c;
  27. }
  28. focus() {
  29. this.node.focus();
  30. }
  31. render () {
  32. const style = {
  33. padding: `0 ${this.props.size / 2.25}px`,
  34. height: `${this.props.size}px`,
  35. lineHeight: `${this.props.size}px`,
  36. ...this.props.style,
  37. };
  38. const className = classNames('button', this.props.className, {
  39. 'button-secondary': this.props.secondary,
  40. 'button--block': this.props.block,
  41. });
  42. return (
  43. <button
  44. className={className}
  45. disabled={this.props.disabled}
  46. onClick={this.handleClick}
  47. ref={this.setRef}
  48. style={style}
  49. title={this.props.title}
  50. >
  51. {this.props.text || this.props.children}
  52. </button>
  53. );
  54. }
  55. }