Vercel v0 - AIでUIを生成するツール

2024.12.26

公式ドキュメント

この記事の要点

• v0はテキストプロンプトからReactコンポーネントを生成するAIツール
• shadcn/ui + Tailwind CSSで本番品質のUIを即座に作成
• 反復的なプロンプト改善でデザインを段階的にブラッシュアップ可能

v0とは

v0は、Vercelが開発したAI駆動のUI生成ツールです。テキストプロンプトからReactコンポーネントを生成し、shadcn/uiとTailwind CSSを使用した本番品質のUIを即座に作成できます。

特徴

  • ✓ テキストからUI生成
  • ✓ shadcn/ui対応
  • ✓ Tailwind CSSスタイリング
  • ✓ コードのエクスポート
  • ✓ 反復的な改善
  • ✓ レスポンシブデザイン

基本的な使い方

プロンプトの例

シンプルなプロンプト:

“A login form with email and password fields”

詳細なプロンプト:

“A pricing page with 3 tiers (Basic, Pro, Enterprise). Each tier should have:

  • Name and price
  • List of features with checkmarks
  • A call-to-action button Use a dark theme with purple accent colors.”

生成されるコード

// v0が生成するコンポーネント例
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { Check } from "lucide-react"

export default function PricingPage() {
  return (
    <div className="container mx-auto py-16">
      <h1 className="text-4xl font-bold text-center mb-12">
        Choose Your Plan
      </h1>
      <div className="grid md:grid-cols-3 gap-8">
        {/* Basic */}
        <Card>
          <CardHeader>
            <CardTitle>Basic</CardTitle>
            <CardDescription>For individuals</CardDescription>
          </CardHeader>
          <CardContent>
            <div className="text-4xl font-bold mb-4">$9/mo</div>
            <ul className="space-y-2">
              <li className="flex items-center gap-2">
                <Check className="h-5 w-5 text-green-500" />
                5 projects
              </li>
              {/* ... */}
            </ul>
          </CardContent>
          <CardFooter>
            <Button className="w-full">Get Started</Button>
          </CardFooter>
        </Card>
        {/* Pro, Enterprise... */}
      </div>
    </div>
  )
}

ポイント: v0はshadcn/uiコンポーネントを基盤に使用するため、生成されたコードはそのまま本番プロジェクトに組み込めます。

効果的なプロンプト

構造を指定

“Create a dashboard layout with:

  • A sidebar on the left with navigation links
  • A header with search bar and user avatar
  • Main content area with a grid of stat cards
  • Use a clean, modern design”

スタイルを指定

“A product card component with:

  • Image at the top (16:9 ratio)
  • Product name and description
  • Price with strikethrough for discounts
  • Add to cart button
  • Subtle shadow on hover
  • Glassmorphism effect”

インタラクションを指定

“A multi-step form wizard with:

  • Step indicator at the top
  • Previous/Next buttons
  • Form validation
  • Success state on completion
  • Smooth transitions between steps”

コードのエクスポート

CLIでのインポート

npx v0 add <component-url>

手動コピー

// v0からコピーしたコード
// 必要なshadcn/uiコンポーネントをインストール
npx shadcn-ui@latest add button card

実践メモ: プロンプトには「具体的なレイアウト」「色」「アニメーション」を明示すると、より意図に近いUIが生成されます。

反復的な改善

初回プロンプト:

“A user profile card”

改善プロンプト:

“Make the avatar larger and add a cover image at the top”

さらに改善:

“Add social media links as icons below the bio”

shadcn/uiとの連携

プロジェクトのセットアップ

# Next.jsプロジェクトを作成
npx create-next-app@latest my-app --typescript --tailwind

# shadcn/uiをセットアップ
npx shadcn-ui@latest init

# v0で生成したコンポーネントに必要なものをインストール
npx shadcn-ui@latest add button card dialog

ディレクトリ構造

src:

  • components/
    • ui/ (shadcn/uiコンポーネント)
      • button.tsx
      • card.tsx
    • generated/ (v0で生成したコンポーネント)
      • pricing-page.tsx
  • app/
    • page.tsx

注意: v0で生成されたコードはプロトタイピングには最��ですが、本番利用前にアクセシビリティやエッジケースの確認を忘れ��に行いましょう。

ユースケース

プロトタイピング

“A landing page for a SaaS product with:

  • Hero section with headline and CTA
  • Features grid with icons
  • Testimonials carousel
  • Pricing section
  • FAQ accordion
  • Footer with links”

コンポーネントライブラリ

“Create a set of form components:

  1. Text input with label and error state
  2. Select dropdown with search
  3. Date picker
  4. File upload with drag and drop”

レイアウト作成

“An admin dashboard layout with:

  • Collapsible sidebar
  • Breadcrumb navigation
  • Data table with sorting and filtering
  • Pagination”

制限事項

注意点:

  • 複雑なロジックは手動で追加が必要
  • データフェッチングは含まれない
  • 状態管理は基本的なもののみ
  • アニメーションは限定的

類似ツール

ツール特徴
v0shadcn/ui特化、Vercel統合
Galileo AIFigma連携、デザイン重視
Uizardワイヤーフレームから変換
Builder.ioビジュアルエディタ

まとめ

v0は、AIを活用してUIを高速に生成できるツールです。shadcn/uiとTailwind CSSをベースにした本番品質のコードを生成し、プロトタイピングやコンポーネント作成を大幅に効率化します。

参考リソース

この技術を体系的に学びたいですか?

未来学では東証プライム上場企業のITエンジニアが24時間サポート。月額24,800円から、退会金0円のオンラインIT塾です。

メールで無料相談する
← 一覧に戻る