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

[codemod] Support dynamic props styled transformation #42683

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jun 19, 2024

An improvement to cover #42675

  • dynamic props specified in the callback object (works with nested style)

    // before
    const DemoToolbarRoot = styled('div', {
     shouldForwardProp: (prop) => prop !== 'demoOptions' && prop !== 'openDemoSource',
    })(({ theme, demoOptions, openDemoSource }) => [
     {
       [theme.breakpoints.up('sm')]: {
         marginTop: demoOptions.bg === 'inline' ? theme.spacing(1) : -1,
         
         
    // after
    const DemoToolbarRoot = styled('div', {
     shouldForwardProp: (prop) => prop !== 'demoOptions' && prop !== 'openDemoSource',
    })(({ theme }) => [
     {
       [theme.breakpoints.up('sm')]: {
         marginTop: -1,
       },
       variants: [
         {
         props: ({ demoOptions }) => demoOptions.bg === 'inline',
           style: { marginTop: theme.spacing(1) }
         },
       ]
  • reduce the number of generated variants

    // before
    {
     marginTop: demoOptions.bg === 'inline' ? theme.spacing(1) : -1,
    }
    
    // after: create one new variant instead of two
    {
     marginTop: -1,
     variants: [
       {
       props: ({ demoOptions }) => demoOptions.bg === 'inline',
         style: { marginTop: theme.spacing(1) }
       },
     ]
    }

I suggest to review only the test case.


@mui-bot
Copy link

mui-bot commented Jun 19, 2024

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against df2deba

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests looks good 👍

@siriwatknp siriwatknp merged commit 3c67e7a into mui:next Jun 20, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: codemod Specific to @mui/codemod v6.x migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants