文档
registry-item.json

registry-item.json

注册表项的规范。

registry-item.json 模式用于定义您的自定义注册表项。

registry-item.json
{
  "$schema": "https://ui.shadcn.org.cn/schema/registry-item.json",
  "name": "hello-world",
  "type": "registry:block",
  "title": "Hello World",
  "description": "A simple hello world component.",
  "files": [
    {
      "path": "registry/new-york/hello-world/hello-world.tsx",
      "type": "registry:component"
    },
    {
      "path": "registry/new-york/hello-world/use-hello-world.ts",
      "type": "registry:hook"
    }
  ],
  "cssVars": {
    "theme": {
      "font-heading": "Poppins, sans-serif"
    },
    "light": {
      "brand": "20 14.3% 4.1%"
    },
    "dark": {
      "brand": "20 14.3% 4.1%"
    }
  }
}

定义

您可以在此处查看 registry-item.json 的 JSON 模式。

$schema

$schema 属性用于指定 registry-item.json 文件的模式。

registry-item.json
{
  "$schema": "https://ui.shadcn.org.cn/schema/registry-item.json"
}

name

项目的名称。这用于在注册表中标识项目。对于您的注册表,它应该是唯一的。

registry-item.json
{
  "name": "hello-world"
}

title

您的注册表项的人类可读标题。保持简短和描述性。

registry-item.json
{
  "title": "Hello World"
}

description

您的注册表项的描述。这可以比 title 更长更详细。

registry-item.json
{
  "description": "A simple hello world component."
}

type

type 属性用于指定您的注册表项的类型。这用于确定项目解析时的项目类型和目标路径。

registry-item.json
{
  "type": "registry:block"
}

支持以下类型

类型描述
registry:block用于包含多个文件的复杂组件。
registry:component用于简单组件。
registry:lib用于 lib 和 utils。
registry:hook用于 Hooks。
registry:ui用于 UI 组件和单文件原语
registry:page用于页面或基于文件的路由。
registry:file用于其他文件。
registry:style用于注册表样式。例如。 new-york
registry:theme用于主题。

author

author 属性用于指定注册表项的作者。

它可以是注册表项独有的,也可以与注册表的作者相同。

registry-item.json
{
  "author": "John Doe <john@doe.com>"
}

dependencies

dependencies 属性用于指定您的注册表项的依赖项。这用于 npm 包。

使用 @version 指定注册表项的版本。

registry-item.json
{
  "dependencies": [
    "@radix-ui/react-accordion",
    "zod",
    "lucide-react",
    "name@1.0.2"
  ]
}

registryDependencies

用于注册表依赖项。可以是名称或 URL。使用项目名称引用 shadcn/ui 组件,使用 URL 引用其他注册表。

  • 对于 shadcn/ui 注册表项,例如 buttoninputselect 等,请使用名称,例如 ['button', 'input', 'select']
  • 对于自定义注册表项,请使用注册表项的 URL,例如 ['https://example.com/r/hello-world.json']
registry-item.json
{
  "registryDependencies": [
    "button",
    "input",
    "select",
    "https://example.com/r/editor.json"
  ]
}

注意:CLI 将自动解析远程注册表依赖项。

files

files 属性用于指定您的注册表项的文件。每个文件都有一个 pathtypetarget(可选)属性。

对于 registry:pageregistry:file 类型,target 属性是必需的。

registry-item.json
{
  "files": [
    {
      "path": "registry/new-york/hello-world/page.tsx",
      "type": "registry:page",
      "target": "app/hello/page.tsx"
    },
    {
      "path": "registry/new-york/hello-world/hello-world.tsx",
      "type": "registry:component"
    },
    {
      "path": "registry/new-york/hello-world/use-hello-world.ts",
      "type": "registry:hook"
    },
    {
      "path": "registry/new-york/hello-world/.env",
      "type": "registry:file",
      "target": "~/.env"
    }
  ]
}

path

path 属性用于指定文件中注册表的路径。构建脚本使用此路径来解析、转换和构建注册表 JSON 有效负载。

type

type 属性用于指定文件的类型。有关更多信息,请参见类型部分。

target

target 属性用于指示文件应放置在项目中的位置。这是可选的,仅对于 registry:pageregistry:file 类型是必需的。

默认情况下,shadcn cli 将读取项目的 components.json 文件以确定目标路径。对于某些文件,例如路由或配置,您可以手动指定目标路径。

使用 ~ 引用项目的根目录,例如 ~/foo.config.js

tailwind

已弃用: 对于 Tailwind v4 项目,请改用 cssVars.theme

tailwind 属性用于 tailwind 配置,例如 themepluginscontent

您可以使用 tailwind.config 属性将颜色、动画和插件添加到您的注册表项。

registry-item.json
{
  "tailwind": {
    "config": {
      "theme": {
        "extend": {
          "colors": {
            "brand": "hsl(var(--brand))"
          },
          "keyframes": {
            "wiggle": {
              "0%, 100%": { "transform": "rotate(-3deg)" },
              "50%": { "transform": "rotate(3deg)" }
            }
          },
          "animation": {
            "wiggle": "wiggle 1s ease-in-out infinite"
          }
        }
      }
    }
  }
}

cssVars

用于为您的注册表项定义 CSS 变量。

registry-item.json
{
  "cssVars": {
    "theme": {
      "font-heading": "Poppins, sans-serif"
    },
    "light": {
      "brand": "20 14.3% 4.1%",
      "radius": "0.5rem"
    },
    "dark": {
      "brand": "20 14.3% 4.1%"
    }
  }
}

css

使用 css 将新规则添加到项目的 CSS 文件中,例如 @layer base@layer components@utility@keyframes 等。

registry-item.json
{
  "css": {
    "@layer base": {
      "body": {
        "font-size": "var(--text-base)",
        "line-height": "1.5"
      }
    },
    "@layer components": {
      "button": {
        "background-color": "var(--color-primary)",
        "color": "var(--color-white)"
      }
    },
    "@utility text-magic": {
      "font-size": "var(--text-base)",
      "line-height": "1.5"
    },
    "@keyframes wiggle": {
      "0%, 100%": {
        "transform": "rotate(-3deg)"
      },
      "50%": {
        "transform": "rotate(3deg)"
      }
    }
  }
}

docs

当通过 CLI 安装您的注册表项时,使用 docs 显示自定义文档或消息。

registry-item.json
{
  "docs": "Remember to add the FOO_BAR environment variable to your .env file."
}

categories

使用 categories 来组织您的注册表项。

registry-item.json
{
  "categories": ["sidebar", "dashboard"]
}

meta

使用 meta 将其他元数据添加到您的注册表项。您可以添加任何您希望对注册表项可用的键/值对。

registry-item.json
{
  "meta": { "foo": "bar" }
}