-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Customizing the color of a raised button is way too complex #10010
Comments
I agree! |
The reason that isn't currently possible is the very same reason the Each of the I believe JSS has some developments in this regard, so never say never. |
When I said "I agree" I was referring to the opportunity we have to make override simpler. I wasn't backing any specific implementation. There are some areas I want to look into:
|
I may have missed something, but why not wrap your custom red button component in a |
@ianschmitz I thought about that too, but I'm weary of performance. @oliviertassinari couldn't it do something like what https://typestyle.github.io/#/core/-style- does? they basically generate a css class based on some style and with a class name which is the hash of the style. If the class is effectively the same (same attributes) then the same class is reused since the hash is the same. That basically allows you to keep using classes while using styles. |
I'd be interested to hear more of the potential performance issues. It's a recommended pattern based on the docs (i use this extensively on work project). Here is a simplified example: const customTheme = outerTheme => ({
...outerTheme,
palette: {
...outerTheme.palette,
primary: red,
},
});
const Button = () => (
<MuiThemeProvider theme={customTheme}>
<Button color="primary">Custom Primary</Button>
</MuiThemeProvider>
); |
I have a similar issue. The default color/backgroundcolor of the when focused is #304ffe. What is the best solution for this? Thank you |
Thanks @ianschmitz i have made my own Textfield now.
|
const customTheme = outerTheme => ({
...outerTheme,
palette: {
...outerTheme.palette,
primary: red,
},
});
const Button = () => (
<MuiThemeProvider theme={customTheme}>
<Button color="primary">Custom Primary</Button>
</MuiThemeProvider>
); @ianschmitz The performance implications of this approach is deeply linked to the JSS work needed behind the scene. The main point: We cache the injected CSS with the following tuple (
It should be fast enough for most of the use cases, but to be cautious. I will document it. |
How come this is closed? There is still no way to change the color and this does not work: const customTheme = outerTheme => ({
...outerTheme,
palette: {
...outerTheme.palette,
primary: red,
},
}); Error: index.js:2178 Warning: Material-UI: missing color argument in fade(undefined, 0.12). |
@joesanta555 I have added 2 examples in the docs: https://github.com/mui-org/material-ui/blob/faf1ead52970e2b1d4adafed8dc69aaa625c5763/docs/src/pages/demos/buttons/CustomizedButtons.js |
Thank you. I read the closed issues before and could not find the 2 examples. Finally a nice way of doing it 🎉 🎈 Thank you again for this |
This is why I think the JSS/CSS-Modules solution is way overboard. I understand why you did it, but there are a lot of cases where it adds way more overhead than it is worth. Honestly, I would love to be able to disable it altogether. This problem is losing me and my clients money as we speak... |
My ultimate dream would be to use css-modules with some theming solution like |
@robbyemmert why dont u like css-modules? :) |
@robbyemmert From an architectural point of view, it should be possible to disable it and extract global CSS. But it would require a bit of effort. What's your issue? Have you seen https://material-ui.com/guides/interoperability/ or https://material-ui.com/customization/themes/#customizing-all-instances-of-a-component-type? @klis87 We are looking into CSS variables support in #12827. We gonna try to follow the community with the most popular styling solutions. |
@oliviertassinari that's fantastic news, can't wait for this! |
I agree that changing button colors is too complex. I want to avoid nesting themes due to performance issues so I've made this custom button component, but I'm not sure if this would have even worse performance issues. I'd love some feedback on it. It works fine and allows me to set any color for any button variants (i.e. either Here's the code:
|
Do you have an example that we could profile? I'm not aware of noticeable performance implications when nesting themes. |
This is more a rant than a real issue really.
I used to have 4 colors for raised buttons: default - gray, primary - blue, secondary - green, contrast - red
Due to the recent change to the palette that removed the contrast color from I embarked into the task of making an additional custom red button and this is what I ended up with:
My first rant is about having to opt-in and out of classes depending on if the button is disabled or not.
If I don't do this then, since the generated classes have more priority than the default ones then the disabled styles are never applied.
Wouldn't it make more sense to make a deep merge of the current theme classes (including overrides) with the custom ones and then create class names based on that merge so that disabled overrides are not lost?
The second rant is about how overly complex this all seems. Couldn't there be something like this instead?
each of those properties would default to undefined, meaning no customization applied and therefore the API is backwards compatible
There's not so much of a problem with IconButton for example, since you can just use something like
still though it is funny how you have to be careful with not setting the color when disabled, so there could be something like icon, disabledIcon and ripple inside colorOverrides
And same thing about checkbox, etc.
Just my two cents 😄
The text was updated successfully, but these errors were encountered: