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] Add PropsProvider for Pigment CSS integration #42635

Closed
siriwatknp opened this issue Jun 13, 2024 · 1 comment · Fixed by #42638
Closed

[material-ui] Add PropsProvider for Pigment CSS integration #42635

siriwatknp opened this issue Jun 13, 2024 · 1 comment · Fixed by #42638
Assignees
Labels
enhancement This is not a bug, nor a new feature v6.x migration

Comments

@siriwatknp
Copy link
Member

siriwatknp commented Jun 13, 2024

Context

The current approach for customizing Material UI component's default props is using the theme.components.*.defaultProps through React context.

For Pigment CSS, it's not possible to use React Component inside the theme because of build-time extraction.

Solution

Extract the defaultProps to another context, PropsProvider, so that users can customize the default props of Material UI components with Pigment CSS.

How's it look like

  1. Before or After migration to v6: no changes required, the defaultProps that pass to the theme will propagate to PropsProvider automatically.

  2. Transitioned to Pigment CSS while having Emotion: no changes required as well, as long as the ThemeProvider is used on the client.

  3. Pigment CSS without Emotion: users need to import PropsProvider from Pigment CSS and pass thetheme.components

    import PropsProvider from '@mui/material/PropsProvider';
    
    <PropsProvider
      value={{
        // copied from the existing theme.components
        MuiButton: { defaultProps: { disableRipple: true } },
        MuiSelect: { defaultProps: { IconComponent: CustomIcon } },
      }}>
      {children}
    </PropsProvider>

    Finally, Emotion can be removed.

Search keywords:

@siriwatknp siriwatknp added enhancement This is not a bug, nor a new feature v6.x migration labels Jun 13, 2024
@siriwatknp siriwatknp added this to the Material UI: v6 milestone Jun 13, 2024
@siriwatknp siriwatknp self-assigned this Jun 13, 2024
@siriwatknp siriwatknp moved this to In progress in Material UI Jun 13, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Material UI Jun 20, 2024
@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 7, 2024

For Pigment CSS, it's not possible to use React Component inside the theme because of build-time extraction.

It's still not clear to me that this is true. We didn't explore #42476 (comment)? The way Yak makes it work doesn't seem to even need the React.cache API, using a global does the same thing, since as I understand it, there no theme nesting support in Pigment CSS: https://yak.js.org/how-does-it-work#the-runtime-part.

I'm connecting the same dots with #43443. It would make sense to me to remove the <DefaultPropsProvider> API, we need this too for server components. Issue updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature v6.x migration
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants