Skip to content

Commit

Permalink
feat: add docs for registry (#6380)
Browse files Browse the repository at this point in the history
* chore: 2.2.0-canary.2

* feat: add docs for registry

* docs(www): update registry docs

* fix: update dep

* docs(www): update docs

* docs(www): update registry docs

* feat: add new label

* fix: lint
  • Loading branch information
shadcn authored Jan 28, 2025
1 parent dd71498 commit 9643db4
Show file tree
Hide file tree
Showing 15 changed files with 851 additions and 9 deletions.
7 changes: 6 additions & 1 deletion apps/www/components/docs-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export function DocsNav({ config }: { config: DocsConfig }) {
{items.map((item, index) => (
<div key={index} className="flex flex-col gap-1">
<h4 className="rounded-md px-2 py-1 text-sm font-semibold">
{item.title}
{item.title}{" "}
{item.label && (
<span className="ml-2 rounded-md bg-[#adfa1d] px-1.5 py-0.5 text-xs font-normal leading-none text-[#000000] no-underline group-hover:no-underline">
{item.label}
</span>
)}
</h4>
{item?.items?.length && (
<DocsNavItems items={item.items} pathname={pathname} />
Expand Down
36 changes: 36 additions & 0 deletions apps/www/config/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,42 @@ export const docsConfig: DocsConfig = {
},
],
},
{
title: "Registry",
label: "New",
items: [
{
title: "Introduction",
href: "/docs/registry",
items: [],
},
{
title: "Getting Started",
href: "/docs/registry/getting-started",
items: [],
},
{
title: "Open in v0",
href: "/docs/registry/open-in-v0",
items: [],
},
{
title: "FAQ",
href: "/docs/registry/faq",
items: [],
},
{
title: "registry.json",
href: "/docs/registry/registry-json",
items: [],
},
{
title: "registry-item.json",
href: "/docs/registry/registry-item-json",
items: [],
},
],
},
],
chartsNav: [
{
Expand Down
27 changes: 22 additions & 5 deletions apps/www/content/docs/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,33 @@ Options:
-h, --help display help for command
```

## Monorepo
## build

In a monorepo, you can specify the path to your workspace with the `-c` or `--cwd` option.
Use the `build` command to generate the registry JSON files.

```bash
npx shadcn@latest init -c ./apps/www
npx shadcn@latest build
```

or
This command reads the `registry.json` file and generates the registry JSON files in the `public/r` directory.

```txt
Usage: shadcn build [options] [registry]
build components for a shadcn registry
Arguments:
registry path to registry.json file (default: "./registry.json")
Options:
-o, --output <path> destination directory for json files (default: "./public/r")
-c, --cwd <cwd> the working directory. defaults to the current directory. (default:
"/Users/shadcn/Code/shadcn/ui/packages/shadcn")
-h, --help display help for command
```

To customize the output directory, use the `--output` option.

```bash
npx shadcn@latest add alert-dialog -c ./apps/www
npx shadcn@latest build --output ./public/registry
```
125 changes: 125 additions & 0 deletions apps/www/content/docs/registry/faq.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: FAQ
description: Frequently asked questions about running a registry.
---

## Frequently asked questions

### What does a complex component look like?

Here's an example of a complex component that installs a page, two components, a hook, a format-date utils and a config file.

```json showLineNumbers
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
{
"path": "registry/hello-world/page.tsx",
"type": "registry:page",
"target": "app/hello/page.tsx"
},
{
"path": "registry/hello-world/components/hello-world.tsx",
"type": "registry:component"
},
{
"path": "registry/hello-world/components/formatted-message.tsx",
"type": "registry:component"
},
{
"path": "registry/hello-world/hooks/use-hello.ts",
"type": "registry:hook"
},
{
"path": "registry/hello-world/lib/format-date.ts",
"type": "registry:utils"
},
{
"path": "registry/hello-world/hello.config.ts",
"type": "registry:file",
"target": "~/hello.config.ts"
}
]
}
```

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

To add a new color you need to add it to `cssVars` and `tailwind.config.theme.extend.colors`.

```json showLineNumbers {10-19} {24-29}
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
// ...
],
"cssVars": {
"light": {
"brand-background": "20 14.3% 4.1%",
"brand-accent": "20 14.3% 4.1%"
},
"dark": {
"brand-background": "20 14.3% 4.1%",
"brand-accent": "20 14.3% 4.1%"
}
},
"tailwind": {
"config": {
"theme": {
"extend": {
"colors": {
"brand": {
"DEFAULT": "hsl(var(--brand-background))",
"accent": "hsl(var(--brand-accent))"
}
}
}
}
}
}
}
```

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`.

### How do I add a Tailwind animation?

To add a new animation you add it to `tailwind.config.theme.extend.animation` and `tailwind.config.theme.extend.keyframes`.

```json showLineNumbers {14-22}
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
// ...
],
"tailwind": {
"config": {
"theme": {
"extend": {
"keyframes": {
"wiggle": {
"0%, 100%": { "transform": "rotate(-3deg)" },
"50%": { "transform": "rotate(3deg)" }
}
},
"animation": {
"wiggle": "wiggle 1s ease-in-out infinite"
}
}
}
}
}
}
```
Loading

0 comments on commit 9643db4

Please sign in to comment.