CLI
The Chakra UI CLI can be used to generate typings for your custom theme tokens, like colors, semantic tokens, component variants, etc.
The CLI scans your theme configuration and generates typings for your custom
tokens in the node_modules/@chakra-ui/styled-system/dist/theming.types.d.ts
file.
Troubleshoot: If the theme typings don't show up immediately, try restarting your TypeScript server (
Cmd + Shift + P > "TypeScript: Restart TS server"
if you're using VSCode).
Installation#
In order to use the CLI, you need to install it as a dev dependency in your project:
npm install --save-dev @chakra-ui/cli#oryarn add --dev @chakra-ui/cli
To make it more convenient, it's also a good idea to create an npm script that triggers it:
// package.json{..."scripts": {..."theme": "chakra-cli tokens path/to/theme.ts","theme:watch": "chakra-cli tokens path/to/theme.ts --watch",},...}
Don't forget to replace path/to/theme.ts
with your theme file location.
Usage#
To generate typings for your theme, run the theme
script:
npm run theme
yarn theme
pnpm theme
If you'd like to continuously generate theme typings as you're editing your
theme, run the theme:watch
script:
npm run theme:watch
yarn theme:watch
pnpm theme:watch
A successful execution should output something like this:
$ chakra-cli tokens src/theme/index.tsChakra UI CLI v2.1.8 by Chakra UIGenerate theme typings for autocompleteℹ Generating chakra theme typings✔ Done✨ Done in 0.83s.