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

[material-ui] Refactor ComponentsVariants type into a generic #39623

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

blakenetz
Copy link
Contributor

@blakenetz blakenetz commented Oct 26, 2023

Refactored ComponentsVariants type to accept a Theme parameter. Doing so makes the ComponentsVariants type share the same signature as the generic ComponentsOverrides type. Since both types are used when overriding a component's style, the callback functions should be identical.

The primary use case is for consumers, like myself, who use a custom Theme interface. We do this through augmenting the createTheme module, which works fine, except for this one instance. The current implementation type-checks the theme parameter correctly in the styleOverrides property, but not in the variants property. Here is an example that might better explain this:

styleOverrides: {
   // Here `theme` is typecasted by the argument passed to the Components interface  
   root: ({ theme }) => { ... },
},
variants: [{
   props: { ... },
   // but here the `theme` is always `Theme`
   styles: ({ theme }) => { ... },
}]

I should also note that the ComponentsVariants and ComponentsOverrides types are only used in the Components interface (also a generic with a Theme param), so this is a low-risk change imho.

…arameter. This change follows the paradigm defined in the ComponentsOverrides interface.
@mui-bot
Copy link

mui-bot commented Oct 26, 2023

Netlify deploy preview

https://deploy-preview-39623--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against e3beef9

@blakenetz blakenetz changed the title Ts components variants generics [mui-material][ComponentsVariants] Refactor ComponentsVariants type into a generic Oct 26, 2023
@blakenetz blakenetz force-pushed the ts-componentsVariants-generics branch from aa8974d to e3beef9 Compare October 26, 2023 17:24
@danilo-leal danilo-leal changed the title [mui-material][ComponentsVariants] Refactor ComponentsVariants type into a generic [material-ui] Refactor ComponentsVariants type into a generic Oct 27, 2023
@danilo-leal danilo-leal added typescript package: material-ui Specific to @mui/material labels Oct 27, 2023
@mnajdova mnajdova requested review from brijeshb42 and removed request for mj12albert November 8, 2023 11:19
@blake-discover
Copy link

@mnajdova, @mj12albert
Is there anything y'all need from me to move this PR forward? Anything I can expand on or clarify?

@danilo-leal danilo-leal merged commit 363a9a6 into mui:master Dec 11, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants