網站導覽

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 則未讀。)

已讀狀態只在這次造訪期間保留。在應用程式中,同一個函式會把變更送到伺服器,若失敗就把該列恢復為未讀;新通知會加入清單,並以同樣的方式計數。區塊留在頁面中:它不是鈴鐺下方的彈出面板,也不會傳送推播通知。

#無障礙

  • 區塊是一個 <section>,以其 <h2> 命名;清單是名為「Notifications」(通知)的 <ul>。
  • 篩選器是名為「Show」(顯示)的 radiogroup。Tab 會到達已選取的選項,方向鍵則移動選擇。
  • 每一列有兩個目標,各自說明自己的作用:標題通往該事物,按鈕將該列標示為已讀。按鈕中的勾號是裝飾;名稱寫在 aria-label 中。
  • 姓名旁的肖像 alt 留空,圖示框則加上 aria-hidden:標題已經說明是誰或是什麼。
  • 時間是帶有 datetime 的 <time>。「Today, 09:31」(今天 09:31)是給讀者看的;屬性則是給其他一切用的。
  • 狀態行是 role="status",因此結果會被讀出而不移動焦點;列離開時,焦點也絕不會落回頁面頂端。
  • 在觸控螢幕上,32px 的按鈕維持原本的大小,點擊目標則擴大到 44px。