logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

button.js (1307B)


  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. style: PropTypes.object,
  14. children: PropTypes.node,
  15. };
  16. static defaultProps = {
  17. size: 36,
  18. };
  19. handleClick = (e) => {
  20. if (!this.props.disabled) {
  21. this.props.onClick(e);
  22. }
  23. }
  24. setRef = (c) => {
  25. this.node = c;
  26. }
  27. focus() {
  28. this.node.focus();
  29. }
  30. render () {
  31. const style = {
  32. padding: `0 ${this.props.size / 2.25}px`,
  33. height: `${this.props.size}px`,
  34. lineHeight: `${this.props.size}px`,
  35. ...this.props.style,
  36. };
  37. const className = classNames('button', this.props.className, {
  38. 'button-secondary': this.props.secondary,
  39. 'button--block': this.props.block,
  40. });
  41. return (
  42. <button
  43. className={className}
  44. disabled={this.props.disabled}
  45. onClick={this.handleClick}
  46. ref={this.setRef}
  47. style={style}
  48. >
  49. {this.props.text || this.props.children}
  50. </button>
  51. );
  52. }
  53. }