导航

v2.1.0
材质

表面

托盘、凸起面板与凹槽构成所有组件共用的材质层级。

本页内容

Master UI 的所有组件都使用同几种材质。可直接用这些材质制作卡片、面板和分组,让自定义布局与组件保持一致的光影和层次。主题介绍了各层次。

托盘、凸起面板和凹槽

<div class="tray">  <div class="sheet flex flex-col gap-md p-lg">    <p class="m(0) text-sm fg-text-strong">Deployment</p>    <div class="well p-md text-sm fg-text-muted">No builds are queued.</div>  </div></div>
<div className="tray">  <div className="sheet flex flex-col gap-md p-lg">    <p className="m(0) text-sm fg-text-strong">Deployment</p>    <div className="well p-md text-sm fg-text-muted">No builds are queued.</div>  </div></div>
<div class="tray">  <div class="sheet flex flex-col gap-md p-lg">    <p class="m(0) text-sm fg-text-strong">Deployment</p>    <div class="well p-md text-sm fg-text-muted">No builds are queued.</div>  </div></div>
<template>  <div class="tray">    <div class="sheet flex flex-col gap-md p-lg">      <p class="m(0) text-sm fg-text-strong">Deployment</p>      <div class="well p-md text-sm fg-text-muted">No builds are queued.</div>    </div>  </div></template>

#凸起面板

凸起面板的圆角半径为 16px,浏览器支持时采用超椭圆角。顶边带有高光,边缘用半像素轮廓勾勒,下方的短阴影逐渐淡出。凸起面板默认使用抬升层级的阴影,可按用途选用更低或更高的层级。

凸起面板的层次

<div class="sheet sheet-flat p-lg text-sm fg-text-muted">Flat</div><div class="sheet sheet-raised p-lg text-sm fg-text-muted">Raised</div><div class="sheet p-lg text-sm fg-text-muted">Lifted</div><div class="sheet sheet-floating p-lg text-sm fg-text-muted">Floating</div>
<>  <div className="sheet sheet-flat p-lg text-sm fg-text-muted">Flat</div>  <div className="sheet sheet-raised p-lg text-sm fg-text-muted">Raised</div>  <div className="sheet p-lg text-sm fg-text-muted">Lifted</div>  <div className="sheet sheet-floating p-lg text-sm fg-text-muted">Floating</div></>
<div class="sheet sheet-flat p-lg text-sm fg-text-muted">Flat</div><div class="sheet sheet-raised p-lg text-sm fg-text-muted">Raised</div><div class="sheet p-lg text-sm fg-text-muted">Lifted</div><div class="sheet sheet-floating p-lg text-sm fg-text-muted">Floating</div>
<template>  <div class="sheet sheet-flat p-lg text-sm fg-text-muted">Flat</div>  <div class="sheet sheet-raised p-lg text-sm fg-text-muted">Raised</div>  <div class="sheet p-lg text-sm fg-text-muted">Lifted</div>  <div class="sheet sheet-floating p-lg text-sm fg-text-muted">Floating</div></template>
类名层次用途
sheet sheet-flat一圈轮廓线,无阴影紧凑的列表和表格
sheet sheet-raised--shadow-raised内容密集的表面上的小卡片
sheet--shadow-lifted卡片和面板
sheet sheet-floating--shadow-floating覆盖在内容上方的弹出层和菜单
sheet sheet-inverse墨色表面搭配抬升层级的阴影页面上唯一用于邀请用户采取行动的表面

#反色

sheet-inverse 是墨色的凸起面板,在 Moonstone 中呈深色,在 Obsidian 中呈珠白色。它把主按钮的表面样式扩展到面板大小,保留相同的光照渐变和顶边高光。每页只用一处,留给需要用户采取行动的内容,例如行动号召。

面板上的文字使用反色墨色。给默认使用高强调墨色的标题添加 fg-text-inverse。默认按钮在面板上最亮,因此一眼就能看出它是操作入口;主按钮的墨色则会和面板的墨色融在一起。

反色

