Skip to content

Commit a99451a

Browse files
committed
Remove style-propable from font-icon
1 parent 484f038 commit a99451a

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

src/font-icon.jsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
import React from 'react';
2-
import StylePropable from './mixins/style-propable';
32
import Transitions from './styles/transitions';
43
import getMuiTheme from './styles/getMuiTheme';
54

5+
function getStyles(props, state) {
6+
const {
7+
color,
8+
hoverColor,
9+
} = props;
10+
11+
const {
12+
baseTheme,
13+
} = state.muiTheme;
14+
15+
const offColor = color || baseTheme.palette.textColor;
16+
const onColor = hoverColor || offColor;
17+
18+
return {
19+
root: {
20+
color: state.hovered ? onColor : offColor,
21+
position: 'relative',
22+
fontSize: baseTheme.spacing.iconSize,
23+
display: 'inline-block',
24+
userSelect: 'none',
25+
transition: Transitions.easeOut(),
26+
},
27+
};
28+
}
29+
30+
631
const FontIcon = React.createClass({
732

833
propTypes: {
@@ -37,15 +62,10 @@ const FontIcon = React.createClass({
3762
muiTheme: React.PropTypes.object,
3863
},
3964

40-
//for passing default theme context to children
4165
childContextTypes: {
4266
muiTheme: React.PropTypes.object,
4367
},
4468

45-
mixins: [
46-
StylePropable,
47-
],
48-
4969
getDefaultProps() {
5070
return {
5171
onMouseEnter: () => {},
@@ -66,11 +86,10 @@ const FontIcon = React.createClass({
6686
};
6787
},
6888

69-
//to update theme inside state whenever a new theme is passed down
70-
//from the parent / owner using context
7189
componentWillReceiveProps(nextProps, nextContext) {
72-
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
73-
this.setState({muiTheme: newMuiTheme});
90+
this.setState({
91+
muiTheme: nextContext.muiTheme || this.state.muiTheme,
92+
});
7493
},
7594

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

94113
render() {
95114
let {
96-
color,
97-
hoverColor,
98115
onMouseLeave,
99116
onMouseEnter,
100117
style,
101118
...other,
102119
} = this.props;
103120

104-
let spacing = this.state.muiTheme.rawTheme.spacing;
105-
let offColor = color ? color :
106-
style && style.color ? style.color :
107-
this.state.muiTheme.rawTheme.palette.textColor;
108-
let onColor = hoverColor ? hoverColor : offColor;
121+
const {
122+
prepareStyles,
123+
} = this.state.muiTheme;
109124

110-
let mergedStyles = this.mergeStyles({
111-
position: 'relative',
112-
fontSize: spacing.iconSize,
113-
display: 'inline-block',
114-
userSelect: 'none',
115-
transition: Transitions.easeOut(),
116-
}, style, {
117-
color: this.state.hovered ? onColor : offColor,
118-
});
125+
const styles = getStyles(this.props, this.state);
119126

120127
return (
121128
<span
122129
{...other}
123130
onMouseLeave={this._handleMouseLeave}
124131
onMouseEnter={this._handleMouseEnter}
125-
style={this.prepareStyles(mergedStyles)}
132+
style={prepareStyles(Object.assign(styles.root, style))}
126133
/>
127134
);
128135
},

0 commit comments

Comments
 (0)