Get the FREE Ultimate OpenClaw Setup Guide →

shadcn-ui

npx machina-cli add skill jezweb/claude-skills/shadcn-ui --openclaw
Files (1)
SKILL.md
5.5 KB

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)

pnpm dlx shadcn@latest add button
pnpm dlx shadcn@latest add input label
pnpm dlx shadcn@latest add card

Feature Components (install as needed)

# Forms
pnpm dlx shadcn@latest add form        # needs: react-hook-form, zod, @hookform/resolvers
pnpm dlx shadcn@latest add textarea select checkbox switch

# Feedback
pnpm dlx shadcn@latest add toast        # needs: sonner
pnpm dlx shadcn@latest add alert badge

# Overlay
pnpm dlx shadcn@latest add dialog sheet popover dropdown-menu

# Data Display
pnpm dlx shadcn@latest add table        # for data tables, also: @tanstack/react-table
pnpm dlx shadcn@latest add tabs separator avatar

# Navigation
pnpm 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

// Don't use empty string values
<SelectItem value="">All</SelectItem>           // BREAKS

// Use sentinel value
<SelectItem value="__any__">All</SelectItem>    // WORKS
const actual = value === "__any__" ? "" : value

React Hook Form — Null Values

// 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

// Don't use dynamic import — icons get tree-shaken in production
import * as LucideIcons from 'lucide-react'
const Icon = LucideIcons[iconName]  // BREAKS in prod

// Use explicit map
import { 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

// 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/:

// button.tsx — add a "brand" variant
const 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:

// 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 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
Building complete UI patternsreferences/recipes.md

Source

git clone https://github.com/jezweb/claude-skills/blob/main/plugins/frontend/skills/shadcn-ui/SKILL.mdView on GitHub

Overview

Shadcn/ui provides a set of React components styled with Tailwind. This skill guides installing components in the correct order after tailwind-theme-builder sets up the theme infrastructure, handling dependencies, and customizing with semantic tokens. It covers common UI recipes such as forms, data tables, navigation, and modals to build cohesive interfaces.

How This Skill Works

After the theme infra exists (CSS vars, ThemeProvider, dark mode), install foundation components (button, input, card) in dependency order, then add feature components as needed. The skill also manages external dependencies (e.g., react-hook-form, zod, @hookform/resolvers, sonner, @tanstack/react-table) and uses semantic tokens for color and sizing instead of raw Tailwind colors. Customization patterns include extending variants and aligning with your theme using the cn utility and component files under src/components/ui.

When to Use It

  • Bootstrapping a themed React project by installing foundation components first, then feature components in dependency order.
  • Adding forms that integrate with react-hook-form, zod, and @hookform/resolvers.
  • Creating data tables that pair shadcn/table with @tanstack/react-table.
  • Setting up navigation with the navigation-menu and related patterns.
  • Customizing components via semantic tokens and variants to align with brand colors.

Quick Start

  1. Step 1: Ensure tailwind-theme-builder has set up the theme infrastructure (CSS vars, ThemeProvider, dark mode).
  2. Step 2: Install foundation components in dependency order (button, input, card).
  3. Step 3: Add feature components (form, table, navigation, dialog) and customize with semantic tokens.

Best Practices

  • Install foundation components before feature components to respect dependencies.
  • Always use semantic tokens from your theme instead of raw Tailwind colors.
  • Install external dependencies separately (e.g., react-hook-form, zod, @hookform/resolvers) and keep versions in sync.
  • Test UI patterns by composing components (forms, modals, tables) into real workflows.
  • Follow the dialog width and radix guidance to avoid layout issues (e.g., consistent breakpoint prefixes).

Example Use Cases

  • Login form using form, input, button with validation via react-hook-form and zod.
  • Data table page with searchable/sortable columns using shadcn/table and @tanstack/react-table.
  • Dashboard navigation with navigation-menu and command patterns for quick actions.
  • Modal dialog that opens a form inside and saves data.
  • Theme-aligned UI using semantic tokens for colors and sizes across components.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers