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.

57 lines
1.4 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. const IconButton = React.createClass({
  3. propTypes: {
  4. title: React.PropTypes.string.isRequired,
  5. icon: React.PropTypes.string.isRequired,
  6. onClick: React.PropTypes.func.isRequired,
  7. size: React.PropTypes.number,
  8. active: React.PropTypes.bool,
  9. style: React.PropTypes.object,
  10. activeStyle: React.PropTypes.object
  11. },
  12. getDefaultProps () {
  13. return {
  14. size: 18,
  15. active: false
  16. };
  17. },
  18. mixins: [PureRenderMixin],
  19. handleClick (e) {
  20. e.preventDefault();
  21. this.props.onClick();
  22. e.stopPropagation();
  23. },
  24. render () {
  25. let style = {
  26. display: 'inline-block',
  27. border: 'none',
  28. padding: '0',
  29. background: 'transparent',
  30. fontSize: `${this.props.size}px`,
  31. width: `${this.props.size * 1.28571429}px`,
  32. height: `${this.props.size}px`,
  33. lineHeight: `${this.props.size}px`,
  34. cursor: 'pointer',
  35. ...this.props.style
  36. };
  37. if (this.props.active) {
  38. style = { ...style, ...this.props.activeStyle };
  39. }
  40. return (
  41. <button aria-label={this.props.title} title={this.props.title} className={`icon-button ${this.props.active ? 'active' : ''}`} onClick={this.handleClick} style={style}>
  42. <i className={`fa fa-fw fa-${this.props.icon}`} aria-hidden='true' />
  43. </button>
  44. );
  45. }
  46. });
  47. export default IconButton;