导航

v2.1.0
应用区块

通知收件箱

页面中的通知:查看全部或未读,可逐条标为已读,也可一次全部标为已读。

通知收件箱是一个页面,列出用户不在时发生的事:是谁做的或者是什么事、何时发生,以及是否已读。它可以筛选出未读的通知,也可以把一条或全部通知标为已读。通知是面板上的一个列表,位于一个分段控件之下。

通知收件箱

<section class="sheet container-inline flex flex-col overflow-hidden max-w(640) mx-auto" data-example="notification-inbox" aria-labelledby="inbox-title">  <header class="flex flex-wrap items-center justify-between gap-sm p-md">    <div class="flex flex-col gap-3xs">      <h2 class="heading heading-sm" id="inbox-title">Notifications</h2>      <p class="m(0) fg-text-muted" data-inbox-count>4 unread</p>    </div>    <div class="flex flex-wrap items-center gap-xs">      <div class="segmented segmented-sm" role="radiogroup" aria-label="Show">        <label class="segmented-item">          <input type="radio" class="segmented-input" name="inbox-filter" value="all" checked disabled>All</label>        <label class="segmented-item">          <input type="radio" class="segmented-input" name="inbox-filter" value="unread" disabled>Unread</label>      </div>      <button type="button" class="btn btn-sm" data-inbox-read-all disabled>Mark all as read</button>    </div>  </header>  <div class="px-md bt(1) bt-solid b-line-hair">    <ul class="list" aria-label="Notifications" data-inbox-list>      <li class="list-row" data-unread>        <span class="avatar list-media">          <img class="avatar-image" src="/demo/people/kenta-nakamura.webp" alt width="256" height="256">        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Kenta Nakamura mentioned you</a>          </p>          <p class="list-description">“Can you check the edge logs?”</p>        </div>        <p class="list-meta">          <time datetime="2026-11-13T09:31">Today, 09:31</time>          <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span>        </p>        <span class="list-end">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Kenta Nakamura mentioned you” as read" data-inbox-read disabled>            <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">              <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" />            </svg>          </button>        </span>      </li>      <li class="list-row" data-unread>        <span class="icon-frame icon-frame-xs list-media" aria-hidden="true">          <svg class="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>        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Deployment failed on atlas.dev</a>          </p>          <p class="list-description">The install step failed.</p>        </div>        <p class="list-meta">          <time datetime="2026-11-13T09:12">Today, 09:12</time>          <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span>        </p>        <span class="list-end">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Deployment failed on atlas.dev” as read" data-inbox-read disabled>            <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">              <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" />            </svg>          </button>        </span>      </li>      <li class="list-row" data-unread>        <span class="avatar list-media">          <img class="avatar-image" src="/demo/people/misaki-sato.webp" alt width="256" height="256">        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Misaki Sato left a comment</a>          </p>          <p class="list-description">“The hero reads much better.”</p>        </div>        <p class="list-meta">          <time datetime="2026-11-12T17:40">Yesterday, 17:40</time>          <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span>        </p>        <span class="list-end">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Misaki Sato left a comment” as read" data-inbox-read disabled>            <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">              <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" />            </svg>          </button>        </span>      </li>      <li class="list-row" data-unread>        <span class="icon-frame icon-frame-xs list-media" aria-hidden="true">          <svg class="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="M8 4.3333L8 7.8892A0.2 0.2 0 0 0 8.094 8.0588L10.6667 9.6667" />          </svg>        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Build minutes are at 62%</a>          </p>          <p class="list-description">760 minutes are left.</p>        </div>        <p class="list-meta">          <time datetime="2026-11-12T08:00">Yesterday, 08:00</time>          <span class="badge badge-sm badge-dot" data-inbox-unread>Unread</span>        </p>        <span class="list-end">          <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Mark “Build minutes are at 62%” as read" data-inbox-read disabled>            <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">              <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" />            </svg>          </button>        </span>      </li>      <li class="list-row">        <span class="avatar list-media">          <img class="avatar-image" src="/demo/people/pohan-chen.webp" alt width="256" height="256">        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Po-han Chen invited you to Borealis</a>          </p>          <p class="list-description">You joined as a member.</p>        </div>        <p class="list-meta">          <time datetime="2026-11-11T14:05">11 November</time>        </p>      </li>      <li class="list-row">        <span class="icon-frame icon-frame-xs list-media" aria-hidden="true">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M4.4667 2L11.5333 2A0.8 0.8 0 0 1 12.3333 2.8L12.3333 12.7907A0.7018 0.7018 0 0 1 11.2833 13.4L10.4293 12.912A0.8 0.8 0 0 0 9.5886 12.9409L8.4438 13.7042A0.8 0.8 0 0 1 7.5562 13.7042L6.4114 12.9409A0.8 0.8 0 0 0 5.5707 12.912L4.7167 13.4A0.7018 0.7018 0 0 1 3.6667 12.7907L3.6667 2.8A0.8 0.8 0 0 1 4.4667 2Z" />            <path d="M6 5.3333L10 5.3333" />            <path d="M6 8.3333L10 8.3333" />          </svg>        </span>        <div class="list-body">          <p class="list-title">            <a class="link link-quiet" href="#inbox-title">Invoice INV-2026-011 was paid</a>          </p>          <p class="list-description">$100.00 for November.</p>        </div>        <p class="list-meta">          <time datetime="2026-11-01T00:00">1 November</time>        </p>      </li>    </ul>    <div data-inbox-empty hidden>      <div class="empty">        <span class="icon-frame empty-media" aria-hidden="true">          <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M3.5 10L7.8545 14.3545A0.2 0.2 0 0 0 8.1413 14.3504L16.5 5.5" />          </svg>        </span>        <h3 class="empty-title">You have read everything</h3>        <p class="empty-description">Nothing is unread. What arrives next is listed here first.</p>        <div class="empty-actions">          <button type="button" class="btn btn-sm" data-inbox-show-all>Show all notifications</button>        </div>      </div>    </div>  </div>  <p class="sr-only" role="status" data-inbox-status></p></section>
切换到“Unread”(未读),用对勾把一条通知标为已读,再把其余的全部标为已读。已读状态只在本次预览中保留。

