網站導覽

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 公開自己的顏色。元件會讀取這個值,以底色營造鏤空效果,例如在角落徽章、堆疊頭像和狀態圓點周圍畫出外環。在面板、托盤、凹槽、卡片或對話框內,外環會自動與底色一致。若使用自訂表面,請將這個屬性設為該表面的背景色。

#使用 utility 組合樣式

這些材質也定義為主題 token,因此可用 bg-surface-raised、shadow-raised、shadow-pressed 和 b-line-contour 等 utility 為自訂元素套用樣式。

用 utility 套用材質

<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;    }  }}