ナビゲーション

v2.1.0
フィードバック

アラート

ページの流れの中に表示するメッセージ。必要に応じてステータスを付けられます。

このページの内容

アラートは、そのページに関するメッセージを本文の流れの中に表示するコンポーネントです。平らな面を 0.5px の輪郭で囲みます。ステータスに応じて背景を淡く色づけ、アイコンの色を変えます。テキストは通常の文字色を保ち、色だけに頼らず意味を伝えます。

アラート

<div class="alert" role="status">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <circle cx="8" cy="8" r="6" /><circle cx="8" cy="5" r="0.5" fill="currentColor" stroke="none" /><path d="M8 8L8 11" />  </svg>  <div class="alert-body">    <p class="alert-title">A new version is available</p>    <p class="alert-description">Reload to use the latest build of the dashboard.</p>  </div>  <button type="button" class="btn btn-sm">Reload</button></div>
import InfoCircleIcon from '@master/icons-react/native/16/soft/info-circle'<div className="alert" role="status">  <InfoCircleIcon className="icon alert-icon" />  <div className="alert-body">    <p className="alert-title">A new version is available</p>    <p className="alert-description">Reload to use the latest build of the dashboard.</p>  </div>  <button type="button" className="btn btn-sm">Reload</button></div>
<script>  import InfoCircleIcon from '@master/icons-svelte/native/16/soft/info-circle'</script><div class="alert" role="status">  <InfoCircleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-title">A new version is available</p>    <p class="alert-description">Reload to use the latest build of the dashboard.</p>  </div>  <button type="button" class="btn btn-sm">Reload</button></div>
<script setup>import InfoCircleIcon from '@master/icons-vue/native/16/soft/info-circle'</script><template>  <div class="alert" role="status">    <InfoCircleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-title">A new version is available</p>      <p class="alert-description">Reload to use the latest build of the dashboard.</p>    </div>    <button type="button" class="btn btn-sm">Reload</button>  </div></template>

#ステータス

読み手に必要な対応に応じてステータスを選び、その意味が文面からも伝わるようにします。

  • alert-info は、状況をすぐに変えるものではない補足情報を伝えます。
  • alert-successは、直前の処理が完了したことを伝えます。
  • alert-warningは、問題が起きる前に注意を促します。
  • alert-dangerは、処理の失敗や操作を続行できないことを伝えます。

ステータス

