Shadcn Ui

jezweb/claude-skills/plugins/frontend/skills/shadcn-ui

作者 jezweb64965d9d9fc7無授權條款1K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫3 天前更新

Install and configure shadcn/ui components for React projects. Guides component selection, installation order, dependency management, customisation with semantic tokens, and common UI recipes (forms, data tables, navigation, modals). Use after tailwind-theme-builder has set up the theme infrastructure, when adding components, building forms, creating data tables, or setting up navigation.

AI 產生的概覽

在已設定主題的 React 專案中安裝並客製 shadcn/ui 元件,含相依順序與 UI 配方。

功能
此技能指導在已具備主題基礎設施的 React 專案中加入 shadcn/ui 元件。它提供基礎元件與功能元件的安裝順序、列出外部相依套件、記錄常見問題,並說明如何透過語意化 CSS 權杖進行客製。它也會指向包含元件目錄與完整 UI 配方(例如表單、資料表格、模態視窗與導覽)的參考檔案。
適用情境
適用於在已設定主題的 React 專案中加入 shadcn/ui 元件、建立表單、製作資料表格或設定導覽的情境。它應在 CSS 變數、components.json 與 cn() 工具等主題基礎設施就緒之後執行。
執行需求
需要一個已具備主題基礎設施(CSS 變數、components.json、cn() 工具)的 React 專案,以及 pnpm 等套件管理工具。元件會引入外部相依套件,包括 react-hook-form、zod、@hookform/resolvers、sonner、@tanstack/react-table、cmdk,以及選用的 date-fns。不附帶指令碼,僅提供說明與參考文件。

shadcn/ui Components

Add shadcn/ui components to a themed React project. This skill runs AFTER tailwind-theme-builder has set up CSS variables, ThemeProvider, and dark mode. It handles component installation, customisation, and combining components into working patterns.

Prerequisite: Theme infrastructure must exist (CSS variables, components.json, cn() utility). Use tailwind-theme-builder first if not set up.

Installation Order

Install components in dependency order. Foundation components first, then feature components:

Foundation (install first)

bash
pnpm dlx shadcn@latest add buttonpnpm dlx shadcn@latest add input labelpnpm dlx shadcn@latest add card

Feature Components (install as needed)

bash
# Formspnpm dlx shadcn@latest add form        # needs: react-hook-form, zod, @hookform/resolverspnpm dlx shadcn@latest add textarea select checkbox switch
# Feedbackpnpm dlx shadcn@latest add toast        # needs: sonnerpnpm dlx shadcn@latest add alert badge
# Overlaypnpm dlx shadcn@latest add dialog sheet popover dropdown-menu
# Data Displaypnpm dlx shadcn@latest add table        # for data tables, also: @tanstack/react-tablepnpm dlx shadcn@latest add tabs separator avatar
# Navigationpnpm dlx shadcn@latest add navigation-menu command

External Dependencies

ComponentRequires
Formreact-hook-form, zod, @hookform/resolvers
Toastsonner
Data Table@tanstack/react-table
Commandcmdk
Date Pickerdate-fns (optional)

Install external deps separately: pnpm add react-hook-form zod @hookform/resolvers

Known Gotchas

These are documented corrections that prevent common bugs:

Radix Select — No Empty Strings

tsx
// Don't use empty string values<SelectItem value="">All</SelectItem>           // BREAKS
// Use sentinel value<SelectItem value="__any__">All</SelectItem>    // WORKSconst actual = value === "__any__" ? "" : value

React Hook Form — Null Values

tsx
// Don't spread {...field} — it passes null which Input rejects<Input  value={field.value ?? ''}  onChange={field.onChange}  onBlur={field.onBlur}  name={field.name}  ref={field.ref}/>

Lucide Icons — Tree-Shaking

tsx
// Don't use dynamic import — icons get tree-shaken in productionimport * as LucideIcons from 'lucide-react'const Icon = LucideIcons[iconName]  // BREAKS in prod
// Use explicit mapimport { Home, Users, Settings, type LucideIcon } from 'lucide-react'const ICON_MAP: Record<string, LucideIcon> = { Home, Users, Settings }const Icon = ICON_MAP[iconName]

Dialog Width Override

tsx
// Default sm:max-w-lg won't be overridden by max-w-6xl<DialogContent className="max-w-6xl">       // DOESN'T WORK
// Use same breakpoint prefix<DialogContent className="sm:max-w-6xl">    // WORKS

Customising Components

shadcn components use semantic CSS tokens from your theme. To customise:

Variant extension

Add custom variants by editing the component file in src/components/ui/:

tsx
// button.tsx — add a "brand" variantconst buttonVariants = cva("...", {  variants: {    variant: {      default: "bg-primary text-primary-foreground",      brand: "bg-brand text-brand-foreground hover:bg-brand/90",      // ... existing variants    },  },})

Colour overrides

Use semantic tokens from your theme — never raw Tailwind colours:

tsx
// Don't use raw colours<Button className="bg-blue-500">             // WRONG
// Use semantic tokens<Button className="bg-primary">              // RIGHT<Card className="bg-card text-card-foreground">  // RIGHT

Workflow

Step 1: Assess Needs

Determine what UI patterns the project needs:

NeedComponents
Forms with validationForm, Input, Label, Select, Textarea, Button, Toast
Data display with sortingTable, Badge, Pagination
Admin CRUD interfaceDialog, Form, Table, Button, Toast
Marketing/landing pageCard, Button, Badge, Separator
Settings/preferencesTabs, Form, Switch, Select, Toast
NavigationNavigationMenu (desktop), Sheet (mobile), ModeToggle

Step 2: Install Components

Install foundation first, then feature components for the identified needs. Use the commands above.

Step 3: Build Recipes

Combine components into working patterns. See references/recipes.md [blocked] for complete working examples:

  • Contact Form — Form + Input + Textarea + Button + Toast
  • Data Table — Table + Column sorting + Pagination + Search
  • Modal CRUD — Dialog + Form + Button
  • Navigation — Sheet + NavigationMenu + ModeToggle
  • Settings Page — Tabs + Form + Switch + Select + Toast

Step 4: Customise

Apply project-specific colours and variants using semantic tokens from the theme.

Reference Files

WhenRead
Choosing components, install commands, propsreferences/component-catalogue.md [blocked]
Building complete UI patternsreferences/recipes.md [blocked]

來源與署名

來源:jezweb/claude-skills位於plugins/frontend/skills/shadcn-ui提交64965d9

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架