本文へスキップ
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)

Button

ユーザーアクションをトリガーするボタンコンポーネント。5種類のバリアント(filled、light、outline、ghost、reverse)と3種類のサイズ(sm、md、lg)、ラベル前後のアイコン指定をサポート。

Storybook で見る(新しいタブで開く)

インストール

import { Button } from "@ginga-ui/core";

基本的な使い方

最もシンプルなボタンの使用例です。

button.tsx
button.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import styles from "./button.module.css";

export function BasicExample() {
  return (
    <DialogTrigger>
      <Button variant="filled">クリック</Button>
      <Modal>
        <Dialog>
          <DialogTitle>クリックされました</DialogTitle>
          <p>
            DialogTrigger で囲むと、ボタンを押したときにダイアログが開きます。
          </p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline">
              閉じる
            </Button>
          </div>
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

バリエーション

5種類のバリアント(filled、light、outline、ghost、reverse)を表示します。

button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";

export function VariantsExample() {
  return (
    <div className={styles.variantRow}>
      <Button variant="filled">Filled</Button>
      <Button variant="light">Light</Button>
      <Button variant="outline">Outline</Button>
      <Button variant="ghost">Ghost</Button>
      <Button variant="reverse">Reverse</Button>
    </div>
  );
}

サイズ

sizeプロップでsm、md、lgの3種類のサイズを指定できます。

button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";

export function SizesExample() {
  return (
    <div className={styles.sizeRow}>
      <Button size="sm">Small</Button>
      <Button size="md">Medium</Button>
      <Button size="lg">Large</Button>
    </div>
  );
}

アイコン付き

startIcon と endIcon で、ラベルの前後にアイコンを表示できます。

button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import { ArrowRight, ChevronDown, Download, Plus } from "lucide-react";
import styles from "./button.module.css";

export function WithIconExample() {
  return (
    <div className={styles.variantRow}>
      <Button startIcon={<Download />}>ダウンロード</Button>
      <Button variant="light" endIcon={<ArrowRight />}>
        次へ
      </Button>
      <Button variant="outline" startIcon={<Plus />} endIcon={<ChevronDown />}>
        追加
      </Button>
    </div>
  );
}

無効化

disabledプロップでボタンを無効化できます。

button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";

export function DisabledExample() {
  return (
    <div className={styles.disabledRow}>
      <Button variant="filled" disabled>
        Disabled Filled
      </Button>
      <Button variant="light" disabled>
        Disabled Light
      </Button>
      <Button variant="outline" disabled>
        Disabled Outline
      </Button>
    </div>
  );
}

フォームでの使用

フォーム送信ボタンとしての使用例です。

button.tsx
button.module.css
import { useState } from "react";
import { Button, Dialog, DialogTitle, Input, Modal } from "@ginga-ui/core";
import { Send } from "lucide-react";
import styles from "./button.module.css";

export function FormExample() {
  const [submittedName, setSubmittedName] = useState<string | null>(null);

  return (
    <>
      <form
        onSubmit={(e) => {
          e.preventDefault();
          const formData = new FormData(e.currentTarget);
          const name = formData.get("name");
          setSubmittedName(typeof name === "string" ? name : "");
        }}
        className={styles.form}
      >
        <Input
          type="text"
          name="name"
          placeholder="名前を入力"
          aria-label="名前"
        />
        <Button
          type="submit"
          variant="filled"
          startIcon={<Send />}
          className={styles.submit}
        >
          送信
        </Button>
      </form>
      <Modal
        isOpen={submittedName !== null}
        onOpenChange={(isOpen) => {
          if (!isOpen) setSubmittedName(null);
        }}
      >
        <Dialog>
          <DialogTitle>送信しました</DialogTitle>
          <p>名前: {submittedName}</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline">
              閉じる
            </Button>
          </div>
        </Dialog>
      </Modal>
    </>
  );
}

Props

Button

名前型既定値説明
variant"filled" | "light" | "outline" | "ghost" | "reverse""filled"ボタンの見た目。
size"sm" | "md" | "lg""md"ボタンのサイズ。
disabledbooleanfalseボタンを無効にします。
startIconReactNode-ラベルの前に表示するアイコン。
endIconReactNode-ラベルの後に表示するアイコン。

上記に加えて、React Aria の Button(新しいタブで開く) の props を受け取ります。

ButtonGroup

React Aria の Group(新しいタブで開く) の props を受け取ります。