From a99451a4d6d7f20457cdbd16ea5668080eb72bbf Mon Sep 17 00:00:00 2001 From: Neil Gabbadon Date: Sun, 7 Feb 2016 20:39:58 -0500 Subject: [PATCH] Remove style-propable from font-icon --- src/font-icon.jsx | 61 ++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/font-icon.jsx b/src/font-icon.jsx index 56de059e2a6548..bf1fc5229ae36a 100644 --- a/src/font-icon.jsx +++ b/src/font-icon.jsx @@ -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: { @@ -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: () => {}, @@ -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) { @@ -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 ( ); },