<div class="alert alert-info" role="status">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <circle cx="8" cy="8" r="6" /><circle cx="8" cy="5" r="0.5" fill="currentColor" stroke="none" /><path d="M8 8L8 11" />  </svg>  <div class="alert-body">    <p class="alert-description">Scheduled maintenance on Sunday from 02:00 to 03:00 UTC.</p>  </div></div><div class="alert alert-success" role="status">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <circle cx="8" cy="8" r="6" /><path d="M5 8L7.1041 9.8703A0.2 0.2 0 0 0 7.3832 9.8573L10.75 6.25" />  </svg>  <div class="alert-body">    <p class="alert-description">Your domain is verified and serving traffic.</p>  </div></div><div class="alert alert-warning" role="status">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <path d="M8.8742 3.8235L13.4246 12.0144A1 1 0 0 1 12.5505 13.5L3.4495 13.5A1 1 0 0 1 2.5754 12.0144L7.1258 3.8235A1 1 0 0 1 8.8742 3.8235Z" /><path d="M8 6.5L8 9" /><circle cx="8" cy="11.5" r="0.5" fill="currentColor" stroke="none" />  </svg>  <div class="alert-body">    <p class="alert-title">Your card expires this month</p>    <p class="alert-description">Update the payment method to keep deployments running.</p>  </div>  <button type="button" class="btn btn-sm">Update</button></div><div class="alert alert-danger" role="alert">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <circle cx="8" cy="8" r="6" transform="rotate(180 8 8)" /><circle cx="8" cy="5" r="0.5" fill="currentColor" stroke="none" transform="rotate(180 8 8)" /><path d="M8 8L8 11" transform="rotate(180 8 8)" />  </svg>  <div class="alert-body">    <p class="alert-title">The build failed</p>    <p class="alert-description">      The install step exited with code 1. Read the logs for the missing dependency.    </p>  </div></div>
import InfoCircleIcon from '@master/icons-react/native/16/soft/info-circle'import CheckCircleIcon from '@master/icons-react/native/16/soft/check-circle'import AlertTriangleIcon from '@master/icons-react/native/16/soft/alert-triangle'import AlertCircleIcon from '@master/icons-react/native/16/soft/alert-circle'<>  <div className="alert alert-info" role="status">    <InfoCircleIcon className="icon alert-icon" />    <div className="alert-body">      <p className="alert-description">Scheduled maintenance on Sunday from 02:00 to 03:00 UTC.</p>    </div>  </div>  <div className="alert alert-success" role="status">    <CheckCircleIcon className="icon alert-icon" />    <div className="alert-body">      <p className="alert-description">Your domain is verified and serving traffic.</p>    </div>  </div>  <div className="alert alert-warning" role="status">    <AlertTriangleIcon className="icon alert-icon" />    <div className="alert-body">      <p className="alert-title">Your card expires this month</p>      <p className="alert-description">Update the payment method to keep deployments running.</p>    </div>    <button type="button" className="btn btn-sm">Update</button>  </div>  <div className="alert alert-danger" role="alert">    <AlertCircleIcon className="icon alert-icon" />    <div className="alert-body">      <p className="alert-title">The build failed</p>      <p className="alert-description">        The install step exited with code 1. Read the logs for the missing dependency.      </p>    </div>  </div></>
<script>  import InfoCircleIcon from '@master/icons-svelte/native/16/soft/info-circle'  import CheckCircleIcon from '@master/icons-svelte/native/16/soft/check-circle'  import AlertTriangleIcon from '@master/icons-svelte/native/16/soft/alert-triangle'  import AlertCircleIcon from '@master/icons-svelte/native/16/soft/alert-circle'</script><div class="alert alert-info" role="status">  <InfoCircleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-description">Scheduled maintenance on Sunday from 02:00 to 03:00 UTC.</p>  </div></div><div class="alert alert-success" role="status">  <CheckCircleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-description">Your domain is verified and serving traffic.</p>  </div></div><div class="alert alert-warning" role="status">  <AlertTriangleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-title">Your card expires this month</p>    <p class="alert-description">Update the payment method to keep deployments running.</p>  </div>  <button type="button" class="btn btn-sm">Update</button></div><div class="alert alert-danger" role="alert">  <AlertCircleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-title">The build failed</p>    <p class="alert-description">      The install step exited with code 1. Read the logs for the missing dependency.    </p>  </div></div>
<script setup>import InfoCircleIcon from '@master/icons-vue/native/16/soft/info-circle'import CheckCircleIcon from '@master/icons-vue/native/16/soft/check-circle'import AlertTriangleIcon from '@master/icons-vue/native/16/soft/alert-triangle'import AlertCircleIcon from '@master/icons-vue/native/16/soft/alert-circle'</script><template>  <div class="alert alert-info" role="status">    <InfoCircleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-description">Scheduled maintenance on Sunday from 02:00 to 03:00 UTC.</p>    </div>  </div>  <div class="alert alert-success" role="status">    <CheckCircleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-description">Your domain is verified and serving traffic.</p>    </div>  </div>  <div class="alert alert-warning" role="status">    <AlertTriangleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-title">Your card expires this month</p>      <p class="alert-description">Update the payment method to keep deployments running.</p>    </div>    <button type="button" class="btn btn-sm">Update</button>  </div>  <div class="alert alert-danger" role="alert">    <AlertCircleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-title">The build failed</p>      <p class="alert-description">        The install step exited with code 1. Read the logs for the missing dependency.      </p>    </div>  </div></template>

#レイアウト

アラートは --alert-radius を使用し、既定値は var(--radius-control-lg) です。トレイの直下に配置する場合は、アラートのこのプロパティを var(--radius-surface) に設定して、トレイの角丸と内側の余白に合わせます。

アイコンに icon alert-icon を指定すると、本文が何行あっても、1 行目の上下中央に揃います。alert-body は残りの幅を使います。本文の後に置いたボタンやリンクは行末に配置され、アラートの幅が狭いときは本文の下に折り返します。

狭いカラムでの表示

<div class="alert alert-warning max-w(280) mx-auto" role="status">  <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <path d="M8.8742 3.8235L13.4246 12.0144A1 1 0 0 1 12.5505 13.5L3.4495 13.5A1 1 0 0 1 2.5754 12.0144L7.1258 3.8235A1 1 0 0 1 8.8742 3.8235Z" /><path d="M8 6.5L8 9" /><circle cx="8" cy="11.5" r="0.5" fill="currentColor" stroke="none" />  </svg>  <div class="alert-body">    <p class="alert-title">Usage is at 90%</p>    <p class="alert-description">Requests are limited when the plan runs out.</p>  </div>  <button type="button" class="btn btn-sm">Upgrade</button></div>
import AlertTriangleIcon from '@master/icons-react/native/16/soft/alert-triangle'<div className="alert alert-warning max-w(280) mx-auto" role="status">  <AlertTriangleIcon className="icon alert-icon" />  <div className="alert-body">    <p className="alert-title">Usage is at 90%</p>    <p className="alert-description">Requests are limited when the plan runs out.</p>  </div>  <button type="button" className="btn btn-sm">Upgrade</button></div>
<script>  import AlertTriangleIcon from '@master/icons-svelte/native/16/soft/alert-triangle'</script><div class="alert alert-warning max-w(280) mx-auto" role="status">  <AlertTriangleIcon class="icon alert-icon" />  <div class="alert-body">    <p class="alert-title">Usage is at 90%</p>    <p class="alert-description">Requests are limited when the plan runs out.</p>  </div>  <button type="button" class="btn btn-sm">Upgrade</button></div>
<script setup>import AlertTriangleIcon from '@master/icons-vue/native/16/soft/alert-triangle'</script><template>  <div class="alert alert-warning max-w(280) mx-auto" role="status">    <AlertTriangleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-title">Usage is at 90%</p>      <p class="alert-description">Requests are limited when the plan runs out.</p>    </div>    <button type="button" class="btn btn-sm">Upgrade</button>  </div></template>

