导航

v2.1.0
自定义

默认主题

Master UI 的默认材质 Moonstone 与 Obsidian,以及对应的令牌用途和实际取值。

本页内容

Master UI 的默认主题采用统一的材质语言。浅色模式是 Moonstone,呈现清透的锌灰色珠光。深色模式是 Obsidian,呈现哑光锌灰玻璃质感,各表面层次分明,边缘清晰可辨。两种模式共用位于上方略偏左的同一光源,使每个凸起表面的顶部边缘都带有一线高光,下方都有一道短而渐隐的阴影。

整体风格克制,以墨色取代彩色,采用半像素轮廓、相互嵌套的圆角,以及随状态变化的层次。细节来自光线而非装饰,边缘只需清晰到足以辨认。

在下文中按界面需要选择表面、线条、文本或层次的角色。这些值对应当前软件包的默认主题。主题定制介绍如何覆盖这些值或构建另一种材质。

Moonstone 与 Obsidian

<div class="tray">  <div class="sheet flex flex-col gap-md p-lg">    <div class="flex items-center justify-between gap-md">      <span class="text-sm fg-text-strong">Production</span>      <span class="badge badge-success badge-dot">Ready</span>    </div>    <input class="input" value="atlas.dev" aria-label="Domain">    <div class="flex items-center justify-between gap-md">      <label class="check">        <input type="checkbox" role="switch" class="switch" checked> Preview builds      </label>      <button type="button" class="btn btn-primary">Deploy</button>    </div>  </div></div>
<div className="tray">  <div className="sheet flex flex-col gap-md p-lg">    <div className="flex items-center justify-between gap-md">      <span className="text-sm fg-text-strong">Production</span>      <span className="badge badge-success badge-dot">Ready</span>    </div>    <input className="input" defaultValue="atlas.dev" aria-label="Domain" />    <div className="flex items-center justify-between gap-md">      <label className="check">        <input type="checkbox" role="switch" className="switch" defaultChecked /> Preview builds      </label>      <button type="button" className="btn btn-primary">Deploy</button>    </div>  </div></div>
<div class="tray">  <div class="sheet flex flex-col gap-md p-lg">    <div class="flex items-center justify-between gap-md">      <span class="text-sm fg-text-strong">Production</span>      <span class="badge badge-success badge-dot">Ready</span>    </div>    <input class="input" value="atlas.dev" aria-label="Domain">    <div class="flex items-center justify-between gap-md">      <label class="check">        <input type="checkbox" role="switch" class="switch" checked> Preview builds      </label>      <button type="button" class="btn btn-primary">Deploy</button>    </div>  </div></div>
<template>  <div class="tray">    <div class="sheet flex flex-col gap-md p-lg">      <div class="flex items-center justify-between gap-md">        <span class="text-sm fg-text-strong">Production</span>        <span class="badge badge-success badge-dot">Ready</span>      </div>      <input class="input" value="atlas.dev" aria-label="Domain">      <div class="flex items-center justify-between gap-md">        <label class="check">          <input type="checkbox" role="switch" class="switch" checked> Preview builds        </label>        <button type="button" class="btn btn-primary">Deploy</button>      </div>    </div>  </div></template>
切换主题,对比 Moonstone 与 Obsidian。两者来自同一份样式表。

状态与层次

同一控件的层次随状态变化。 静止、悬停和按下状态分别使用凸起、凸起悬停和按下状态的阴影令牌,按下时表面还会凹入。默认的 --lift 会在支持悬停的指针悬停于按钮上时让按钮上移 0.5px,在按下时让按钮下移 0.5px。剖面图放大了层次差异。可在实时预览中体验两种配色方案下的实际交互。

#原则

设计解释了默认材质、层级、几何形态和交互状态背后的设计取舍。做设计决策时可参考其中的指导。本页记录 @master/ui 实现的令牌和用法。

packages/ui/theme.css 是这些值的可执行源文件。组件样式读取其中的令牌,Paper 等主题可替换这些令牌,无需重写组件。

#表面

所有表面共用一套层级,每一级对应一种用途。按表面承担的角色选择层级,主题会给出浅色和深色模式下的对应值。

