暗黑模式
暗黑模式调整表面、文字与强调色之间的关系,同时保留内容和界面层级。它适合光线较暗的环境,以及需要让内容在安静背景中突出的场景。
阅读舒适度
避免大面积过强对比、明亮边框和同样饱和的强调色。浅色文字放在纯黑背景上并不一定舒适。应结合周围环境检查长时间阅读、密集表格、次级说明和选中状态。
保持信息层级
阅读顺序、操作位置和状态含义应保持一致。卡片表面、页面背景和浮层在没有强阴影时也应可区分。弱化次级颜色时,必要信息仍应清晰可见。
颜色与表面
调色板应适应背景;简单反转 RGB 无法保留感知亮度和色彩关系。使用 colorText、colorBgContainer、colorBgElevated 和 colorBorder 等语义设计令牌(design tokens)。错误颜色应配合文字信息,选中状态应具有明确的选择标识。
调色板主色
- colorPrimaryBg
#15325b- colorPrimaryBorder
#15325b- colorPrimaryHover
#3c89e8- colorPrimary
#1668dc- colorPrimaryActive
#1554ad- colorText
rgba(255,255,255,0.85)- colorTextSecondary
rgba(255,255,255,0.65)- colorBgContainer
#141414
red
#2a12151#4314182#58181c3#791a1f4#a61d245#d320296#e847497#f373708#f89f9a9#fac8c310
volcano
#2b16111#441d122#5927163#7c31184#aa3e195#d84a1b6#e870407#f3956a8#f8b6929#fad4bc10
orange
#2b1d111#442a112#5938153#7c4a154#aa62155#d87a166#e89a3c7#f3b7658#f8cf8d9#fae3b710
gold
#2b21111#4431112#5942143#7c59144#aa77145#d896146#e8b3397#f3cc628#f8df8b9#faedb510
yellow
#2b26111#443b112#5950143#7c6e144#aa95145#d8bd146#e8d6397#f3ea628#f8f48b9#fafab510
lime
#1f26111#2e3c102#3e4f133#536d134#6f94125#8bbb116#a9d1347#c9e75d8#e4f88b9#f0fab510
green
#1623121#1d37122#2749163#3063174#3c86185#49aa196#6abe397#8fd4608#b2e58b9#d5f2bb10
cyan
#1121231#1135362#1448483#1462624#1385855#13a8a86#33bcb77#58d1c98#84e2d89#b2f1e810
blue
#111a2c1#1125452#15325b3#15417e4#1554ad5#1668dc6#3c89e87#65a9f38#8dc5f89#b7dcfa10
geekblue
#1316291#161d402#1c27553#2031754#263ea05#2b4acb6#5273e07#7f9ef38#a8c1f89#d2e0fa10
purple
#1a13251#24163a2#301c4d3#3e20694#51258f5#642ab56#854eca7#ab7ae08#cda8f09#ebd7fa10
magenta
#2913211#40162f2#551c3b3#75204f4#a026695#cb2b836#e0529c7#f37fb78#f8a8cc9#fad2e310
颜色角色与调色板
ColorPicker 修改主色,公开令牌展示语义角色与十二种基础调色板。
PaletteExample.svelte<script lang="ts"> import { Button, ColorPicker, ConfigProvider, theme } from '@woodger/antd'; import PaletteReadout from './PaletteReadout.svelte'; let { dark = false }: { dark?: boolean } = $props(); let primary = $state('#1677ff'); </script> <div class="controls"> <span id="design-primary-label">{("调色板主色")}</span> <ColorPicker aria-labelledby="design-primary-label" value={primary} showText disabledAlpha onChange={(_, css) => { primary = css; }} /> <Button onclick={() => { primary = '#1677ff'; }}>{("重置调色板颜色")}</Button> </div> <ConfigProvider theme={{ ...(dark ? { mode: 'dark', algorithm: theme.darkAlgorithm } : {}), token: { colorPrimary: primary } }}> <PaletteReadout /> </ConfigProvider> <style> .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; } </style>PaletteReadout.svelte<script lang="ts"> import { theme } from '@woodger/antd'; const current = theme.useToken(); const colors = [ 'red', 'volcano', 'orange', 'gold', 'yellow', 'lime', 'green', 'cyan', 'blue', 'geekblue', 'purple', 'magenta' ] as const; const levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const; const roles = [ 'colorPrimaryBg', 'colorPrimaryBorder', 'colorPrimaryHover', 'colorPrimary', 'colorPrimaryActive', 'colorText', 'colorTextSecondary', 'colorBgContainer' ] as const; </script> <div class="surface"> <dl aria-label={("调色板语义角色")}> {#each roles as role (role)} <div class="role"><dt>{role}</dt><dd><span class="swatch" style:background={current .token[role]} aria-hidden="true"></span><code>{current.token[role]}</code></dd></div> {/each} </dl> <div class="palettes" aria-label={("主题基础调色板")}> {#each colors as color (color)} <section aria-label={color}> <h4>{color}</h4> <ol> {#each levels as level (level)} <li><span class="swatch" style:background={current.token[`${color}${level}`]} aria-hidden="true" ></span><code>{current.token[`${color}${level}`]}</code><small>{level}</small></li> {/each} </ol> </section> {/each} </div> </div> <style> .surface { padding: 16px; background: var(--ant-color-bg-container); color: var(--ant-color-text); border-radius: 6px; } dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px 24px; margin: 0 0 24px; } dt { overflow-wrap: anywhere; font-size: 12px; } dd { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; } .palettes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 24px; } h4 { margin: 0 0 8px; font-size: 14px; font-weight: 500; } ol { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; } li { display: flex; align-items: center; gap: 8px; min-width: 0; } .swatch { flex: none; width: 24px; height: 20px; border: 1px solid var(--ant-color-border-secondary); border-radius: 3px; } code { font-size: 11px; overflow-wrap: anywhere; } small { margin-inline-start: auto; color: var(--ant-color-text-secondary); font-size: 11px; } </style>
@woodger/antd 中的主题
在顶部设置中切换主题,并对照此页面与组件示例。主题指南演示了独立的 ConfigProvider 范围和响应式令牌读取。自定义表面应使用同一主题中的颜色。
图像与状态
分别检查图标、图表、照片和透明图像。如果浅色背景属于插图本身,可保留该背景。对于表单,应检查 focus、hover、disabled、错误及加载状态;切换主题应保留输入数据和焦点。
本材料改编自 Ant Design. MIT.