Skip to content

Commit b3b2fe2

Browse files
authored
feat(shadcn): registry updates (#7016)
* feat(shadcn): registry updates * tests: fix snapshots * feat(shadcn): add new theme prop * fix: handle theme for index * tests(shadcn): fix * docs(www): update registry item docs * chore: add changeset * docs: update theming docs
1 parent 1fcb318 commit b3b2fe2

12 files changed

Lines changed: 424 additions & 51 deletions

File tree

.changeset/warm-fans-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": minor
3+
---
4+
5+
add theme prop to registry-item schema

apps/www/content/docs/registry/faq.mdx

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,46 @@ Here's an example of a complex component that installs a page, two components, a
4949

5050
### How do I add a new Tailwind color?
5151

52+
<Tabs defaultValue="v4">
53+
54+
<TabsList>
55+
<TabsTrigger value="v4">Tailwind CSS v4</TabsTrigger>
56+
<TabsTrigger value="v3">Tailwind CSS v3</TabsTrigger>
57+
</TabsList>
58+
59+
<TabsContent value="v4">
60+
61+
To add a new color you need to add it to `cssVars` under `light` and `dark` keys.
62+
63+
```json showLineNumbers {10-18}
64+
{
65+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
66+
"name": "hello-world",
67+
"title": "Hello World",
68+
"type": "registry:block",
69+
"description": "A complex hello world component",
70+
"files": [
71+
// ...
72+
],
73+
"cssVars": {
74+
"light": {
75+
"brand-background": "20 14.3% 4.1%",
76+
"brand-accent": "20 14.3% 4.1%"
77+
},
78+
"dark": {
79+
"brand-background": "20 14.3% 4.1%",
80+
"brand-accent": "20 14.3% 4.1%"
81+
}
82+
}
83+
}
84+
```
85+
86+
The CLI will update the project CSS file. Once updated, the new colors will be available to be used as utility classes: `bg-brand` and `text-brand-accent`.
87+
88+
</TabsContent>
89+
90+
<TabsContent value="v3">
91+
5292
To add a new color you need to add it to `cssVars` and `tailwind.config.theme.extend.colors`.
5393

5494
```json showLineNumbers {10-19} {24-29}
@@ -90,9 +130,47 @@ To add a new color you need to add it to `cssVars` and `tailwind.config.theme.ex
90130

91131
The CLI will update the project CSS file and tailwind.config.js file. Once updated, the new colors will be available to be used as utility classes: `bg-brand` and `text-brand-accent`.
92132

93-
### How do I add a Tailwind animation?
133+
</TabsContent>
134+
</Tabs>
135+
136+
### How do I add or override a Tailwind theme variable?
137+
138+
<Tabs defaultValue="v4">
139+
140+
<TabsList>
141+
<TabsTrigger value="v4">Tailwind CSS v4</TabsTrigger>
142+
<TabsTrigger value="v3">Tailwind CSS v3</TabsTrigger>
143+
</TabsList>
144+
145+
<TabsContent value="v4">
146+
147+
To add or override a theme variable you add it to `cssVars.theme` under the key you want to add or override.
148+
149+
```json showLineNumbers {10-15}
150+
{
151+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
152+
"name": "hello-world",
153+
"title": "Hello World",
154+
"type": "registry:block",
155+
"description": "A complex hello world component",
156+
"files": [
157+
// ...
158+
],
159+
"cssVars": {
160+
"theme": {
161+
"text-base": "3rem",
162+
"ease-in-out": "cubic-bezier(0.4, 0, 0.2, 1)",
163+
"font-heading": "Poppins, sans-serif"
164+
}
165+
}
166+
}
167+
```
168+
169+
</TabsContent>
94170

95-
To add a new animation you add it to `tailwind.config.theme.extend.animation` and `tailwind.config.theme.extend.keyframes`.
171+
<TabsContent value="v3">
172+
173+
To override a theme variable you add it to `tailwind.config.theme.extend` under the key you want to override.
96174

97175
```json showLineNumbers {14-22}
98176
{
@@ -108,18 +186,15 @@ To add a new animation you add it to `tailwind.config.theme.extend.animation` an
108186
"config": {
109187
"theme": {
110188
"extend": {
111-
"keyframes": {
112-
"wiggle": {
113-
"0%, 100%": { "transform": "rotate(-3deg)" },
114-
"50%": { "transform": "rotate(3deg)" }
115-
}
116-
},
117-
"animation": {
118-
"wiggle": "wiggle 1s ease-in-out infinite"
189+
"text": {
190+
"base": "3rem"
119191
}
120192
}
121193
}
122194
}
123195
}
124196
}
125197
```
198+
199+
</TabsContent>
200+
</Tabs>

apps/www/content/docs/registry/registry-item-json.mdx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ The `registry-item.json` schema is used to define your custom registry items.
2121
"path": "registry/new-york/hello-world/use-hello-world.ts",
2222
"type": "registry:hook"
2323
}
24-
]
24+
],
25+
"cssVars": {
26+
"theme": {
27+
"font-heading": "Poppins, sans-serif"
28+
},
29+
"light": {
30+
"brand": "20 14.3% 4.1%"
31+
},
32+
"dark": {
33+
"brand": "20 14.3% 4.1%"
34+
}
35+
}
2536
}
2637
```
2738

@@ -41,7 +52,7 @@ The `$schema` property is used to specify the schema for the `registry-item.json
4152

