網站導覽

v2.1.0
回饋

提示訊息

隨頁面內容排列的訊息,可選擇加上狀態。

本頁內容

提示訊息隨頁面內容排列,說明與所在頁面有關的事。提示訊息採平面樣式,外框為半像素。設定狀態後,背景會帶有淡淡的狀態色,圖示也會套用狀態色。文字沿用原本的高對比色,並明確說明狀態,讓讀者無須靠顏色理解。

提示訊息

<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。無論後面有幾行文字,圖示都會對齊第一行的中央。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中性訊息採用平面樣式,外框寬半個像素。內文後的按鈕或連結位於列尾,警示寬度不足時會換到內文下方。
alert-info用於暫時不影響操作的補充資訊,以資訊色顯示淡色底和圖示搭配 alert 使用
alert-success剛完成的操作以淡底色和圖示呈現,兩者皆採用成功狀態的色調搭配 alert 使用
alert-warning提醒使用者留意潛在問題,背景和圖示都採用警告色,背景色較淡。搭配 alert 使用
alert-danger表示失敗或操作受阻,背景和圖示都採用危險色,背景色較淡。搭配 alert 使用
alert-icon在圖示上搭配 icon 使用,讓圖示垂直對齊第一行文字的中央,後續換行不影響對齊
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;  }}