File size: 2,443 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "CLI"
description:
  Learn more to use the Chakra CLI command to generate snippets and typings
---

The Chakra UI CLI can be used to generate typings for your custom theme tokens,
like colors, semantic tokens, recipe variants, etc.

## Installation

In order to use the CLI, you need to install it as a dev dependency in your
project:

:::code-group

```bash [npm]
npm i -D @chakra-ui/cli
```

```bash [pnpm]
pnpm add -D @chakra-ui/cli
```

```bash [bun]
bun add -d @chakra-ui/cli
```

:::

:::warning

To use the CLI tool, please ensure that the version of Node.js is `>= 20.6.0`.

:::

## Usage

Use the Chakra CLI to run any of the commands listed below with your preferred
package manager.

```bash
Usage: npx chakra [options] [command]

The official CLI for Chakra UI projects

Options:
  -V, --version               output the version number
  -h, --help                  display help for command

Commands:
  typegen [options] <source>  Generate theme and recipe typings
  snippet                     Add snippets to your project for better DX
  eject [options]             Take control over the default theme tokens and recipes
  help [command]              display help for command
```

## `chakra typegen`

Generates theme and recipe typings for your custom theme. This helps to provide
autocompletion and type safety in your project.

```bash
# Generate typings
chakra typegen src/theme.ts

# Watch for changes and rebuild
chakra typegen src/theme.ts --watch

# Generate strict types for props variant and size
chakra typegen src/theme.ts --strict
```

## `chakra snippet`

Generates useful component compositions that boost your development speed.

```bash
# Add all snippets
chakra snippet add --all

# Add a specific snippet
chakra snippet add button

# List all available snippets
chakra snippet list

# Specify a custom directory
chakra snippet add dialog --outdir ./components/custom
```

## `chakra eject`

Generated the file(s) that contain the default theme tokens and recipes so you
can have full control over them.

```bash
# Copy the tokens and recipes to your project
chakra eject --outdir src/theme
```

## FAQ

### Autocomplete for custom tokens not working?

After generating the typings, you need to "Restart TS Server" for the
autocomplete to show up.

Alternatively, you can install the `@chakra-ui/cli` package locally as a dev
dependency and run the `chakra typegen` command to generate the typings.