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.
 
 
 
 

61 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,
  7. size: React.PropTypes.number,
  8. active: React.PropTypes.bool,
  9. style: React.PropTypes.object,
  10. activeStyle: React.PropTypes.object,
  11. disabled: React.PropTypes.bool
  12. },
  13. getDefaultProps () {
  14. return {
  15. size: 18,
  16. active: false,
  17. disabled: false
  18. };
  19. },
  20. mixins: [PureRenderMixin],
  21. handleClick (e) {
  22. e.preventDefault();
  23. if (!this.props.disabled) {
  24. this.props.onClick();
  25. }
  26. },
  27. render () {
  28. let style = {
  29. display: 'inline-block',
  30. border: 'none',
  31. padding: '0',
  32. background: 'transparent',
  33. fontSize: `${this.props.size}px`,
  34. width: `${this.props.size * 1.28571429}px`,
  35. height: `${this.props.size}px`,
  36. lineHeight: `${this.props.size}px`,
  37. ...this.props.style
  38. };
  39. if (this.props.active) {
  40. style = { ...style, ...this.props.activeStyle };
  41. }
  42. return (
  43. <button aria-label={this.props.title} title={this.props.title} className={`icon-button ${this.props.active ? 'active' : ''} ${this.props.disabled ? 'disabled' : ''}`} onClick={this.handleClick} style={style}>
  44. <i className={`fa fa-fw fa-${this.props.icon}`} aria-hidden='true' />
  45. </button>
  46. );
  47. }
  48. });
  49. export default IconButton;