docs: complete handbook and prepare component verification tasks

This commit is contained in:
maoyingjie
2026-10-27 21:46:42 +08:00
parent 4da00943f1
commit 26df6e88a2
32 changed files with 2207 additions and 39 deletions
+140
View File
@@ -0,0 +1,140 @@
---
title: 颜色
description: HeroUI v3 的调色板与主题系统
---
颜色通过语义变量表达用途。浅色和深色共用变量名称,由主题容器决定实际取值;组件使用变量而不是各自硬编码品牌色。本页沿用固定 HeroUI 基线的颜色分类,类名使用本库的 `hv-` 前缀。
以下色板同时展示 Light / Dark。悬停或键盘聚焦查看变量名,点击色块复制浏览器解析后的颜色值;复制的是当前主题下的颜色,不是变量名。
## 强调色
强调色代表品牌或产品的主识别色,用于吸引对关键操作、高亮与重点时刻的注意。应节制使用,以保留视觉层级。组件从基础强调色派生悬停和柔和背景;改变 `--accent` 时也应保证配对前景色可读。
<DocsColorSection name="强调色" :tokens="['--accent', '--accent-hover', '--accent-foreground', '--accent-soft', '--accent-soft-hover', '--accent-soft-foreground']" />
## 默认(中性色)
默认色构成系统的中性骨架,适用于大多数非强调的界面元素。它与页面背景、卡片表面有不同用途,不应随意互换。
<DocsColorSection name="默认" :tokens="['--default', '--default-hover', '--default-foreground', '--default-soft', '--default-soft-hover', '--default-soft-foreground']" />
## 成功
成功色表达积极结果、确认与完成状态,常见于反馈、状态指示与校验通过等场景。
<DocsColorSection name="成功" :tokens="['--success', '--success-hover', '--success-foreground', '--success-soft', '--success-soft-hover', '--success-soft-foreground']" />
## 警告
警告色表示需要谨慎、存在风险或需要留意的操作。它用于提醒和复核,不应替代危险色表达破坏性操作。
<DocsColorSection name="警告" :tokens="['--warning', '--warning-hover', '--warning-foreground', '--warning-soft', '--warning-soft-hover', '--warning-soft-foreground']" />
## 危险
危险色用于错误、严重告警和破坏性操作。组件的错误样式还需要关联错误说明与实际校验语义,仅改变颜色不会使字段成为无效状态。
<DocsColorSection name="危险" :tokens="['--danger', '--danger-hover', '--danger-foreground', '--danger-soft', '--danger-soft-hover', '--danger-soft-foreground']" />
## 前景色
`--foreground` 用于正文与图标,`--muted` 用于次要信息。带专用背景的组件应使用其配对前景色,例如 `--accent-foreground`,而不是固定白色。
<DocsColorSection name="前景色" :tokens="['--foreground', '--muted']" />
## 背景色
背景是界面的基底画布;secondary 和 tertiary 在同一画布上建立层级。inverse 提供反色背景,使用时仍需自行确认文字对比度。
<DocsColorSection name="背景色" :tokens="['--background', '--background-secondary', '--background-tertiary', '--background-inverse']" />
## 表面色
表面色用于卡片、面板和其他非浮层容器;`--overlay` 专门用于 Popover、Modal、菜单等浮层。表面通过明度、层级和阴影区分内容,不依赖强烈色相差异。
<DocsColorSection name="表面色" :tokens="['--surface', '--surface-secondary', '--surface-tertiary', '--surface-hover', '--overlay']" />
每层还有对应的 foreground:`--surface-foreground`、`--surface-secondary-foreground`、`--surface-tertiary-foreground` 和 `--overlay-foreground`。
## 表单字段
字段有独立的背景、文本、placeholder、hover/focus 和边框变量。修改这些变量可以调整表单而不改变按钮或卡片的基础表面。
<DocsColorSection name="表单字段" :tokens="['--field-background', '--field-foreground', '--field-placeholder', '--field-hover', '--field-focus', '--field-border', '--field-border-hover', '--field-border-focus']" />
默认 `--field-border` 是透明色,色板可能显示底层表面。`--field-border-width` 决定字段描边宽度;焦点环使用 `--focus`,错误状态使用 `--danger`。
## 分隔线
分隔线用于轻量组织内容,边框用于轮廓。secondary/tertiary 是相对于表面的派生层次。
<DocsColorSection name="分隔与边框" :tokens="['--separator', '--separator-secondary', '--separator-tertiary', '--border', '--border-secondary', '--border-tertiary']" />
## 其他
焦点、链接、分段控件、遮罩和滚动条也使用语义变量。
<DocsColorSection name="其他" :tokens="['--focus', '--link', '--segment', '--segment-foreground', '--backdrop', '--scrollbar-thumb', '--scrollbar-track']" />
`--scrollbar-track` 默认透明,滚动条的宽度和模式参见[主题中的滚动条](/themes#滚动条)。
## 基础色
基础色是主题的底层取值,明暗模式之间不变。业务页面通常优先选择语义颜色,而不是直接使用黑色或白色。
<DocsColorSection name="基础色" :tokens="['--white', '--black', '--snow', '--eclipse']" />
## 如何使用颜色
组件通过 `variant` 等公开属性选择已有样式;自定义内容可以直接使用 CSS 变量。
```vue
<template>
<section class="summary">项目摘要</section>
</template>
<style scoped>
.summary {
background: var(--surface);
color: var(--surface-foreground);
border: 1px solid var(--border);
border-radius: var(--radius-xl);
}
</style>
```
使用 Tailwind 的应用需要在自己的构建中注册语义令牌,再使用 `bg-background`、`text-foreground` 等工具类。当前预编译 CSS **不会自动向消费者的 Tailwind 编译器注册令牌**;完整接入示例见[添加自定义颜色](/themes#添加自定义颜色)。
## 默认主题
默认值采用固定基线的 OKLCH 颜色与 `color-mix()` 派生公式。全局主题用 `.light` / `.dark` 或 `data-theme="light"` / `data-theme="dark"` 显式设置。
```html
<html class="dark">
<!-- 页面及挂载到 body 的浮层共同继承主题 -->
</html>
```
主题切换、跟随系统以及持久化由应用控制,见[深色模式](/dark-mode)。组件包当前没有公共 `useTheme`。
## 自定义颜色
在库 CSS 之后覆盖语义变量。局部主题同时添加 `light` 或 `dark`,使依赖这些颜色的派生变量在容器内重新计算。
```css
.light[data-theme="brand"] {
--accent: oklch(0.62 0.2 300);
--accent-foreground: var(--snow);
}
.dark[data-theme="brand"] {
--accent: oklch(0.72 0.17 300);
--accent-foreground: var(--eclipse);
}
```
```html
<section class="light" data-theme="brand">...</section>
```
派生变量继承的是计算结果,不能假定在任意子节点只覆盖 `--accent` 就会重新计算祖先的所有派生颜色。局部主题中的浮层还需使用支持的挂载目标,见[主题](/themes#快速开始)。