Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FontIcon] Remove style-propable mixin #3230

Merged
merged 1 commit into from
Feb 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions src/font-icon.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import React from 'react';
import StylePropable from './mixins/style-propable';
import Transitions from './styles/transitions';
import getMuiTheme from './styles/getMuiTheme';

function getStyles(props, state) {
const {
color,
hoverColor,
} = props;

const {
baseTheme,
} = state.muiTheme;

const offColor = color || baseTheme.palette.textColor;
const onColor = hoverColor || offColor;

return {
root: {
color: state.hovered ? onColor : offColor,
position: 'relative',
fontSize: baseTheme.spacing.iconSize,
display: 'inline-block',
userSelect: 'none',
transition: Transitions.easeOut(),
},
};
}


const FontIcon = React.createClass({

propTypes: {
Expand Down Expand Up @@ -37,15 +62,10 @@ const FontIcon = React.createClass({
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

mixins: [
StylePropable,
],

getDefaultProps() {
return {
onMouseEnter: () => {},
Expand All @@ -66,11 +86,10 @@ const FontIcon = React.createClass({
};
},

//to update theme inside state whenever a new theme is passed down
//from the parent / owner using context
componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
this.setState({
muiTheme: nextContext.muiTheme || this.state.muiTheme,
});
},

_handleMouseLeave(e) {
Expand All @@ -93,36 +112,24 @@ const FontIcon = React.createClass({

render() {
let {
color,
hoverColor,
onMouseLeave,
onMouseEnter,
style,
...other,
} = this.props;

let spacing = this.state.muiTheme.rawTheme.spacing;
let offColor = color ? color :
style && style.color ? style.color :
this.state.muiTheme.rawTheme.palette.textColor;
let onColor = hoverColor ? hoverColor : offColor;
const {
prepareStyles,
} = this.state.muiTheme;

let mergedStyles = this.mergeStyles({
position: 'relative',
fontSize: spacing.iconSize,
display: 'inline-block',
userSelect: 'none',
transition: Transitions.easeOut(),
}, style, {
color: this.state.hovered ? onColor : offColor,
});
const styles = getStyles(this.props, this.state);

return (
<span
{...other}
onMouseLeave={this._handleMouseLeave}
onMouseEnter={this._handleMouseEnter}
style={this.prepareStyles(mergedStyles)}
style={prepareStyles(Object.assign(styles.root, style))}
/>
);
},
Expand Down