Files
heroui-vue/apps/docs/themes.md
T

54 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 主题
description: 使用与 HeroUI 相同的语义变量定制组件外观
---
## 默认主题
浅色和深色变量移植自固定基线的 default/variables.css,采用相同的 OKLCH 颜色与派生公式。按钮、表面、输入框和开关共同使用这些变量。
## 浅色与深色
文档右上角切换主题,页面与组件同步更新。应用支持 `.light`、`.dark`、`data-theme="light"` 与 `data-theme="dark"`。
```html
<html class="dark"></html>
```
## 语义颜色
| 变量 | 用途 |
| ------------------------------------------------------------- | ------------------ |
| --background / --foreground | 页面背景与正文 |
| --surface / --surface-secondary / --surface-tertiary | 分层表面 |
| --accent / --accent-foreground | 主要操作与选中状态 |
| --default / --default-foreground | 默认控件背景与文字 |
| --muted | 次要文本 |
| --danger / --danger-foreground | 危险操作与无效状态 |
| --field-background / --field-foreground / --field-placeholder | 表单输入 |
| --border / --separator / --focus | 边界、分隔和焦点 |
## 自定义主题
```css
[data-theme="brand"] {
--accent: oklch(0.62 0.2 300);
--accent-foreground: oklch(0.99 0 0);
--radius: 0.75rem;
}
```
```html
<section class="light" data-theme="brand">...</section>
```
将上述样式放在库样式之后,覆盖容器变量。嵌套容器加上 light 或 dark,使派生颜色在该容器重新计算。浅深自定义主题应分别声明值;应用继承基线的派生颜色与阴影公式。
## 圆角与阴影
默认 `--radius: 0.5rem`,`--field-radius: calc(var(--radius) * 1.5)`。Card 使用 `min(32px, var(--radius-3xl))`,Button 使用 3xl 圆角。不要为不同页面独立设置近似圆角或品牌蓝。
## 动效
支持 prefers-reduced-motion 和 data-reduce-motion 状态。保留基线的 hover、press、focus 与过渡时间。