-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
How to change the style of components dynamically? #7408
Comments
@dsslimshaddy This is the solution we are using for implementing our components. Here are a scope of the possibilities:
|
I think the JSS support rule' properties as function ( It will make customizing lot easier. |
@oliviertassinari , @dsslimshaddy is right. Material UI v1 depends on react-jss 7.0.2 which is the latest version of react-jss. It should support However, this doesn't seem to work? |
@ConneXNL Material-UI isn't directly using react-jss. The dynamic properties haven't been implemented by lack of time. Users can always use |
Ah I see ;) Do you have an example of how to mix react-jss with the MuiThemes or is not that easy? |
@ConneXNL I have never tried. |
I just wrapped createMuiTheme: const createDynamicMuiTheme = (color) => {
return createMuiTheme({
overrides: {
MuiInput: {
inkbar: {
'&:after': {
backgroundColor: color
}
},
},
},
});
}; But this is probably bad for performance? |
@ConneXNL Updating the theme rerender the whole tree. That's no something that should be done frequentely. |
<MuiThemeProvider theme={createDynamicMuiTheme(color)}>
<TextField/>
</MuiThemeProvider> I did wrap the textfield with the Provider or am i now injecting the entire css tree multiple times ? :) Are the dynamic props scheduled for Version 1 though? I am having to do all of this just to use the removed funtionality of |
@ConneXNL Your solution shouldn't suffer from performance issue given the children tree is small.
This won't block the release of v1. But that can always be added along the way. |
@ConneXNL I know it's a closed issue, but for anyone stumbling across this, to use react-jss with material-ui, all you have to do is replace material-ui's |
@JM-Mendez We have move the conversation to #7633 |
@oliviertassinari, the point of @dsslimshaddy is a good way to solve that problem but another approach is implement a property that modifies the property of a inner component, in this case, you could implement an property called barProps and using this you could use the property style to modify the style of the inner element:
|
https://www.webpackbin.com/bins/-Kon08wq7y0PT-JC4ufF
This is my current code. Since the stylesheet is static there is no way I can pass props to objects inside it. So my current approach is to use some defined classes like.
and do this
call using
It's not perfect, it's not even good I think but I would like to know what are the possibilities?
The text was updated successfully, but these errors were encountered: