本文へスキップ
Ginga UI
Ginga UI
English

はじめに

  • 概要
  • クイックスタート
  • テーマ生成
  • 要素の差し替え
  • 全コンポーネント

フォーム

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

表示

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

タイポグラフィ

  • Heading
  • Paragraph

ナビゲーション

  • Anchor

レイアウト

  • Box

リソース

  • 変更履歴
  • GitHub(新しいタブで開く)

ロゴ: Twemoji(新しいタブで開く) (CC-BY 4.0)

クイックスタート

Ginga UIを使い始めるための簡単なガイドです。わずか3ステップで、美しいUIコンポーネントを使い始められます。

1. インストール

パッケージマネージャーを使ってGinga UIをインストールします。

pnpm add @ginga-ui/core

npmやyarnを使用している場合:

npm install @ginga-ui/core
# または
yarn add @ginga-ui/core

2. CSS変数のインポート

各コンポーネントのCSSはインポート時に自動で読み込まれます。ルートコンポーネントでは、テーマのCSS変数定義のみをインポートします。Next.js App Routerの場合はlayout.tsxに記述します。

app/layout.tsx
import "@ginga-ui/core/variables.css";

3. コンポーネントを使う

コンポーネントを@ginga-ui/coreからインポートして使用します。

import {
  Button,
  Card,
  Dialog,
  DialogTitle,
  DialogTrigger,
  Heading,
  Modal,
} from "@ginga-ui/core";

export default function App() {
  return (
    <Card>
      <Heading level={2}>はじめての Ginga UI</Heading>
      <DialogTrigger>
        <Button variant="filled">クリックしてみる</Button>
        <Modal>
          <Dialog>
            <DialogTitle>クリックされました</DialogTitle>
            <Button slot="close">閉じる</Button>
          </Dialog>
        </Modal>
      </DialogTrigger>
    </Card>
  );
}

Next.js App Routerでの完全な例

Next.js 13以降のApp Routerを使用する場合の完全なセットアップ例です。

app/layout.tsx
app/page.tsx
import { ThemeClient } from "@ginga-ui/utils";
import "@ginga-ui/core/variables.css";
import "./globals.css";

export default async function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  // サーバーサイドでテーマを生成(オプション)
  const themeClient = new ThemeClient({ provider: "openai" });
  const result = await themeClient.generateTheme("モダンでクリーンなデザイン");

  return (
    <html lang="ja">
      <body>
        {result.type === "success" && <style>{result.CSSCode}</style>}
        {children}
      </body>
    </html>
  );
}

描画する要素を差し替える

すべてのコンポーネントはrenderを受け取ります。関数を渡すと、スタイルや挙動はそのままに、next/linkなどの別のコンポーネントで要素を描画できます。

import { Anchor } from "@ginga-ui/core";
import NextLink from "next/link";

export function DocsLink() {
  return (
    <Anchor href="/docs" render={(props) => <NextLink {...props} />}>
      ドキュメント
    </Anchor>
  );
}

守るべき点や、差し替わる要素の詳細は要素の差し替えを参照してください。

次のステップ

  • 全コンポーネントを確認して、利用可能なUIパーツを探索
  • テーマ生成を試して、AIによる自動スタイリングを体験
  • 各コンポーネントの詳細ページで、使い方やバリエーションをチェック