Skip to content

[codemod] Support dynamic props styled transformation#42683

Merged
siriwatknp merged 3 commits intomui:nextfrom
siriwatknp:fix/styled-codemod
Jun 20, 2024
Merged

[codemod] Support dynamic props styled transformation#42683
siriwatknp merged 3 commits intomui:nextfrom
siriwatknp:fix/styled-codemod

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
joserodolfofreitas pushed a commit to joserodolfofreitas/material-ui that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants