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
muiThemeProvider improvement: global style provider #6020
Comments
It can. Create a higher-order-component like this (this example uses import {PropTypes} from 'react'
import createHelper from 'recompose/createHelper'
import getContext from 'recompose/getContext'
const withMuiTheme = () => getContext({muiTheme: PropTypes.object.isRequired})
export default createHelper(withMuiTheme, 'withMuiTheme') Then simply wrap the component you want to get the theme in with this HOC. |
@PolGuixe You raise an important point. Should we apply a default style? I don't think that we should do it by default. That's quite intrusive. @clayne11 Is right, if your only concern is regarding how to access the |
Thanks @clayne11 and @oliviertassinari. Currently I am using a @oliviertassinari I agree with you that it shouldn't be by default. But it can be done in a way that it accepts the props to do it and the overhead for the people who don't need it is minimal. What do you think? |
I wouldn't mix concern. For instance, you had to add an additional On the import React, { PropTypes } from 'react';
import { createStyleSheet } from 'jss-theme-reactor';
import withStyles from 'material-ui/styles/withStyles';
const styleSheet = createStyleSheet('Main', (theme) => ({
root: {
fontFamily: theme.typography.fontFamily,
},
}));
const Main = (props) => {
return (
<div className={props.classes.root}>
{props.children}
</div>
);
};
Main.propTypes = {
children: PropTypes.node.isRequired,
classes: PropTypes.object.isRequired,
};
export default withStyles(styleSheet)(Main); Here is the equivalent on the import React, { PropTypes } from 'react';
import muiThemeable from 'material-ui/styles/muiThemeable';
const Main = (props) => {
const style = {
fontFamily: props.muiTheme.baseTheme.fontFamily,
}
return (
<div style={style}>
{props.children}
</div>
);
};
Main.propTypes = {
children: PropTypes.node.isRequired,
muiTheme: PropTypes.object.isRequired,
};
export default muiThemeable()(Main); That sounds simple enough. I'm wondering what the gain of abstracting that away. |
I don't really understand what you would be abstracting. It's already as simple as it can be IMO. |
@oliviertassinari I see. Are Currently I just require import React from 'react';
const getGlobalStyles = palette => ({
color: palette.textColor,
});
class GlobalStyleProvider extends React.PureComponent {
static contextTypes = {
muiTheme: React.PropTypes.object.isRequired,
}
render() {
const globalStyle = getGlobalStyles(this.context.muiTheme.palette);
return (
<div style={globalStyle}>
{this.props.children}
</div>
);
}
}
export default GlobalStyleProvider; I can't see |
@PolGuixe
It does change a lot. I have been talking about it. You can have a look at #4066. That's a long discussion. I'm closing this issue as I think we went down the rabbit hole 🐰 . |
It would be cool if the muiThemeProvider could apply a "global" style so other elements can inherit from it.
A good example is font color. So the muiTheme.palette.textColor can be inherited from other elements.
The text was updated successfully, but these errors were encountered: