import React from 'react';
import Motion from 'react-motion/lib/Motion';
import spring from 'react-motion/lib/spring';
import PropTypes from 'prop-types';

export default class IconButton extends React.PureComponent {

  static propTypes = {
    className: PropTypes.string,
    title: PropTypes.string.isRequired,
    icon: PropTypes.string.isRequired,
    onClick: PropTypes.func,
    size: PropTypes.number,
    active: PropTypes.bool,
    pressed: PropTypes.bool,
    expanded: PropTypes.bool,
    style: PropTypes.object,
    activeStyle: PropTypes.object,
    disabled: PropTypes.bool,
    inverted: PropTypes.bool,
    animate: PropTypes.bool,
    overlay: PropTypes.bool,
    tabIndex: PropTypes.string,
  };

  static defaultProps = {
    size: 18,
    active: false,
    disabled: false,
    animate: false,
    overlay: false,
    tabIndex: '0',
  };

  handleClick = (e) =>  {
    e.preventDefault();

    if (!this.props.disabled) {
      this.props.onClick(e);
    }
  }

  render () {
    const style = {
      fontSize: `${this.props.size}px`,
      width: `${this.props.size * 1.28571429}px`,
      height: `${this.props.size * 1.28571429}px`,
      lineHeight: `${this.props.size}px`,
      ...this.props.style,
      ...(this.props.active ? this.props.activeStyle : {}),
    };

    const classes = ['icon-button'];

    if (this.props.active) {
      classes.push('active');
    }

    if (this.props.disabled) {
      classes.push('disabled');
    }

    if (this.props.inverted) {
      classes.push('inverted');
    }

    if (this.props.overlay) {
      classes.push('overlayed');
    }

    if (this.props.className) {
      classes.push(this.props.className);
    }

    return (
      <Motion defaultStyle={{ rotate: this.props.active ? -360 : 0 }} style={{ rotate: this.props.animate ? spring(this.props.active ? -360 : 0, { stiffness: 120, damping: 7 }) : 0 }}>
        {({ rotate }) =>
          <button
            aria-label={this.props.title}
            aria-pressed={this.props.pressed}
            aria-expanded={this.props.expanded}
            title={this.props.title}
            className={classes.join(' ')}
            onClick={this.handleClick}
            style={style}
            tabIndex={this.props.tabIndex}
          >
            <i style={{ transform: `rotate(${rotate}deg)` }} className={`fa fa-fw fa-${this.props.icon}`} aria-hidden='true' />
          </button>
        }
      </Motion>
    );
  }

}

@@ -147,16 +147,53 @@
 -types';
+%0Aimport classNames from 'classnames';
 %0A%0Aexport
@@ -1342,129 +1342,70 @@
 nst 
-classes = %5B'icon-button'%5D;%0A%0A    if (this.props.active) %7B%0A      classes.push('active');%0A    %7D%0A%0A    if (this.props.
+%7B%0A      active,%0A      animate,%0A      className,%0A      
 disabled
 ) %7B%0A
@@ -1404,78 +1404,52 @@
 bled
-) %7B
+,
 %0A      
-classes.push('disabled');%0A    %7D%0A%0A    if (this.props.
+expanded,%0A      icon,%0A      
 inverted
 ) %7B%0A
@@ -1448,59 +1448,77 @@
 rted
-) %7B
+,
 %0A      
-classes.push('inverted');%0A    %7D%0A
+overlay,%0A      pressed,%0A      tabIndex,%0A      title,
 %0A    
-if (
+%7D = 
 this
@@ -1527,139 +1527,149 @@
 rops
-.overlay) %7B%0A      classes.push('overlayed');%0A    %7D%0A%0A    if (this.props.className) %7B%0A      classes.push(this.props.className);
+;%0A%0A    const classes = classNames(className, 'icon-button', %7B%0A      active,%0A      disabled,%0A      inverted,%0A      overlayed: overlay,
 %0A    %7D
+);
 %0A%0A  
@@ -1717,27 +1717,16 @@
 rotate: 
-this.props.
 active ?
@@ -1755,27 +1755,16 @@
 rotate: 
-this.props.
 animate 
@@ -1772,27 +1772,16 @@
  spring(
-this.props.
 active ?
@@ -1898,27 +1898,16 @@
 -label=%7B
-this.props.
 title%7D%0A 
@@ -1931,27 +1931,16 @@
 ressed=%7B
-this.props.
 pressed%7D
@@ -1967,27 +1967,16 @@
 panded=%7B
-this.props.
 expanded
@@ -1996,27 +1996,16 @@
  title=%7B
-this.props.
 title%7D%0A 
@@ -2037,18 +2037,8 @@
 sses
-.join(' ')
 %7D%0A  
@@ -2122,27 +2122,16 @@
 bIndex=%7B
-this.props.
 tabIndex
@@ -2231,27 +2231,16 @@
 fw fa-$%7B
-this.props.
 icon%7D%60%7D 

Refactor and simplify icon_button.js (#5413)