Mmohebifar

mui-grid-v2-props-migration-react

Automatically rewrite legacy Grid v2 props to the current Material UI Grid API for React projects using `@mui/material/Grid2`, `@mui/system/Grid`, or `@mui/joy/Grid`, including deterministic prop renames/removals and safe JSX cleanup.

transformationmigrationmuigrid2reactjsxtsx
Public
0 executions

Run locally

npx codemod mui-grid-v2-props-migration-react

mui-grid-v2-props-migration-react

Automatically rewrite legacy Grid v2 props to the current Material UI Grid API for React projects using @mui/material/Grid2, @mui/system/Grid, or @mui/joy/Grid, including deterministic prop renames/removals and safe JSX cleanup.

What It Rewrites

This codemod parses js, jsx, ts, and tsx files with JSX support and only rewrites JSX elements whose component name resolves to an import from:

  • @mui/material/Grid2
  • @mui/material/Unstable_Grid2
  • @mui/system/Grid
  • @mui/joy/Grid

By default it performs these JSX migrations:

  • xs, sm, md, lg, xl -> size
  • xsOffset, smOffset, mdOffset, lgOffset, xlOffset -> offset
  • removes legacy item
  • rewrites zeroMinWidth to sx={{ minWidth: 0 }} and merges with existing sx
  • leaves container unchanged
  • skips ambiguous size/offset conflicts unless forced with params

Examples

tsx
tsx
tsx

Preserve Cases

  • local <Grid> components or other libraries with the same prop names
  • files without JSX
  • already-migrated size/offset usage
  • ambiguous conflicts such as size={foo} with legacy breakpoint props, unless force-conflict-resolution=true

Usage

bash

Optional params:

  • stabilize-import=true: rewrite @mui/material/Unstable_Grid2 imports to @mui/material/Grid2
  • compact-single-breakpoint=true: emit compact size when only xs remains
  • force-conflict-resolution=true: remove legacy breakpoint props even when existing size/offset props are non-object expressions
  • legacy-precedence=true: when conflicts are forced, prefer legacy breakpoint values over existing size/offset values

Example:

bash

Development

bash

References

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.