Skip to content

Commit

Permalink
[codemod] Add theme-v6 migration (#42056)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed May 2, 2024
1 parent 450c4f6 commit 0824b98
Show file tree
Hide file tree
Showing 23 changed files with 4,233 additions and 2,014 deletions.
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 @@ -1099,8 +1099,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;
}

0 comments on commit 0824b98

Please sign in to comment.