<section class="sheet sheet-inverse flex flex-wrap items-center justify-between gap-md p-lg">  <div class="flex flex-col gap-3xs">    <h3 class="heading heading-sm fg-text-inverse">Your trial ends in three days</h3>    <p class="m(0) text-sm">Add a card to keep your projects online.</p>  </div>  <button type="button" class="btn btn-sm">Add a card</button></section>
<section className="sheet sheet-inverse flex flex-wrap items-center justify-between gap-md p-lg">  <div className="flex flex-col gap-3xs">    <h3 className="heading heading-sm fg-text-inverse">Your trial ends in three days</h3>    <p className="m(0) text-sm">Add a card to keep your projects online.</p>  </div>  <button type="button" className="btn btn-sm">Add a card</button></section>
<section class="sheet sheet-inverse flex flex-wrap items-center justify-between gap-md p-lg">  <div class="flex flex-col gap-3xs">    <h3 class="heading heading-sm fg-text-inverse">Your trial ends in three days</h3>    <p class="m(0) text-sm">Add a card to keep your projects online.</p>  </div>  <button type="button" class="btn btn-sm">Add a card</button></section>
<template>  <section class="sheet sheet-inverse flex flex-wrap items-center justify-between gap-md p-lg">    <div class="flex flex-col gap-3xs">      <h3 class="heading heading-sm fg-text-inverse">Your trial ends in three days</h3>      <p class="m(0) text-sm">Add a card to keep your projects online.</p>    </div>    <button type="button" class="btn btn-sm">Add a card</button>  </section></template>

#凹槽

凹槽低于周围表面,带有柔和的内阴影、一圈半像素轮廓线和底边下方的一道高光。输入字段、分段控件的轨道和开关都采用凹槽。

--well-radius 设置应用主题圆角缩放系数前的凹槽圆角半径。默认值为 var(--radius-control)。

凹槽

<div class="well p-lg text-sm fg-text-muted">Drop files here</div>
<div className="well p-lg text-sm fg-text-muted">Drop files here</div>
<div class="well p-lg text-sm fg-text-muted">Drop files here</div>
<template>  <div class="well p-lg text-sm fg-text-muted">Drop files here</div></template>

#托盘

托盘向内凹陷,可容纳一个或多个凸起面板。4px 的内边距让圆角相互贴合,托盘的圆角半径等于面板缩放后的圆角半径加上这段内边距。使用默认的 1.6 倍圆角缩放系数时,16px 的表面圆角半径变为 25.6px,托盘的圆角半径为 29.6px。

托盘

<div class="tray">  <p class="m(0) px-md py-sm text-xs fg-text-muted">Recent</p>  <div class="sheet p-lg text-sm fg-text-body">Quarterly report.pdf</div></div>
<div className="tray">  <p className="m(0) px-md py-sm text-xs fg-text-muted">Recent</p>  <div className="sheet p-lg text-sm fg-text-body">Quarterly report.pdf</div></div>
<div class="tray">  <p class="m(0) px-md py-sm text-xs fg-text-muted">Recent</p>  <div class="sheet p-lg text-sm fg-text-body">Quarterly report.pdf</div></div>
<template>  <div class="tray">    <p class="m(0) px-md py-sm text-xs fg-text-muted">Recent</p>    <div class="sheet p-lg text-sm fg-text-body">Quarterly report.pdf</div>  </div></template>

直接放在托盘里的其他组件也需要采用凸起面板的圆角半径。在该组件的根元素上设置相应属性,凹槽用 --well-radius,代码块或面板用 --code-radius,窗口用 --window-radius,警示用 --alert-radius。属性值设为 var(--radius-surface)。托盘在圆角缩放后加上 4px 的内边距,因此默认主题和 Paper 都能保持这种圆角关系。嵌套更深的组件保留各自的圆角半径。

托盘中的凹槽

<div class="tray">  <div class="well p-lg text-sm" style="--well-radius: var(--radius-surface)">    No builds are queued.  </div></div>
<div className="tray">  <div className="well p-lg text-sm" style={{ '--well-radius': 'var(--radius-surface)' } as React.CSSProperties}>    No builds are queued.  </div></div>
<div class="tray">  <div class="well p-lg text-sm" style="--well-radius: var(--radius-surface)">    No builds are queued.  </div></div>
<template>  <div class="tray">    <div class="well p-lg text-sm" style="--well-radius: var(--radius-surface)">      No builds are queued.    </div>  </div></template>

#表面颜色

每个表面都通过 --surface-color 提供自己的颜色。组件会读取这个属性,用所在表面的颜色绘制环线,形成镂空效果,例如围绕角标、堆叠头像和状态圆点绘制的环线。这样,在凸起面板、托盘、凹槽、卡片或对话框中,环线会自动与表面同色。使用自定义表面时,将此属性设为它的背景色。

#使用工具类组合

这些材质也以主题令牌提供,可用 bg-surface-raised、shadow-raised、shadow-pressed 和 b-line-contour 为自定义元素应用材质。

应用材质的工具类

