组件
- 手风琴 (Accordion)
- 警告 (Alert)
- 警告对话框 (Alert Dialog)
- 宽高比 (Aspect Ratio)
- 头像 (Avatar)
- 徽章 (Badge)
- 面包屑 (Breadcrumb)
- 按钮 (Button)
- 按钮组 (Button Group)
- 日历 (Calendar)
- 卡片 (Card)
- 轮播图 (Carousel)
- 图表 (Chart)
- 复选框 (Checkbox)
- 折叠面板 (Collapsible)
- 组合框 (Combobox)
- 命令面板 (Command)
- 上下文菜单 (Context Menu)
- 数据表格 (Data Table)
- 日期选择器 (Date Picker)
- 对话框 (Dialog)
- 抽屉 (Drawer)
- 下拉菜单 (Dropdown Menu)
- 空状态 (Empty)
- 字段 (Field)
- 表单 (Form)
- 悬停卡片 (Hover Card)
- 输入框 (Input)
- 输入组 (Input Group)
- 验证码输入 (Input OTP)
- 项 (Item)
- 键盘按键 (Kbd)
- 标签 (Label)
- 菜单栏 (Menubar)
- 原生选择器 (Native Select)
- 导航菜单 (Navigation Menu)
- 数字输入框 (Number Field)
- 分页 (Pagination)
- 引脚输入 (Pin Input)
- 气泡卡片 (Popover)
- 进度条 (Progress)
- 单选框组 (Radio Group)
- 范围日历 (Range Calendar)
- 可调整大小 (Resizable)
- 滚动区域 (Scroll Area)
- 选择器 (Select)
- 分隔线 (Separator)
- 侧边栏抽屉 (Sheet)
- 侧边栏 (Sidebar)
- 骨架屏 (Skeleton)
- 滑块 (Slider)
- 轻量提示 (Sonner)
- 加载动画 (Spinner)
- 步骤条 (Stepper)
- 开关 (Switch)
- 表格 (Table)
- 标签页 (Tabs)
- 标签输入 (Tags Input)
- 文本域 (Textarea)
- 吐司提示 (Toast)
- 切换按钮 (Toggle)
- 切换按钮组 (Toggle Group)
- 工具提示 (Tooltip)
- 排版 (Typography)
开始使用
registry:style
扩展 shadcn-vue 的自定义样式
以下注册项是一个扩展了 shadcn-vue 的自定义样式。在运行 npx shadcn-vue init 时,它会:
- 安装
@iconify/vue作为依赖。 - 将
Login01区块和calendar组件添加到项目中。 - 从远程注册表添加
editor。 - 将
font-sans变量设置为Inter, sans-serif。 - 在浅色和深色模式下安装
brand品牌颜色。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "example-style",
"type": "registry:style",
"dependencies": ["@iconify/vue"],
"registryDependencies": [
"Login01",
"calendar",
"https://example.com/r/editor.json"
],
"cssVars": {
"theme": {
"font-sans": "Inter, sans-serif"
},
"light": {
"brand": "20 14.3% 4.1%"
},
"dark": {
"brand": "20 14.3% 4.1%"
}
}
}从零开始的自定义样式
以下注册项是一个不扩展 shadcn-vue 的自定义样式。请查看 extends: none 字段。
它可以用于从零开始创建新样式,例如自定义组件、CSS 变量、依赖项等。
在运行 npx shadcn-vue add 时,以下操作将会:
- 安装
tailwind-merge和clsx作为依赖。 - 从 shadcn-vue 注册表添加
utils注册项。 - 从远程注册表添加
button、input、label和select组件。 - 安装新的 CSS 变量:
main,bg,border,text,ring。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"extends": "none",
"name": "new-style",
"type": "registry:style",
"dependencies": ["tailwind-merge", "clsx"],
"registryDependencies": [
"utils",
"https://example.com/r/button.json",
"https://example.com/r/input.json",
"https://example.com/r/label.json",
"https://example.com/r/select.json"
],
"cssVars": {
"theme": {
"font-sans": "Inter, sans-serif"
},
"light": {
"main": "#88aaee",
"bg": "#dfe5f2",
"border": "#000",
"text": "#000",
"ring": "#000"
},
"dark": {
"main": "#88aaee",
"bg": "#272933",
"border": "#000",
"text": "#e6e6e6",
"ring": "#fff"
}
}
}registry:theme
自定义主题
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-theme",
"type": "registry:theme",
"cssVars": {
"light": {
"background": "oklch(1 0 0)",
"foreground": "oklch(0.141 0.005 285.823)",
"primary": "oklch(0.546 0.245 262.881)",
"primary-foreground": "oklch(0.97 0.014 254.604)",
"ring": "oklch(0.746 0.16 232.661)",
"sidebar-primary": "oklch(0.546 0.245 262.881)",
"sidebar-primary-foreground": "oklch(0.97 0.014 254.604)",
"sidebar-ring": "oklch(0.746 0.16 232.661)"
},
"dark": {
"background": "oklch(1 0 0)",
"foreground": "oklch(0.141 0.005 285.823)",
"primary": "oklch(0.707 0.165 254.624)",
"primary-foreground": "oklch(0.97 0.014 254.604)",
"ring": "oklch(0.707 0.165 254.624)",
"sidebar-primary": "oklch(0.707 0.165 254.624)",
"sidebar-primary-foreground": "oklch(0.97 0.014 254.604)",
"sidebar-ring": "oklch(0.707 0.165 254.624)"
}
}
}自定义颜色
以下样式将使用 shadcn-vue 默认值进行初始化,然后添加一个自定义的 brand 颜色。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-style",
"type": "registry:style",
"cssVars": {
"light": {
"brand": "oklch(0.99 0.00 0)"
},
"dark": {
"brand": "oklch(0.14 0.00 286)"
}
}
}registry:block
自定义区块
此区块从 shadcn-vue 注册表安装 Login01 区块。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "Login01",
"type": "registry:block",
"description": "A simple login form.",
"registryDependencies": ["button", "card", "input", "label"],
"files": [
{
"path": "blocks/Login01/page.vue",
"content": "import { LoginForm } ...",
"type": "registry:page",
"target": "pages/login/index.vue"
},
{
"path": "blocks/login-01/components/LoginForm.vue",
"content": "...",
"type": "registry:component"
}
]
}安装区块并覆盖基元组件
您可以从 shadcn-vue 注册表安装区块,并使用您的自定义基元覆盖现有的基元组件。
在运行 npx shadcn-vue add 时,以下操作将会:
- 从 shadcn-vue 注册表添加
Login01区块。 - 使用远程注册表中的组件覆盖
button、input和label基元。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-login",
"type": "registry:block",
"registryDependencies": [
"Login01",
"https://example.com/r/button.json",
"https://example.com/r/input.json",
"https://example.com/r/label.json"
]
}CSS 变量
自定义主题变量
向 theme 对象添加自定义主题变量。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-theme",
"type": "registry:theme",
"cssVars": {
"theme": {
"font-heading": "Inter, sans-serif",
"shadow-card": "0 0 0 1px rgba(0, 0, 0, 0.1)"
}
}
}覆盖 Tailwind CSS 变量
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-theme",
"type": "registry:theme",
"cssVars": {
"theme": {
"spacing": "0.2rem",
"breakpoint-sm": "640px",
"breakpoint-md": "768px",
"breakpoint-lg": "1024px",
"breakpoint-xl": "1280px",
"breakpoint-2xl": "1536px"
}
}
}添加自定义 CSS
基础样式
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-style",
"type": "registry:style",
"css": {
"@layer base": {
"h1": {
"font-size": "var(--text-2xl)"
},
"h2": {
"font-size": "var(--text-xl)"
}
}
}
}组件
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-card",
"type": "registry:component",
"css": {
"@layer components": {
"card": {
"background-color": "var(--color-white)",
"border-radius": "var(--rounded-lg)",
"padding": "var(--spacing-6)",
"box-shadow": "var(--shadow-xl)"
}
}
}
}添加自定义工具类
简单工具类
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-component",
"type": "registry:component",
"css": {
"@utility content-auto": {
"content-visibility": "auto"
}
}
}复杂工具类
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-component",
"type": "registry:component",
"css": {
"@utility scrollbar-hidden": {
"scrollbar-hidden": {
"&::-webkit-scrollbar": {
"display": "none"
}
}
}
}
}功能性工具类
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-component",
"type": "registry:component",
"css": {
"@utility tab-*": {
"tab-size": "var(--tab-size-*)"
}
}
}添加自定义动画
注意:要使用动画,您需要在 CSS 中定义 @keyframes,并在 cssVars 中定义 theme。
{
"$schema": "https://vue.shadcn.org.cn/schema/registry-item.json",
"name": "custom-component",
"type": "registry:component",
"cssVars": {
"theme": {
"--animate-wiggle": "wiggle 1s ease-in-out infinite"
}
},
"css": {
"@keyframes wiggle": {
"0%, 100%": {
"transform": "rotate(-3deg)"
},
"50%": {
"transform": "rotate(3deg)"
}
}
}
}