#アクセシビリティ

  • ページの読み込み後に表示されるアラートには、ライブリージョンが必要です。role="status" は読み上げの切れ目を待ち、role="alert" は進行中の読み上げに割り込みます。role="alert" は、すぐに対応が必要なエラーに限って使います。
  • ページに最初から含まれるアラートには、ロールの指定は不要です。
  • アイコンには aria-hidden="true" を指定します。メッセージはテキストで伝えます。

#クラス

クラス説明
alert中立的なメッセージです。平らな面を 0.5px の線で囲みます。本文に続くボタンやリンクは行末に配置し、アラートの幅が狭いときは本文の下に折り返します。
alert-infoまだ状況が変わっていない段階の補足情報です。情報色の淡い背景と、同系色のアイコンで示します。alert と併用します
alert-success直前に完了した処理を、成功を示す淡い背景色と、同系色のアイコンで示します。alert と併用します
alert-warning問題が起きる前の注意喚起です。警告色の淡い背景と、同系色のアイコンで示します。alert と併用します
alert-danger失敗や実行できない操作を、危険を示す淡い背景色と、同系色のアイコンで示します。alert と併用します
alert-iconアイコンに icon と併せて指定します。テキストが何行あっても、アイコンの中心を 1 行目の中央に合わせます。
alert-bodyテキストを収め、残りの幅を占める領域
alert-titleメッセージの要点を短い文言で示し、強調します。
alert-descriptionタイトルの下に表示する文です。タイトルがない場合は、メッセージ全文を表示します。

#カスタムプロパティ

プロパティ既定値説明
--alert-radiusvar(--radius-control-lg)角のスケールを適用する前の円弧の半径です。トレイに直接収める場合は var(--radius-surface) を使います。指定先:alert

#ソース

@master/ui/components/alert.css
/* * Alert: a message in the flow of the page, about the page it sits in. * A flat face with a half-pixel contour; a status tints the face faintly and colors the icon, and the words * stay in ink, so the hue never carries the meaning alone. When there is no room, the action wraps under the text. */@layer components.ui {  .alert {    --alert-radius: var(--radius-control-lg);    --alert-tone: var(--color-text-muted);    --icon-size: 1rem;    display: flex;    flex-wrap: wrap;    align-items: flex-start;    /*     * A wrapped row starts 1rem down: a small button that wraps under the text gives back the 6px it reaches     * above its line, so it still stands about .625rem below the words.     */    gap: 1rem .75rem;    padding: .75rem .875rem;    border-radius: calc(var(--alert-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-chip);    color: var(--color-text-body);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    font-size: .84375rem;    line-height: 1.5;    /*     * A toned face is opaque, so it is the surface what it holds stands on: a ring cut out of it (an avatar's, a     * status dot's) shows the tint. The neutral face is a translucent chip and leaves the surface under it as it is.     */    &:is(.alert-info, .alert-success, .alert-warning, .alert-danger) {      --surface-color: color-mix(in oklab, var(--alert-tone) 6%, var(--color-surface-raised));      background: var(--surface-color);      box-shadow: inset 0 0 0 .5px color-mix(in oklab, var(--alert-tone) 34%, transparent);    }    &.alert-info { --alert-tone: var(--color-info); }    &.alert-success { --alert-tone: var(--color-success); }    &.alert-warning { --alert-tone: var(--color-warning); }    &.alert-danger { --alert-tone: var(--color-danger); }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /*   * The icon centers on the first line of text, however many lines follow. A status colors this icon, and only   * this one: the icon of a button the alert holds stays in the button's ink.   */  .alert-icon {    --icon-color: var(--alert-tone);    margin-block: calc((1lh - var(--icon-size)) / 2);  }  /*   * A button the alert holds centers on the first line of text as the icon does: it reaches as far above and   * below that line as it is taller than it, so it neither stands lower than the title nor deepens the alert.   * The line is the alert's own, .84375rem at 1.5, which the button cannot read as 1lh of its own.   */  .alert .btn {    margin-block: calc((.84375rem * 1.5 - var(--btn-height)) / 2);  }  /* The words take the remaining width and never shrink below a readable measure before the action wraps. */  .alert-body {    display: grid;    flex: 1 1 12rem;    gap: .125rem;    min-width: 0;  }  .alert-title {    margin: 0;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    text-wrap: balance;    overflow-wrap: anywhere;  }  .alert-description {    margin: 0;    text-wrap: pretty;    overflow-wrap: anywhere;  }}