-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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 jss to tss-react codemod #31802
Changes from all commits
3823dcd
430fc65
345f302
070ade2
113abbb
22bf666
6267946
c4ca5e3
8f6f5db
5c22b87
8723b10
1142657
c556b4b
05f5e93
f7e1474
94f3f80
814513e
a48db98
7ea397d
6fe7ccc
4cc5800
f159bcb
2ee9c61
5cb51af
d776428
95e1ac2
332ca88
a82261b
cdf74bc
32d2a39
d14da5e
38b4bfa
f7273a6
15fbd0d
ebc6a86
0d2f2c8
f84957c
a9f87f3
28c1703
dde9f3c
734d362
5096566
cbc8124
59b8a45
d625dc5
f20875f
5ce079c
264794f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,6 +605,88 @@ You can find more details about this breaking change in [the migration guide](ht | |
> **Note:** This approach converts the first element in the return statement into styled component but also increases CSS specificity to override nested children. | ||
> This codemod should be adopted after handling all breaking changes, [check out the migration documentation](https://mui.com/material-ui/guides/migration-v4/) | ||
|
||
#### `jss-to-tss-react` | ||
|
||
Migrate JSS styling with `makeStyles` or `withStyles` to the corresponding `tss-react` API. | ||
|
||
```diff | ||
-import clsx from 'clsx'; | ||
-import {makeStyles, createStyles} from '@material-ui/core/styles'; | ||
+import { makeStyles } from 'tss-react/mui'; | ||
|
||
-const useStyles = makeStyles((theme) => createStyles< | ||
ryancogswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 'root' | 'small' | 'child', {color: 'primary' | 'secondary', padding: number} | ||
-> | ||
-({ | ||
- root: ({color, padding}) => ({ | ||
+const useStyles = makeStyles<{color: 'primary' | 'secondary', padding: number}, 'child' | 'small'>({name: 'App'})((theme, { color, padding }, classes) => ({ | ||
ryancogswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ root: { | ||
padding: padding, | ||
- '&:hover $child': { | ||
+ [`&:hover .${classes.child}`]: { | ||
backgroundColor: theme.palette[color].main, | ||
} | ||
- }), | ||
+ }, | ||
small: {}, | ||
child: { | ||
border: '1px solid black', | ||
height: 50, | ||
- '&$small': { | ||
+ [`&.${classes.small}`]: { | ||
height: 30 | ||
} | ||
} | ||
-}), {name: 'App'}); | ||
+})); | ||
|
||
function App({classes: classesProp}: {classes?: any}) { | ||
ryancogswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- const classes = useStyles({color: 'primary', padding: 30, classes: classesProp}); | ||
+ const { classes, cx } = useStyles({ | ||
+ color: 'primary', | ||
+ padding: 30 | ||
+ }, { | ||
+ props: { | ||
+ classes: classesProp | ||
+ } | ||
+ }); | ||
ryancogswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div className={classes.root}> | ||
<div className={classes.child}> | ||
The Background take the primary theme color when the mouse hovers the parent. | ||
</div> | ||
- <div className={clsx(classes.child, classes.small)}> | ||
+ <div className={cx(classes.child, classes.small)}> | ||
The Background take the primary theme color when the mouse hovers the parent. | ||
I am smaller than the other child. | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; | ||
``` | ||
|
||
```sh | ||
npx @mui/codemod v5.0.0/jss-to-tss-react <path> | ||
``` | ||
|
||
The following scenarios are not currently handled by this codemod and will be marked with a | ||
"TODO jss-to-tss-react codemod" comment: | ||
|
||
- If the hook returned by `makeStyles` (e.g. `useStyles`) is exported and used in another file, | ||
the usages in other files will not be converted. | ||
- Arrow functions as the value for a CSS prop will not be converted. Arrow functions **are** | ||
supported at the rule level, though with some caveats listed below. | ||
- In order for arrow functions at the rule level to be converted, the parameter must use object | ||
destructuring (e.g. `root: ({color, padding}) => (...)`). If the parameter is not destructured | ||
(e.g. `root: (props) => (...)`), it will not be converted. | ||
- If an arrow function at the rule level contains a code block (i.e. contains an explicit `return` | ||
statement) rather than just an object expression, it will not be converted. | ||
|
||
You can find more details about migrating from JSS to tss-react in [the migration guide](https://mui.com/guides/migration-v4/#2-use-tss-react). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great if we can list here things that are not supported, for example the "TODOs" added in This will make sure we are transparent and will help future contributors to take features one by one and add them as part of the codemod. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added documentation about the scenarios that produce TODO comments. |
||
|
||
#### `link-underline-hover` | ||
|
||
Apply `underline="hover"` to `<Link />` that does not define `underline` prop (to get the same behavior as in v4). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit here for applying some changes from master. Would be great if you can double check if this is the changed content on the migration guide (LGTM btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a merge of those migration guide changes yesterday, but I should have installed the merge tool that I use at work onto my home computer. I used my IDE's merge resolution instead and looks like it didn't behave the way I thought and lost a lot of the changes that I thought I was merging in. Thanks for fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of my previous migration guide changes were lost during your fix of my bad merge. I've reapplied those changes now.