材质层级

<div class="tray">  <p class="m(0) px-md py-sm text-xs fg-text-muted">Tray</p>  <div class="sheet flex flex-col gap-md p-lg">    <p class="m(0) text-xs fg-text-muted">Raised sheet</p>    <div class="well p-md text-xs fg-text-muted">Inset well</div>    <div class="sheet sheet-floating p-md text-xs fg-text-muted">Floating</div>  </div></div>
<div className="tray">  <p className="m(0) px-md py-sm text-xs fg-text-muted">Tray</p>  <div className="sheet flex flex-col gap-md p-lg">    <p className="m(0) text-xs fg-text-muted">Raised sheet</p>    <div className="well p-md text-xs fg-text-muted">Inset well</div>    <div className="sheet sheet-floating p-md text-xs fg-text-muted">Floating</div>  </div></div>
<div class="tray">  <p class="m(0) px-md py-sm text-xs fg-text-muted">Tray</p>  <div class="sheet flex flex-col gap-md p-lg">    <p class="m(0) text-xs fg-text-muted">Raised sheet</p>    <div class="well p-md text-xs fg-text-muted">Inset well</div>    <div class="sheet sheet-floating p-md text-xs fg-text-muted">Floating</div>  </div></div>
<template>  <div class="tray">    <p class="m(0) px-md py-sm text-xs fg-text-muted">Tray</p>    <div class="sheet flex flex-col gap-md p-lg">      <p class="m(0) text-xs fg-text-muted">Raised sheet</p>      <div class="well p-md text-xs fg-text-muted">Inset well</div>      <div class="sheet sheet-floating p-md text-xs fg-text-muted">Floating</div>    </div>  </div></template>
令牌角色MoonstoneObsidian
--color-surface-base页面底面98.6%19.4%
--color-surface-tray承托面板的凹槽96%17.4%
--color-surface-raised用于卡片、按钮的凸起表面100%24.2%
--color-surface-raised-low凸起表面渐变的底端99.3%22.8%
--color-surface-inset用于字段、轨道的凹槽96.6%16.4%
--color-surface-inset-hover指针悬停时的同一凹槽95.8%15.4%
--color-surface-floating浮在内容上方的弹出层和菜单100%26.4%
--color-surface-chip中性色的胶囊标签和徽标96.5%白色,不透明度 7%
--color-surface-inverse用于主要按钮、已选中控件的墨色22%95%
--color-surface-scrim模态对话框背后的遮罩明度 18%,不透明度 20%黑色,不透明度 55%

除明确标注的不透明度外,数值表示 OKLCH 明度。凸起表面采用从 raised 到 raised-low 的自上而下渐变,由 @apply --surface-sheet 生成。按用途选择角色。floating 用于区分浮在面板上方的菜单,inset 用于标示面板内的字段。颜色令牌只提供颜色,元素的定位和阴影由其他样式控制。

#线条

Moonstone 的线条使用不同不透明度的中性墨色,Obsidian 则使用不同不透明度的白色。其中两种是 1px 分隔线,其余三种是轮廓,使用模糊半径为零的 box-shadow 绘制成半像素环线,不占用布局空间。不透明度按这一线宽调校,使轮廓纤细且清晰可辨。

令牌MoonstoneObsidian绘制规格用途
--color-line-hair6.5%7.5%1px表面内部的低对比分隔线
--color-line-divider12%13%1px区段之间及标签页栏的分隔线
--color-line-contour12%14%.5px各表面的外轮廓
--color-line-strong20%23%.5px悬停时的轮廓、开关轨道、键帽
--color-line-mark32%36%.5px复选框、字段聚焦时的轮廓
--color-texture20%23%点和 .5px 细线构成纹理的图案,默认沿用 --color-line-strong,主题可另行设置

需要一眼就能找到的控件,其轮廓比表面的更清晰。输入字段叠加两道轮廓线,复选框则使用标记轮廓令牌。

#文字

文字使用柔和的墨色,避开纯黑和纯白。

令牌用途
--color-text-strong标题、标签和值
--color-text-body正文
--color-text-muted提示、说明文字和未激活的选项
--color-text-disabled禁用的控件
--color-text-inverse墨色表面上的文字
--color-focus焦点轮廓