区块提供可直接复制的标记,沿用页面的文字颜色和字号。预览在 body 上设置 fg-text-body text-sm。每个区块都是尺寸容器,会根据自身宽度重排,无论放在宽页面、侧边栏大小的空间还是对话框中。

#区块组成

  • 一块保持阅读宽度的面板,max-w(640):标题区包含标题、数量和控件,然后是列表。区块较窄时,控件换行到标题下方。
  • 数量是标题下的文字:“4 unread”(4 条未读)。它与各行显示的是同一个数字,因为两者都由同一份状态绘制。
  • “All”(全部)或“Unread”是由两个原生单选按钮组成的 segmented。 筛选是在少数几项中选一项,这正是单选按钮组的含义;浏览器保留它的方向键操作和选中状态,也不会把未选中的项播报为“已选中”。
  • 每条通知是一个 list-row:是谁或是什么,作为 list-media;一个标题,它是通往事物本身的链接;一行详情;它们下方是通知到达的时间。人用头像表示;系统用图标框表示,这样失败的部署就不必借用一张面孔。
  • 未读用文字表示。 时间旁有一个带圆点的中性徽标,写着“Unread”。它不是 aria-current,也不是 aria-selected:两者都不表示“尚未阅读”,一行也不会因为是新的就成为被选中的行。
  • 未读行的末尾有一个低调的按钮,用来把它标为已读。按钮的名称带有该行的标题:“Mark “Deployment failed on atlas.dev” as read”(将“Deployment failed on atlas.dev”标为已读)。已读的行没有按钮,也没有徽标。
  • “Mark all as read”(全部标为已读)与筛选控件放在一起,不与各行放在一起,没有未读通知时处于禁用状态。
  • 没有未读不等于什么都没有。 “Unread”筛选下没有任何行时,用一个空状态写明“You have read everything”(你已读完全部通知),并提供回到全部通知的入口。从未收到过通知的收件箱是另一种状态,需要另一套文案。

标题和详情各占一行,超出部分以省略号结尾:通知只是指向事物的指针,其余内容在事物本身那里。

#哪些操作需要脚本

各行都在标记中,因此没有脚本也能完整阅读收件箱;它的控件在标记中是 disabled 的,由脚本启用。此后 main.js 维护一份列表:每条通知以及它是否未读,从各行中读取一次。一切都由这份列表绘制。

  • 筛选控件显示所有行或未读的行。数量、各行和空结果不可能彼此不一致,因为它们都没有被单独保存。
  • 把一条标为已读会从该行中移除徽标和按钮。在“Unread”筛选下,这一行也会离开列表。
  • 焦点随之移动。 一行被标为已读后,焦点移到下一个未读行的按钮;没有则移到前一个未读行的按钮;一个都不剩时,移到筛选控件。“Mark all as read”在被禁用之前,会先把焦点交给筛选控件。
  • 一行以 polite 方式播报的状态文字,不绘制出来,说明结果和剩余数量:““Kenta Nakamura mentioned you” marked as read. 3 unread.”(“Kenta Nakamura mentioned you”已标为已读。还剩 3 条未读。)

已读状态只在本次访问期间保留。在实际应用中,同一个函数把更改发送到服务器,如果发送失败,就把该行恢复为未读;新通知以同样的方式加入列表并计入数量。区块留在页面之中:它不是铃铛下方的弹出层,也不发送推送通知。

#无障碍

  • 区块是一个以其 <h2> 命名的 <section>,列表是一个名为“Notifications”(通知)的 <ul>。
  • 筛选控件是一个名为“Show”(显示)的 radiogroup。按 Tab 键到达已选中的选项,方向键移动选择。
  • 每行有两个目标,各自说明自己的作用:标题通往事物本身,按钮把该行标为已读。按钮中的对勾只是装饰;名称写在 aria-label 中。
  • 姓名旁的人像 alt 留空,图标框设置 aria-hidden:标题已经说明了是谁或是什么。
  • 时间是带有 datetime 的 <time>。“Today, 09:31”(今天 09:31)是给用户看的;这个属性则供其他一切使用。
  • 状态行设置 role="status",因此结果会被播报而不移动焦点;某一行离开时,焦点也绝不会落回页面顶部。
  • 在触摸屏上,32px 的按钮保持原有尺寸,点击目标则扩大到 44px。