用途
该技能用于在 8bitcn-ui 组件库中登记 8-bit 复古风格组件,使它们可以通过 shadcn 的 add 命令被发现和使用:shadcn add @8bitcn/[component-name]。当需要向组件库添加新的 8-bit 组件时应用此规范。
组件条目模式
在 registry.json 中登记单个组件时,使用 registry:component 类型,包含名称、标题、描述、registryDependencies 与 files 数组。示例中 button 组件的 files 同时包含组件文件与 retro.css:
{
"name": "button",
"type": "registry:component",
"title": "8-bit Button",
"description": "A simple 8-bit button component",
"registryDependencies": ["button"],
"files": [
{
"path": "components/ui/8bit/button.tsx",
"type": "registry:component",
"target": "components/ui/8bit/button.tsx"
},
{
"path": "components/ui/8bit/styles/retro.css",
"type": "registry:component",
"target": "components/ui/8bit/styles/retro.css"
}
]
}
区块条目模式
对于游戏界面等预构建布局,使用 registry:block 类型,并可设置 categories 字段。示例 chapter-intro 区块的 registryDependencies 为 card,categories 为 gaming,files 中除区块文件外还包含 retro.css 与 card.tsx:
{
"name": "chapter-intro",
"type": "registry:block",
"title": "8-bit Chapter Intro",
"description": "A cinematic chapter/level intro with pixel art background.",
"registryDependencies": ["card"],
"categories": ["gaming"],
"files": [
{
"path": "components/ui/8bit/blocks/chapter-intro.tsx",
"type": "registry:block",
"target": "components/ui/8bit/blocks/chapter-intro.tsx"
},
{
"path": "components/ui/8bit/styles/retro.css",
"type": "registry:component",
"target": "components/ui/8bit/styles/retro.css"
},
{
"path": "components/ui/8bit/card.tsx",
"type": "registry:component",
"target": "components/ui/8bit/card.tsx"
}
]
}
必需的 retro.css
registry 条目中必须始终包含 retro.css,无论组件还是区块,都要在 files 数组中登记该样式文件:
"files": [
{
"path": "components/ui/8bit/new-component.tsx",
"type": "registry:component",
"target": "components/ui/8bit/new-component.tsx"
},
{
"path": "components/ui/8bit/styles/retro.css",
"type": "registry:component",
"target": "components/ui/8bit/styles/retro.css"
}
]
分类
使用面向游戏的分类,例如:"categories": ["gaming"]。可用分类包括:gaming、layout、form、data-display、feedback、navigation、overlay。
注册表依赖
registryDependencies 应列出基础 shadcn 依赖,而非 8-bit 版本,例如:"registryDependencies": ["button", "dialog"]。对于包含多个组件的区块:"registryDependencies": ["card", "button", "progress"]。
关键原则
- 类型:单个组件使用 registry:component,布局使用 registry:block。
- 必须包含 retro.css:始终加入 files 数组。
- 目标路径:source 与 target 使用相同路径。
- 分类:复古主题组件使用 gaming。
- 依赖:只列出基础 shadcn/ui 组件(不是 8-bit 版本)。
- 描述:为 CLI 输出提供清晰、简洁的描述。
添加新组件的步骤
- 在 components/ui/8bit/component.tsx 中创建组件。
- 更新 registry.json,参照现有组件作为模板添加条目。
- 包含 retro.css 依赖。
- 使用命令测试:
pnpm dlx shadcn@latest add @8bitcn/component。
适用场景与限制
适用于维护 8bitcn-ui 组件库、需要让新增的像素风组件或游戏界面区块可被 shadcn CLI 安装的场景。限制方面,资料未提供其他平台兼容性、构建流程或额外工具链的说明。