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.

46 lines
1.0 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. },
  10. getDefaultProps () {
  11. return {
  12. size: 18,
  13. active: false
  14. };
  15. },
  16. mixins: [PureRenderMixin],
  17. handleClick (e) {
  18. e.preventDefault();
  19. this.props.onClick();
  20. e.stopPropagation();
  21. },
  22. render () {
  23. const style = {
  24. display: 'inline-block',
  25. fontSize: `${this.props.size}px`,
  26. width: `${this.props.size}px`,
  27. height: `${this.props.size}px`,
  28. lineHeight: `${this.props.size}px`
  29. };
  30. return (
  31. <a href='#' title={this.props.title} className={`icon-button ${this.props.active ? 'active' : ''}`} onClick={this.handleClick} style={style}>
  32. <i className={`fa fa-fw fa-${this.props.icon}`}></i>
  33. </a>
  34. );
  35. }
  36. });
  37. export default IconButton;