#层次

层次从按下形成的凹槽延伸至最上方的浮层。凸起的表面由顶部边缘内侧的高光、一道半像素轮廓线和三到六层向下投射的阴影构成。

层次

<div class="p-lg r-lg bg-surface-inset shadow-pressed text-xs fg-text-muted">pressed</div><div class="p-lg r-lg bg-surface-raised shadow-flat text-xs fg-text-muted">flat</div><div class="p-lg r-lg bg-surface-raised shadow-raised text-xs fg-text-muted">raised</div><div class="p-lg r-lg bg-surface-raised shadow-raised-hover text-xs fg-text-muted">  raised-hover</div><div class="p-lg r-lg bg-surface-raised shadow-lifted text-xs fg-text-muted">lifted</div><div class="p-lg r-lg bg-surface-floating shadow-floating text-xs fg-text-muted">floating</div>
<>  <div className="p-lg r-lg bg-surface-inset shadow-pressed text-xs fg-text-muted">pressed</div>  <div className="p-lg r-lg bg-surface-raised shadow-flat text-xs fg-text-muted">flat</div>  <div className="p-lg r-lg bg-surface-raised shadow-raised text-xs fg-text-muted">raised</div>  <div className="p-lg r-lg bg-surface-raised shadow-raised-hover text-xs fg-text-muted">    raised-hover  </div>  <div className="p-lg r-lg bg-surface-raised shadow-lifted text-xs fg-text-muted">lifted</div>  <div className="p-lg r-lg bg-surface-floating shadow-floating text-xs fg-text-muted">    floating  </div></>
<div class="p-lg r-lg bg-surface-inset shadow-pressed text-xs fg-text-muted">pressed</div><div class="p-lg r-lg bg-surface-raised shadow-flat text-xs fg-text-muted">flat</div><div class="p-lg r-lg bg-surface-raised shadow-raised text-xs fg-text-muted">raised</div><div class="p-lg r-lg bg-surface-raised shadow-raised-hover text-xs fg-text-muted">  raised-hover</div><div class="p-lg r-lg bg-surface-raised shadow-lifted text-xs fg-text-muted">lifted</div><div class="p-lg r-lg bg-surface-floating shadow-floating text-xs fg-text-muted">floating</div>
<template>  <div class="p-lg r-lg bg-surface-inset shadow-pressed text-xs fg-text-muted">pressed</div>  <div class="p-lg r-lg bg-surface-raised shadow-flat text-xs fg-text-muted">flat</div>  <div class="p-lg r-lg bg-surface-raised shadow-raised text-xs fg-text-muted">raised</div>  <div class="p-lg r-lg bg-surface-raised shadow-raised-hover text-xs fg-text-muted">    raised-hover  </div>  <div class="p-lg r-lg bg-surface-raised shadow-lifted text-xs fg-text-muted">lifted</div>  <div class="p-lg r-lg bg-surface-floating shadow-floating text-xs fg-text-muted">floating</div></template>
令牌用途
--shadow-pressed凹槽和按下的控件
--shadow-flat只有一道轮廓线的平坦表面
--shadow-raised静止状态的按钮、胶囊标签和小卡片
--shadow-raised-hover指针悬停在这些元素上时,轮廓更清晰
--shadow-lifted卡片和面板
--shadow-floating菜单和弹出层
--shadow-overlay对话框

例如,--shadow-raised 在高光和轮廓下方叠加 0 1px 2px -1px、0 2px 4px -2px 和 0 4px 8px -4px。层次越高,整组阴影的偏移范围越大。负扩展值让阴影贴近元素,模糊则柔化阴影边缘。这些令牌表现视觉深度,堆叠顺序仍由元素的布局和平台行为决定。

#墨色

墨色表面使用反色填充,例如主按钮、已勾选的复选框、发出的消息,以及页面中唯一的反色面板。所有墨色表面的顶部边缘都带有相同的高光,四周也有相同的细线,因此无论大小,看起来都是同一种材质。

