94.2k

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.",
  "registryDependencies": [
    "button",
    "@acme/input-form",
    "https://example.com/r/foo"
  ],
  "dependencies": ["is-even@3.0.0", "motion"],
  "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"
}

名称

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

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

标题

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

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

描述

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

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

类型

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用于主题。
registry:item用于通用注册表项。

作者

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

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

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

依赖项

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

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

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

registryDependencies

用于注册表依赖项。可以是名称、命名空间或 URL。

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

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

文件

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 属性用于指定注册表中文件的路径。此路径由构建脚本用于解析、转换和构建注册表 JSON 有效负载。

类型

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

目标

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@plugin 等。

registry-item.json
{
  "css": {
    "@plugin @tailwindcss/typography": {},
    "@plugin foo": {},
    "@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)"
      }
    }
  }
}

envVars

使用 envVars 向注册表项添加环境变量。

registry-item.json
{
  "envVars": {
    "NEXT_PUBLIC_APP_URL": "https://:4000",
    "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres",
    "OPENAI_API_KEY": ""
  }
}

环境变量将添加到 .env.local.env 文件中。现有变量不会被覆盖。

文档

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

registry-item.json
{
  "docs": "To get an OPENAI_API_KEY, sign up for an account at https://platform.openai.com."
}

类别

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

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

元数据

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

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