網站導覽

v2.1.0
材質

堆疊

將多個項目呈現為一組,並在最上層面板下方露出堆疊的邊緣。

本頁內容

堆疊將多個項目呈現為一組,例如同類通知、一併傳送的檔案,或同一份文件的多個草稿。它容納最上層的面板,並在後方繪製另外兩層,逐層縮窄、下移、變淡,看起來像疊在最上層面板下方的兩張薄片,而非陰影。

堆疊

<div class="pile w-full max-w(340)">  <article class="card">    <header class="card-header">      <h3 class="card-title">3 deployments failed</h3>      <p class="card-description">atlas.dev, in the last hour</p>      <button class="card-action btn btn-sm" type="button">Show all</button>    </header>  </article></div>
<div className="pile w-full max-w(340)">  <article className="card">    <header className="card-header">      <h3 className="card-title">3 deployments failed</h3>      <p className="card-description">atlas.dev, in the last hour</p>      <button className="card-action btn btn-sm" type="button">Show all</button>    </header>  </article></div>
<div class="pile w-full max-w(340)">  <article class="card">    <header class="card-header">      <h3 class="card-title">3 deployments failed</h3>      <p class="card-description">atlas.dev, in the last hour</p>      <button class="card-action btn btn-sm" type="button">Show all</button>    </header>  </article></div>
<template>  <div class="pile w-full max-w(340)">    <article class="card">      <header class="card-header">        <h3 class="card-title">3 deployments failed</h3>        <p class="card-description">atlas.dev, in the last hour</p>        <button class="card-action btn btn-sm" type="button">Show all</button>      </header>    </article>  </div></template>

#堆疊的外觀

堆疊用來容納一個面板,例如卡片、面板或檔案。下方兩層由樣式表繪製,每層比上一層左右各內縮 8px,並下移 6px。堆疊會在最上層面板下方預留 12px,因此後續內容不必另外留空間。

下方各層的圓角由 --pile-radius 設定,預設使用標準的面板圓角。若最上層面板用了不同的圓角,請把這個屬性設為相同的值,如下方的檔案範例。用 --pile-step 和 --pile-inset 可以調整每層露出的幅度。

檔案

<div class="pile w-full max-w(280)" style="--pile-radius: var(--radius-control-lg)">  <div class="file">    <span class="file-page">pdf</span>    <div class="file-body">      <p class="file-name">Quarterly report.pdf</p>      <p class="file-meta">and 4 more files · 12.8 MB</p>    </div>  </div></div>
<div className="pile w-full max-w(280)" style={{ '--pile-radius': 'var(--radius-control-lg)' } as React.CSSProperties}>  <div className="file">    <span className="file-page">pdf</span>    <div className="file-body">      <p className="file-name">Quarterly report.pdf</p>      <p className="file-meta">and 4 more files · 12.8 MB</p>    </div>  </div></div>
<div class="pile w-full max-w(280)" style="--pile-radius: var(--radius-control-lg)">  <div class="file">    <span class="file-page">pdf</span>    <div class="file-body">      <p class="file-name">Quarterly report.pdf</p>      <p class="file-meta">and 4 more files · 12.8 MB</p>    </div>  </div></div>
<template>  <div class="pile w-full max-w(280)" style="--pile-radius: var(--radius-control-lg)">    <div class="file">      <span class="file-page">pdf</span>      <div class="file-body">        <p class="file-name">Quarterly report.pdf</p>        <p class="file-meta">and 4 more files · 12.8 MB</p>      </div>    </div>  </div></template>

#標明項目數量

最上層下方的兩層只供裝飾。不論堆疊代表三個項目還是三十個,下方都只畫兩層,螢幕閱讀器也不會讀出。請在最上層用文字標明項目數量,並提供查看全部項目的方式,例如加上開啟群組的按鈕,或前往清單的連結。

#堆疊、清單或頭像群組

堆疊適合無須顯示所有項目的情況。若每個項目都必須可見,請使用清單。呈現一群人時,可用頭像群組讓頭像部分重疊。需要逐張切換投影片時,則使用輪播。

#無障礙

  • 堆疊本身不加上角色或名稱,語意由其中的面板提供。
  • 請用文字標明項目數量,因為畫出的層數無法反映實際數量。
  • 在強制色彩模式下,下方兩層會使用系統輪廓線,並呈現為完全不透明。

#類別

類別說明
pile容納最上層面板的容器。後方有兩層裝飾面板,每層比上一層左右各內縮 8px,並下移 6px。

#自訂屬性

屬性預設值說明
--pile-radiusvar(--radius-surface)下方裝飾面板的圓角,應設為與最上層面板相同。
--pile-step.375rem每個面板從上方一層面板底部露出的高度
--pile-inset.5rem每個面板相對於上方一層面板,左右各內縮的距離

#原始程式碼

@master/ui/components/pile.css
/* * Pile: several things shown as one, with the edges of the others under it. * The pile holds one surface, the top one, and draws two more behind it: each a step narrower, a step lower * and a step fainter, so they read as sheets lying under the first and not as a shadow. Nothing in them is * content: say how many there are in words, on the top one. * Geometry: each sheet under the top is 8px in on both sides and shows 6px below the one above it. They take * the corner in --pile-radius, a surface's corner unless the top sheet has another. */@layer components.ui {  .pile {    --pile-radius: var(--radius-surface);    --pile-step: .375rem;    --pile-inset: .5rem;    position: relative;    /* The sheets lie behind the top one, and no further back than the pile. */    isolation: isolate;    display: grid;    min-width: 0;    margin: 0;    padding-block-end: calc(var(--pile-step) * 2);    &::before, &::after {      content: '';      position: absolute;      inset-block-start: 1rem;      border-radius: calc(var(--pile-radius) * var(--corner-scale));      corner-shape: var(--corner-shape);      background: var(--color-surface-raised-low);      box-shadow: var(--shadow-flat), 0 1px 2px -1px var(--color-shade-2);      pointer-events: none;    }    /* The second sheet. */    &::before {      z-index: -1;      inset-block-end: var(--pile-step);      inset-inline: var(--pile-inset);      opacity: .8;    }    /* The third. */    &::after {      z-index: -2;      inset-block-end: 0;      inset-inline: calc(var(--pile-inset) * 2);      opacity: .5;    }    @media (forced-colors: active) {      &::before, &::after {        outline: 1px solid CanvasText;        outline-offset: -1px;        opacity: 1;      }    }  }}