令牌作用
--color-surface-inverse-high, --color-surface-inverse-low墨色面板上的光照效果
--color-ink-high, --color-ink-low墨色控件静止时更圆润的光照效果
--color-ink-high-hover, --color-ink-low-hover, --color-ink-pressed同一控件在指针悬停和按下时的光照效果
--color-ink-highlight所有墨色表面顶部边缘的高光线
--color-ink-edge墨色表面四周的细线
--color-surface-tip工具提示在 Moonstone 中使用墨色表面,在 Obsidian 中使用较浅的表面
--shadow-ink, --shadow-ink-hover, --shadow-ink-pressed墨色控件在各状态下的层次
--shadow-ink-mark小面积的选中填充,例如选中的复选框、单选按钮或日期
--shadow-ink-well, --shadow-thumb-on-ink轨道的填充部分及沿轨道移动的滑块
--shadow-tip工具提示和图表的数值读数

带色相的控件(如品牌色控件或破坏性操作的确认控件)以自身色相调配表面、边缘和光晕的颜色,--color-tone-highlight 和 --color-tone-highlight-soft 提供高光。

#滑块、图片和页面提供的颜色

令牌作用
--color-thumb-high, --color-thumb-low开关、滑动条和对比组件上的珠白色滑块
--color-thumb-on-high, --color-thumb-on-low开启状态下的开关滑块
--color-line-image, --color-line-image-strong图片和头像边缘内侧的细线,让它们与所在表面保持清晰的边界
--color-line-on-color, --color-highlight-on-color页面提供的颜色所用的边缘和高光,例如色样
--color-on-image, --color-on-image-shade叠在图片上的元素在两种主题中都使用白色和深色阴影
--color-mark, --color-mark-underline荧光笔笔迹及其下划线形式
--color-sheen扫过骨架屏的高光
--color-focus-halo输入字段聚焦时,轮廓外侧的柔和光晕

#形状

与表面一样,圆角半径也按用途划分。胶囊标签是小型标记,控件供按压或输入,表面则是面板。令牌定义在 @theme 中,因此也可通过工具类使用,例如 r-control 使用控件的基础圆角半径。组件还会应用下文介绍的连续圆角形状和缩放,完整效果需要这些设置与圆角半径配合。

令牌值适用对象
--radius-chip6px徽标、键帽、复选框、骨架屏
--radius-control-sm8px小号按钮和字段、菜单行、选项、分段控件的滑块
--radius-control10px按钮、字段、凹槽
--radius-control-lg12px大号按钮和字段、警示框、选择项、轻提示
--radius-surface16px面板、卡片

外层容器的圆角半径由内部元素决定,等于内侧半径加上两者之间的内缩距离。托盘的圆角半径比面板大 4px,菜单的圆角半径比菜单行大 4px,分段控件轨道的圆角半径等于滑块半径加上内缩距离,字段内按钮的圆角半径比字段小 4px。这样,间距在转角处也保持等宽。只有胶囊形元素、圆点和头像采用更圆的轮廓。

嵌套圆角

<div class="tray max-w(360) mx-auto">  <div class="sheet flex flex-col gap-md p-lg">    <div class="input-group">      <input class="input-group-field" value="atlas.dev" aria-label="Domain">      <button type="button" class="btn">Verify</button>    </div>    <div class="segmented" role="radiogroup" aria-label="Environment">      <label class="segmented-item">        <input type="radio" class="segmented-input" name="environment" checked>Production      </label>      <label class="segmented-item">        <input type="radio" class="segmented-input" name="environment">Preview      </label>    </div>  </div></div>
<div className="tray max-w(360) mx-auto">  <div className="sheet flex flex-col gap-md p-lg">    <div className="input-group">      <input className="input-group-field" defaultValue="atlas.dev" aria-label="Domain" />      <button type="button" className="btn">Verify</button>    </div>    <div className="segmented" role="radiogroup" aria-label="Environment">      <label className="segmented-item">        <input type="radio" className="segmented-input" name="environment" defaultChecked />Production      </label>      <label className="segmented-item">        <input type="radio" className="segmented-input" name="environment" />Preview      </label>    </div>  </div></div>
<div class="tray max-w(360) mx-auto">  <div class="sheet flex flex-col gap-md p-lg">    <div class="input-group">      <input class="input-group-field" value="atlas.dev" aria-label="Domain">      <button type="button" class="btn">Verify</button>    </div>    <div class="segmented" role="radiogroup" aria-label="Environment">      <label class="segmented-item">        <input type="radio" class="segmented-input" name="environment" checked>Production      </label>      <label class="segmented-item">        <input type="radio" class="segmented-input" name="environment">Preview      </label>    </div>  </div></div>
<template>  <div class="tray max-w(360) mx-auto">    <div class="sheet flex flex-col gap-md p-lg">      <div class="input-group">        <input class="input-group-field" value="atlas.dev" aria-label="Domain">        <button type="button" class="btn">Verify</button>      </div>      <div class="segmented" role="radiogroup" aria-label="Environment">        <label class="segmented-item">          <input type="radio" class="segmented-input" name="environment" checked>Production        </label>        <label class="segmented-item">          <input type="radio" class="segmented-input" name="environment">Preview        </label>      </div>    </div>  </div></template>

