Alert
重要な情報をユーザーに伝えるアラート。4種類のバリアント(info、success、warning、danger)をサポート。
インストール
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" | メッセージの種類を表す配色。 |
icon | ReactNode | - | 内容の前に表示するアイコン。 |
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(新しいタブで開く) 要素の属性を受け取ります。