Components
@shadcn/react
Utilities
registry.json 架构用于定义你自定义的组件注册表。
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "shadcn",
"homepage": "https://ui.shadcn.com",
"items": [
{
"name": "hello-world",
"type": "registry:block",
"title": "Hello World",
"description": "一个简单的 hello world 组件。",
"registryDependencies": [
"button",
"@acme/input-form",
"https://example.com/r/foo"
],
"dependencies": ["is-even@3.0.0", "motion"],
"files": [
{
"path": "registry/default/hello-world/hello-world.tsx",
"type": "registry:component"
}
]
}
]
}你也可以使用 include 将一个大型注册表组织到多个 registry.json 文件中。
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"include": [
"components/ui/registry.json",
"hooks/registry.json"
]
}公共 GitHub 仓库使用相同的源注册表格式。CLI 读取根目录下的 registry.json,解析 include,并从仓库中安装文件。更多信息请参阅 GitHub registry 文档。
定义#
你可以在这里查看 registry.json 的 JSON 架构。
$schema#
$schema 属性用于指定 registry.json 文件的架构。
{
"$schema": "https://ui.shadcn.com/schema/registry.json"
}name#
name 属性用于指定你的注册表的名称。该名称用于数据属性及其他元数据。
{
"name": "acme"
}homepage#
注册表的主页地址。该地址用于数据属性及其他元数据。
{
"homepage": "https://acme.com"
}include#
include 属性用于将其他 registry.json 文件组合成一个注册表。
{
"include": [
"components/ui/registry.json",
"hooks/registry.json"
]
}每个 include 路径必须是指向明确 registry.json 文件的相对路径。
不支持文件夹简写。
{
"include": [
"components/ui/registry.json"
]
}包含的 registry.json 文件可以省略 name 和 homepage。这些字段
仅在根 registry.json 中是必需的。
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"items": [
{
"name": "button",
"type": "registry:ui",
"files": [
{
"path": "button.tsx",
"type": "registry:ui"
}
]
}
]
}当 shadcn build 解析 include 时,项目文件路径会相对于声明该项目的
registry.json 文件读取。生成的注册表输出会被展平,并且不包含 include。
注册表项目名称在解析后的注册表中必须唯一,包括所有 包含的文件。
items#
注册表中的 items。每个 item 必须实现registry-item 架构规范。
{
"items": [
{
"name": "hello-world",
"type": "registry:block",
"title": "Hello World",
"description": "一个简单的 hello world 组件。",
"registryDependencies": [
"button",
"@acme/input-form",
"https://example.com/r/foo"
],
"dependencies": ["is-even@3.0.0", "motion"],
"files": [
{
"path": "registry/default/hello-world/hello-world.tsx",
"type": "registry:component"
}
]
}
]
}根 registry.json 必须至少定义 items 或 include 其中之一。如果
省略 items,其默认值为空数组。
有关更多信息,请参阅registry-item 架构文档。