常见问题
有关运行注册表的常见问题。
常见问题
¥Frequently asked questions
复杂组件是什么样的?
¥What does a complex component look like?
以下是安装页面、两个组件、一个钩子、一个格式日期实用程序和一个配置文件的复杂组件的示例。
¥Here's an example of a complex component that installs a page, two components, a hook, a format-date utils and a config file.
{
"$schema": "https://shadcn.nodejs.cn/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
{
"path": "registry/new-york/hello-world/page.tsx",
"type": "registry:page",
"target": "app/hello/page.tsx"
},
{
"path": "registry/new-york/hello-world/components/hello-world.tsx",
"type": "registry:component"
},
{
"path": "registry/new-york/hello-world/components/formatted-message.tsx",
"type": "registry:component"
},
{
"path": "registry/new-york/hello-world/hooks/use-hello.ts",
"type": "registry:hook"
},
{
"path": "registry/new-york/hello-world/lib/format-date.ts",
"type": "registry:utils"
},
{
"path": "registry/new-york/hello-world/hello.config.ts",
"type": "registry:file",
"target": "~/hello.config.ts"
}
]
}
如何添加新的 Tailwind 颜色?
¥How do I add a new Tailwind color?
要添加新颜色,你需要将其添加到 cssVars
的 light
和 dark
键下。
¥To add a new color you need to add it to cssVars
under light
and dark
keys.
{
"$schema": "https://shadcn.nodejs.cn/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
// ...
],
"cssVars": {
"light": {
"brand-background": "20 14.3% 4.1%",
"brand-accent": "20 14.3% 4.1%"
},
"dark": {
"brand-background": "20 14.3% 4.1%",
"brand-accent": "20 14.3% 4.1%"
}
}
}
CLI 将更新项目 CSS 文件。更新后,新颜色将可用作实用程序类:bg-brand
和 text-brand-accent
。
¥The CLI will update the project CSS file. Once updated, the new colors will be available to be used as utility classes: bg-brand
and text-brand-accent
.
如何添加或覆盖 Tailwind 主题变量?
¥How do I add or override a Tailwind theme variable?
要添加或覆盖主题变量,请将其添加到要添加或覆盖的键下的 cssVars.theme
中。
¥To add or override a theme variable you add it to cssVars.theme
under the key you want to add or override.
{
"$schema": "https://shadcn.nodejs.cn/schema/registry-item.json",
"name": "hello-world",
"title": "Hello World",
"type": "registry:block",
"description": "A complex hello world component",
"files": [
// ...
],
"cssVars": {
"theme": {
"text-base": "3rem",
"ease-in-out": "cubic-bezier(0.4, 0, 0.2, 1)",
"font-heading": "Poppins, sans-serif"
}
}
}