shadcn-ui-expert by majesteitbart/talentmatcher
npx skills add https://github.com/majesteitbart/talentmatcher --skill shadcn-ui-expertshadcn-ui 是一个精心设计、易于访问的 React 组件集合,基于 TypeScript、Tailwind CSS 和 Radix UI 原语构建。本技能将指导您完成组件选择、实现、定制和最佳实践。
首先,在您的项目中初始化 shadcn-ui:
npx shadcn-ui@latest init
这将创建一个用于配置的 components.json 文件。选择您的框架:
使用 CLI 安装单个组件:
# 安装按钮组件
npx shadcn-ui@latest add button
# 安装表单组件
npx shadcn-ui@latest add form input select checkbox
# 安装数据表格
npx shadcn-ui@latest add data-table
或者直接要求我“添加一个登录表单”——我可以使用 MCP 服务器通过自然语言处理安装。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
用途:数据收集、用户输入、验证
form - 使用 React Hook Form 的复杂表单input - 文本字段textarea - 多行文本select - 下拉选择checkbox - 布尔值输入radio-group - 从选项中进行单选switch - 切换布尔状态date-picker - 日期选择combobox - 可搜索的自动完成选择用途:应用结构、导航流程、内容组织
sidebar - 可折叠的侧边导航tabs - 标签页内容accordion - 可折叠区域breadcrumb - 导航路径navigation-menu - 下拉菜单scroll-area - 自定义可滚动区域用途:模态框、确认框、浮动内容
dialog - 模态对话框alert-dialog - 确认提示drawer - 移动端友好的侧边面板popover - 浮动弹出框tooltip - 悬停信息提示dropdown-menu - 菜单下拉框context-menu - 右键菜单用途:展示结构化数据
table - 基础 HTML 表格data-table - 具有排序/筛选/分页功能的高级表格avatar - 用户头像badge - 状态标签card - 内容容器用途:用户反馈、加载状态、提醒
alert - 提醒消息toast - 通知progress - 进度条skeleton - 加载占位符spinner - 加载指示器通过回答以下问题来选择正确的组件:
用户在与什么交互?
inputselect 或 comboboxcheckbox 或 switchform应该如何显示?
input、selectdialogdrawertooltip上下文是什么?
field 组件与 form 结合使用buttondata-table是否需要验证?
form + field + React Hook Forminput、select)import { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import * as z from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormField, FormItem, FormLabel, FormControl } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
})
function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values)
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input placeholder="you@example.com" {...field} />
</FormControl>
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
)
}
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DeleteDialog() {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="destructive">Delete</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
This action cannot be undone.
</DialogDescription>
</DialogHeader>
<div className="flex gap-3 justify-end">
<Button variant="outline">Cancel</Button>
<Button variant="destructive">Delete</Button>
</div>
</DialogContent>
</Dialog>
)
}
所有组件都使用 Tailwind CSS 进行样式设计。通过以下方式自定义外观:
直接向组件添加类:
<Button className="w-full text-lg">Full Width</Button>
<Input className="rounded-lg border-2" />
shadcn/ui 使用 CSS 变量进行主题设置。编辑 app/globals.css:
@layer base {
:root {
--primary: 222.2 47.4% 11.2%;
--secondary: 210 40% 96%;
}
}
在您的框架中启用深色模式:
next.config.js 中配置tailwind.config.js 中添加深色类检测dark 类许多组件都有内置变体:
<Button variant="outline" />
<Button variant="ghost" />
<Button variant="destructive" />
<Badge variant="secondary" />
组合小组件,而不是修改大组件:
// ✅ 良好:组合组件
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
</CardHeader>
<CardContent>
<Form>...</Form>
</CardContent>
</Card>
// ❌ 避免:过度修改单个组件
<CustomDialog withHeader={true} withForm={true} />
利用 TypeScript 确保属性安全:
import { Button } from "@/components/ui/button"
import type { ButtonProps } from "@/components/ui/button"
type CustomButtonProps = ButtonProps & {
label: string
}
shadcn/ui 使用内置可访问性的 Radix UI 原语:
只需正确使用组件;可访问性自然具备。
React.memoshadcn-ui@latest add form 集成 React Hook Formnext-themes 工作tailwind.config.js 包含组件路径remix 的表单操作配合使用在初始化期间编辑 components.json 或手动更新 globals.css 中的 CSS 变量。
按照 shadcn/ui 的模式在 components/ui/ 中创建您自己的组件:
// components/ui/my-component.tsx
import * as React from "react"
export interface MyComponentProps
extends React.HTMLAttributes<HTMLDivElement> {}
const MyComponent = React.forwardRef<HTMLDivElement, MyComponentProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={className}
{...props}
/>
)
)
MyComponent.displayName = "MyComponent"
export { MyComponent }
使用 CSS 变量层:
.brand-a {
--primary: 220 90% 56%;
--secondary: 0 0% 100%;
}
.brand-b {
--primary: 0 100% 50%;
--secondary: 200 100% 50%;
}
具有客户端验证的复杂表单的最佳实践:
npm install react-hook-form zod @hookform/resolvers
满足高级表单需求的替代方案:
npm install @tanstack/react-form
向我询问特定的表单模式(登录、注册、多步骤等)
tailwind.config.js 中配置components.json 中的 path 设置是否正确npm install/components/ui/name 导入的zod 和 @hookform/resolverszodResolver 与 useForm 结合使用有关特定任务的详细指导:
每周安装量
351
仓库
GitHub 星标
1
首次出现
Jan 22, 2026
安全审计
安装于
opencode315
gemini-cli306
codex296
github-copilot277
cursor273
claude-code265
shadcn-ui is a collection of beautifully-designed, accessible React components built with TypeScript, Tailwind CSS, and Radix UI primitives. This skill guides you through component selection, implementation, customization, and best practices.
First, initialize shadcn-ui in your project:
npx shadcn-ui@latest init
This creates a components.json file for configuration. Choose your framework:
Use the CLI to install individual components:
# Install a button component
npx shadcn-ui@latest add button
# Install form components
npx shadcn-ui@latest add form input select checkbox
# Install a data table
npx shadcn-ui@latest add data-table
Or ask me directly to "add a login form" - I can use the MCP server to handle installation with natural language.
Use for : Data collection, user input, validation
form - Complex forms with React Hook Forminput - Text fieldstextarea - Multi-line textselect - Dropdown selectionscheckbox - Boolean inputsradio-group - Single selection from optionsswitch - Toggle boolean statesdate-picker - Date selectioncombobox - Searchable select with autocompleteUse for : App structure, navigation flows, content organization
sidebar - Collapsible side navigationtabs - Tabbed contentaccordion - Collapsible sectionsbreadcrumb - Navigation pathnavigation-menu - Dropdown menusscroll-area - Custom scrollable regionsUse for : Modals, confirmations, floating content
dialog - Modal dialogsalert-dialog - Confirmation promptsdrawer - Mobile-friendly side panelspopover - Floating popoverstooltip - Hover informationdropdown-menu - Menu dropdownscontext-menu - Right-click menusUse for : Showing structured data
table - Basic HTML tablesdata-table - Advanced tables with sorting/filtering/paginationavatar - User profile imagesbadge - Status labelscard - Content containersUse for : User feedback, loading states, alerts
alert - Alert messagestoast - Notificationsprogress - Progress barsskeleton - Loading placeholdersspinner - Loading indicatorsAsk yourself these questions to choose the right component:
What is the user interacting with?
inputselect or comboboxcheckbox or switchformHow should it be displayed?
input, selectdialogimport { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import * as z from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormField, FormItem, FormLabel, FormControl } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
})
function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values)
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input placeholder="you@example.com" {...field} />
</FormControl>
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
)
}
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DeleteDialog() {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="destructive">Delete</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
This action cannot be undone.
</DialogDescription>
</DialogHeader>
<div className="flex gap-3 justify-end">
<Button variant="outline">Cancel</Button>
<Button variant="destructive">Delete</Button>
</div>
</DialogContent>
</Dialog>
)
}
All components use Tailwind CSS for styling. Customize appearance through:
Add classes directly to components:
<Button className="w-full text-lg">Full Width</Button>
<Input className="rounded-lg border-2" />
shadcn/ui uses CSS variables for theming. Edit app/globals.css:
@layer base {
:root {
--primary: 222.2 47.4% 11.2%;
--secondary: 210 40% 96%;
}
}
Enable dark mode in your framework:
next.config.jstailwind.config.jsdark classMany components have built-in variants:
<Button variant="outline" />
<Button variant="ghost" />
<Button variant="destructive" />
<Badge variant="secondary" />
Combine small components rather than modifying large ones:
// ✅ Good: Compose components
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
</CardHeader>
<CardContent>
<Form>...</Form>
</CardContent>
</Card>
// ❌ Avoid: Over-modifying single component
<CustomDialog withHeader={true} withForm={true} />
Leverage TypeScript for prop safety:
import { Button } from "@/components/ui/button"
import type { ButtonProps } from "@/components/ui/button"
type CustomButtonProps = ButtonProps & {
label: string
}
shadcn/ui uses Radix UI primitives with accessibility built-in:
Just use components correctly; accessibility comes free.
React.memo for frequently-rerendered components if neededshadcn-ui@latest add form for React Hook Form integrationnext-themestailwind.config.js includes component pathsremix form actionsEdit components.json during init or manually update CSS variables in globals.css.
Create your own components in components/ui/ following shadcn/ui patterns:
// components/ui/my-component.tsx
import * as React from "react"
export interface MyComponentProps
extends React.HTMLAttributes<HTMLDivElement> {}
const MyComponent = React.forwardRef<HTMLDivElement, MyComponentProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={className}
{...props}
/>
)
)
MyComponent.displayName = "MyComponent"
export { MyComponent }
Use CSS variable layers:
.brand-a {
--primary: 220 90% 56%;
--secondary: 0 0% 100%;
}
.brand-b {
--primary: 0 100% 50%;
--secondary: 200 100% 50%;
}
Best practice for complex forms with client-side validation:
npm install react-hook-form zod @hookform/resolvers
Alternative for advanced form requirements:
npm install @tanstack/react-form
Ask me for specific form patterns (login, signup, multi-step, etc.)
tailwind.config.jscomponents.json has correct path settingnpm install after adding components/components/ui/namezod and @hookform/resolverszodResolver with useFormFor detailed guidance on specific tasks:
Weekly Installs
351
Repository
GitHub Stars
1
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode315
gemini-cli306
codex296
github-copilot277
cursor273
claude-code265
TanStack Query v5 完全指南:React 数据管理、乐观更新、离线支持
2,500 周安装
drawertooltipWhat's the context?
field component with formbuttondata-tableDoes it need validation?
form + field + React Hook Forminput, select)