Docs
registry-item.json

registry-item.json

注册表项目的规范。

registry-item.json 架构用于定义您的自定义注册表项目。

registry-item.json
{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hello-world",
  "type": "registry:block",
  "title": "Hello World",
  "description": "一个简单的 hello world 组件。",
  "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

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

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

name

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

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

title

您的注册表项目的可读标题。保持简短且具描述性。

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

description

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

registry-item.json
{
  "description": "一个简单的 hello world 组件。"
}

type

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

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

支持以下类型:

类型描述
registry:block用于具有多个文件的复杂组件。
registry:component用于简单组件。
registry:lib用于库和实用程序。
registry:hook用于钩子。
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(可选)属性。

target 属性是 registry:pageregistry:file 类型所必需的。

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 属性用于指定文件的类型。有关更多信息,请参见 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%"
    }
  }
}

docs

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

registry-item.json
{
  "docs": "请记得将 FOO_BAR 环境变量添加到您的 .env 文件中。"
}

categories

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

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

meta

使用 meta 为您的注册表项目添加额外的元数据。您可以添加任何希望在注册表项目中可用的键/值对。

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