docs: complete handbook and prepare component verification tasks
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 apps/docs/src/components/color-section.tsx.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
// Vue DOM/CSS token display; copying keeps the browser's resolved CSS color.
|
||||
import { ref } from "vue";
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
defineProps<{ name: string; tokens: string[] }>();
|
||||
const message = ref("");
|
||||
async function copy(event: MouseEvent, token: string) {
|
||||
const value = getComputedStyle(
|
||||
event.currentTarget as HTMLElement,
|
||||
).backgroundColor;
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
message.value = `已复制 ${token}: ${value}`;
|
||||
} catch {
|
||||
message.value = `无法复制,请使用变量 ${token}`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="docs-color-section not-prose">
|
||||
<div
|
||||
v-for="theme in ['light', 'dark']"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-column"
|
||||
>
|
||||
<div class="docs-color-header">
|
||||
<strong>{{ name }}</strong>
|
||||
<span>{{ theme === "light" ? "Light" : "Dark" }}</span>
|
||||
</div>
|
||||
<Tooltip v-for="token in tokens" :key="token" :delay="0">
|
||||
<Button
|
||||
variant="ghost"
|
||||
class="docs-color-token"
|
||||
:style="{ backgroundColor: `var(${token})` }"
|
||||
:aria-label="`复制 ${theme} ${token}`"
|
||||
@click="copy($event, token)"
|
||||
>
|
||||
<span>{{ token }}</span>
|
||||
</Button>
|
||||
<TooltipContent>
|
||||
{{ token }} · 点击复制浏览器解析后的颜色值
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<span class="docs-color-message" role="status">{{ message }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.docs-color-section {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-block: 20px;
|
||||
}
|
||||
.docs-color-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
color: var(--foreground);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.docs-color-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.docs-color-header span {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.docs-color-token {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
padding: 12px;
|
||||
justify-content: start;
|
||||
border-radius: 12px;
|
||||
border: 1px solid color-mix(in oklab, var(--foreground) 12%, transparent);
|
||||
}
|
||||
.docs-color-token span {
|
||||
background: inherit;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
color: transparent;
|
||||
filter: invert(1) grayscale(1) contrast(100);
|
||||
font-size: 12px;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
}
|
||||
.docs-color-message {
|
||||
grid-column: 1 / -1;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
.docs-color-section {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,6 +2,7 @@ import type { Theme } from "vitepress";
|
||||
import { IconCopy, IconCheck } from "@tabler/icons-vue";
|
||||
import { Button } from "@heroui-vue/components";
|
||||
import DocsComponents from "./DocsComponents.vue";
|
||||
import DocsColorSection from "./DocsColorSection.vue";
|
||||
import Layout from "./Layout.vue";
|
||||
import Demo from "./Demo.vue";
|
||||
import "@heroui-vue/styles/css";
|
||||
@@ -14,6 +15,7 @@ export default {
|
||||
app.component("ComponentPreview", Demo);
|
||||
app.component("DocsCopyButton", Button);
|
||||
app.component("DocsComponents", DocsComponents);
|
||||
app.component("DocsColorSection", DocsColorSection);
|
||||
app.component("DocsCopyIcon", IconCopy);
|
||||
app.component("DocsCheckIcon", IconCheck);
|
||||
},
|
||||
|
||||
@@ -392,7 +392,12 @@ export const guideGroups: DocsGroup[] = [
|
||||
{
|
||||
title: "手册",
|
||||
items: [
|
||||
{ title: "颜色", url: "/colors" },
|
||||
{ title: "主题", url: "/themes" },
|
||||
{ title: "深色模式", url: "/dark-mode" },
|
||||
{ title: "样式", url: "/styling" },
|
||||
{ title: "动画", url: "/animation" },
|
||||
{ title: "组合", url: "/composition" },
|
||||
{ title: "字段与表单基础", url: "/fields" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
---
|
||||
title: 动画
|
||||
description: 为 HeroUI v3 组件添加流畅的动画和过渡
|
||||
---
|
||||
|
||||
组件使用内置 CSS 过渡与关键帧,也可以在应用中添加自定义 CSS 或 Vue 动画。浮层动画还与定位、焦点及卸载有关,不能只给静态元素添加一个动画类就替代组件生命周期。
|
||||
|
||||
## 内置动画
|
||||
|
||||
浮层进入与退出时使用明确的阶段标记,按钮使用原生与数据状态。Vue 组件把这些状态适配到真实 DOM,再由样式控制:
|
||||
|
||||
```css
|
||||
.hv-popover[data-entering="true"] {
|
||||
/* 进入关键帧 */
|
||||
}
|
||||
.hv-popover[data-exiting="true"] {
|
||||
/* 退出关键帧 */
|
||||
}
|
||||
.hv-button:active,
|
||||
.hv-button[data-pressed="true"] {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
```
|
||||
|
||||
<ComponentPreview name="handbook-animation" />
|
||||
|
||||
| 状态 | 用途与边界 |
|
||||
| ---------------------------------------------- | ------------------------------------------------ |
|
||||
| `data-hovered="true"` | 部分交互组件的悬停状态,也可能使用原生 `:hover` |
|
||||
| `data-pressed="true"` | 按下反馈,不等同于已经触发业务提交 |
|
||||
| `data-focus-visible="true"` | 键盘焦点提示;原生 `:focus-visible` 也可能参与 |
|
||||
| `disabled` / `aria-disabled` / `data-disabled` | 按实际组件语义与属性格式使用 |
|
||||
| `data-entering="true"` / `data-exiting="true"` | 组件暴露的动画阶段,不是任意组件通用的控制属性 |
|
||||
| `aria-expanded` | 触发器展开语义,不能用它判断面板是否可见、可点击 |
|
||||
|
||||
正常关闭时,Presence 保留浮层以播放退出动画,完成后卸载并按组件规则恢复焦点。用户禁用动画或动画被取消时,状态也需要清理;应用不要以过早的外层 `v-if` 抢先删除整套 Root/Content。设置 `display: none`、修改关键帧或 Portal 目标都可能影响退出阶段。
|
||||
|
||||
## CSS 动画
|
||||
|
||||
组件接受应用自定义的类。标准 CSS 无需额外动画库:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Card } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card class="fade-in">Welcome!</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.fade-in {
|
||||
animation: welcome 200ms ease-out;
|
||||
}
|
||||
@keyframes welcome {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.fade-in {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
.fade-in[data-reduce-motion="true"],
|
||||
:global([data-reduce-motion="true"]) .fade-in {
|
||||
animation: none;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
对自己插入、删除的普通内容可使用 Vue `<Transition>`。不要在本身管理 Presence 的弹层外再建立互相冲突的卸载状态源。内部使用的 `tw-animate-css` 已随库样式编译,但不会在消费者构建中自动生成任意 `animate-*` 工具;自定义 Tailwind 动画需要在应用内配置。
|
||||
|
||||
## Framer Motion
|
||||
|
||||
官方的 Framer Motion / `motion/react` 示例依赖 React,不能直接用于 Vue。本库没有绑定第三方 Vue 动画库。可以先用 CSS 与 Vue Transition;确需动画库时,在应用内选择兼容 Vue 的库,并单独验证它的根元素、事件和 ref 透传。
|
||||
|
||||
尤其不要为了动画把 Button 的根节点替换成无按钮语义的 div,也不要让动画包装层拦截键盘事件。第三方库的安装和集成不作为本库当前已经验收的能力。
|
||||
|
||||
## 渲染属性
|
||||
|
||||
用作用域插槽读取组件状态,将自定义反馈施加到实际根或内容上:
|
||||
|
||||
```vue
|
||||
<Button as-child v-slot="{ isPressed }">
|
||||
<button :style="{ opacity: isPressed ? 0.8 : 1 }">Interactive Button</button>
|
||||
</Button>
|
||||
```
|
||||
|
||||
这是 Button 的状态插槽,不是 React render prop。`asChild` 必须保留唯一且语义正确的 DOM 根。已有按钮按下缩放时,不应再给同一根叠加冲突的 transform;复杂内容可在根内增加 span 作为独立动画目标。
|
||||
|
||||
## 无障碍
|
||||
|
||||
减少动态效果支持系统 `prefers-reduced-motion: reduce`,以及元素或祖先上的显式 `data-reduce-motion="true"`。应用级禁用建议设置在 `<html>`,以覆盖挂载到 body 的浮层:
|
||||
|
||||
```html
|
||||
<html data-reduce-motion="true">
|
||||
...
|
||||
</html>
|
||||
```
|
||||
|
||||
局部设置只影响该 DOM 子树;内容经 Teleport 挂载到其他地方后,不会自动继承触发器祖先的属性。上面的示例把 PopoverContent `to` 指向同一个容器,因此局部控制也能影响弹层。
|
||||
|
||||
库的共享变体覆盖组件装饰动画及伪元素。应用自定义动画仍需自行处理系统偏好和显式属性;不能因为子节点是库组件,就假定第三方动画会自动停止。`data-reduce-motion="false"` 不应被文稿解释为能够绕过系统减少动效偏好的统一保证。
|
||||
|
||||
本轮已验证代表性 Popover 的动态取消与卸载,以及若干浮层 BEM 的最终减少动效规则;其他嵌套、方向和组件生命周期按后续任务逐项验收。没有据此声称整库所有动画均已验收。
|
||||
|
||||
## 性能技巧
|
||||
|
||||
优先用 transform 与 opacity 表达位移和渐变,减少无必要的布局变化。高度展开等交互确实需要测量时,复用组件原有机制,不用固定假高度覆盖真实内容。
|
||||
|
||||
`will-change` 只用于确有动画的目标,避免长时间为大量元素保留图层。自定义动画不要修改定位库拥有的 wrapper transform;在允许的内容节点上做视觉变换。动画完成、取消、快速重开、卸载和减少动效切换都应释放监听与观察器。
|
||||
|
||||
## 下一步
|
||||
|
||||
- [样式](/styling):class、数据状态与 CSS 层。
|
||||
- [组合](/composition):唯一根、事件与插槽。
|
||||
- [主题](/themes):主题变量及 Portal 继承。
|
||||
@@ -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#快速开始)。
|
||||
@@ -0,0 +1,158 @@
|
||||
---
|
||||
title: 组合
|
||||
description: 使用组件组合模式构建灵活的 UI
|
||||
---
|
||||
|
||||
组合的目标是在保留组件语义、状态和可访问行为的同时调整外观与结构。Vue 使用具名部件、普通属性、`v-model`、具名/作用域插槽,以及按需支持的 `as` / `asChild`。
|
||||
|
||||
## 与框架无关的样式
|
||||
|
||||
`@heroui-vue/styles` 提供变体函数和 CSS,不运行 React。只想把组件样式用于原生元素时,可以从样式包导入函数:
|
||||
|
||||
```ts
|
||||
import { buttonVariants, tv, type VariantProps } from "@heroui-vue/styles";
|
||||
import "@heroui-vue/styles/css";
|
||||
```
|
||||
|
||||
当前完整 CSS 通过 `/css` 导入,JS 根导出提供变体函数;没有公开官方那套 `/components/button.css`、`/themes/default` 等子路径。按需入口仍是后续任务,见[导入策略](/themes#导入策略)。
|
||||
|
||||
## 多态样式
|
||||
|
||||
可将样式应用到符合实际用途的原生元素。例如导航链接可以采用按钮外观,而实际操作继续使用 button:
|
||||
|
||||
<ComponentPreview name="handbook-composition" />
|
||||
|
||||
第一个元素仍是链接,后两个示例展示实际 Button 与 Link。样式相似不代表键盘模型相同;不要把所有元素统一改成 div,也不要用 `role="button"` 掩盖缺少键盘处理的问题。
|
||||
|
||||
## 直接应用类名
|
||||
|
||||
用完整 BEM 类名可复用预编译样式:
|
||||
|
||||
```html
|
||||
<a class="hv-button hv-button--secondary hv-button--md" href="/settings">
|
||||
Settings
|
||||
</a>
|
||||
```
|
||||
|
||||
此时只有样式,禁用、加载、焦点管理和表单行为由元素与应用负责。本库组件通常是获得完整交互的更直接方式。
|
||||
|
||||
## 使用变体函数
|
||||
|
||||
变体函数决定类名和默认变体,不建立 Vue 状态:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { buttonVariants } from "@heroui-vue/styles";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a
|
||||
href="/settings"
|
||||
:class="buttonVariants({ variant: 'secondary', size: 'sm' })"
|
||||
>
|
||||
Settings
|
||||
</a>
|
||||
</template>
|
||||
```
|
||||
|
||||
Button 的函数返回类名字符串;Card、Popover 等带 slots 的函数返回部件函数集合。按函数真实返回类型使用,例如 `cardVariants().base()`,不要假定所有 variants 都有相同的返回结构。
|
||||
|
||||
## 复合组件
|
||||
|
||||
复杂组件导出协同工作的具名部件,不采用默认的 React `Popover.Trigger` 对象写法:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Popover>
|
||||
<Button>打开</Button>
|
||||
<PopoverContent>
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>标题</PopoverHeading>
|
||||
内容
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
```
|
||||
|
||||
`PopoverRoot` 是 `Popover` 的同一实现别名;按各组件公开导出选择。需要上下文的 Trigger、Item、Content 不能脱离对应 Root 任意放置。复杂包装应透传显式数据和插槽,不通过执行未知子组件的 setup/render 来探测元数据。
|
||||
|
||||
普通值使用 `v-model`;展开状态通常使用 `v-model:open`,二态控件按 API 使用 `v-model:checked`。Root 与子控件不要绑定两个相互冲突的值源。受控组件会发出更新提案,父级可以拒绝,显示值仍应保持父级接受值。
|
||||
|
||||
## 混合使用变体函数
|
||||
|
||||
`cn` 可以合并类名,`tv` 可以扩展变体。注意多个组件的根样式可能同时定义尺寸、布局和 transform,不应仅为拼出外观就叠加互相冲突的根类。
|
||||
|
||||
```ts
|
||||
import { cn, buttonVariants } from "@heroui-vue/styles";
|
||||
|
||||
const classes = cn(buttonVariants({ variant: "ghost" }), "font-semibold");
|
||||
```
|
||||
|
||||
应用新增的工具类需要由自己的构建产出。合并函数不会生成 CSS,也不会让未公开的变体名称自动成为组件 prop。
|
||||
|
||||
## 自定义组件
|
||||
|
||||
把可复用业务布局包装成 Vue 组件时,明确以下边界:
|
||||
|
||||
- `$attrs`、class/style、ARIA 和原生事件落到哪个实际节点。
|
||||
- `v-model` 是否保留受控接受值和更新事件。
|
||||
- 默认、具名和作用域插槽分别传给哪个部件。
|
||||
- ref 返回包装组件还是实际控件;需要的方法通过 `defineExpose` 明确公开。
|
||||
|
||||
多根组件设置 `inheritAttrs: false` 并显式转交属性。事件取消、capture 和子节点监听必须保持正确顺序,不能同时手动调用和再次透传导致双触发。包装示例见[创建包装组件](/styling#创建包装组件)。
|
||||
|
||||
## 自定义变体
|
||||
|
||||
扩展样式函数,不改写原组件已定义的 prop 取值:
|
||||
|
||||
```ts
|
||||
import { buttonVariants, tv, type VariantProps } from "@heroui-vue/styles";
|
||||
|
||||
export const customButton = tv({
|
||||
extend: buttonVariants,
|
||||
variants: {
|
||||
emphasis: { quiet: "opacity-80", strong: "font-bold" },
|
||||
},
|
||||
defaultVariants: { emphasis: "quiet" },
|
||||
});
|
||||
export type CustomButtonVariants = VariantProps<typeof customButton>;
|
||||
```
|
||||
|
||||
将计算结果通过 class 传给 Button;`emphasis` 属于你的包装组件,不是库 Button 新增的 API。不要直接向 Button 传入不存在的 `variant="gradient"`。
|
||||
|
||||
## 自定义 DOM 元素
|
||||
|
||||
支持 `asChild` 的部件把自身属性、交互与默认插槽中的唯一根节点合并。Button 的根仍需是原生 button:
|
||||
|
||||
```vue
|
||||
<Button as-child v-slot="{ isPressed }">
|
||||
<button type="button" :data-custom="isPressed ? 'pressed' : 'idle'">点按</button>
|
||||
</Button>
|
||||
```
|
||||
|
||||
遵循组件期待的元素语义;保留唯一根;自定义 Vue 组件继续把属性、事件和 ref 边界转交到实际 DOM。原生 submit/reset、disabled、focus 和 ARIA 不能因换根而丢失。Button 与 Link 的行为模型不同,支持 `asChild` 不等于任意元素都可互换。
|
||||
|
||||
`as` 一般选择组件支持的标签,`asChild` 合并已有根;两者范围由各组件 API 决定。不要将 React 的 `render` 或 `ref` prop 原样传入 Vue。
|
||||
|
||||
## 框架集成
|
||||
|
||||
Vue 客户端应用可直接使用原生链接。路由器适配可用它提供的自定义链接插槽或把导航外观用于路由链接,前提是仍生成正确的 anchor 并透传 href、事件与可访问属性。基础包不强依赖 Vue Router。
|
||||
|
||||
Next.js 示例不适用于 Vue;当前不提供 Nuxt 服务端消费承诺。第三方路由和动画包装的全部组合尚未逐项验收,应按真实 DOM、键盘、事件取消和实例方法检查,不能只凭 TypeScript 编译通过判断可用。
|
||||
|
||||
## 下一步
|
||||
|
||||
- [样式](/styling):类名、CSS Modules 与状态。
|
||||
- [动画](/animation):动画和卸载的协调。
|
||||
- [所有组件](/components):逐组件的 Props、插槽和状态契约。
|
||||
@@ -0,0 +1,95 @@
|
||||
---
|
||||
title: 深色模式
|
||||
description: 在 HeroUI v3 中添加浅色、深色以及跟随系统的主题切换
|
||||
---
|
||||
|
||||
主题的实际外观由 CSS 变量决定;选择浅色、深色或跟随系统、保存偏好以及更新根元素标记,是应用的职责。支持 `.light`、`.dark` 和内置的 `data-theme` 值。下面示例只影响预览容器,不会修改你在文档站选择的外观。
|
||||
|
||||
<ComponentPreview name="handbook-dark-mode" />
|
||||
|
||||
## 在 Next.js 中使用 next-themes
|
||||
|
||||
官方这一节面向 React/Next.js。Vue 客户端项目不使用 `next-themes`,当前也不支持 SSR、水合或 Nuxt 服务端渲染。客户端应用可以在入口引入库样式,再由自己的状态逻辑更新 `<html>`。
|
||||
|
||||
```ts
|
||||
import "@heroui-vue/styles/css";
|
||||
|
||||
function applyTheme(theme: "light" | "dark") {
|
||||
const root = document.documentElement;
|
||||
root.classList.toggle("light", theme === "light");
|
||||
root.classList.toggle("dark", theme === "dark");
|
||||
root.dataset.theme = theme;
|
||||
}
|
||||
```
|
||||
|
||||
这段函数在浏览器中调用。将主题放在根元素上,挂载到 body 的浮层也能继承。不要把服务端注入、无闪烁水合等能力推断为本库支持。
|
||||
|
||||
## 使用自定义主题名称
|
||||
|
||||
自定义主题名称需要有对应的 CSS 选择器,并明确它所采用的明暗模式。内置 CSS 不会自动识别 `ocean` 这样的任意名称。
|
||||
|
||||
```html
|
||||
<html class="dark" data-theme="ocean"></html>
|
||||
```
|
||||
|
||||
```css
|
||||
/* 放在库 CSS 之后 */
|
||||
.light[data-theme="ocean"] {
|
||||
--accent: oklch(0.62 0.2 253.83);
|
||||
--accent-foreground: var(--snow);
|
||||
}
|
||||
.dark[data-theme="ocean"] {
|
||||
--accent: oklch(0.72 0.16 253.83);
|
||||
--accent-foreground: var(--eclipse);
|
||||
}
|
||||
```
|
||||
|
||||
让 `.dark` 与 `data-theme` 表达一致的选择,避免 `.dark[data-theme="light"]` 等冲突组合。局部容器与 Portal 的边界见[主题](/themes#快速开始)。
|
||||
|
||||
## 在 React 中使用 useTheme
|
||||
|
||||
官方的 `useTheme` 是 React API,当前 Vue 组件包没有同名导出。Vue 应用可以采用已有的 VueUse,不需要为了使用组件再安装一套 React 主题管理器。
|
||||
|
||||
如果应用已使用 VueUse,可以在应用级单一入口调用 `useColorMode`:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { useColorMode } from "@vueuse/core";
|
||||
|
||||
const mode = useColorMode({
|
||||
storageKey: "app-appearance",
|
||||
emitAuto: true,
|
||||
});
|
||||
// mode.value: 'light' / 'dark' / 'auto';auto 表示跟随系统。
|
||||
// 默认更新 html 的 class,并保存应用自己的偏好。
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<label>
|
||||
外观
|
||||
<select v-model="mode">
|
||||
<option value="light">浅色</option>
|
||||
<option value="dark">深色</option>
|
||||
<option value="auto">跟随系统</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
```
|
||||
|
||||
VueUse 是应用的可选依赖,使用前在应用内安装;它不是从 `@heroui-vue/components` 导入。顶部示例用 `usePreferredDark` 解析系统偏好,保留独立预览状态,不写入存储。应保存用户选择的模式,而不是把 `auto` 固化为某次解析出的 `dark`。
|
||||
|
||||
## 同时为两种主题设置样式
|
||||
|
||||
优先使用语义变量,它们会随主题变化:
|
||||
|
||||
```css
|
||||
.panel {
|
||||
background: var(--surface);
|
||||
color: var(--surface-foreground);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
```
|
||||
|
||||
只在两种模式确实需要不同规则时使用显式选择器。Vue 单文件组件内可用 `:global(.dark) .panel`,CSS Modules 可使用 `$style` 配合全局主题选择器。使用 Tailwind `dark:` 时由应用配置对应变体;仅导入库的预编译 CSS 不会改变应用编译器的规则。
|
||||
|
||||
系统 `prefers-color-scheme` 本身不会为本库全部主题变量自动添加 `.dark`;需要应用逻辑解析偏好并更新主题标记。主题控制的完整兼容性仍在后续排查范围中,不把文档站自己的切换器等同于库的公共 API。
|
||||
@@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Spinner,
|
||||
Skeleton,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
const reduced = ref(false);
|
||||
const target = ref<HTMLElement>();
|
||||
</script>
|
||||
<template>
|
||||
<section
|
||||
ref="target"
|
||||
:data-reduce-motion="reduced ? 'true' : undefined"
|
||||
class="motion-demo"
|
||||
>
|
||||
<label>
|
||||
<input v-model="reduced" type="checkbox" />
|
||||
减少动态效果
|
||||
</label>
|
||||
<div class="flex items-center gap-4">
|
||||
<Spinner aria-label="加载中" />
|
||||
<Skeleton class="h-6 w-32" />
|
||||
<Button>点按动画</Button>
|
||||
</div>
|
||||
<Popover>
|
||||
<Button>查看进出场动画</Button>
|
||||
<PopoverContent :to="target">
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>动画与卸载</PopoverHeading>
|
||||
<p>关闭时保留退出阶段;减少动态效果时禁用装饰动画。</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</section>
|
||||
</template>
|
||||
<style scoped>
|
||||
.motion-demo {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { Button, Link, buttonVariants } from "@heroui-vue/components";
|
||||
import { tv } from "@heroui-vue/styles";
|
||||
const count = ref(0);
|
||||
const customButton = tv({
|
||||
extend: buttonVariants,
|
||||
variants: { emphasis: { strong: "font-bold" } },
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<a href="#自定义变体" :class="buttonVariants({ variant: 'secondary' })">
|
||||
链接采用按钮外观
|
||||
</a>
|
||||
<Button
|
||||
as-child
|
||||
v-slot="{ isPressed }"
|
||||
:class="customButton({ emphasis: 'strong' })"
|
||||
@click="count++"
|
||||
>
|
||||
<button type="button" :data-custom-state="isPressed ? 'pressed' : 'idle'">
|
||||
自定义根节点 · {{ count }}
|
||||
</button>
|
||||
</Button>
|
||||
<Link href="/components/button">查看 Button API</Link>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { usePreferredDark } from "@vueuse/core";
|
||||
import { Button, Card, Input } from "@heroui-vue/components";
|
||||
const mode = ref("system");
|
||||
const systemDark = usePreferredDark();
|
||||
const resolved = computed(() =>
|
||||
mode.value === "system" ? (systemDark.value ? "dark" : "light") : mode.value,
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="mode-demo">
|
||||
<label>
|
||||
外观
|
||||
<select v-model="mode">
|
||||
<option value="light">浅色</option>
|
||||
<option value="dark">深色</option>
|
||||
<option value="system">跟随系统</option>
|
||||
</select>
|
||||
</label>
|
||||
<section :class="resolved" class="mode-preview">
|
||||
<Card>
|
||||
<strong>主题预览</strong>
|
||||
<p>当前选择:{{ mode }};解析为:{{ resolved }}。</p>
|
||||
</Card>
|
||||
<Input aria-label="深色模式预览" placeholder="输入内容" />
|
||||
<Button>继续</Button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.mode-demo {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
.mode-preview {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
padding: 20px;
|
||||
border-radius: 16px;
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
}
|
||||
select {
|
||||
padding: 4px 8px;
|
||||
background: var(--field-background);
|
||||
color: var(--field-foreground);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { Button } from "@heroui-vue/components";
|
||||
const pending = ref(false);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Button as-child v-slot="{ isPressed, isHovered, isFocusVisible }">
|
||||
<button class="handbook-state-button">
|
||||
{{
|
||||
isPressed
|
||||
? "按下中"
|
||||
: isHovered
|
||||
? "悬停中"
|
||||
: isFocusVisible
|
||||
? "键盘焦点"
|
||||
: "与我交互"
|
||||
}}
|
||||
</button>
|
||||
</Button>
|
||||
<Button is-disabled>禁用</Button>
|
||||
<Button :is-pending="pending">{{ pending ? "加载中" : "正常操作" }}</Button>
|
||||
<label>
|
||||
<input v-model="pending" type="checkbox" />
|
||||
加载状态
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.handbook-state-button[data-pressed="true"] {
|
||||
outline: 2px solid var(--focus);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Input,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
const theme = ref("light");
|
||||
const target = ref<HTMLElement>();
|
||||
</script>
|
||||
<template>
|
||||
<div class="handbook-theme-demo">
|
||||
<label>
|
||||
预览主题
|
||||
<select v-model="theme">
|
||||
<option value="light">浅色</option>
|
||||
<option value="dark">深色</option>
|
||||
</select>
|
||||
</label>
|
||||
<section
|
||||
ref="target"
|
||||
:class="theme"
|
||||
class="theme-preview"
|
||||
data-theme="ocean"
|
||||
>
|
||||
<Card>
|
||||
<strong>自定义主题</strong>
|
||||
<p>组件通过同一组语义变量更新外观。</p>
|
||||
</Card>
|
||||
<Input aria-label="主题预览邮箱" placeholder="输入你的邮箱" />
|
||||
<Popover>
|
||||
<Button>打开主题弹层</Button>
|
||||
<PopoverContent :to="target">
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>同一主题容器</PopoverHeading>
|
||||
<p>to 指向局部容器,保留 CSS 变量继承。</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.handbook-theme-demo {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
.theme-preview {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
padding: 20px;
|
||||
border-radius: 16px;
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
}
|
||||
[data-theme="ocean"] {
|
||||
--accent: oklch(0.62 0.2 253.83);
|
||||
--accent-foreground: var(--snow);
|
||||
}
|
||||
select {
|
||||
background: var(--field-background);
|
||||
color: var(--field-foreground);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
</style>
|
||||
+11
-7
@@ -56,10 +56,14 @@ import { Button } from "@heroui-vue/components";
|
||||
|
||||
## 开发命令
|
||||
|
||||
| 命令 | 功能 |
|
||||
| -------------- | --------------- |
|
||||
| pnpm dev | 文档开发站 |
|
||||
| pnpm dev:docs | 文档开发站 |
|
||||
| pnpm build | 库与样式构建 |
|
||||
| pnpm typecheck | Vue 类型检查 |
|
||||
| pnpm test | 行为与 SSR 测试 |
|
||||
| 命令 | 功能 |
|
||||
| -------------- | -------------- |
|
||||
| pnpm dev | 文档开发站 |
|
||||
| pnpm dev:docs | 文档开发站 |
|
||||
| pnpm build | 库与样式构建 |
|
||||
| pnpm typecheck | Vue 类型检查 |
|
||||
| pnpm test | 客户端行为测试 |
|
||||
|
||||
## 接下来
|
||||
|
||||
阅读手册了解 [颜色](/colors)、[主题](/themes)、[深色模式](/dark-mode)、[样式](/styling)、[动画](/animation) 与 [组合](/composition)。每篇会标明当前 Vue 接口和固定官方基线的差异;文稿完整不代表所有组件状态已经逐项验收。
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
title: 样式
|
||||
description: 使用 CSS、Tailwind 或 CSS-in-JS 为 HeroUI 组件设置样式
|
||||
---
|
||||
|
||||
组件提供变体属性、Vue `class` / `style`、BEM 类名和状态属性。样式包提供预编译 CSS;Tailwind 是构建自定义工具类的可选方案,不是消费组件的必要运行时。
|
||||
|
||||
## 基础样式
|
||||
|
||||
通过组件属性选择基线变体;用 Vue 的 `class`(字符串、数组、对象)和 `style` 增加局部样式。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Button } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Button
|
||||
variant="secondary"
|
||||
class="custom-button"
|
||||
:style="{ fontWeight: 600 }"
|
||||
>
|
||||
Custom Button
|
||||
</Button>
|
||||
</template>
|
||||
```
|
||||
|
||||
`class` 通常落在当前部件的实际 DOM 上;多部件组件应将样式放到目标部件。PopoverContent、TableScrollContainer 与输入控件不是同一个节点,不能把所有样式都加在 Root 上。
|
||||
|
||||
## 滚动条
|
||||
|
||||
库的滚动区域通过共享变量使用标准 CSS 滚动条。`data-scrollbar` 可放在滚动槽、组件根或祖先:
|
||||
|
||||
| 属性值 | 结果 |
|
||||
| --------- | ------------------------- |
|
||||
| `thin` | 主题化纤细滚动条 |
|
||||
| `default` | 浏览器/操作系统默认滚动条 |
|
||||
| `none` | 隐藏滚动条,仍可滚动 |
|
||||
|
||||
```vue
|
||||
<Table data-scrollbar="default">
|
||||
<TableScrollContainer><!-- 实际表格部件 --></TableScrollContainer>
|
||||
</Table>
|
||||
```
|
||||
|
||||
自定义滚动区可直接使用 `scrollbar-width: var(--scrollbar-width)`、`scrollbar-color: var(--scrollbar-color)` 和 `scrollbar-gutter: var(--scrollbar-gutter)`。官方 `scrollbar` / `scrollbar-thin` / `scrollbar-default` / `scrollbar-none` 工具在库源码中存在,但当前没有公开 utilities 源 CSS 入口;不能仅凭它们出现在官方文档中,就在消费者项目直接使用未生成的工具类。更多变量见[主题](/themes#滚动条)。
|
||||
|
||||
## 基于状态的样式
|
||||
|
||||
原生伪类与组件数据属性共同驱动视觉状态。以下规则用于 Button:
|
||||
|
||||
```css
|
||||
.hv-button[data-hovered="true"],
|
||||
.hv-button:hover {
|
||||
/* 悬停 */
|
||||
}
|
||||
.hv-button[data-pressed="true"],
|
||||
.hv-button:active {
|
||||
/* 按下 */
|
||||
}
|
||||
.hv-button[data-focus-visible="true"],
|
||||
.hv-button:focus-visible {
|
||||
/* 键盘焦点 */
|
||||
}
|
||||
.hv-button[aria-disabled="true"],
|
||||
.hv-button:disabled {
|
||||
/* 禁用 */
|
||||
}
|
||||
```
|
||||
|
||||
<ComponentPreview name="handbook-states" />
|
||||
|
||||
不是所有部件都会生成全部数据属性。有的输入依赖原生 `:focus`,有的 Reka 部件采用 `data-state` 或存在式属性;请使用各组件文档公开的状态。禁用还需实际阻止操作、退出 Tab 顺序或符合该控件的焦点模型,不能只降低透明度。
|
||||
|
||||
## 渲染属性
|
||||
|
||||
React 的函数式 `className` / `style` 和 render props 不直接用于 Vue。需要组件内部状态时,使用该组件提供的作用域插槽。Button 的状态与自定义根节点可这样组合:
|
||||
|
||||
```vue
|
||||
<Button as-child v-slot="{ isPressed }">
|
||||
<button :class="{ 'is-pressed': isPressed }">点按</button>
|
||||
</Button>
|
||||
```
|
||||
|
||||
只有默认插槽中的唯一根节点接收 asChild 的合并属性。Input 等组件不提供同一套状态插槽,不能将 Button 的插槽契约推广到整库。部分颜色组件的 `styleFn` 是其专有 API。
|
||||
|
||||
## BEM 类名
|
||||
|
||||
本库沿用 BEM,并使用 `hv-` 命名空间:
|
||||
|
||||
```css
|
||||
.hv-button {
|
||||
/* Block */
|
||||
}
|
||||
.hv-accordion__trigger {
|
||||
/* Element */
|
||||
}
|
||||
.hv-button--secondary {
|
||||
/* Modifier */
|
||||
}
|
||||
.hv-button--lg {
|
||||
/* Size modifier */
|
||||
}
|
||||
```
|
||||
|
||||
可在全局样式中覆盖:
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-button {
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
库 CSS 使用 `theme, base, components, utilities` 层顺序。需要确保覆盖优先级时,应检查实际层、选择器与导入顺序;无层的应用 CSS 会优先于普通有层规则。Vue scoped 样式触及嵌套部件时使用 `:deep()` 或直接给该部件添加类,不在文档壳中隐藏组件问题。
|
||||
|
||||
## 创建包装组件
|
||||
|
||||
使用公开 Props 类型与 `tv` 扩展变体。包装组件需要显式管理 `$attrs`、插槽、事件和需要公开的方法,不能把 DOM `ref` 当作普通属性传递。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { computed, useAttrs } from "vue";
|
||||
import { Button } from "@heroui-vue/components";
|
||||
import { buttonVariants, tv } from "@heroui-vue/styles";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<{ emphasis?: "quiet" | "strong" }>();
|
||||
const attrs = useAttrs();
|
||||
const custom = tv({
|
||||
extend: buttonVariants,
|
||||
variants: { emphasis: { quiet: "opacity-80", strong: "font-bold" } },
|
||||
});
|
||||
const classes = computed(() => custom({ emphasis: props.emphasis }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Button v-bind="attrs" :class="classes"><slot /></Button>
|
||||
</template>
|
||||
```
|
||||
|
||||
此例为展示包装层:它不额外暴露 Button 实例。应用若需要 `focus()`,应在支持该方法的部件上绑定实例,并通过 `defineExpose` 明确转交。完整组合原则见[组合](/composition)。
|
||||
|
||||
## CSS-in-JS 集成
|
||||
|
||||
只要工具产出类名或 Vue 可接受的 style 对象,就可以通过现有边界传入。官方 styled-components/Emotion React 示例不直接适用;当前没有验证所有 Vue CSS-in-JS 绑定,也不要求消费者增加此类依赖。
|
||||
|
||||
## 响应式设计
|
||||
|
||||
自定义内容可使用标准 CSS 媒体查询:
|
||||
|
||||
```css
|
||||
.custom-button {
|
||||
width: 100%;
|
||||
}
|
||||
@media (min-width: 48rem) {
|
||||
.custom-button {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
使用 `md:` 等 Tailwind 工具类时,需要应用自行安装并配置 Tailwind。静态声明完整类名,不通过动态拼接 `bg-${color}` 等字符串期待构建器生成样式。
|
||||
|
||||
## CSS 模块
|
||||
|
||||
Vue SFC 的 CSS Modules 可以把生成的类传给组件:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<Button :class="$style.button">Scoped Button</Button>
|
||||
</template>
|
||||
|
||||
<style module>
|
||||
.button {
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
示例中的 Button 需按前述方式导入。CSS Modules 负责类名隔离,不改变组件透传或 CSS 层优先级;独立消费者的完整覆盖仍列入后续排查。
|
||||
|
||||
## 组件类名参考
|
||||
|
||||
| 组件 | 常见类名 |
|
||||
| --------- | ---------------------------------------------------------------------------------------- |
|
||||
| Button | `.hv-button`、`.hv-button--{variant}`、`.hv-button--{size}`、`.hv-button--icon-only` |
|
||||
| Accordion | `.hv-accordion`、`.hv-accordion__item`、`.hv-accordion__trigger`、`.hv-accordion__panel` |
|
||||
| Input | `.hv-input`、`.hv-input--secondary` |
|
||||
| Popover | `.hv-popover`、`.hv-popover__dialog`、`.hv-popover__heading` |
|
||||
|
||||
完整部件、状态与 API 以各组件页为准:[Button](/components/button)、[Accordion](/components/accordion)、[Input](/components/input)、[Popover](/components/popover)。这些类名赋予样式,不自动赋予键盘交互和 ARIA 语义。
|
||||
|
||||
## 下一步
|
||||
|
||||
- [动画](/animation):进入、退出与减少动态效果。
|
||||
- [主题](/themes):语义变量、层与导入策略。
|
||||
- [组合](/composition):变体、自定义 DOM 和具名部件。
|
||||
+283
-29
@@ -1,53 +1,307 @@
|
||||
---
|
||||
title: 主题
|
||||
description: 使用与 HeroUI 相同的语义变量定制组件外观
|
||||
description: 使用 CSS 变量和全局样式自定义 HeroUI 的设计系统
|
||||
---
|
||||
|
||||
## 默认主题
|
||||
主题通过基础变量、语义变量与派生公式管理颜色、圆角、阴影和状态。默认变量来自固定 HeroUI 基线,Vue 组件使用本库独立维护的样式包。
|
||||
|
||||
浅色和深色变量移植自固定基线的 default/variables.css,采用相同的 OKLCH 颜色与派生公式。按钮、表面、输入框和开关共同使用这些变量。
|
||||
## 工作原理
|
||||
|
||||
## 浅色与深色
|
||||
库在构建时使用 Tailwind CSS 4,将语义变量映射到组件规则。消费者导入的是预编译 CSS,不必为了使用 Button 再安装 Tailwind。应用自己的工具类需要自己的 Tailwind 构建;预编译文件不会把源码中的 `@theme` 注册到另一个编译器。
|
||||
|
||||
文档右上角切换主题,页面与组件同步更新。应用支持 `.light`、`.dark`、`data-theme="light"` 与 `data-theme="dark"`。
|
||||
| 层 | 用途 |
|
||||
| ------------ | ------------------------------ |
|
||||
| `theme` | 工具令牌及主题映射 |
|
||||
| `base` | 默认变量、基础规则与滚动条模式 |
|
||||
| `components` | 组件结构、变体和状态 |
|
||||
| `utilities` | 构建中使用的工具类 |
|
||||
|
||||
```html
|
||||
<html class="dark"></html>
|
||||
变量名称表示用途:`--accent` 是主要操作,`--field-background` 是字段背景,`--surface` 是非浮层表面。不要把它们替换为不同页面各自定义的近似色。完整语义分类见[颜色](/colors)。
|
||||
|
||||
## 快速开始
|
||||
|
||||
浏览器应用引入一次完整样式,再给根元素设置主题标记:
|
||||
|
||||
```ts
|
||||
import "@heroui-vue/styles/css";
|
||||
```
|
||||
|
||||
## 语义颜色
|
||||
```html
|
||||
<html class="light">
|
||||
<body>
|
||||
...
|
||||
</body>
|
||||
</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 | 边界、分隔和焦点 |
|
||||
支持 `.light`、`.dark`、`data-theme="light"` 和 `data-theme="dark"`;默认是浅色。跟随系统与偏好存储由应用负责,见[深色模式](/dark-mode)。
|
||||
|
||||
## 自定义主题
|
||||
在库样式之后覆盖变量,可定义主题。局部容器仍添加 `light` / `dark`,让派生变量重新在该容器计算:
|
||||
|
||||
<ComponentPreview name="handbook-theme" />
|
||||
|
||||
这个示例把 PopoverContent `to` 指向局部主题容器。默认挂载到 body 的浮层不会继承触发器局部祖先的变量、减少动效或滚动条模式。全局主题放在 html;局部场景采用各组件真实支持的 `to` / Portal / ConfigProvider 配置。不能仅因为 Vue 逻辑上下文仍存在,就认为 CSS DOM 继承也会穿过 Teleport。
|
||||
|
||||
```css
|
||||
[data-theme="brand"] {
|
||||
/* 导入库 CSS 后再定义 */
|
||||
.light[data-theme="brand"] {
|
||||
--accent: oklch(0.62 0.2 300);
|
||||
--accent-foreground: oklch(0.99 0 0);
|
||||
--radius: 0.75rem;
|
||||
--accent-foreground: var(--snow);
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
.dark[data-theme="brand"] {
|
||||
--accent: oklch(0.72 0.17 300);
|
||||
--accent-foreground: var(--eclipse);
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<section class="light" data-theme="brand">...</section>
|
||||
## 自定义组件
|
||||
|
||||
优先用 size/variant 等公开属性选择已有变体,再覆盖明确的目标部件或变量。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-button {
|
||||
font-weight: 600;
|
||||
}
|
||||
.hv-card {
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
将上述样式放在库样式之后,覆盖容器变量。嵌套容器加上 light 或 dark,使派生颜色在该容器重新计算。浅深自定义主题应分别声明值;应用继承基线的派生颜色与阴影公式。
|
||||
局部样式可以通过组件 class 传入;scoped CSS 访问嵌套部件时使用 `:deep()`,或者直接给对应部件加类。状态样式应匹配实际 DOM 属性,不能按 React Aria 的属性格式推断所有 Reka/Vue 部件。
|
||||
|
||||
## 圆角与阴影
|
||||
圆角来自 `--radius` 派生尺度,字段来自 `--field-radius`,阴影分为 surface/overlay/field。组件可能对最终圆角设置上限,例如 Card 使用 `min(32px, var(--radius-3xl))`;修改变量不代表能绕过组件自身的上限。
|
||||
|
||||
默认 `--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 与过渡时间。
|
||||
```ts
|
||||
import { Button } from "@heroui-vue/components";
|
||||
import { buttonVariants } from "@heroui-vue/styles";
|
||||
import "@heroui-vue/styles/css";
|
||||
```
|
||||
|
||||
具名 JS 导入与按需 CSS 是两项不同能力。当前包公开 JS 根入口和完整预编译 CSS,尚未开放官方的基础层、主题、组件 CSS、utilities、variants 子路径。
|
||||
|
||||
| 策略 | 当前支持 |
|
||||
| ------------------------------------------------------------ | ------------------------------------------- |
|
||||
| Vue 组件具名导入 | 支持;由消费者 bundler 处理 JS tree shaking |
|
||||
| 样式函数具名导入 | 支持,例如 buttonVariants、tv、cn |
|
||||
| `/css` 完整预编译样式 | 支持,CSS 标记为 sideEffects |
|
||||
| `/components/button.css` 等单组件 CSS | 尚未开放,不使用该路径编写消费代码 |
|
||||
| `/themes/default`、`/base`、`/utilities`、`/variants` 源入口 | 尚未开放 |
|
||||
| 去掉组件样式、只用基础层自行设计 | 当前没有对应公开导入策略 |
|
||||
|
||||
这些路径需要后续打包任务补齐并用独立 tarball 验证;不能通过引用仓库源码相对路径来冒充发布能力。无需 Tailwind 的消费者继续使用完整 CSS 与普通 CSS 变量。
|
||||
|
||||
## 添加自定义颜色
|
||||
|
||||
新增应用语义颜色时,在应用里声明变量;如果还希望生成 Tailwind 工具类,在应用 CSS 中显式注册:
|
||||
|
||||
```css
|
||||
/* 应用自行配置 Tailwind CSS 4 后使用 */
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--brand: oklch(0.62 0.2 300);
|
||||
--brand-foreground: oklch(0.99 0 0);
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-brand: var(--brand);
|
||||
--color-brand-foreground: var(--brand-foreground);
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-surface: var(--surface);
|
||||
--color-accent: var(--accent);
|
||||
}
|
||||
```
|
||||
|
||||
然后应用可以生成 `bg-brand text-brand-foreground` 等类。这里的 `@theme` 是应用配置,不是从当前库包中导入的源主题入口。无 Tailwind 时直接使用 `background: var(--brand)`。
|
||||
|
||||
覆盖基础色后,需在适当主题根重新计算 hover/soft 等派生变量。`@theme inline` 的映射只把语义变量交给工具类,不替代主题变量自身的派生计算。
|
||||
|
||||
## 变量参考
|
||||
|
||||
变量分为固定基础值、明暗主题值和 `color-mix()` 等派生值。下面按当前实际源码列出默认值;配对前景色与透明色应结合具体背景检查。可覆盖变量并不代表任意组件的所有组合已经完成视觉验收。
|
||||
|
||||
### 基础、语义与派生变量
|
||||
|
||||
| 变量 | 浅色默认值 | 深色默认值 |
|
||||
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--white` | `oklch(100% 0 0)` | `oklch(100% 0 0)` |
|
||||
| `--black` | `oklch(0% 0 0)` | `oklch(0% 0 0)` |
|
||||
| `--snow` | `oklch(0.9911 0 0)` | `oklch(0.9911 0 0)` |
|
||||
| `--eclipse` | `oklch(0.2103 0.0059 285.89)` | `oklch(0.2103 0.0059 285.89)` |
|
||||
| `--spacing` | `0.25rem` | `0.25rem` |
|
||||
| `--border-width` | `1px` | `1px` |
|
||||
| `--field-border-width` | `0px` | `0px` |
|
||||
| `--disabled-opacity` | `0.5` | `0.5` |
|
||||
| `--ring-offset-width` | `2px` | `2px` |
|
||||
| `--cursor-interactive` | `pointer` | `pointer` |
|
||||
| `--cursor-disabled` | `not-allowed` | `not-allowed` |
|
||||
| `--radius` | `0.5rem` | `0.5rem` |
|
||||
| `--field-radius` | `calc(var(--radius) * 1.5)` | `calc(var(--radius) * 1.5)` |
|
||||
| `--accent` | `oklch(0.6204 0.195 253.83)` | `oklch(0.6204 0.195 253.83)` |
|
||||
| `--accent-foreground` | `var(--snow)` | `var(--snow)` |
|
||||
| `--success` | `oklch(0.7329 0.1935 150.81)` | `oklch(0.7329 0.1935 150.81)` |
|
||||
| `--success-foreground` | `var(--eclipse)` | `var(--eclipse)` |
|
||||
| `--field-border` | `transparent` | `transparent` |
|
||||
| `--skeleton-animation` | `shimmer` | `shimmer` |
|
||||
| `--z-index-overlay` | `100000` | `100000` |
|
||||
| `--z-index-toast` | `calc(var(--z-index-overlay) + 1)` | `calc(var(--z-index-overlay) + 1)` |
|
||||
| `--tooltip-delay` | `1500ms` | `1500ms` |
|
||||
| `--tooltip-close-delay` | `500ms` | `500ms` |
|
||||
| `--background` | `oklch(0.9702 0 0)` | `oklch(12% 0.005 285.823)` |
|
||||
| `--foreground` | `var(--eclipse)` | `var(--snow)` |
|
||||
| `--surface` | `var(--white)` | `oklch(0.2103 0.0059 285.89)` |
|
||||
| `--surface-foreground` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--surface-secondary` | `oklch(0.9524 0.0013 286.37)` | `oklch(0.257 0.0037 286.14)` |
|
||||
| `--surface-secondary-foreground` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--surface-tertiary` | `oklch(0.9373 0.0013 286.37)` | `oklch(0.2721 0.0024 247.91)` |
|
||||
| `--surface-tertiary-foreground` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--overlay` | `var(--white)` | `oklch(0.2103 0.0059 285.89)` |
|
||||
| `--overlay-foreground` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--muted` | `oklch(0.5517 0.0138 285.94)` | `oklch(70.5% 0.015 286.067)` |
|
||||
| `--scrollbar` | `var(--scrollbar-thumb)` | `var(--scrollbar-thumb)` |
|
||||
| `--scrollbar-thumb` | `color-mix(in oklch, var(--foreground) 15%, transparent)` | `color-mix(in oklch, var(--foreground) 15%, transparent)` |
|
||||
| `--scrollbar-track` | `transparent` | `transparent` |
|
||||
| `--scrollbar-gutter` | `auto` | `auto` |
|
||||
| `--scrollbar-width` | `thin` | `thin` |
|
||||
| `--scrollbar-color` | `var(--scrollbar-thumb) var(--scrollbar-track)` | `var(--scrollbar-thumb) var(--scrollbar-track)` |
|
||||
| `--default` | `oklch(94% 0.001 286.375)` | `oklch(27.4% 0.006 286.033)` |
|
||||
| `--default-foreground` | `var(--eclipse)` | `var(--snow)` |
|
||||
| `--field-background` | `var(--white)` | `oklch(0.2103 0.0059 285.89)` |
|
||||
| `--field-foreground` | `oklch(0.2103 0.0059 285.89)` | `var(--foreground)` |
|
||||
| `--field-placeholder` | `var(--muted)` | `var(--muted)` |
|
||||
| `--warning` | `oklch(0.7819 0.1585 72.33)` | `oklch(0.8203 0.1388 76.34)` |
|
||||
| `--warning-foreground` | `var(--eclipse)` | `var(--eclipse)` |
|
||||
| `--danger` | `oklch(0.6532 0.2328 25.74)` | `oklch(0.594 0.1967 24.63)` |
|
||||
| `--danger-foreground` | `var(--snow)` | `var(--snow)` |
|
||||
| `--segment` | `var(--white)` | `oklch(0.3964 0.01 285.93)` |
|
||||
| `--segment-foreground` | `var(--eclipse)` | `var(--foreground)` |
|
||||
| `--border` | `oklch(90% 0.004 286.32)` | `oklch(28% 0.006 286.033)` |
|
||||
| `--separator` | `oklch(92% 0.004 286.32)` | `oklch(25% 0.006 286.033)` |
|
||||
| `--focus` | `var(--accent)` | `var(--accent)` |
|
||||
| `--link` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--backdrop` | `rgba(0, 0, 0, 0.5)` | `rgba(0, 0, 0, 0.6)` |
|
||||
| `--surface-hover` | `color-mix( in oklab, var(--surface) 92%, var(--surface-foreground) 8% )` | `color-mix( in oklab, var(--surface) 92%, var(--surface-foreground) 8% )` |
|
||||
| `--background-secondary` | `color-mix( in oklab, var(--background) 96%, var(--foreground) 4% )` | `color-mix( in oklab, var(--background) 96%, var(--foreground) 4% )` |
|
||||
| `--background-tertiary` | `color-mix( in oklab, var(--background) 92%, var(--foreground) 8% )` | `color-mix( in oklab, var(--background) 92%, var(--foreground) 8% )` |
|
||||
| `--background-inverse` | `var(--foreground)` | `var(--foreground)` |
|
||||
| `--default-hover` | `color-mix( in oklab, var(--default) 96%, var(--default-foreground) 4% )` | `color-mix( in oklab, var(--default) 96%, var(--default-foreground) 4% )` |
|
||||
| `--accent-hover` | `color-mix( in oklab, var(--accent) 90%, var(--accent-foreground) 10% )` | `color-mix( in oklab, var(--accent) 90%, var(--accent-foreground) 10% )` |
|
||||
| `--success-hover` | `color-mix( in oklab, var(--success) 90%, var(--success-foreground) 10% )` | `color-mix( in oklab, var(--success) 90%, var(--success-foreground) 10% )` |
|
||||
| `--warning-hover` | `color-mix( in oklab, var(--warning) 90%, var(--warning-foreground) 10% )` | `color-mix( in oklab, var(--warning) 90%, var(--warning-foreground) 10% )` |
|
||||
| `--danger-hover` | `color-mix( in oklab, var(--danger) 90%, var(--danger-foreground) 10% )` | `color-mix( in oklab, var(--danger) 90%, var(--danger-foreground) 10% )` |
|
||||
| `--field-hover` | `color-mix( in oklab, var(--field-background, var(--default)) 90%, var(--field-foreground, var(--foreground)) 2% )` | `color-mix( in oklab, var(--field-background, var(--default)) 90%, var(--field-foreground, var(--foreground)) 2% )` |
|
||||
| `--field-focus` | `var(--field-background, var(--default))` | `var(--field-background, var(--default))` |
|
||||
| `--field-border-hover` | `color-mix( in oklab, var(--field-border, var(--border)) 88%, var(--field-foreground, var(--foreground)) 10% )` | `color-mix( in oklab, var(--field-border, var(--border)) 88%, var(--field-foreground, var(--foreground)) 10% )` |
|
||||
| `--field-border-focus` | `color-mix( in oklab, var(--field-border, var(--border)) 74%, var(--field-foreground, var(--foreground)) 22% )` | `color-mix( in oklab, var(--field-border, var(--border)) 74%, var(--field-foreground, var(--foreground)) 22% )` |
|
||||
| `--default-soft` | `color-mix(in oklab, var(--default) 50%, transparent)` | `color-mix(in oklab, var(--default) 50%, transparent)` |
|
||||
| `--default-soft-foreground` | `var(--default-foreground)` | `var(--default-foreground)` |
|
||||
| `--default-soft-hover` | `color-mix(in oklab, var(--default) 60%, transparent)` | `color-mix(in oklab, var(--default) 60%, transparent)` |
|
||||
| `--accent-soft` | `color-mix(in oklab, var(--accent) 15%, transparent)` | `color-mix(in oklab, var(--accent) 12%, transparent)` |
|
||||
| `--accent-soft-foreground` | `color-mix( in oklab, var(--accent) 70%, var(--foreground) 30% )` | `color-mix( in oklab, var(--accent) 80%, var(--foreground) 30% )` |
|
||||
| `--accent-soft-hover` | `color-mix(in oklab, var(--accent) 20%, transparent)` | `color-mix(in oklab, var(--accent) 16%, transparent)` |
|
||||
| `--danger-soft` | `color-mix(in oklab, var(--danger) 15%, transparent)` | `color-mix(in oklab, var(--danger) 15%, transparent)` |
|
||||
| `--danger-soft-foreground` | `color-mix( in oklab, var(--danger) 70%, var(--foreground) 40% )` | `color-mix( in oklab, var(--danger) 80%, var(--foreground) 30% )` |
|
||||
| `--danger-soft-hover` | `color-mix(in oklab, var(--danger) 20%, transparent)` | `color-mix(in oklab, var(--danger) 20%, transparent)` |
|
||||
| `--warning-soft` | `color-mix(in oklab, var(--warning) 15%, transparent)` | `color-mix(in oklab, var(--warning) 12%, transparent)` |
|
||||
| `--warning-soft-foreground` | `color-mix( in oklab, var(--warning) 80%, var(--foreground) 70% )` | `color-mix( in oklab, var(--warning) 80%, var(--foreground) 30% )` |
|
||||
| `--warning-soft-hover` | `color-mix(in oklab, var(--warning) 20%, transparent)` | `color-mix(in oklab, var(--warning) 16%, transparent)` |
|
||||
| `--success-soft` | `color-mix(in oklab, var(--success) 15%, transparent)` | `color-mix(in oklab, var(--success) 12%, transparent)` |
|
||||
| `--success-soft-foreground` | `color-mix( in oklab, var(--success) 80%, var(--foreground) 60% )` | `color-mix( in oklab, var(--success) 80%, var(--foreground) 30% )` |
|
||||
| `--success-soft-hover` | `color-mix(in oklab, var(--success) 20%, transparent)` | `color-mix(in oklab, var(--success) 16%, transparent)` |
|
||||
| `--separator-secondary` | `color-mix( in oklab, var(--surface) 85%, var(--surface-foreground) 15% )` | `color-mix( in oklab, var(--surface) 85%, var(--surface-foreground) 15% )` |
|
||||
| `--separator-tertiary` | `color-mix( in oklab, var(--surface) 81%, var(--surface-foreground) 19% )` | `color-mix( in oklab, var(--surface) 81%, var(--surface-foreground) 19% )` |
|
||||
| `--border-secondary` | `color-mix( in oklab, var(--surface) 78%, var(--surface-foreground) 22% )` | `color-mix( in oklab, var(--surface) 78%, var(--surface-foreground) 22% )` |
|
||||
| `--border-tertiary` | `color-mix( in oklab, var(--surface) 66%, var(--surface-foreground) 34% )` | `color-mix( in oklab, var(--surface) 66%, var(--surface-foreground) 34% )` |
|
||||
| `--surface-shadow` | `0 2px 4px 0 rgba(0, 0, 0, 0.04), 0 1px 2px 0 rgba(0, 0, 0, 0.06), 0 0 1px 0 rgba(0, 0, 0, 0.06)` | `0 0 0 0 transparent inset` |
|
||||
| `--overlay-shadow` | `0 2px 8px 0 rgba(0, 0, 0, 0.06), 0 -6px 12px 0 rgba(0, 0, 0, 0.03), 0 14px 28px 0 rgba(0, 0, 0, 0.08)` | `0 0 1px 0 rgba(255, 255, 255, 0.3) inset` |
|
||||
| `--field-shadow` | `0 2px 4px 0 rgba(0, 0, 0, 0.04), 0 1px 2px 0 rgba(0, 0, 0, 0.06), 0 0 1px 0 rgba(0, 0, 0, 0.06)` | `0 0 0 0 transparent inset` |
|
||||
|
||||
### 圆角、缓动与动画映射
|
||||
|
||||
这些为库内部 Tailwind 主题桥接中的尺度;消费者是否能使用同名工具类,取决于自己的构建配置。
|
||||
|
||||
| 令牌 | 公式或值 |
|
||||
| ----------------------- | ------------------------------------------------ |
|
||||
| `--radius-field` | `var(--field-radius, calc(var(--radius) * 1.5))` |
|
||||
| `--border-width-field` | `var(--field-border-width, var(--border-width))` |
|
||||
| `--radius-xs` | `calc(var(--radius) * 0.25)` |
|
||||
| `--radius-sm` | `calc(var(--radius) * 0.5)` |
|
||||
| `--radius-md` | `calc(var(--radius) * 0.75)` |
|
||||
| `--radius-lg` | `calc(var(--radius) * 1)` |
|
||||
| `--radius-xl` | `calc(var(--radius) * 1.5)` |
|
||||
| `--radius-2xl` | `calc(var(--radius) * 2)` |
|
||||
| `--radius-3xl` | `calc(var(--radius) * 3)` |
|
||||
| `--radius-4xl` | `calc(var(--radius) * 4)` |
|
||||
| `--ease-smooth` | `ease` |
|
||||
| `--ease-in-quad` | `cubic-bezier(0.55, 0.085, 0.68, 0.53)` |
|
||||
| `--ease-in-cubic` | `cubic-bezier(0.55, 0.055, 0.675, 0.19)` |
|
||||
| `--ease-in-quart` | `cubic-bezier(0.895, 0.03, 0.685, 0.22)` |
|
||||
| `--ease-in-quint` | `cubic-bezier(0.755, 0.05, 0.855, 0.06)` |
|
||||
| `--ease-in-expo` | `cubic-bezier(0.95, 0.05, 0.795, 0.035)` |
|
||||
| `--ease-in-circ` | `cubic-bezier(0.6, 0.04, 0.98, 0.335)` |
|
||||
| `--ease-out-quad` | `cubic-bezier(0.25, 0.46, 0.45, 0.94)` |
|
||||
| `--ease-out-cubic` | `cubic-bezier(0.215, 0.61, 0.355, 1)` |
|
||||
| `--ease-out-quart` | `cubic-bezier(0.165, 0.84, 0.44, 1)` |
|
||||
| `--ease-out-quint` | `cubic-bezier(0.23, 1, 0.32, 1)` |
|
||||
| `--ease-out-expo` | `cubic-bezier(0.19, 1, 0.22, 1)` |
|
||||
| `--ease-out-circ` | `cubic-bezier(0.075, 0.82, 0.165, 1)` |
|
||||
| `--ease-out-fluid` | `cubic-bezier(0.32, 0.72, 0, 1)` |
|
||||
| `--ease-in-out-quad` | `cubic-bezier(0.455, 0.03, 0.515, 0.955)` |
|
||||
| `--ease-in-out-cubic` | `cubic-bezier(0.645, 0.045, 0.355, 1)` |
|
||||
| `--ease-in-out-quart` | `cubic-bezier(0.77, 0, 0.175, 1)` |
|
||||
| `--ease-in-out-quint` | `cubic-bezier(0.86, 0, 0.07, 1)` |
|
||||
| `--ease-in-out-expo` | `cubic-bezier(1, 0, 0, 1)` |
|
||||
| `--ease-in-out-circ` | `cubic-bezier(0.785, 0.135, 0.15, 0.86)` |
|
||||
| `--ease-linear` | `linear` |
|
||||
| `--animate-spin-fast` | `spin 0.75s linear infinite` |
|
||||
| `--animate-skeleton` | `skeleton 2s linear infinite` |
|
||||
| `--animate-caret-blink` | `caret-blink 1.2s ease-out infinite` |
|
||||
|
||||
`--skeleton-animation` 当前只在 Skeleton 挂载时从 html 读取,支持 shimmer/pulse/none;局部或动态修改该变量尚不生效。需要响应式切换时使用 Skeleton 公开的 `animationType` 属性。Tooltip 延时变量也不应被假定为所有 Vue 属性的自动默认值,需以组件 API 为准。
|
||||
|
||||
`data-vibrant-palette="true"` 提供更饱和的 soft 前景色配方,适合已经确认文本对比度的设计。它不是新增的组件 variant,不替代真实可访问性检查。
|
||||
|
||||
## 滚动条
|
||||
|
||||
滚动插槽使用标准 `scrollbar-width`、`scrollbar-color`、`scrollbar-gutter`,不靠全局 `::-webkit-scrollbar` 覆盖。通过 `data-scrollbar` 在祖先或目标槽选择模式:
|
||||
|
||||
| 模式 | `data-scrollbar` | 行为 |
|
||||
| ----------- | ---------------- | ---------------------------- |
|
||||
| HeroUI 纤细 | 默认 / `thin` | 读取主题滑块与轨道变量 |
|
||||
| 浏览器默认 | `default` | 原生 auto 宽度与颜色 |
|
||||
| 隐藏 | `none` | 不显示滚动条,仍保留滚动能力 |
|
||||
|
||||
```html
|
||||
<html data-scrollbar="default">
|
||||
<main data-scrollbar="thin">...</main>
|
||||
</html>
|
||||
```
|
||||
|
||||
嵌套模式覆盖祖先模式;主题根会声明滚动条默认变量,所以独立嵌套主题需要明确自己的模式。自定义容器可直接应用变量:
|
||||
|
||||
```css
|
||||
.scroll-region {
|
||||
overflow: auto;
|
||||
scrollbar-width: var(--scrollbar-width);
|
||||
scrollbar-color: var(--scrollbar-color);
|
||||
scrollbar-gutter: var(--scrollbar-gutter);
|
||||
}
|
||||
```
|
||||
|
||||
组件级用法与源 utilities 的发布边界见[样式](/styling#滚动条)。局部模式同样遵循 DOM 继承,默认 body Portal 不继承触发器子树的设置。
|
||||
|
||||
## 资源
|
||||
|
||||
- [颜色](/colors):每类语义颜色及明暗色板。
|
||||
- [深色模式](/dark-mode):应用主题状态、系统偏好与持久化。
|
||||
- [样式](/styling):BEM、属性透传、包装和导入。
|
||||
- [动画](/animation):减少动态效果与退出生命周期。
|
||||
- 当前规范仍有逐组件排查项;本页描述可用接口及明确边界,不代表全库完成全部规范验收。
|
||||
|
||||
Reference in New Issue
Block a user