Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 044c595

Browse files
committed
feature(docs): added CLI docs page + updated button and input theming docs
1 parent df3f9e7 commit 044c595

File tree

4 files changed

+88
-22
lines changed

4 files changed

+88
-22
lines changed

configs/styled-system.sidebar.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"title": "Chakra Factory",
3737
"path": "/docs/styled-system/chakra-factory"
3838
},
39+
{
40+
"title": "CLI",
41+
"path": "/docs/styled-system/cli"
42+
},
3943
{
4044
"title": "Global Styles",
4145
"path": "/docs/styled-system/global-styles"
@@ -54,7 +58,6 @@
5458
}
5559
]
5660
},
57-
5861
{
5962
"title": "Theming",
6063
"path": "/docs/theming",
@@ -81,4 +84,4 @@
8184
]
8285
}
8386
]
84-
}
87+
}

content/docs/components/button/theming.mdx

+3-10
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,9 @@ export const buttonTheme = defineStyleConfig({
8282
<Button size="xl">...</Button>
8383
```
8484

85-
Every time you're adding anything new to the theme, you'd need to run the cli
86-
command to get proper autocomplete in your IDE. Here's how you can do that:
87-
88-
```bash
89-
# run it once:
90-
npx chakra-cli tokens path/to/theme.ts
91-
92-
# or run it in watch mode:
93-
npx chakra-cli tokens path/to/theme.ts --watch
94-
```
85+
Every time you're adding anything new to the theme, you'd need to run the CLI
86+
command to get proper autocomplete in your IDE. You can learn more about the CLI
87+
tool [here](/docs/styled-system/cli).
9588

9689
## Adding a custom variant
9790

content/docs/components/input/theming.mdx

+3-10
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,9 @@ export const inputTheme = defineMultiStyleConfig({ sizes })
278278
<Input size="xl" ... />
279279
```
280280

281-
Every time you're adding anything new to the theme, you'd need to run the cli
282-
command to get proper autocomplete in your IDE. Here's how you can do that:
283-
284-
```bash
285-
# run it once:
286-
npx chakra-cli tokens path/to/theme.ts
287-
288-
# or run it in watch mode:
289-
npx chakra-cli tokens path/to/theme.ts --watch
290-
```
281+
Every time you're adding anything new to the theme, you'd need to run the CLI
282+
command to get proper autocomplete in your IDE. You can learn more about the CLI
283+
tool [here](/docs/styled-system/cli).
291284

292285
## Adding a custom variant
293286

content/docs/styled-system/cli.mdx

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: 'CLI'
3+
package: '@chakra-ui/cli'
4+
description: Using the CLI command to generate theme typings
5+
category: 'features'
6+
---
7+
8+
Chakra UI also comes with a CLI tool that you can use to generate typings for
9+
your custom theme tokens, like colors, semantic tokens, etc... The CLI scans
10+
your theme configuration and generates typings for your custom tokens in the
11+
`node_modules/@chakra-ui/styled-system/dist/theming.types.d.ts` file.
12+
13+
> **Troubleshoot:** If the theme typings don't show up immediately, try
14+
> restarting your TypeScript server
15+
> (`Cmd + Shift + P > "TypeScript: Restart TS server"` if you're using VSCode).
16+
17+
## Installation
18+
19+
In order to use the CLI, you need to install it as a dev dependency in your
20+
project:
21+
22+
```bash
23+
npm install --save-dev @chakra-ui/cli
24+
#or
25+
yarn add --dev @chakra-ui/cli
26+
```
27+
28+
To make it more convenient, it's also a good idea to create an npm script that
29+
triggers it:
30+
31+
```json
32+
// package.json
33+
{
34+
...
35+
"scripts": {
36+
...
37+
"theme": "chakra-cli tokens path/to/theme.ts",
38+
"theme:watch": "chakra-cli tokens path/to/theme.ts --watch",
39+
},
40+
...
41+
}
42+
```
43+
44+
Don't forget to replace `path/to/theme.ts` with your theme file location.
45+
46+
## Usage
47+
48+
To generate typings for your theme, run the `theme` script:
49+
50+
```bash
51+
npm run theme
52+
# or
53+
yarn theme
54+
```
55+
56+
If you'd like to continuously generate theme typings as you're editing your
57+
theme, run the `theme:watch` script:
58+
59+
```bash
60+
npm run theme:watch
61+
# or
62+
yarn theme:watch
63+
```
64+
65+
A successfull execution should output something like this:
66+
67+
```sh
68+
$ chakra-cli tokens src/theme/index.ts
69+
70+
Chakra UI CLI v2.1.8 by Chakra UI
71+
Generate theme typings for autocomplete
72+
73+
74+
ℹ Generating chakra theme typings
75+
✔ Done
76+
✨ Done in 0.83s.
77+
```

0 commit comments

Comments
 (0)