#连续圆角

border-radius 绘制四分之一圆弧。圆弧接上直边时,曲率会从零骤增至圆弧的曲率,因此接合处看起来像有一道凸肩。用 corner-shape: squircle 绘制的超椭圆圆角会更早开始转弯,曲率逐渐增大,让直边平滑过渡到圆角。

浏览器支持 corner-shape 时,组件绘制超椭圆圆角,否则使用四分之一圆弧。半径相同时,超椭圆圆角的轮廓更贴近角部,因此组件将半径乘以 --corner-scale,使两种圆角看起来一样圆润。使用超椭圆圆角时取 1.6,否则取 1。这两个值统一在主题中设置,供所有组件读取。

属性支持 corner-shape不支持
--corner-shapesquircleround
--corner-scale1.61

胶囊形元素、圆点、头像和滑块仍使用标准圆形轮廓。主题定制 介绍如何统一使用圆弧圆角。

#排版

主题不会下载字体。文档使用 Geist,控件读取预设中的字体族令牌。请先在应用中加载字体,再指定使用该字体。文档站点的排版设置如下:

app.css
@theme {  --font-sans: 'Geist';  --font-feature-sans: 'ss02', 'ss03', 'ss04', 'ss06', 'ss07', 'ss08';}body {  font-weight: 350;}

控件标签使用 --font-weight-control(460),以略偏轻的中等字重保持清晰,避免显得厚重。标题保持常规字重,通过字号和墨色区分层级。

#动效

一组缓动曲线让交互响应迅速,也让用于说明变化的动效平缓展开。控件的位移由一个长度值决定。--lift 对应半个像素,凸起控件在指针悬停时上浮半个像素,按下时下沉半个像素。卡片的上浮距离是控件的两倍。将该值设为 0px 即可取消主题中的位移动效。启用减少动态效果时已采用此设置。

令牌值用途
--easing-glidecubic-bezier(.22, 1, .36, 1)所有状态变化
--duration-press60ms按下控件
--duration-quick160ms悬停和聚焦、弹出层、菜单、工具提示以及所有退场动效
--duration-base280ms滑块和面板的移动、对话框入场
--lift.5px凸起控件的上浮和下沉距离

浮层的入场和退场动效都由 CSS 定义。@starting-style 定义元素入场的起始帧,display 和 overlay 借助 allow-discrete 进行过渡,使退场动效在元素离开顶层前播完。退场比入场更短。启用减少动态效果时,仅保留淡入淡出,移除位移和缩放。

#状态色与品牌色

界面仅使用 --color-info、--color-success、--color-warning 和 --color-danger 这四种色相传达状态。每种颜色都经过调整,用作文字颜色时在对应主题中清晰可读。下文的分类色标记的是数据,而不是状态。

品牌色是界面自身唯一不表示状态的色相,每个视图只在 btn-brand 上使用一次。

令牌值用途
--color-brandvar(--color-indigo-50)品牌表面的底色
--color-brand-ink接近白色品牌表面上的文字
--color-brand-textMoonstone 中为 indigo-60,Obsidian 中为 indigo-30页面上使用品牌色的文字

