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

Alert

重要な情報をユーザーに伝えるアラート。4種類のバリアント(info、success、warning、danger)をサポート。

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

インストール

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

基本的な使い方

タイトルと説明文を持つシンプルなアラートです。

お知らせ

メンテナンスのため、明日の午前2時から4時までサービスを停止します。

alert.tsx
import { Alert, AlertDescription, AlertTitle } from "@ginga-ui/core";
import { Info } from "lucide-react";

export function BasicExample() {
  return (
    <Alert icon={<Info />}>
      <AlertTitle>お知らせ</AlertTitle>
      <AlertDescription>
        メンテナンスのため、明日の午前2時から4時までサービスを停止します。
      </AlertDescription>
    </Alert>
  );
}

バリアント

info、success、warning、dangerの4種類のバリアントを指定できます。

情報

新しいバージョンが利用可能です。

成功

変更が保存されました。

警告

ストレージの空き容量が少なくなっています。

エラー

データの読み込みに失敗しました。

alert.tsx
alert.module.css
import { Alert, AlertDescription, AlertTitle } from "@ginga-ui/core";
import styles from "./alert.module.css";
import { CircleAlert, CircleCheck, Info, TriangleAlert } from "lucide-react";

export function VariantsExample() {
  return (
    <div className={styles.alertStack}>
      <Alert variant="info" icon={<Info />}>
        <AlertTitle>情報</AlertTitle>
        <AlertDescription>新しいバージョンが利用可能です。</AlertDescription>
      </Alert>
      <Alert variant="success" icon={<CircleCheck />}>
        <AlertTitle>成功</AlertTitle>
        <AlertDescription>変更が保存されました。</AlertDescription>
      </Alert>
      <Alert variant="warning" icon={<TriangleAlert />}>
        <AlertTitle>警告</AlertTitle>
        <AlertDescription>
          ストレージの空き容量が少なくなっています。
        </AlertDescription>
      </Alert>
      <Alert variant="danger" icon={<CircleAlert />}>
        <AlertTitle>エラー</AlertTitle>
        <AlertDescription>データの読み込みに失敗しました。</AlertDescription>
      </Alert>
    </div>
  );
}

説明文のみ

タイトルを省略して説明文だけを表示できます。動的に挿入して通知する場合はrole属性にalertを渡すか、Toastの利用を検討してください。

プロフィールを更新しました。

alert.tsx
import { Alert, AlertDescription } from "@ginga-ui/core";
import { CircleCheck } from "lucide-react";

export function DescriptionOnlyExample() {
  return (
    <Alert variant="success" icon={<CircleCheck />}>
      <AlertDescription>プロフィールを更新しました。</AlertDescription>
    </Alert>
  );
}

Props

Alert

名前型既定値説明
variant"info" | "success" | "warning" | "danger""info"メッセージの種類を表す配色。
iconReactNode-内容の前に表示するアイコン。
render(props) => ReactElement-ルート要素を差し替える関数。受け取った props を渡した要素(next/link など)を返します。

上記に加えて、HTML の div(新しいタブで開く) 要素の属性を受け取ります。

AlertTitle

名前型既定値説明
render(props) => ReactElement-ルート要素を差し替える関数。受け取った props を渡した要素(next/link など)を返します。

上記に加えて、HTML の div(新しいタブで開く) 要素の属性を受け取ります。

AlertDescription

名前型既定値説明
render(props) => ReactElement-ルート要素を差し替える関数。受け取った props を渡した要素(next/link など)を返します。

上記に加えて、HTML の p(新しいタブで開く) 要素の属性を受け取ります。