Skip to content

Commit

Permalink
IconButton FontIcon child hover styling
Browse files Browse the repository at this point in the history
  • Loading branch information
troutowicz committed May 13, 2015
1 parent 7898b03 commit a40a430
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
28 changes: 24 additions & 4 deletions src/font-icon.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var React = require('react');
var StylePropable = require('./mixins/style-propable');
var Spacing = require('./styles/spacing');
var Transitions = require('./styles/transitions');

var FontIcon = React.createClass({

Expand All @@ -12,7 +13,7 @@ var FontIcon = React.createClass({

getInitialState: function() {
return {
isHovered: false,
hovered: false,
};
},

Expand All @@ -25,7 +26,8 @@ var FontIcon = React.createClass({
position: 'relative',
fontSize: Spacing.iconSize + 'px',
display: 'inline-block',
userSelect: 'none'
userSelect: 'none',
transition: Transitions.easeOut()
};
if (!styles.color && !this.props.className) {
styles.color = this.getTheme().textColor;
Expand All @@ -35,16 +37,34 @@ var FontIcon = React.createClass({

render: function() {
var {
onMouseOut,
onMouseOver,
style,
...other
} = this.props;

return (
<span {...other}
<span
{...other}
onMouseOut={this._handleMouseOut}
onMouseOver={this._handleMouseOver}
style={this.mergeAndPrefix(
this.getStyles(),
this.props.style)} />
this.props.style,
this.state.hovered && this.props.hoverStyle)} />
);
},

_handleMouseOut: function(e) {
this.setState({hovered: false});

if (this.props.onMouseOut) this.props.onMouseOut(e);
},

_handleMouseOver: function(e) {
this.setState({hovered: true});

if (this.props.onMouseOver) this.props.onMouseOver(e);
}
});

Expand Down
7 changes: 5 additions & 2 deletions src/icon-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ var IconButton = React.createClass({
}

if (this.props.iconClassName) {
var { iconHoverStyle, ...iconStyle } = this.props.iconStyle;

fonticon = (
<FontIcon
className={this.props.iconClassName}
className={this.props.iconClassName}
hoverStyle={this.mergeAndPrefix(iconHoverStyle)}
style={this.mergeAndPrefix(
styles.icon,
this.props.disabled && styles.iconWhenDisabled,
this.props.iconStyle
iconStyle
)}/>
);
}
Expand Down

0 comments on commit a40a430

Please sign in to comment.