Alert

Alertは、ユーザーに重要な情報やフィードバックを伝えるための通知コンポーネントです。ステータスに応じたアイコンと色を自動的に適用し、情報、成功、警告、エラーの4種類のメッセージを表現できます。

3
Variants
3
Sizes
4
Colors
Pure
React

Playground

Preview
defaultinfo
Heads up!

You can add components to your app using the CLI.

Variant
Color
Size
Options
<Alert>
  <Alert.Title>Heads up!</Alert.Title>
  <Alert.Description>
    You can add components to your app using the CLI.
  </Alert.Description>
</Alert>

Variants

Alert
Default
ティント背景に薄いボーダー。一般的な通知に使用。
情報通知
Alert
Outline
ボーダーのみ。背景を透明に保ちたい場合に。
軽い注意
Alert
Filled
ソリッド背景。強い視覚的強調が必要な場合に。
重要な警告

Sizes

sm
パディング12px
タイトル13px
説明12px
アイコン16px
default
パディング16px
タイトル14px
説明13px
アイコン18px
lg
パディング20px
タイトル16px
説明14px
アイコン20px

Colors

Information

A new software update is available. See what's new in version 3.0.

Success

Your changes have been saved successfully.

Warning

Your trial period will expire in 3 days.

Features

Closable

closableを有効にすると閉じるボタンが表示されます。onCloseでコールバックを受け取れます。

Saved!

Your changes have been saved.

<Alert color="success" closable onClose={() => setVisible(false)}>
  <Alert.Title>Saved!</Alert.Title>
  <Alert.Description>Your changes have been saved.</Alert.Description>
</Alert>

Custom Icon

iconでカスタムアイコンを設定、hideIconでアイコンを非表示にできます。

New feature available!

Check out the latest updates.

Simple message without icon

This alert has no icon.

{/* Custom icon */}
<Alert icon={<Rocket className="icon-md" />}>
  <Alert.Title>New feature!</Alert.Title>
</Alert>

{/* No icon */}
<Alert hideIcon>
  <Alert.Title>Simple message</Alert.Title>
</Alert>

Variant × Color Matrix

3つのバリアントと4つのカラーの全12パターン。

default

Info

This is a default info alert.

Success

This is a default success alert.

Warning

This is a default warning alert.

outline

Info

This is a outline info alert.

Success

This is a outline success alert.

Warning

This is a outline warning alert.

filled

Info

This is a filled info alert.

Success

This is a filled success alert.

Warning

This is a filled warning alert.

API

Component Structure

Alert— Pure React
.Title.Description

Props

Alert (Root)

variant"default"
"default" | "outline" | "filled"

外観バリアント(default: ティント背景、outline: ボーダー、filled: ソリッド)

color"info"
"info" | "success" | "warning" | "error"

セマンティックカラー(アイコン・色・ARIAロールを自動決定)

size"default"
"sm" | "default" | "lg"

サイズ(パディング・フォント・アイコンを一括制御)

closablefalse
boolean

閉じるボタンの表示

onCloseundefined
() => void

閉じるボタンのコールバック

closeIconundefined
ReactNode

カスタム閉じるアイコン

iconauto (by color)
ReactNode

カスタムステータスアイコン

hideIconfalse
boolean

アイコンを非表示にする

radius"lg"
"none" | "sm" | "base" | "md" | "lg" | "xl" | "2xl" | "3xl" | "full"

角丸

Alert.Title

childrenundefined
ReactNode

タイトルテキスト

classNameundefined
string

追加のCSSクラス

Alert.Description

childrenundefined
ReactNode

説明テキスト

classNameundefined
string

追加のCSSクラス

Anatomy

1
2
3
4
5
1
Root
アラートコンテナ
2
Icon
ステータスアイコン
3
Title
タイトル
4
Description
説明テキスト
5
Close
閉じるボタン

Best Practices

推奨

  • ステータスに適したcolorを使用する
  • タイトルと説明で簡潔にメッセージを伝える
  • 一時的な通知にはclosableを使用する

避けるべき

  • 1ページに大量のAlertを表示しない
  • 重大なエラーにdefaultバリアントを使わない — filledを使用する
  • 一時的な通知にAlertを使わない — Toastを使用する
  • ユーザーの確認が必要な場合にAlertを使わない — Modalを使用する

Alert vs Toast

どちらもユーザーへの通知に使いますが、表示の持続性とインタラクションが異なります。

表示

Alert: ページ内に固定(永続的)

Toast: 一時的に表示され自動で消える

トリガー

Alert: ページロード時・状態変化時

Toast: ユーザーアクション後のフィードバック

コンテンツ

Alert: タイトル+説明(リッチ)

Toast: 短いメッセージ(1〜2行)

閉じ方

Alert: 手動(closable)or 常時表示

Toast: 自動消去(数秒後)

用途

Alert: システム状態、警告、エラー

Toast: 保存完了、コピー完了など

ARIA

Alert: role="alert" / role="status"

Toast: role="status" + aria-live

使い分けのポイント: Alertはページ内の「状態通知」に使用。ユーザーのアクションに対する一時的なフィードバックにはToastを使用します。

Accessibility

ARIA / WCAG

  • role="alert" error時に自動付与
  • role="status" info/success/warning時
  • 閉じるボタンにaria-label="Close"
  • 装飾アイコンにaria-hidden="true"