Open amakk opened 1 year ago
Steps:
npx @mui/codemod v5.0.0/jss-to-styled dialog.js
Starting file:
import React from 'react' import MuiDialog from '@mui/material/Dialog' import makeStyles from '@mui/styles/makeStyles' const useDialogStyles = makeStyles((theme) => ({ dialogPaper: { marginLeft: theme.spacing(1), marginRight: theme.spacing(1), maxWidth: (props) => props.maxWidth && `${props.maxWidth} !important`, }, })) export function Dialog({ open, onClose, children, maxWidth = '600px', ...props }) { const classes = useDialogStyles({ maxWidth }) return ( <MuiDialog open={open} scroll={'body'} onClose={onClose} classes={{ paperScrollBody: classes.dialogPaper }} style={{ display: 'block' }} {...props} > {children} </MuiDialog> ) }
This file gets generated:
import React from 'react' import { styled } from '@mui/material/styles'; import MuiDialog from '@mui/material/Dialog' const PREFIX = 'dialog'; const classes = { dialogPaper: `${PREFIX}-dialogPaper` }; const StyledMuiDialog = styled(MuiDialog)(( { theme } ) => ({ [`& .${classes.dialogPaper}`]: { marginLeft: theme.spacing(1), marginRight: theme.spacing(1), maxWidth: (props) => props.maxWidth && `${props.maxWidth} !important`, } })); const useDialogStyles = makeStyles(( { theme } ) => ({ [`& .${classes.dialogPaper}`]: { marginLeft: theme.spacing(1), marginRight: theme.spacing(1), maxWidth: (props) => props.maxWidth && `${props.maxWidth} !important`, } })) export function Dialog({ open, onClose, children, maxWidth = '600px', ...props }) { const classes = useDialogStyles({ maxWidth }) return ( <StyledMuiDialog open={open} scroll={'body'} onClose={onClose} classes={{ paperScrollBody: classes.dialogPaper }} style={{ display: 'block' }} {...props} > {children} </StyledMuiDialog> ); }
The makeStyles call and useDialogStyles hook call shouldn't be there anymore. I'm expecting the file to be something like this:
makeStyles
useDialogStyles
import React from 'react' import { styled } from '@mui/material/styles'; import MuiDialog from '@mui/material/Dialog' const PREFIX = 'dialog'; const classes = { dialogPaper: `${PREFIX}-dialogPaper` }; const StyledMuiDialog = styled(MuiDialog)(( { theme } ) => ({ [`& .${classes.dialogPaper}`]: { marginLeft: theme.spacing(1), marginRight: theme.spacing(1), maxWidth: (props) => props.maxWidth && `${props.maxWidth} !important`, } })); export function Dialog({ open, onClose, children, maxWidth = '600px', ...props }) { return ( <StyledMuiDialog open={open} scroll={'body'} onClose={onClose} classes={{ paperScrollBody: classes.dialogPaper }} style={{ display: 'block' }} {...props} > {children} </StyledMuiDialog> ); }
I'm trying to migrate from material UI v4 to v5. Since this codemod is not producing working code, I'm not able to carry out this migration easily.
npx @mui/envinfo
Do you want to submit a PR?
I've never worked with codemod code before, so I don't think I'd be able to
Duplicates
Latest version
Steps to reproduce 🕹
Steps:
npx @mui/codemod v5.0.0/jss-to-styled dialog.js
Starting file:
Current behavior 😯
This file gets generated:
Expected behavior 🤔
The
makeStyles
call anduseDialogStyles
hook call shouldn't be there anymore. I'm expecting the file to be something like this:Context 🔦
I'm trying to migrate from material UI v4 to v5. Since this codemod is not producing working code, I'm not able to carry out this migration easily.
Your environment 🌎
``` I'm not able to run @mui/envinfo - it hangs and doesn't output anything or use any system resources. ```npx @mui/envinfo