Communitygithub.com

ComeOnOliver/skillshub

UI コンポーネントを構築する際に使用します。ShadCN UI パターン、アクセシビリティ基準(Radix UI)、および2025年11月時点の TailwindCSS のベストプラクティスを適用します。

skillshub とは?

この AI エージェントスキルは、ShadCN UI パターンに基づいて React コンポーネントを構築、リファクタリングする際のガイドです。2025年11月時点の最新のベストプラクティスに従い、ShadCN UI の「コピペ」方式によるコンポーネントの完全な所有権、Radix UI が提供する WCAG 2.1 AA 準拠のアクセシビリティ、TailwindCSS によるカスタマイズ性を重視します。Next.js 15 の App Router と Server Components との互換性があり、TypeScript による型安全なプロパティとバリアント定義をサポートします。このスキルを使用することで、開発者は一貫性のあるアクセシブルでメンテナンスしやすい UI を効率的に構築できます。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/barnhardt-enterprises-inc/shadcn-ui-patterns

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

ShadCN UI パターン - 2025年11月基準

使用するタイミング

  • 新しい UI コンポーネントの構築
  • 既存コンポーネントの ShadCN へのリファクタリング
  • バリデーション付きフォームの実装
  • モーダル、ダイアログ、オーバーレイの作成
  • アクセシビリティ準拠の確保

ShadCN UI を選ぶ理由

  • npm ではなくコピペ - コンポーネントコードを完全に所有
  • Radix UI プリミティブ - アクセシビリティが組み込み済み(WCAG 2.1 AA 準拠)
  • TailwindCSS ファースト - 完全なカスタマイズ、CSS-in-JS 不要
  • TypeScript ネイティブ - 型安全なプロパティとバリアント
  • Server コンポーネント対応 - Next.js 15 App Router と互換性あり

基本原則

1. コンポーネントのインストールパターン

# 必要なコンポーネントを個別にインストール
npx shadcn@latest add button
npx shadcn@latest add dialog
npx shadcn@latest add form
npx shadcn@latest add input
npx shadcn@latest add label

コンポーネントは src/components/ui/ ディレクトリにコピーされます。コードはあなたが所有します。

2. コンポーネントの使用パターン

Button コンポーネント

import { Button } from "@/components/ui/button"

// ✅ 推奨:意味的なバリアントを使用
<Button variant="default">保存</Button>
<Button variant="destructive">削除</Button>
<Button variant="outline">キャンセル</Button>
<Button variant="ghost">スキップ</Button>
<Button variant="link">詳細を見る</Button>

// ✅ 推奨:サイズバリアントを使用
<Button size="default">中</Button>
<Button size="sm">小</Button>
<Button size="lg">大</Button>
<Button size="icon"><アイコン /></Button>

// ❌ 非推奨:Button コンポーネントを使わずにカスタムボタンを作成
<button className="px-4 py-2 bg-blue-500">悪い例</button>

Dialog/Modal コンポーネント

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"

// ✅ 推奨:適切なダイアログ構造を使用(アクセシビリティ)
<Dialog>
  <DialogTrigger asChild>
    <Button>設定を開く</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>設定</DialogTitle>
      <DialogDescription>
        ここでアプリケーションの設定を行えます。
      </DialogDescription>
    </DialogHeader>
    {/* ダイアログの内容 */}
  </DialogContent>
</Dialog>

// ❌ 非推奨:DialogHeader や DialogTitle を省略(スクリーンリーダーで問題が発生)
<DialogContent>
  <h2>設定</h2> {/* 誤り:DialogTitle を使用すべき */}
</DialogContent>

Form コンポーネント(React Hook Form + Zod)

import { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import * as z from "zod"
import {
  Form,
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"

// ✅ 推奨:最初に Zod スキーマを定義(バリデーション)
const formSchema = z.object({
  email: z.string().email("無効なメールアドレスです"),
  password: z.string().min(8, "パスワードは8文字以上である必要があります"),
})

function LoginForm() {
  const form = useForm<z.infer<typeof formSchema>>({
    resolver: zodResolver(formSchema),
    defaultValues: {
      email: "",
      password: "",
    },
  })

  async function onSubmit(values: z.infer<typeof formSchema>) {
    // 型安全なバリデーション済みデータ
    console.log(values)
  }

  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
        <FormField
          control={form.control}
          name="email"
          render={({ field }) => (
            <FormItem>
              <FormLabel>メールアドレス</FormLabel>
              <FormControl>
                <Input placeholder="[email protected]" {...field} />
              </FormControl>
              <FormDescription>
                メールアドレスは第三者と共有されません。
              </FormDescription>
              <FormMessage />
            </FormItem>
          )}
        />

        <FormField
          control={form.control}
          name="password"
          render={({ field }) => (
            <FormItem>
              <FormLabel>パスワード</FormLabel>
              <FormControl>
                <Input type="password" {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />

        <Button type="submit">サインイン</Button>
      </form>
    </Form>
  )
}

// ❌ 非推奨:バリデーションなしで非制御フォームを使用
<form>
  <input name="email" /> {/* バリデーションなし */}
</form>

3. Server コンポーネント vs Client コンポーネント

// ✅ 推奨:静的なダイアログには Server コンポーネントを使用
import { Dialog, DialogContent } from "@/components/ui/dialog"

export default function ServerDialog() {
  // 'use client' は不要
  return <Dialog>...</Dialog>
}

// ✅ 推奨:状態が必要な場合は Client コンポーネントを使用
'use client'

import { useState } from 'react'
import { Dialog, DialogContent } from "@/components/ui/dialog"

export function ClientDialog() {
  const [open, setOpen] = useState(false)

  return (
    <Dialog open={open} onOpenChange={setOpen}>
      <DialogContent>...</DialogContent>
    </Dialog>
  )
}

4. アクセシビリティ要件

フォーカス管理

// ✅ 推奨:適切なフォーカス管理のために asChild を指定して DialogTrigger を使用
<DialogTrigger asChild>
  <Button>開く</Button>
</DialogTrigger>

// ❌ 非推奨:適切なフォーカス処理なしで手動でトリガー
<Button onClick={() => setOpen(true)}>開く</Button>

キーボードナビゲーション

// ✅ ShadCN が自動的に処理:
// - ESC でダイアログを閉じる
// - Tab でフォーカス可能な要素間を移動
// - Enter/Space でボタンを起動
// - 矢印キーでメニューを移動

// ❌ 非推奨:正当な理由なくデフォルトのキーボード動作を上書き

スクリーンリーダーサポート

// ✅ 推奨:常に DialogTitle を含める(ARIA 必須)
<DialogHeader>
  <DialogTitle>プロジェクトを削除</DialogTitle>
  <DialogDescription>
    この操作は元に戻せません。
  </DialogDescription>
</DialogHeader>

// ❌ 非推奨:誤った方法で視覚的に隠されたタイトルを使用
<DialogTitle className="sr-only">削除</DialogTitle>
// 明確な視覚的な代替手段がある場合のみ非表示にしてください

5. よく使うコンポーネント

コンポーネントユースケース主要なプロパティ
Buttonすべてのクリック可能な操作variant, size, asChild
Dialogモーダル、確認画面open, onOpenChange
Sheetサイドパネル、ドロワーside, open, onOpenChange
Popoverツールチップ、メニューopen, onOpenChange
Formすべてのフォームform (useForm から)
Inputテキスト入力type, placeholder
Selectドロップダウンvalue, onValueChange
Checkboxブール値の入力checked, onCheckedChange
RadioGroup単一選択value, onValueChange
Tableデータテーブルtable (TanStack Table から)
CardコンテンツコンテナCardHeader, CardContent, CardFooter
Toast通知title, description, variant
CommandコマンドパレットonSelect
Tabsタブナビゲーションvalue, onValueChange

6. TailwindCSS のベストプラクティス

// ✅ 推奨:Tailwind ユーティリティクラスを使用
<Button className="w-full mt-4">送信</Button>

// ✅ 推奨:条件付きクラスには cn() ヘルパーを使用
import { cn } from "@/lib/utils"

<Button className={cn(
  "w-full",
  isLoading && "opacity-50 cursor-not-allowed"
)}>
  送信
</Button>

// ❌ 非推奨:インラインスタイルを使用
<Button style={{ width: '100%', marginTop: '16px' }}>送信</Button>

// ❌ 非推非推奨:コンポーネント用のカスタム CSS ファイルを作成
/* styles.css */
.my-button { width: 100%; }

7. ダークモード対応

// ✅ 推奨:Tailwind のダークモードクラスを使用
<div className="bg-white dark:bg-gray-900 text-black dark:text-white">
  コンテンツ
</div>

// ✅ ShadCN コンポーネントはダークモードが組み込み済み
<Button variant="default">
  {/* ダークモードで自動的にスタイル適用 */}
</Button>

よくある間違いをチェック

❌ DialogTitle の欠落(アクセシビリティ違反)

// 悪い例
<DialogContent>
  <h2>設定</h2>
  <p>コンテンツ</p>
</DialogContent>

// 良い例
<DialogContent>
  <DialogHeader>
    <DialogTitle>設定</DialogTitle>
  </DialogHeader>
  <p>コンテンツ</p>
</DialogContent>

❌ フォームに Form コンポーネントを使用していない

// 悪い例 - バリデーションなし、UX が悪い
<form>
  <input name="email" />
  <button type="submit">送信</button>
</form>

// 良い例 - バリデーション、エラーメッセージ、アクセシビリティ
<Form {...form}>
  <form onSubmit={form.handleSubmit(onSubmit)}>
    <FormField name="email" ... />
  </form>
</Form>

❌ バリアントを使用せずに色をハードコーディング

// 悪い例
<Button className="bg-red-500 hover:bg-red-600">削除</Button>

// 良い例
<Button variant="destructive">削除</Button>

❌ トリガーに asChild を使用していない

// 悪い例 - 不要なネストされたボタンを作成
<DialogTrigger>
  <Button>開く</Button>
</DialogTrigger>
// レンダリング結果: <button><button>開く</button></button> (無効な HTML)

// 良い例 - プロパティを単一のボタンに統合
<DialogTrigger asChild>
  <Button>開く</Button>
</DialogTrigger>
// レンダリング結果: <button>開く</button>

ShadCN コンポーネントのテスト

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Dialog, DialogTrigger, DialogContent } from '@/components/ui/dialog'

describe('Dialog', () => {
  it('トリガーがクリックされたときに開くこと', async () => {
    const user = userEvent.setup()

    render(
      <Dialog>
        <DialogTrigger asChild>
          <button>開く</button>
        </DialogTrigger>
        <DialogContent>
          <div>ダイアログの内容</div>
        </DialogContent>
      </Dialog>
    )

    // 初期状態ではダイアログの内容は表示されていない
    expect(screen.queryByText('ダイアログの内容')).not.toBeInTheDocument()

    // トリガーをクリック
    await user.click(screen.getByText('開く'))

    // ダイアログの内容が表示される
    expect(screen.getByText('ダイアログの内容')).toBeInTheDocument()
  })

  it('ESC キーで閉じること', async () => {
    const user = userEvent.setup()

    render(
      <Dialog defaultOpen>
        <DialogContent>ダイアログの内容</DialogContent>
      </Dialog>
    )

    expect(screen.getByText('ダイアログの内容')).toBeInTheDocument()

    await user.keyboard('{Escape}')

    expect(screen.queryByText('ダイアログの内容')).not.toBeInTheDocument()
  })
})

リソース

2025年11月の注記

ShadCN UI は、2025年11月時点での React コンポーネントライブラリの業界標準です。一貫性、アクセシビリティ、保守性のために、すべての新しい Quetrex アプリケーションは ShadCN UI を使用する必要があります。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

関連スキル