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 · 0 comments · Fixed by #42638
Closed

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

siriwatknp opened this issue Jun 13, 2024 · 0 comments · 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:

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.

1 participant