|
|
@ -24,7 +24,6 @@ export default class IconButton extends React.PureComponent { |
|
|
|
disabled: PropTypes.bool, |
|
|
|
disabled: PropTypes.bool, |
|
|
|
inverted: PropTypes.bool, |
|
|
|
inverted: PropTypes.bool, |
|
|
|
animate: PropTypes.bool, |
|
|
|
animate: PropTypes.bool, |
|
|
|
flip: PropTypes.bool, |
|
|
|
|
|
|
|
overlay: PropTypes.bool, |
|
|
|
overlay: PropTypes.bool, |
|
|
|
tabIndex: PropTypes.string, |
|
|
|
tabIndex: PropTypes.string, |
|
|
|
label: PropTypes.string, |
|
|
|
label: PropTypes.string, |
|
|
@ -39,6 +38,21 @@ export default class IconButton extends React.PureComponent { |
|
|
|
tabIndex: '0', |
|
|
|
tabIndex: '0', |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
|
|
|
|
activate: false, |
|
|
|
|
|
|
|
deactivate: false, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) { |
|
|
|
|
|
|
|
if (!nextProps.animate) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.active && !nextProps.active) { |
|
|
|
|
|
|
|
this.setState({ activate: false, deactivate: true }); |
|
|
|
|
|
|
|
} else if (!this.props.active && nextProps.active) { |
|
|
|
|
|
|
|
this.setState({ activate: true, deactivate: false }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleClick = (e) => { |
|
|
|
handleClick = (e) => { |
|
|
|
e.preventDefault(); |
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
|
|
@ -81,44 +95,31 @@ export default class IconButton extends React.PureComponent { |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
active, |
|
|
|
active, |
|
|
|
animate, |
|
|
|
|
|
|
|
className, |
|
|
|
className, |
|
|
|
disabled, |
|
|
|
disabled, |
|
|
|
expanded, |
|
|
|
expanded, |
|
|
|
icon, |
|
|
|
icon, |
|
|
|
inverted, |
|
|
|
inverted, |
|
|
|
flip, |
|
|
|
|
|
|
|
overlay, |
|
|
|
overlay, |
|
|
|
pressed, |
|
|
|
pressed, |
|
|
|
tabIndex, |
|
|
|
tabIndex, |
|
|
|
title, |
|
|
|
title, |
|
|
|
} = this.props; |
|
|
|
} = this.props; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
activate, |
|
|
|
|
|
|
|
deactivate, |
|
|
|
|
|
|
|
} = this.state; |
|
|
|
|
|
|
|
|
|
|
|
const classes = classNames(className, 'icon-button', { |
|
|
|
const classes = classNames(className, 'icon-button', { |
|
|
|
active, |
|
|
|
active, |
|
|
|
disabled, |
|
|
|
disabled, |
|
|
|
inverted, |
|
|
|
inverted, |
|
|
|
|
|
|
|
activate, |
|
|
|
|
|
|
|
deactivate, |
|
|
|
overlayed: overlay, |
|
|
|
overlayed: overlay, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const flipDeg = flip ? -180 : -360; |
|
|
|
|
|
|
|
const rotateDeg = active ? flipDeg : 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const motionDefaultStyle = { |
|
|
|
|
|
|
|
rotate: rotateDeg, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const springOpts = { |
|
|
|
|
|
|
|
stiffness: this.props.flip ? 60 : 120, |
|
|
|
|
|
|
|
damping: 7, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const motionStyle = { |
|
|
|
|
|
|
|
rotate: animate ? spring(rotateDeg, springOpts) : 0, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!animate) { |
|
|
|
|
|
|
|
// Perf optimization: avoid unnecessary <Motion> components unless
|
|
|
|
|
|
|
|
// we actually need to animate.
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<button |
|
|
|
<button |
|
|
|
aria-label={title} |
|
|
|
aria-label={title} |
|
|
@ -135,32 +136,8 @@ export default class IconButton extends React.PureComponent { |
|
|
|
disabled={disabled} |
|
|
|
disabled={disabled} |
|
|
|
> |
|
|
|
> |
|
|
|
<Icon id={icon} fixedWidth aria-hidden='true' /> |
|
|
|
<Icon id={icon} fixedWidth aria-hidden='true' /> |
|
|
|
</button> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<Motion defaultStyle={motionDefaultStyle} style={motionStyle}> |
|
|
|
|
|
|
|
{({ rotate }) => |
|
|
|
|
|
|
|
(<button |
|
|
|
|
|
|
|
aria-label={title} |
|
|
|
|
|
|
|
aria-pressed={pressed} |
|
|
|
|
|
|
|
aria-expanded={expanded} |
|
|
|
|
|
|
|
title={title} |
|
|
|
|
|
|
|
className={classes} |
|
|
|
|
|
|
|
onClick={this.handleClick} |
|
|
|
|
|
|
|
onMouseDown={this.handleMouseDown} |
|
|
|
|
|
|
|
onKeyDown={this.handleKeyDown} |
|
|
|
|
|
|
|
onKeyPress={this.handleKeyPress} |
|
|
|
|
|
|
|
style={style} |
|
|
|
|
|
|
|
tabIndex={tabIndex} |
|
|
|
|
|
|
|
disabled={disabled} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Icon id={icon} style={{ transform: `rotate(${rotate}deg)` }} fixedWidth aria-hidden='true' /> |
|
|
|
|
|
|
|
{this.props.label} |
|
|
|
{this.props.label} |
|
|
|
</button>) |
|
|
|
</button> |
|
|
|
} |
|
|
|
|
|
|
|
</Motion> |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|