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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8c82481
init theme-style-overrides
siriwatknp Apr 29, 2024
ded1462
fix MemberExpression case
siriwatknp Apr 22, 2024
149d475
update styled-v6
siriwatknp Apr 29, 2024
a736393
move logic to util
siriwatknp Apr 29, 2024
8000a56
apply migrateToVariant
siriwatknp Apr 29, 2024
473266d
add test case
siriwatknp Apr 29, 2024
2f42458
migrate landing page theme
siriwatknp Apr 29, 2024
3c62047
migrate checkout theme
siriwatknp Apr 29, 2024
ca60151
migrate sign-in theme
siriwatknp Apr 29, 2024
ad6a748
migrate sign-in side theme
siriwatknp Apr 29, 2024
587dbfd
migrate sign-up theme
siriwatknp Apr 29, 2024
ae08d4e
add readme
siriwatknp Apr 29, 2024
6696bf9
rename to theme-v6
siriwatknp Apr 29, 2024
a6853ae
move theme variants to root slot
siriwatknp Apr 29, 2024
d6bd25f
Revert "migrate landing page theme"
siriwatknp Apr 29, 2024
3359383
Revert "migrate checkout theme"
siriwatknp Apr 29, 2024
04dac56
Revert "migrate sign-in theme"
siriwatknp Apr 29, 2024
7e040d8
Revert "migrate sign-in side theme"
siriwatknp Apr 29, 2024
453b4ef
Revert "migrate sign-up theme"
siriwatknp Apr 29, 2024
9d939a7
migrate checkout theme
siriwatknp Apr 29, 2024
f0e79d3
migrate landing page theme
siriwatknp Apr 29, 2024
50be466
migrate sign in theme
siriwatknp Apr 29, 2024
ff2a5c4
migrate sign-in-side them
siriwatknp Apr 29, 2024
9660dd4
migrate sign-up theme
siriwatknp Apr 29, 2024
080c381
run prettier
siriwatknp Apr 30, 2024
615d338
Merge matching props (dark styles)
zanivan Apr 30, 2024
3d906e1
Run docs:typescript:formatted
zanivan Apr 30, 2024
a2c0967
Merge branch 'codemod/theme-sx' of https://github.com/siriwatknp/mate…
zanivan Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
383 changes: 224 additions & 159 deletions docs/data/material/getting-started/templates/checkout/getCheckoutTheme.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

360 changes: 209 additions & 151 deletions docs/data/material/getting-started/templates/landing-page/getLPTheme.js

Large diffs are not rendered by default.

360 changes: 209 additions & 151 deletions docs/data/material/getting-started/templates/landing-page/getLPTheme.tsx

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

352 changes: 205 additions & 147 deletions docs/data/material/getting-started/templates/sign-in/getSignInTheme.js

Large diffs are not rendered by default.

352 changes: 205 additions & 147 deletions docs/data/material/getting-started/templates/sign-in/getSignInTheme.tsx

Large diffs are not rendered by default.

352 changes: 205 additions & 147 deletions docs/data/material/getting-started/templates/sign-up/getSignUpTheme.js

Large diffs are not rendered by default.

352 changes: 205 additions & 147 deletions docs/data/material/getting-started/templates/sign-up/getSignUpTheme.tsx

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,74 @@ npx @mui/codemod@next deprecations/step-connector-classes <path>

### v6.0.0

#### `theme-v6`

```bash
npx @mui/codemod@next v6.0.0/theme-v6 <path>
```

Update the theme creation from `@mui/system@v5` to be compatible with `@pigment-css/react`.

- replace palette mode conditional with `theme.applyStyles()`
- replace `ownerState` with `variants`
- move theme variants to the root slot

```diff
createTheme({
components: {
MuiButton: {
- variants: [
- {
- props: { color: 'primary' },
- style: {
- color: 'red',
- },
- },
- ],
styleOverrides: {
- root: ({ theme, ownerState }) => ({
+ root: ({ theme }) => ({
...ownerState.variant === 'contained' && {
backgroundColor: alpha(theme.palette.primary.main, 0.8),
...theme.palette.mode === 'dark' && {
backgroundColor: alpha(theme.palette.primary.light, 0.9),
}
},
+ variants: [
+ {
+ prop: { variant: 'contained' },
+ style: {
+ backgroundColor: alpha(theme.palette.primary.main, 0.8),
+ },
+ },
+ {
+ prop: { variant: 'contained' },
+ style: {
+ ...theme.applyStyles('dark', {
+ backgroundColor: alpha(theme.palette.primary.light, 0.9),
+ })
+ },
+ },
+ {
+ prop: { color: 'primary' },
+ style: {
+ color: 'red',
+ },
+ },
+ ],
})
}
}
}
})
```

#### `styled-v6`

```bash
npx @mui/codemod@next v6.0.0/styled-v6 <path>
```

Updates the usage of `styled` from `@mui/system@v5` to be compatible with `@pigment-css/react`.

This codemod transforms the styles based on props to `variants` by looking for `styled` calls:
Expand Down
14 changes: 14 additions & 0 deletions packages/mui-codemod/src/util/getReturnExpression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {import('ast-types').namedTypes.ArrowFunctionExpression | import('ast-types').namedTypes.FunctionExpression} node
*/
export default function getReturnExpression(node) {
let body = node.body;
if (body === 'BlockStatement') {
body = body.body;
}

if (Array.isArray(body)) {
return body.find((statement) => statement.type === 'ReturnStatement')?.argument;
}
return body;
}