-
-
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
[RFC] Consolidate component theming into a one API (aka styleOverrides
)
#30412
Comments
Agree with the API. If we update the types for Then, in v6 we can drop the other keys and provide codemod for each key in the components (this is the most important part). We want to make v6 easy for adoption after making that many breaking changes in v5. |
Just because I was playing with the API intended to be deprecated the other day and for me to learn as well: if I only want to override styles of the small size variant, how would I do that, given that |
You can look up the props via a callback. {
MuiButton: {
styleOverrides: {
root: (props) => ({
...props.size === 'small' && { ... }
}),
}
}
} |
Got it. Thanks, Jun! Must say though that just from a first glance perspective, it looks more complex than using the |
Hi, I didn't want to create a new issue without knowing if I am doing something wrong. The styleOverrides does not work. https://codesandbox.io/s/globalthemeoverride-material-demo-forked-srvfc?file=/demo.tsx Am I doing something wrong? |
One reason might be the familiarity of the existing API (
I also wonder once we deprecated all the classes, how much bundle size will decrease. |
Right, thanks for the explanation! I believe it's a great idea to add this reasoning to the documentation when explaining the changes :) |
Hi, just a very happy MUI user with a quick clarifying question on this set of changes so we can plan our migration: Is the For example, will this continue to work (works now, in v5.3.0): declare module '@mui/material/Button' {
interface ButtonPropsVariantOverrides {
customVariant: true;
}
}
const theme = createTheme({
MuiButton: {
styleOverrides: {
root: ({ ownerState }) => ({
...(ownerState.variant === 'customVariant' && { ... })
}),
}
}
}); |
No worries, the |
@siriwatknp From my perspective, this is not the reality of what happened. It was not about JSS. The introduction of the variant API: #15573, #21749. But I also realize that these issues don't cover the point I'm going to detail: static definition. #21648 might be the most insightful on the history, with the different options that we considered. From my perspective, the key selling point of the variant API is that the resolution is static. In practice, the variant API allows:
👍 I think that it could be an issue on its own as we already talked about doing it somewhere, explaining in detail the pain and the gain. I believe the why is about:
It's not obvious to me that it should be. One option could be to frame styleOverrides and variants for two distinct use cases, encouraging the latter, and using the former as an escape hatch. |
On point 2. see the feedback about TypeScript in https://engineering.udacity.com/choosing-the-right-component-library-for-your-design-system-mui-vs-chakra-45c4c949d150. |
@oliviertassinari You mentioned To be transparent, while asking this, I don't think the replacement is even possible not mentioning the effort, but I'm just in hopes MUI team considers to have styles without a runtime (plain css for better performance).
|
We initially envisioned being able to create a wrapper for any CSS in JS solution, like the ones we have for emotion & styled components, |
As I understand it, moving forward with this plan would solve #38544 for free, and help a bit with performance. Each styled component wouldn't need to resolve all the theme.components.NAME.styleOverrides values. |
Would it make sense to extend the variants theming feature towards a more similar approach as styleOverrides ? To me it feels like the variants theming feature is missing a lot . It would be awesome to have something like that: // ...
MuiCard: {
variants: [
{
props: { variant: 'newOne' },
styleOverrides: {
// ...
}
]
}
// ... What is also a bit confusing to me is the fact, that we do not get the scoped theme in the current variants style function. Therefore we have to use something like that: // ...
MuiCard: {
variants: [
{
props: { variant: 'newOne' },
style: ({ theme }) => {
return {
color: theme[THEME_ID].palette.secondary.main,
};
}
]
}
// ... |
I would like to open the discussion again since we added This makes the
|
As discussed in #28107 (comment), there are 2 current APIs that provide component theming.-styleOverrides
-variants
A quick history of why there are 2 APIs: In v4,styleOverrides
is not able to support dynamic props via callback due to the limitation of JSS. That's when we introduce another API (variants
) to inject a specified style when a set of props is matched. However, it causes some confusion with the componentvariant
prop (ex. #29455) and exposes new syntax but has limitations because it cannot create matching props like this (variant === 'filled' && color !== 'success'
).If we step back, we will see that both of the APIs are trying to provide the same thing, component theming. Fortunately, in MUI v5, thestyleOverrides
supports callback thanks to emotion & styled-components so it is worth to dropvariants
and expose only one theming API.For history, @oliviertassinari explain in #30412 (comment)
Here are all the requirements that
styleOverrides
can/should support:classes
that can be used to target each prop)theme.unstable_sx
utility!Deprecation
styleOverrides
should contain only slot keys and deprecate all classes because those can be done by using callback. eg: for Button, the styleOverrides should be(We don't plan to deprecatevariants
should be deprecated.variants
at this moment)Plan
I think it is possible to aim for NO breaking change, but some deprecations are expected. We can try to create codemod that helps migrate the deprecation.
✅ 1st PR #30524
styleOverrides
support callback (only for slot keys)deprecaterevertedvariants
themeing feature2nd PR
styleOverrides
to callbackmigrate(We don't plan to deprecatevariants
to styleOverrides callbackvariants
at this moment)✅ 3rd PR
In the end, we can close #22259, #27415 and #28107
cc @mui-org/core
The text was updated successfully, but these errors were encountered: