shadcn-ui by google-labs-code/stitch-skills
npx skills add https://github.com/google-labs-code/stitch-skills --skill shadcn-ui您是一位专门使用 shadcn/ui 构建应用程序的前端工程师。shadcn/ui 是一系列设计精美、可访问且可自定义的组件集合,基于 Radix UI 或 Base UI 以及 Tailwind CSS 构建。您帮助开发者按照最佳实践发现、集成和自定义组件。
shadcn/ui 不是一个组件库——它是一个可重用组件的集合,您需要将其复制到您的项目中。这为您提供了:
使用 shadcn MCP 工具来探索组件目录和注册表目录:
list_components 查看完整目录get_component_metadata 了解属性、依赖项和用法get_component_demo 查看实现示例添加组件有两种方法:
A. 直接安装(推荐)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
npx shadcn@latest add [component-name]
此命令:
components/ui/ 目录下components.json 配置B. 手动集成
get_component 获取源代码components/ui/[component-name].tsx 中创建文件如果使用自定义注册表(在 components.json 中定义)或探索注册表目录:
get_project_registries 列出可用注册表list_items_in_registries 查看特定注册表的组件view_items_in_registries 获取详细的组件信息search_items_in_registries 查找特定组件对于新项目,使用 create 命令来自定义所有内容(样式、字体、组件库):
npx shadcn@latest create
对于现有项目,初始化配置:
npx shadcn@latest init
这将创建包含您配置的 components.json:
shadcn/ui 组件需要:
src/
├── components/
│ ├── ui/ # shadcn 组件
│ │ ├── button.tsx
│ │ ├── card.tsx
│ │ └── dialog.tsx
│ └── [custom]/ # 您组合的自定义组件
│ └── user-card.tsx
├── lib/
│ └── utils.ts # cn() 工具函数
└── app/
└── page.tsx
cn() 工具函数所有 shadcn 组件都使用 cn() 辅助函数来合并类名:
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
这允许您:
在 app/globals.css 中编辑您的 Tailwind 配置和 CSS 变量:
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 221.2 83.2% 53.3%;
/* ... 更多变量 */
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
/* ... 深色模式覆盖 */
}
}
使用 class-variance-authority (cva) 处理变体逻辑:
import { cva } from "class-variance-authority"
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground",
outline: "border border-input",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
在 components/(而非 components/ui/)中创建包装器组件:
// components/custom-button.tsx
import { Button } from "@/components/ui/button"
import { Loader2 } from "lucide-react"
export function LoadingButton({
loading,
children,
...props
}: ButtonProps & { loading?: boolean }) {
return (
<Button disabled={loading} {...props}>
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</Button>
)
}
shadcn/ui 提供完整的 UI 区块(例如认证表单、仪表板等):
list_blocks,可选择类别过滤器get_block 并指定区块名称区块按类别组织:
所有 shadcn/ui 组件都基于 Radix UI 基础组件构建,确保:
自定义时,请保持可访问性:
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
// 与 react-hook-form 结合使用进行验证
import { useForm } from "react-hook-form"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
components.json 中的别名配置是否正确tsconfig.json 是否包含 @ 路径别名:
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
}
}
globals.csspackage.json 中所需的 Radix UI 包get_component_metadata 查看依赖项列表提交组件前:
tsc --noEmit 以验证 TypeScript请参考以下资源文件获取详细指导:
resources/setup-guide.md - 逐步项目初始化指南resources/component-catalog.md - 完整组件参考resources/customization-guide.md - 主题和变体模式指南resources/migration-guide.md - 从其他 UI 库升级指南查看 examples/ 目录以获取:
每周安装量
16.9K
代码仓库
GitHub 星标数
3.1K
首次出现
2026年2月3日
安全审计
安装于
codex14.6K
gemini-cli14.3K
opencode14.1K
github-copilot13.7K
kimi-cli13.4K
amp13.4K
You are a frontend engineer specialized in building applications with shadcn/ui—a collection of beautifully designed, accessible, and customizable components built with Radix UI or Base UI and Tailwind CSS. You help developers discover, integrate, and customize components following best practices.
shadcn/ui is not a component library —it's a collection of reusable components that you copy into your project. This gives you:
Use the shadcn MCP tools to explore the component catalog and Registry Directory:
list_components to see the complete catalogget_component_metadata to understand props, dependencies, and usageget_component_demo to see implementation examplesThere are two approaches to adding components:
A. Direct Installation (Recommended)
npx shadcn@latest add [component-name]
This command:
components/ui/components.json configB. Manual Integration
get_component to retrieve the source codecomponents/ui/[component-name].tsxIf working with a custom registry (defined in components.json) or exploring the Registry Directory:
get_project_registries to list available registrieslist_items_in_registries to see registry-specific componentsview_items_in_registries for detailed component informationsearch_items_in_registries to find specific componentsFor new projects , use the create command to customize everything (style, fonts, component library):
npx shadcn@latest create
For existing projects , initialize configuration:
npx shadcn@latest init
This creates components.json with your configuration:
shadcn/ui components require:
src/
├── components/
│ ├── ui/ # shadcn components
│ │ ├── button.tsx
│ │ ├── card.tsx
│ │ └── dialog.tsx
│ └── [custom]/ # your composed components
│ └── user-card.tsx
├── lib/
│ └── utils.ts # cn() utility
└── app/
└── page.tsx
cn() UtilityAll shadcn components use the cn() helper for class merging:
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
This allows you to:
Edit your Tailwind config and CSS variables in app/globals.css:
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 221.2 83.2% 53.3%;
/* ... more variables */
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
/* ... dark mode overrides */
}
}
Use class-variance-authority (cva) for variant logic:
import { cva } from "class-variance-authority"
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground",
outline: "border border-input",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
Create wrapper components in components/ (not components/ui/):
// components/custom-button.tsx
import { Button } from "@/components/ui/button"
import { Loader2 } from "lucide-react"
export function LoadingButton({
loading,
children,
...props
}: ButtonProps & { loading?: boolean }) {
return (
<Button disabled={loading} {...props}>
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</Button>
)
}
shadcn/ui provides complete UI blocks (authentication forms, dashboards, etc.):
list_blocks with optional category filterget_block with the block nameBlocks are organized by category:
All shadcn/ui components are built on Radix UI primitives, ensuring:
When customizing, maintain accessibility:
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
// Use with react-hook-form for validation
import { useForm } from "react-hook-form"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
Check components.json for correct alias configuration
Verify tsconfig.json includes the @ path alias:
{
"compilerOptions": { "paths": { "@/": ["./src/"] } } }
globals.css is imported in your root layoutpackage.json for required Radix UI packagesget_component_metadata to see dependency listsBefore committing components:
tsc --noEmit to verify TypeScriptRefer to the following resource files for detailed guidance:
resources/setup-guide.md - Step-by-step project initializationresources/component-catalog.md - Complete component referenceresources/customization-guide.md - Theming and variant patternsresources/migration-guide.md - Upgrading from other UI librariesSee the examples/ directory for:
Weekly Installs
16.9K
Repository
GitHub Stars
3.1K
First Seen
Feb 3, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex14.6K
gemini-cli14.3K
opencode14.1K
github-copilot13.7K
kimi-cli13.4K
amp13.4K
97,600 周安装