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] Add theme-v6 migration #42056

Merged
merged 28 commits into from May 2, 2024
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Apr 29, 2024

Most of the code comes from #41743 because the style conversion is the same.

Templates: https://deploy-preview-42056--material-ui.netlify.app/material-ui/getting-started/templates/
Docs: https://github.com/siriwatknp/material-ui/tree/codemod/theme-sx/packages/mui-codemod#theme-v6

Tested by transforming all the template themes.

@siriwatknp siriwatknp added the package: codemod Specific to @mui/codemod label Apr 29, 2024
@mui-bot
Copy link

mui-bot commented Apr 29, 2024

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against a2c0967

Copy link
Contributor

@zanivan zanivan left a comment

Choose a reason for hiding this comment

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

Design-wise, it looks good! I have a question, though, and it's not exactly related to the codemod:

As I see, currently, to add custom light/dark styles we should do something like this:

              // light
              {
                props: {
                  color: 'secondary',
                  variant: 'outlined',
                },
                style: {
                    color: gray[900],
                },
              },

              // dark
              {
                props: {
                  color: 'secondary',
                  variant: 'outlined',
                },
                style: {
                  ...theme.applyStyles('dark', {
                    color: gray[300],
                  }),
                },
              },

Is it possible to have something like this instead?

              // light
              {
                props: {
                  color: 'secondary',
                  variant: 'outlined',
                },
                style: {
                    color: gray[900],
                  ...theme.applyStyles('dark', {
                    color: gray[300],
                  }),
                },
              },

IMHO it would be easier to organize and reduce some lines of code.


On a different note, we're working on the Dashboard template right now, and the idea is to have it ready for the React Conf. Should we migrate the theme there too? cc @noraleonte

@brijeshb42
Copy link
Contributor

brijeshb42 commented Apr 30, 2024

@zanivan Yes. What you have proposed is already possible. It might be a limitation on the codemod side that the output is like that. But if you are writing the variants manually, you can do the above.

@siriwatknp
Copy link
Member Author

Is it possible to have something like this instead?

Good point. I'd say it's good to have because matching the props and merging the styles with codemod is a lot of work (for sure it can be done). I will improve it when I have time but at least it works at the moment.

Comment on lines +19 to +24
if (path.parent.parent.parent.get('key', 'name').value === 'styleOverrides') {
args = [path.node];
}

// 1. collecting styles that should be tranformed
args.forEach((arg) => {
Copy link
Member

Choose a reason for hiding this comment

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

args always has one element, right? Why turn it into an array? Was the original intent to collect all nodes first?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't review this in-depth (it's a huge one, and reading large codemod code is confusing 😅), but I assume this is just extracting the previous code into a function, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't review this in-depth

I would not recommend either. Checking the test cases should be enough.

@zanivan
Copy link
Contributor

zanivan commented Apr 30, 2024

@zanivan Yes. What you have proposed is already possible. It might be a limitation on the codemod side that the output is like that. But if you are writing the variants manually, you can do the above.

Since it was an issue with the codemod, I went ahead and merged the duplicated props—there weren't so many, actually. Let me know if that's ok, or if anything needs to be corrected

@siriwatknp siriwatknp merged commit 0824b98 into mui:next May 2, 2024
22 checks passed
const transformed = root.toSource(printOptions);

if (shouldTransform) {
// recast adds extra newlines that we don't want, https://github.com/facebook/jscodeshift/issues/249

Choose a reason for hiding this comment

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

@ElonVolo fyi.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants