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

[Button] Remove style-propable mixin from flat-button-label #3197

Merged
merged 1 commit into from
Feb 6, 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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 We should get rid of this ContextPure too.

});
},

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;