Ordo UI
Foundations

Contrast

normal / high 两档对比度;高对比度只覆盖语义 token 并加粗焦点环与控件边框。

Contrast

对比度是主题的可访问性开关,取值 normal / high。

<ThemeProvider theme={{ contrast: 'high' }}>
  <App />
</ThemeProvider>
<html data-contrast="high">

完整接入、forced-colors 与品牌色注意事项见 可访问性与高对比度。

token 变化

Token亮色 normal亮色 high暗色 normal暗色 high
--background0 0% 100%0 0% 100%240 10% 4%0 0% 0%
--foreground240 10% 3.9%0 0% 0%0 0% 95%0 0% 100%
--muted-foreground240 3.8% 46.1%0 0% 25%240 5% 64.9%0 0% 82%
--border240 5.9% 90%0 0% 20%240 4% 16%0 0% 60%
--ring240 5.9% 10%216 100% 30%240 4.8% 83.9%210 100% 72%
--destructive0 84.2% 60.2%0 74% 35%358 46% 54%0 85% 72%

高对比度还会覆盖 sidebar / content / accent / chart / scrollbar 等全部语义 token,数据源见 packages/ui/src/theme/contrast.json,CSS 由 gen-contrast 生成。

行为层

  • :focus-visible 增加 3px --ring outline + 2px offset。
  • button / input / textarea / select / checkbox / radio / switch 边框加粗到 2px。
  • disabled / data-disabled / aria-disabled="true" 透明度从 0.5 提到 0.7。
  • 不改任何组件 className;消费方升级主题 CSS 即可获得。

验收

packages/ui/src/theme/contrast.test.ts 逐对计算 WCAG:

  • 文本 token ≥ 4.5:1;
  • 边框 / 焦点 / 图表 token ≥ 3:1;
  • 所有值必须是 HSL 三元组或 transparent。
pnpm --filter @mox-hub/ui test contrast.test.ts
pnpm --filter @mox-hub/ui lint:contrast

品牌色由 ThemeProvider 写成内联变量,优先级高于高对比 CSS;使用 brand 时需自行保证 primary / ring 的对比度。