Chakra UI provides Codemod transformations to help upgrade your Chakra UI codebase when a component is updated or deprecated.
Codemods are transformations that run on your codebase programmatically. This allows for a large amount of changes to be applied without having to manually go through every file.
If you're using a monorepo, you'll need to cd into the specific package that has Chakra UI installed. Otherwise, you can run these at the root of your project.
npx @chakra-ui/codemod [path]The codemod will ask you a few questions:
- Which files or directory should the codemods be applied? [text]
- Which codemod(s) would like to apply? [select]
--dry: Pass if you want to perform a dry run?--print: Pass if you want to print the modified files
If you are running this command in a git repository, please commit or stash your changes first
- Update
colortocolorScheme - Update import from
@chakra-ui/coreto@chakra-ui/react - Rename
sizeprop forBoxorPseudoBoxtowandh - Update
SliderJSX structure - Rename
ThemeProvidertoChakraProvider - Update component Imports to reflect updates
- Update
useDisclosuresignature - Change
v0Icons tov1Icons - Replace string icon prop to
ButtonandIconButtonto icon elements from@chakra-ui/icons
To watch and build TS files run:
yarn watchLink this package in your global node_modules by running:
npm linkTo execute the command run:
# no path
chakra-codemod
> Run chakra codemod in: <current-directory>
# relative path
chakra-codemod my-app
> Run chakra codemod in: <current-directory>/my-app
# absolute path
chakra-codemod /Users/you/development/my-app
> Run chakra codemod in: /Users/you/development/my-app
# absolute path with tranformer name
chakra-codemod /Users/you/development/my-app core-to-react
> Run chakra core-to-react codemod in: /Users/you/development/my-app- https://skovy.dev/jscodeshift-custom-transform/
- https://www.toptal.com/javascript/write-code-to-rewrite-your-code
- https://github.com/vutran/preact-codemod
- https://github.com/vercel/next.js/tree/canary/packages/next-codemod
Write transforms for:
RadioGroupandCheckboxGroupJSX update.- Skeleton update (https://chakra-ui.com/docs/migration#radiogroup)
- Rename
ListPropsfromstylePostostylePosition - Update CircularProgress
thicknesscalculation (https://chakra-ui.com/docs/migration#circularprogress) - Update Skeleton props (https://chakra-ui.com/docs/migration#skeleton)
- Update Collapse Props from
isOpentoin - Update Icon to work for this JSXExpression scenario:
<Icon name={isOpen ? 'chevron-up' : 'chevron-down'} size="24px" />