颜色
颜色有助于区分操作和文本,以及正常状态和警告或错误。必须在应用程序的所有页面中维护其角色。
颜色角色
| 角色 | 应用 | 设计令牌(design tokens) |
|---|---|---|
| 主要 | 主要动作,所选项目 | colorPrimary |
| 成功 | 已完成运营 | colorSuccess |
| 警告 | 需要注意的情况 | colorWarning |
| 错误 | 操作失败或输入不正确 | colorError |
| 文字和表面 | 阅读、背景、边框 | colorText、colorBgContainer、colorBorder |
不要仅使用一种颜色来指示状态:添加签名、图标或消息。即使没有色调识别,相邻元素也必须能够区分。
成功
警告
错误
信息
产品调色板
Ant Design 有基本的调色板和中性色调。在您的产品中,选择主要颜色并一致地使用语义角色。要进行配置,请将 colorPrimary 传递给 ConfigProvider 主题。
不要将白色背景和黑色文本锁定到应用程序组件中:使用当前主题标记来保持深色模式下的可读性。
主要动作
colorPrimary 选中项
colorPrimaryBg 关联
colorLink检查状态
比较正常、hover、focus、活动和 disabled。检查所选填充顶部的文本以及字段背景上的错误。 设置主题 描述通用标记和组件标记,ColorPicker 允许您使用自定义颜色。
模型与系统层次
Ant Design 区分系统级与产品级色彩。系统定义协调色相、中性色和可视化基础;产品选择主色,并将其他角色连接到任务。HSB 通过色相、饱和度与明度讨论颜色变化,而不局限于 CSS 表达。
基础调色板
基础体系包含十二个色系,每个十级。浅色调色板通常以第六级作为主色,其他级用于背景、边框和交互状态。暗黑模式会根据环境重新计算色彩关系。
下方调色板读取当前公开主题令牌。选择主色后,会在示例范围内重新计算语义角色。顶部主题设置可比较浅色与暗色体系,无需从 CSS 复制数值。
调色板主色
- colorPrimaryBg
#e6f4ff- colorPrimaryBorder
#91caff- colorPrimaryHover
#4096ff- colorPrimary
#1677ff- colorPrimaryActive
#0958d9- colorText
rgba(0,0,0,0.88)- colorTextSecondary
rgba(0,0,0,0.65)- colorBgContainer
#ffffff
red
#fff1f01#ffccc72#ffa39e3#ff78754#ff4d4f5#f5222d6#cf13227#a8071a8#8200149#5c001110
volcano
#fff2e81#ffd8bf2#ffbb963#ff9c6e4#ff7a455#fa541c6#d4380d7#ad21028#8714009#610b0010
orange
#fff7e61#ffe7ba2#ffd5913#ffc0694#ffa9405#fa8c166#d46b087#ad4e008#8738009#61250010
gold
#fffbe61#fff1b82#ffe58f3#ffd6664#ffc53d5#faad146#d488067#ad68008#874d009#61340010
yellow
#feffe61#ffffb82#fffb8f3#fff5664#ffec3d5#fadb146#d4b1067#ad8b008#8768009#61470010
lime
#fcffe61#f4ffb82#eaff8f3#d3f2614#bae6375#a0d9116#7cb3057#5b8c008#3f66009#25400010
green
#f6ffed1#d9f7be2#b7eb8f3#95de644#73d13d5#52c41a6#389e0d7#2378048#1352009#092b0010
cyan
#e6fffb1#b5f5ec2#87e8de3#5cdbd34#36cfc95#13c2c26#08979c7#006d758#00474f9#00232910
blue
#e6f4ff1#bae0ff2#91caff3#69b1ff4#4096ff5#1677ff6#0958d97#003eb38#002c8c9#001d6610
geekblue
#f0f5ff1#d6e4ff2#adc6ff3#85a5ff4#597ef75#2f54eb6#1d39c47#10239e8#0611789#03085210
purple
#f9f0ff1#efdbff2#d3adf73#b37feb4#9254de5#722ed16#531dab7#3910858#22075e9#12033810
magenta
#fff0f61#ffd6e72#ffadd23#ff85c04#f759ab5#eb2f966#c41d7f7#9e10688#7806509#52033910
颜色角色与调色板
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>
中性色
文字、表面、边框与分隔线占据工作界面的大部分。它们的差异无需频繁使用鲜艳强调色即可建立层级。透明度与背景共同决定最终颜色,因此应结合实际表面评估,而不是只看孤立色样。
本材料改编自 Ant Design. MIT.