4253
### name
4354

44-
The `name` property is used to specify the name of your registry item.
55+
The name of the item. This is used to identify the item in the registry. It should be unique for your registry.
4556

4657
```json title="registry-item.json" showLineNumbers
4758
{
@@ -71,7 +82,7 @@ A description of your registry item. This can be longer and more detailed than t
7182

7283
### type
7384

74-
The `type` property is used to specify the type of your registry item.
85+
The `type` property is used to specify the type of your registry item. This is used to determine the type and target path of the item when resolved for a project.
7586

7687
```json title="registry-item.json" showLineNumbers
7788
{
@@ -90,6 +101,8 @@ The following types are supported:
90101
| `registry:ui` | Use for UI components and single-file primitives |
91102
| `registry:page` | Use for page or file-based routes. |
92103
| `registry:file` | Use for miscellaneous files. |
104+
| `registry:style` | Use for registry styles. eg. `new-york` |
105+
| `registry:theme` | Use for themes. |
93106

94107
### author
95108

@@ -122,7 +135,7 @@ Use `@version` to specify the version of your registry item.
122135

123136
### registryDependencies
124137

125-
Used for registry dependencies. Can be names or URLs.
138+
Used for registry dependencies. Can be names or URLs. Use the name of the item to reference shadcn/ui components and urls to reference other registries.
126139

127140
- For `shadcn/ui` registry items such as `button`, `input`, `select`, etc use the name eg. `['button', 'input', 'select']`.
128141
- For custom registry items use the URL of the registry item eg. `['https://example.com/r/hello-world.json']`.
@@ -189,6 +202,8 @@ Use `~` to refer to the root of the project e.g `~/foo.config.js`.
189202

190203
### tailwind
191204

205+
**DEPRECATED:** Use `cssVars.theme` instead for Tailwind v4 projects.
206+
192207
The `tailwind` property is used for tailwind configuration such as `theme`, `plugins` and `content`.
193208

194209
You can use the `tailwind.config` property to add colors, animations and plugins to your registry item.
@@ -225,6 +240,9 @@ Use to define CSS variables for your registry item.
225240
```json title="registry-item.json" showLineNumbers
226241
{
227242
"cssVars": {
243+
"theme": {
244+
"font-heading": "Poppins, sans-serif"
245+
},
228246
"light": {
229247
"brand": "20 14.3% 4.1%",
230248
"radius": "0.5rem"
@@ -236,11 +254,6 @@ Use to define CSS variables for your registry item.
236254
}
237255
```
238256

239-
<Callout>
240-
**Note:** When adding colors, make sure to also add them to the
241-
`tailwind.config.theme.extend.colors` property.
242-
</Callout>
243-
244257
### docs
245258

246259
Use `docs` to show custom documentation or message when installing your registry item via the CLI.

apps/www/content/docs/theming.mdx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Here's the list of variables available for customization:
9292

9393
```css title="app/globals.css"
9494
:root {
95+
--radius: 0.625rem;
9596
--background: oklch(1 0 0);
9697
--foreground: oklch(0.145 0 0);
9798
--card: oklch(1 0 0);
@@ -107,7 +108,6 @@ Here's the list of variables available for customization:
107108
--accent: oklch(0.97 0 0);
108109
--accent-foreground: oklch(0.205 0 0);
109110
--destructive: oklch(0.577 0.245 27.325);
110-
--destructive-foreground: oklch(0.577 0.245 27.325);
111111
--border: oklch(0.922 0 0);
112112
--input: oklch(0.922 0 0);
113113
--ring: oklch(0.708 0 0);
@@ -116,7 +116,6 @@ Here's the list of variables available for customization:
116116
--chart-3: oklch(0.398 0.07 227.392);
117117
--chart-4: oklch(0.828 0.189 84.429);
118118
--chart-5: oklch(0.769 0.188 70.08);
119-
--radius: 0.625rem;
120119
--sidebar: oklch(0.985 0 0);
121120
--sidebar-foreground: oklch(0.145 0 0);
122121
--sidebar-primary: oklch(0.205 0 0);
@@ -130,22 +129,21 @@ Here's the list of variables available for customization:
130129
.dark {
131130
--background: oklch(0.145 0 0);
132131
--foreground: oklch(0.985 0 0);
133-
--card: oklch(0.145 0 0);
132+
--card: oklch(0.205 0 0);
134133
--card-foreground: oklch(0.985 0 0);
135-
--popover: oklch(0.145 0 0);
134+
--popover: oklch(0.269 0 0);
136135
--popover-foreground: oklch(0.985 0 0);
137-
--primary: oklch(0.985 0 0);
136+
--primary: oklch(0.922 0 0);
138137
--primary-foreground: oklch(0.205 0 0);
139138
--secondary: oklch(0.269 0 0);
140139
--secondary-foreground: oklch(0.985 0 0);
141140
--muted: oklch(0.269 0 0);
142141
--muted-foreground: oklch(0.708 0 0);
143-
--accent: oklch(0.269 0 0);
142+
--accent: oklch(0.371 0 0);
144143
--accent-foreground: oklch(0.985 0 0);
145-
--destructive: oklch(0.396 0.141 25.723);
146-
--destructive-foreground: oklch(0.637 0.237 25.331);
147-
--border: oklch(0.269 0 0);
148-
--input: oklch(0.269 0 0);
144+
--destructive: oklch(0.704 0.191 22.216);
145+
--border: oklch(1 0 0 / 10%);
146+
--input: oklch(1 0 0 / 15%);
149147
--ring: oklch(0.556 0 0);
150148
--chart-1: oklch(0.488 0.243 264.376);
151149
--chart-2: oklch(0.696 0.17 162.48);
@@ -158,7 +156,7 @@ Here's the list of variables available for customization:
158156
--sidebar-primary-foreground: oklch(0.985 0 0);
159157
--sidebar-accent: oklch(0.269 0 0);
160158
--sidebar-accent-foreground: oklch(0.985 0 0);
161-
--sidebar-border: oklch(0.269 0 0);
159+
--sidebar-border: oklch(1 0 0 / 10%);
162160
--sidebar-ring: oklch(0.439 0 0);
163161
}
164162
```

0 commit comments

Comments
 (0)