shadcn-ui
shadcn/uiのコンポーネントライブラリに関するインストール・設定・実装パターンを包括的に提供します。shadcn/uiのセットアップ、コンポーネントの追加、React Hook FormとZodを使ったフォーム構築、Tailwind CSSによるテーマカスタマイズ、またはボタン・ダイアログ・ドロップダウン・テーブル・複雑なフォームレイアウトなどのUIパターンを実装する際に活用してください。
description の原文を見る
Provides complete shadcn/ui component library patterns including installation, configuration, and implementation of accessible React components. Use when setting up shadcn/ui, installing components, building forms with React Hook Form and Zod, customizing themes with Tailwind CSS, or implementing UI patterns like buttons, dialogs, dropdowns, tables, and complex form layouts.
SKILL.md 本文
shadcn/ui コンポーネントパターン
shadcn/ui、Radix UI、Tailwind CSS を使用してアクセシブルでカスタマイズ可能な UI コンポーネントを構築します。
概要
- コンポーネントはプロジェクトにコピーされます — コードを所有し、カスタマイズできます
- Radix UI プリミティブに基づいており、完全なアクセシビリティを実現
- Tailwind CSS と CSS 変数でスタイリングとテーマ対応
- CLI ベースのインストール:
npx shadcn@latest add <component>
使用時機
ユーザーの以下のようなリクエストがある場合に有効化してください:
- 「shadcn/ui をセットアップしたい」、「shadcn を初期化したい」、「shadcn コンポーネントを追加したい」
- 「button/input/form/dialog/card/select/toast/table/chart をインストールしたい」
- 「React Hook Form」、「Zod バリデーション」、「バリデーション付きフォーム」
- 「アクセシブルなコンポーネント」、「Radix UI」、「Tailwind テーマ」
- 「shadcn button」、「shadcn dialog」、「shadcn sheet」、「shadcn table」
- 「ダークモード」、「CSS 変数」、「カスタムテーマ」
- 「Recharts を使用したチャート」、「棒グラフ」、「折れ線グラフ」、「円グラフ」
クイックリファレンス
利用可能なコンポーネント
| コンポーネント | インストールコマンド | 説明 |
|---|---|---|
button | npx shadcn@latest add button | バリエーション: default、destructive、outline、secondary、ghost、link |
input | npx shadcn@latest add input | テキスト入力フィールド |
form | npx shadcn@latest add form | React Hook Form 統合とバリデーション |
card | npx shadcn@latest add card | ヘッダー、コンテンツ、フッター付きコンテナ |
dialog | npx shadcn@latest add dialog | モーダルオーバーレイ |
sheet | npx shadcn@latest add sheet | スライドオーバーパネル(上/右/下/左) |
select | npx shadcn@latest add select | ドロップダウンセレクト |
toast | npx shadcn@latest add toast | 通知トースト |
table | npx shadcn@latest add table | データテーブル |
menubar | npx shadcn@latest add menubar | デスクトップ スタイルのメニューバー |
chart | npx shadcn@latest add chart | テーマ対応の Recharts ラッパー |
textarea | npx shadcn@latest add textarea | 複数行テキスト入力 |
checkbox | npx shadcn@latest add checkbox | チェックボックス入力 |
label | npx shadcn@latest add label | アクセシブルなフォームラベル |
インストラクション
プロジェクトの初期化
# 新しい Next.js プロジェクト
npx create-next-app@latest my-app --typescript --tailwind --eslint --app
cd my-app
npx shadcn@latest init
# 既存プロジェクト
npm install tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react
npx shadcn@latest init
# コンポーネントのインストール
npx shadcn@latest add button input form card dialog select toast
基本的なコンポーネント使用法
// バリエーションとサイズ付きボタン
import { Button } from "@/components/ui/button"
<Button variant="default">Default</Button>
<Button variant="destructive" size="sm">Delete</Button>
<Button variant="outline" disabled>Loading...</Button>
Zod バリデーション付きフォーム
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email("Invalid email"),
password: z.string().min(8, "Password must be at least 8 characters"),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { email: "", password: "" },
})
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)} className="space-y-4">
<FormField name="email" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<FormField name="password" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl><Input type="password" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<Button type="submit">Login</Button>
</form>
</Form>
)
}
高度な複数フィールドフォーム、API 送信コンタクトフォーム、ログインカードパターンについては、references/forms-and-validation.md を参照してください。
ダイアログ(モーダル)
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit Profile</DialogTitle>
</DialogHeader>
{/* content */}
</DialogContent>
</Dialog>
トースト通知
// 1. app/layout.tsx に <Toaster /> を追加
import { Toaster } from "@/components/ui/toaster"
// 2. コンポーネント内で使用
import { useToast } from "@/components/ui/use-toast"
const { toast } = useToast()
toast({ title: "Success", description: "Changes saved." })
toast({ variant: "destructive", title: "Error", description: "Something went wrong." })
棒グラフ
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies import("@/components/ui/chart").ChartConfig
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<BarChart data={data}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
<ChartTooltip content={<ChartTooltipContent />} />
</BarChart>
</ChartContainer>
折れ線グラフ、エリアグラフ、円グラフの例については、references/charts-components.md を参照してください。
例
バリデーション付きログインフォーム
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email("Invalid email"),
password: z.string().min(8, "Min 8 characters"),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { email: "", password: "" },
})
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)} className="space-y-4">
<FormField name="email" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<FormField name="password" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl><Input type="password" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<Button type="submit">Login</Button>
</form>
</Form>
)
}
アクション付きデータテーブル
import { ColumnDef } from "@tanstack/react-table"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { DataTable } from "@/components/ui/data-table"
const columns: ColumnDef<User>[] = [
{ id: "select", header: ({ table }) => (
<Checkbox checked={table.getIsAllPageRowsSelected()} />
), cell: ({ row }) => (
<Checkbox checked={row.getIsSelected()} />
)},
{ accessorKey: "name", header: "Name" },
{ accessorKey: "email", header: "Email" },
{ id: "actions", cell: ({ row }) => (
<Button variant="ghost" size="sm">Edit</Button>
)},
]
フォーム付きダイアログ
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Add User</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Add New User</DialogTitle>
</DialogHeader>
{/* <LoginForm /> */}
</DialogContent>
</Dialog>
トースト通知
import { useToast } from "@/components/ui/use-toast"
import { Button } from "@/components/ui/button"
const { toast } = useToast()
toast({ title: "Saved", description: "Changes saved successfully." })
toast({ variant: "destructive", title: "Error", description: "Failed to save." })
ベストプラクティス
- アクセシビリティ: Radix UI プリミティブを使用 — ARIA 属性は組み込まれています
- クライアントコンポーネント: インタラクティブなコンポーネント(フック、イベント)には
"use client"を追加 - タイプセーフティ: フォーム検証には TypeScript と Zod スキーマを使用
- テーマ設定:
globals.cssで CSS 変数を設定して一貫した設計を実現 - カスタマイズ: コンポーネントファイルを直接変更 — コードを所有できます
- パスエイリアス:
tsconfig.jsonで@エイリアスが設定されていることを確認 - レジストリセキュリティ: 信頼できるレジストリからのみコンポーネントをインストール。本番環境使用前に生成されたコードを確認
- ダークモード: CSS 変数戦略と
next-themesでセットアップ - フォーム: 常に
Form、FormField、FormItem、FormLabel、FormMessageを一緒に使用 - Toaster: ルートレイアウトに
<Toaster />を一度追加
制約と警告
- NPM パッケージではない: コンポーネントはプロジェクトにコピーされます。バージョン管理された依存関係ではありません
- レジストリセキュリティ:
npx shadcn@latest addから取得されるコンポーネントはリモートから取得されます。インストール前に必ずレジストリソースが信頼できることを確認してください - クライアントコンポーネント: ほとんどのインタラクティブコンポーネントには
"use client"ディレクティブが必須 - Radix 依存関係: すべての
@radix-uiパッケージがインストールされていることを確認 - Tailwind 必須: コンポーネントは Tailwind CSS ユーティリティに依存
- パスエイリアス: インポートのために
tsconfig.jsonで@エイリアスを設定
リファレンス
詳細なパターンとコード例については、以下のファイルを参照してください:
references/setup-and-configuration.md— 完全なインストール、tsconfig、tailwind config、CSS 変数references/ui-components.md— Button、Input、Card、Dialog、Sheet、Select、Toast、Table、Menubarreferences/forms-and-validation.md— React Hook Form + Zod、高度なフォーム、ログインカード、コンタクトフォームreferences/charts-components.md— Bar、Line、Area、Pie チャートと ChartContainer、テーマ設定references/nextjs-integration.md— App Router、Server/Client コンポーネント、ダークモード、メタデータreferences/customization.md— カスタムバリエーション、CSS 変数、cn() ユーティリティ、コンポーネント拡張
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- giuseppe-trisciuoglio
- ライセンス
- MIT
- 最終更新
- 不明
Source: https://github.com/giuseppe-trisciuoglio/developer-kit / ライセンス: MIT
関連スキル
doubt-driven-development
重要な判断はすべて、本番環境への展開前に新しい視点から対抗的レビューを実施します。速度より正確性が重要な場合、不慣れなコードを扱う場合、本番環境・セキュリティに関わるロジック・取り消し不可の操作など影響度が高い場合、または後でバグを修正するよりも今検証する方が効率的な場合に活用してください。
apprun-skills
TypeScriptを使用したAppRunアプリケーションのMVU設計に関する総合的なガイダンスが得られます。コンポーネントパターン、イベントハンドリング、状態管理(非同期ジェネレータを含む)、パラメータと保護機能を備えたルーティング・ナビゲーション、vistestを使用したテストに対応しています。AppRunコンポーネントの設計・レビュー、ルートの配線、状態フローの管理、AppRunテストの作成時に活用してください。
desloppify
コードベースのヘルスチェックと技術負債の追跡ツールです。コード品質、技術負債、デッドコード、大規模ファイル、ゴッドクラス、重複関数、コードスメル、命名規則の問題、インポートサイクル、結合度の問題についてユーザーが質問した場合に使用してください。また、ヘルススコアの確認、次の改善項目の提案、クリーンアップ計画の作成をリクエストされた際にも対応します。29言語に対応しています。
debugging-and-error-recovery
テストが失敗したり、ビルドが壊れたり、動作が期待と異なったり、予期しないエラーが発生したりした場合に、体系的な根本原因デバッグをガイドします。推測ではなく、根本原因を見つけて修正するための体系的なアプローチが必要な場合に使用してください。
test-driven-development
テスト駆動開発により実装を進めます。ロジックの実装、バグの修正、動作の変更など、あらゆる場面で活用できます。コードが正常に動作することを証明する必要がある場合、バグ報告を受けた場合、既存機能を修正する予定がある場合に使用してください。
incremental-implementation
変更を段階的に実施します。複数のファイルに影響する機能や変更を実装する場合に使用してください。大量のコードを一度に書こうとしている場合や、タスクが一度では完結できないほど大きい場合に活用します。