Skip to content

Commit

Permalink
Merge pull request #3197 from newoga/#2852/flat-button-label
Browse files Browse the repository at this point in the history
[Button] Remove style-propable mixin from flat-button-label
  • Loading branch information
oliviertassinari committed Feb 6, 2016
2 parents 6508dd4 + 927ce03 commit 53394d5
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/buttons/flat-button-label.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import React from 'react';
import ContextPure from '../mixins/context-pure';
import StylePropable from '../mixins/style-propable';
import getMuiTheme from '../styles/getMuiTheme';

function getStyles(props, state) {
const {
baseTheme,
} = state.muiTheme;

return {
root: {
position: 'relative',
paddingLeft: baseTheme.spacing.desktopGutterLess,
paddingRight: baseTheme.spacing.desktopGutterLess,
},
};
}

const FlatButtonLabel = React.createClass({

propTypes: {
Expand All @@ -18,14 +31,12 @@ const FlatButtonLabel = React.createClass({
muiTheme: React.PropTypes.object,
},

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

mixins: [
ContextPure,
StylePropable,
],

statics: {
Expand All @@ -48,11 +59,10 @@ const FlatButtonLabel = 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 || nextContext.muiTheme,
});
},

render: function() {
Expand All @@ -61,19 +71,16 @@ const FlatButtonLabel = React.createClass({
style,
} = this.props;

const contextKeys = this.constructor.getRelevantContextKeys(this.state.muiTheme);
const {
prepareStyles,
} = this.state.muiTheme;

const mergedRootStyles = this.mergeStyles({
position: 'relative',
paddingLeft: contextKeys.spacingDesktopGutterLess,
paddingRight: contextKeys.spacingDesktopGutterLess,
}, style);
const styles = getStyles(this.props, this.state);

return (
<span style={this.prepareStyles(mergedRootStyles)}>{label}</span>
<span style={prepareStyles(Object.assign(styles.root, style))}>{label}</span>
);
},

});

export default FlatButtonLabel;

0 comments on commit 53394d5

Please sign in to comment.