<div class="p-lg r-lg bg-surface-raised shadow-raised text-sm fg-text-body">  bg-surface-raised shadow-raised</div>
<div className="p-lg r-lg bg-surface-raised shadow-raised text-sm fg-text-body">  bg-surface-raised shadow-raised</div>
<div class="p-lg r-lg bg-surface-raised shadow-raised text-sm fg-text-body">  bg-surface-raised shadow-raised</div>
<template>  <div class="p-lg r-lg bg-surface-raised shadow-raised text-sm fg-text-body">    bg-surface-raised shadow-raised  </div></template>

#类名

类名说明
sheet凸起的表面,带 16px 圆角、半像素轮廓和抬升阴影
sheet-flat仅有一圈轮廓,无阴影,适合紧凑的列表和表格。与 sheet 一同使用
sheet-raised采用比默认低一级的凸起阴影,适合放在内容密集的表面上的小卡片。与 sheet 一同使用
sheet-floating提供浮层表面和阴影,适用于显示在内容上方的弹出层和菜单。与 sheet 一同使用
sheet-inverse采用墨色底和反相文字色的面板,用于页面中唯一引导用户采取行动的区域。与 sheet 一同使用
well带 10px 圆角和内阴影的凹陷表面
tray容纳一个或多个面板的凹陷托盘,内边距为 4px。托盘的 20px 圆角包住面板的 16px 圆角。

#自定义属性

属性默认值说明
--well-radiusvar(--radius-control)应用圆角缩放前的圆角半径。凹槽直接置于托盘内时,使用 var(--radius-surface)。在 well 上设置
--surface-colorvar(--color-surface-raised)面板的颜色。描边环读取此颜色,在下方表面上形成镂空效果。浮层面板和反色面板各自设置颜色。在 sheet 上设置
--surface-colorvar(--color-surface-inset)凹槽的颜色。描边环读取此颜色,在下方表面上形成镂空效果。在 well 上设置
--surface-colorvar(--color-surface-tray)托盘的颜色。描边环读取此颜色,在下方表面上形成镂空效果。在 tray 上设置

#源码

@master/ui/components/surface.css
/* * Surfaces: the material ladder in markup. * tray (a recessed holder) → sheet (a raised face) → floating; a well sits below its surroundings. * A sheet can also be ink, for the one surface on a page that asks for something. * Radii nest by a 4px inset: tray 20 → sheet 16, and a control inside is 10. * Each surface publishes its color as --surface-color, so a ring that cuts a shape out of it * (a corner badge, a stack of avatars) matches whatever it sits on. */@layer components.ui {  .sheet {    --surface-color: var(--color-surface-raised);    position: relative;    min-width: 0;    border-radius: calc(var(--radius-surface) * var(--corner-scale));    corner-shape: var(--corner-shape);    @apply --surface-sheet;    color: var(--color-text-body);    box-shadow: var(--shadow-lifted);    &.sheet-raised {      box-shadow: var(--shadow-raised);    }    &.sheet-floating {      --surface-color: var(--color-surface-floating);      background: var(--color-surface-floating);      box-shadow: var(--shadow-floating);    }    &.sheet-flat {      background: var(--color-surface-raised);      box-shadow: var(--shadow-flat);    }    /*     * Inverse: a sheet of ink, pearl on obsidian. It is the face of a primary button at the size of a surface:     * the same fall of light, the same line of light on its top edge. Use one on a page, for the moment     * that asks for something. Words on it take the inverse ink; a default button on it reads as the action.     */    &.sheet-inverse {      @apply --on-ink;      --surface-color: var(--color-surface-inverse);      @apply --surface-ink;      color: var(--color-text-inverse);      box-shadow:        inset 0 .5px 0 var(--color-ink-highlight),        0 0 0 .5px var(--color-ink-edge),        0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3), 0 8px 16px -8px var(--color-shade-4);    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  .well {    --well-radius: var(--radius-control);    --surface-color: var(--color-surface-inset);    min-width: 0;    border-radius: calc(var(--well-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-inset);    box-shadow: var(--shadow-pressed);    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* A tray's corner is the sheet's corner plus its 4px inset, so the gap keeps one width around the bend. */  .tray {    --surface-color: var(--color-surface-tray);    position: relative;    min-width: 0;    padding: 4px;    border-radius: calc(var(--radius-surface) * var(--corner-scale) + 4px);    corner-shape: var(--corner-shape);    background: var(--color-surface-tray);    color: var(--color-text-body);    /* Recessed by tone and a hairline; it holds raised sheets, so it casts no shadow of its own. */    box-shadow: inset 0 0 0 .5px var(--color-line-hair), inset 0 1px 2px -1px var(--color-shade-2);    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }}