导航

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;  }}