导航

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>

#标明数量

顶层下方的两层表面仅用于装饰。无论叠层代表 3 项还是 30 项,下面始终只有两层,辅助技术也不会播报这两层。请在顶层表面用文字标明实际数量,并提供查看全部项目的入口,例如打开该组的按钮或指向列表的链接。

#叠层、列表还是头像组

无需逐项展示时,可使用叠层。如果每一项都需要显示,请使用列表。展示多个人时,使用头像组,让头像彼此重叠。需要逐张浏览幻灯片时,使用轮播。

#无障碍

  • 叠层本身不添加角色或无障碍名称,其语义由内部的表面提供。
  • 叠放效果无法传达实际数量,请用文字标明。
  • 在强制颜色模式下,下方两层使用系统颜色绘制轮廓,并且完全不透明。

#类名

类名说明
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;      }    }  }}