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

Migrating CSS variables in mui/material version 5 to using the OOB way of CSS variables in version 6 #44251

Closed
noobDev31 opened this issue Oct 29, 2024 · 6 comments
Labels
support: Stack Overflow Please ask the community on Stack Overflow v6.x migration

Comments

@noobDev31
Copy link

noobDev31 commented Oct 29, 2024

What's the problem?

I am trying to migrate our way of doing css variables with theme in V5 to use the newer way of CSS variables in V6.
I am having the following themeProvider config which uses the css variables how can i utilises the new css theme variable flag to maintain my functionality

https://stackblitz.com/edit/react-sbuu88?file=ThemeProvider.tsx,Demo.tsx,ThemeProvider.config.ts,coreBadge.ts,coreAlert.ts,coreAutocomplete.ts,dsmConfig.ts,coreAppBar.ts,tsconfig.json,index.html

What are the requirements?

Want to use the best practises on the Material UI V6 for utilizing the css theme variables

What are our options?

No response

Proposed solution

No response

Resources and benchmarks

No response

Search keywords:

@noobDev31 noobDev31 added RFC Request For Comments status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 29, 2024
@noobDev31
Copy link
Author

noobDev31 commented Oct 29, 2024

Also if you see coreAutoComplete.ts on line 160 i start to get errors like these -

image

Any particular best way that I can avoid them because the theme variables are mostly Record<string, string>?

@mj12albert mj12albert removed the RFC Request For Comments label Oct 29, 2024
@mj12albert mj12albert changed the title [RFC] Migrating CSS variables in mui/material version 5 to using the OOB way of CSS variables in version 6 Migrating CSS variables in mui/material version 5 to using the OOB way of CSS variables in version 6 Oct 29, 2024
@mj12albert
Copy link
Member

Want to use the best practises on the Material UI V6 for utilizing the css theme variables

Generally, the best practice is just to follow the docs 😅 :

@mj12albert
Copy link
Member

Also if you see coreAutoComplete.ts on line 160 i start to get errors like these -

Sorry there's a lot of other stuff in your stackblitz, would you mind making a minimal repro? (here are some tips) @noobDev31

@mj12albert mj12albert added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 29, 2024
@noobDev31
Copy link
Author

noobDev31 commented Oct 29, 2024

Also if you see coreAutoComplete.ts on line 160 i start to get errors like these -

Sorry there's a lot of other stuff in your stackblitz, would you mind making a minimal repro? (here are some tips) @noobDev31

https://stackblitz.com/edit/react-sbuu88?file=ThemeProvider.tsx,Demo.tsx,ThemeProvider.config.ts,coreAutocomplete.ts,dsmConfig.ts,tsconfig.json,index.html

Do you think the above is a bit more minimal than before? (Please read the comment on line 21 to 24 of coreAutocomplete.ts)
The problem is that the dsmConfig for the colors is a type of Record<string, string> , but the theme interface on MUI usually expects a certain color from the palette so that's why the error comes up

Do you think i should create my own definition of Theme but I am not sure how that is possible with the module augmentation logic for different special colors that MUI recommends.

That's why i specifically asked about the theme css variables because that's what is causing me like more than 100 errors in a lot of components.

if you have any further questions feel free to ask about the code above 😄

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Oct 29, 2024
@mj12albert
Copy link
Member

OK I don't think this is an issue with Material UI, but my opinionated take is that this whole DSMconfig thing in your sandbox is a bit over-complicated/over-engineered.

Per your comment here, this is not a good way to fix it, but if you go down this route I don't see how it can be avoided

// so basically here if I do
      //    let backgroundColor = `${
      //      (theme.palette?.[DSMConfig.autocompleteSelectedColor as keyof Palette] as PaletteColor)?.main
      //    }`;
      // this fixes the below issue but its not a good way to fix it.
      let backgroundColor = `${
        theme.palette?.[DSMConfig.autocompleteSelectedColor]?.main
      }`;

@mj12albert mj12albert added support: Stack Overflow Please ask the community on Stack Overflow and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 30, 2024
Copy link

👋 Thanks for using this project!

We use GitHub issues exclusively as a bug and feature requests tracker, however, this issue appears to be a support request.

For support with Material UI please check out https://mui.com/material-ui/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: Stack Overflow Please ask the community on Stack Overflow v6.x migration
Projects
None yet
Development

No branches or pull requests

2 participants