品牌表面的边缘、高光和辉光都以 --color-brand 为基础混色,覆盖这一个令牌即可一并调整。如果品牌色较浅,请将 --color-brand-ink 设为深色墨色。

状态色与品牌色

<span class="badge badge-info badge-dot">Info</span><span class="badge badge-success badge-dot">Success</span><span class="badge badge-warning badge-dot">Warning</span><span class="badge badge-danger badge-dot">Danger</span><button type="button" class="btn btn-brand btn-sm">Upgrade</button>
<>  <span className="badge badge-info badge-dot">Info</span>  <span className="badge badge-success badge-dot">Success</span>  <span className="badge badge-warning badge-dot">Warning</span>  <span className="badge badge-danger badge-dot">Danger</span>  <button type="button" className="btn btn-brand btn-sm">Upgrade</button></>
<span class="badge badge-info badge-dot">Info</span><span class="badge badge-success badge-dot">Success</span><span class="badge badge-warning badge-dot">Warning</span><span class="badge badge-danger badge-dot">Danger</span><button type="button" class="btn btn-brand btn-sm">Upgrade</button>
<template>  <span class="badge badge-info badge-dot">Info</span>  <span class="badge badge-success badge-dot">Success</span>  <span class="badge badge-warning badge-dot">Warning</span>  <span class="badge badge-danger badge-dot">Danger</span>  <button type="button" class="btn btn-brand btn-sm">Upgrade</button></template>

#分类色

分类色表示某样东西属于哪一类数据,例如一个项目、一个日历或一个标签。预设中从 stone 到 red 的 23 个具名色板,每个都提供四个角色:--color-category-<name>-surface、-text、-line 和 -mark。同一角色在所有色板中的明度都相同,因此没有哪个分类比其他分类更显眼;色相和彩度则是该色板在这一明度下的取值。每个角色都针对自身的底色,以及 Moonstone、Obsidian 和 Paper 的基础面和凸起面检查过对比度。

角色用途对比度
-surface分类徽标、值胶囊标签、事件或图标框下方的淡色底纹—
-text写在该底纹或页面上的文字4.5:1
-line围绕底纹的装饰性轮廓;绝不能作为控件唯一的边界—
-mark标记分类的圆点或色条3:1

组件通过 --category-surface、--category-text、--category-line 和 --category-mark 读取这些角色,它们由 category-<name> 类设置。作为分类的红色并不表示危险:危险使用 --color-danger。

分类色

<span class="badge badge-category badge-dot category-blue">Platform</span><span class="badge badge-category badge-dot category-pink">Marketing</span><span class="badge badge-category badge-dot category-amber">Finance</span><span class="badge badge-category badge-dot category-teal">Design</span>
<>  <span className="badge badge-category badge-dot category-blue">Platform</span>  <span className="badge badge-category badge-dot category-pink">Marketing</span>  <span className="badge badge-category badge-dot category-amber">Finance</span>  <span className="badge badge-category badge-dot category-teal">Design</span></>
<span class="badge badge-category badge-dot category-blue">Platform</span><span class="badge badge-category badge-dot category-pink">Marketing</span><span class="badge badge-category badge-dot category-amber">Finance</span><span class="badge badge-category badge-dot category-teal">Design</span>
<template>  <span class="badge badge-category badge-dot category-blue">Platform</span>  <span class="badge badge-category badge-dot category-pink">Marketing</span>  <span class="badge badge-category badge-dot category-amber">Finance</span>  <span class="badge badge-category badge-dot category-teal">Design</span></template>

#配色方案

随配色方案变化的颜色使用 light-dark()。部分高光和叠在图像上的颜色在两种方案中保持一致。主题遵循元素的 color-scheme。Master CSS 预设在根元素上设置 color-scheme: light dark,并允许你为整个页面或某个子树固定配色方案:

<html data-theme="dark">  …  <aside data-theme="light">A moonstone panel on an obsidian page</aside></html>

深色模式沿用同一份样式表和同一套组件类名。

#自定义

要覆盖主题令牌或构建完整主题,请参阅主题定制。要选择使用工具类、令牌、组件属性还是自行维护源码,请参阅自定义。