feat: add Separator Kbd and Chip components
This commit is contained in:
@@ -240,6 +240,12 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
|
||||
- 普通组件和组合组件都要测试 `$attrs` 的最终落点。Switch 的字段容器承接 class/style/data-*,实际 Content 按钮承接 ARIA 和 DOM 事件;不能因用户自定义默认插槽,就丢失根组件的 aria-label。
|
||||
- `useAttrs()` 不是普通响应式对象。需要随父级更新的属性,不用无响应式依赖的 computed 缓存快照;在渲染时读取,并测试父级动态修改 ARIA 属性。
|
||||
- `$attrs` 不在 setup 解构成长期快照;过滤键值的对象在渲染时生成。验收覆盖空对象→新增→修改→删除→再次新增,包含 ARIA、class/style 和事件处理器;只测已有属性换值不足以发现键集合变化的问题。
|
||||
- 渲染函数中 `{ ...attrs, class: baseClass }` 会覆盖调用者 class;显式合并字符串、数组、对象 class,并检查动态更新后旧类移除、基础类保留。子部件覆盖父级颜色等变体时,用槽函数一次求值替换该变体,不拼接冲突的父子变体类。
|
||||
- 不在 computed 中缓存 `slots.default()` 的 VNode 结果;在渲染上下文中重新读取。组合子项先展开 Fragment,再跳过 Comment/Text 等非成员节点;保留成员 key,验证条件开关、父级替换插槽闭包、成员增删重排及 max/自动计数联动。
|
||||
- 不用 `as never` / `any` 消除公开 props 类型错误;运行时声明使用对应 `PropType`,保持字面量联合和默认值。类型回归既验证合法值,也用 `@ts-expect-error` 验证非法值,并抽查 dist 声明,而非只检查源码能编译。
|
||||
- 需要适配激活行为时,验证完整 keydown→keyup 只激活一次,调用者 preventDefault 可取消;不重复模拟原生元素已有的键盘行为。事件处理器可能是函数数组,必须保留 capture、冒泡与 stopImmediatePropagation 语义。
|
||||
- 不能直接调用 attrs 回调来冒充 DOM click;检查真实 target/currentTarget、插槽处理器与祖先事件委托。组件 ref 可能是公开实例,调用 focus 前先解析真实元素;自定义 asChild 根节点核对语义和可聚焦性。现有私有 `_vts` 适配不得当作通用实现照抄,涉及 Vue 升级时专项回归。
|
||||
- `asChild` 采用 Reka Primitive 合并属性,明确要求唯一有效根元素。它是 Vue 对 React render prop 的适配,不宣称复刻原有事件模型。
|
||||
- 受控值由父组件决定,非受控值维护内部初值。父组件拒绝 Input 更新时,检查真实 input.value 是否恢复,不能只检查 update:modelValue 是否发出。
|
||||
- 表单必须检查实际 `FormData`、未选中值是否省略、禁用值是否省略、默认提交值、required、reset 与被取消的 reset。受控 reset 不能覆盖父级值;非受控 reset 恢复初始值。
|
||||
|
||||
@@ -48,9 +48,12 @@ const groups = [
|
||||
{ title: "AvatarGroup 头像组", url: "/components/avatar-group" },
|
||||
{ title: "Button 按钮", url: "/components/button" },
|
||||
{ title: "Card 卡片", url: "/components/card" },
|
||||
{ title: "Chip 标签", url: "/components/chip" },
|
||||
{ title: "CloseButton 关闭按钮", url: "/components/close-button" },
|
||||
{ title: "Input 输入框", url: "/components/input" },
|
||||
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
||||
{ title: "Link 链接", url: "/components/link" },
|
||||
{ title: "Separator 分隔符", url: "/components/separator" },
|
||||
{ title: "Skeleton 骨架屏", url: "/components/skeleton" },
|
||||
{ title: "Spinner 加载指示器", url: "/components/spinner" },
|
||||
{ title: "Surface 表面", url: "/components/surface" },
|
||||
|
||||
@@ -7,9 +7,12 @@ description: 已迁移组件及文档
|
||||
- [AvatarGroup 头像组](./components/avatar-group)
|
||||
- [Button 按钮](./components/button)
|
||||
- [Card 卡片](./components/card)
|
||||
- [Chip 标签](./components/chip)
|
||||
- [CloseButton 关闭按钮](./components/close-button)
|
||||
- [Input 输入框](./components/input)
|
||||
- [Kbd 键盘按键](./components/kbd)
|
||||
- [Link 链接](./components/link)
|
||||
- [Separator 分隔符](./components/separator)
|
||||
- [Skeleton 骨架屏](./components/skeleton)
|
||||
- [Spinner 加载指示器](./components/spinner)
|
||||
- [Surface 表面](./components/surface)
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
---
|
||||
title: Chip 标签
|
||||
description: 用于显示标签、状态与分类的小型信息徽章
|
||||
component: chip
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Chip } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="chip-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
> 纯文本子节点会自动包裹在 `<ChipLabel>` 中。
|
||||
|
||||
```vue
|
||||
<Chip>
|
||||
Label text
|
||||
</Chip>
|
||||
```
|
||||
|
||||
显式使用部件或组合内容时不会重复包装:
|
||||
|
||||
```vue
|
||||
<Chip>
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>标签</ChipLabel>
|
||||
</Chip>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="chip-variants" />
|
||||
|
||||
### 状态类型
|
||||
|
||||
<ComponentPreview name="chip-statuses" />
|
||||
|
||||
### 带图标
|
||||
|
||||
<ComponentPreview name="chip-with-icon" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="chip-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 Chip 组件类。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-chip {
|
||||
@apply rounded-full text-xs;
|
||||
}
|
||||
|
||||
.hv-chip__label {
|
||||
@apply font-medium;
|
||||
}
|
||||
|
||||
.hv-chip--accent {
|
||||
@apply border-accent/20;
|
||||
}
|
||||
|
||||
.hv-chip--accent .hv-chip__label {
|
||||
@apply text-accent;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Chip 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/chip.css)):
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-chip` - 基础标签容器样式
|
||||
- `.hv-chip__label` - 标签文本 slot 样式
|
||||
|
||||
#### 颜色类 [!toc]
|
||||
|
||||
- `.hv-chip--accent` - 强调色变体
|
||||
- `.hv-chip--danger` - 危险色变体
|
||||
- `.hv-chip--default` - 默认色变体
|
||||
- `.hv-chip--success` - 成功色变体
|
||||
- `.hv-chip--warning` - 警告色变体
|
||||
|
||||
#### 变体类 [!toc]
|
||||
|
||||
- `.hv-chip--primary` - 填充背景的主变体
|
||||
- `.hv-chip--secondary` - 带边框的次变体
|
||||
- `.hv-chip--tertiary` - 透明背景的三级变体
|
||||
- `.hv-chip--soft` - 浅色背景的 soft 变体
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-chip--sm` - 小尺寸
|
||||
- `.hv-chip--md` - 中尺寸(默认)
|
||||
- `.hv-chip--lg` - 大尺寸
|
||||
|
||||
#### 复合变体类 [!toc]
|
||||
|
||||
Chip 支持组合变体与颜色类(如 `.hv-chip--secondary.hv-chip--accent`)。以下组合有默认样式:
|
||||
|
||||
**Primary Variants:**
|
||||
|
||||
- `.hv-chip--primary.hv-chip--accent` - 填充背景的 primary accent 组合
|
||||
- `.hv-chip--primary.hv-chip--success` - 填充背景的 primary success 组合
|
||||
- `.hv-chip--primary.hv-chip--warning` - 填充背景的 primary warning 组合
|
||||
- `.hv-chip--primary.hv-chip--danger` - 填充背景的 primary danger 组合
|
||||
|
||||
**Soft Variants:**
|
||||
|
||||
- `.hv-chip--accent.hv-chip--soft` - 浅色背景的 soft accent 组合
|
||||
- `.hv-chip--success.hv-chip--soft` - 浅色背景的 soft success 组合
|
||||
- `.hv-chip--warning.hv-chip--soft` - 浅色背景的 soft warning 组合
|
||||
- `.hv-chip--danger.hv-chip--soft` - 浅色背景的 soft danger 组合
|
||||
|
||||
**Note:** 可使用 CSS 中的 `@layer components` 指令为任意变体-颜色组合(如 `.hv-chip--secondary.hv-chip--accent`、`.hv-chip--tertiary.hv-chip--success`)应用自定义样式。
|
||||
|
||||
## API 参考
|
||||
|
||||
### Chip
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------- | ------------------------------------------------------------- | ------------- | --------------------------------------------------- |
|
||||
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | 标签颜色变体 |
|
||||
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'soft'` | `'secondary'` | 视觉样式变体 |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 标签尺寸 |
|
||||
| 默认插槽 | `Component` | - | 标签内显示的内容;纯文本/数字自动包装为 `ChipLabel` |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### ChipLabel
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | 标签文本内容 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件或 slot 基础类合并;不要使用 React 的 `className`。
|
||||
|
||||
纯文本或数字默认插槽会在渲染时包装为 `ChipLabel`;显式 `ChipLabel` 或图标等组合内容不会重复包装。文本与组合内容之间动态切换时会按当前插槽重新判断。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Card 卡片](./card) · [Avatar 头像](./avatar)
|
||||
@@ -0,0 +1,142 @@
|
||||
---
|
||||
title: Kbd 键盘按键
|
||||
description: 展示键盘快捷键与按键组合
|
||||
component: kbd
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="kbd-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
</template>
|
||||
```
|
||||
|
||||
`KbdAbbr` 根据 `keyValue` 显示按键符号,并自动设置无障碍 `title`。`KbdContent` 包裹按键字母或文本。
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="kbd-variants" />
|
||||
|
||||
### 导航按键
|
||||
|
||||
<ComponentPreview name="kbd-navigation-keys" />
|
||||
|
||||
### 行内用法
|
||||
|
||||
<ComponentPreview name="kbd-inline-usage" />
|
||||
|
||||
### 说明文字
|
||||
|
||||
<ComponentPreview name="kbd-instructional-text" />
|
||||
|
||||
### 特殊按键
|
||||
|
||||
<ComponentPreview name="kbd-special-keys" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="kbd-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 Kbd 组件类。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-kbd {
|
||||
@apply bg-gray-100 dark:bg-gray-800 border-gray-300;
|
||||
}
|
||||
|
||||
.hv-kbd__abbr {
|
||||
@apply font-bold;
|
||||
}
|
||||
|
||||
.hv-kbd__content {
|
||||
@apply text-sm;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Kbd 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/kbd.css)):
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-kbd` - 基础按键样式,含背景、边框与间距
|
||||
- `.hv-kbd__abbr` - 修饰键的缩写元素
|
||||
- `.hv-kbd__content` - 按键文本的内容包裹层
|
||||
|
||||
## API 参考
|
||||
|
||||
### Kbd
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------- | --------------------------- | ----------- | ----------------------------- |
|
||||
| `variant` | `'default' \| 'light'` | `'default'` | 按键视觉变体 |
|
||||
| 默认插槽 | `Component` | - | 按键内容 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### KbdAbbr
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | --------------------------- | ------ | --------------------------------------------------------------------------- |
|
||||
| `keyValue` | `KbdKey` | - | 要显示的按键;符号与 `title` 由映射表给出(如 `command` → `⌘` / `Command`) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### KbdContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | 按键文本内容 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与对应 slot 的基础类合并;不要使用 React 的 `className`。
|
||||
|
||||
### KbdContent Type
|
||||
|
||||
`keyValue` prop 可用的按键值:
|
||||
|
||||
| Modifier Keys | Special Keys | Navigation Keys | Function Keys |
|
||||
| ------------- | ------------ | --------------- | ------------- |
|
||||
| `command` | `enter` | `up` | `fn` |
|
||||
| `shift` | `delete` | `down` | |
|
||||
| `ctrl` | `escape` | `left` | |
|
||||
| `option` | `tab` | `right` | |
|
||||
| `alt` | `space` | `pageup` | |
|
||||
| `win` | `capslock` | `pagedown` | |
|
||||
| | `help` | `home` | |
|
||||
| | | `end` | |
|
||||
|
||||
上游文档表格曾写作 `Kbd.Key` 与 `title`/`children`;实际实现与全部演示使用 `KbdAbbr` 的 `keyValue` 与 `KbdContent`。本库按实现迁移,并同时导出 `kbdKeysMap`、`kbdKeysLabelMap` 与 `KbdKey` 类型。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Button 按钮](./button) · [Link 链接](./link)
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
title: Separator 分隔符
|
||||
description: 在内容区块之间进行视觉分隔。
|
||||
component: separator
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="separator-basic" />
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="separator-variants" />
|
||||
|
||||
### 与 Surface 组合
|
||||
|
||||
Separator 组件会根据不同的表面背景自动适配,以获得更好的可见性。
|
||||
|
||||
<ComponentPreview name="separator-with-surface" />
|
||||
|
||||
### 垂直方向
|
||||
|
||||
<ComponentPreview name="separator-vertical" />
|
||||
|
||||
### 带内容
|
||||
|
||||
<ComponentPreview name="separator-with-content" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
Vue 使用 `as-child` 将分隔符属性合并到默认插槽中唯一的自定义根元素,对应上游 `render` 函数示例,不将 render prop 原样搬入 Vue。
|
||||
|
||||
<ComponentPreview name="separator-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="separator-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-separator {
|
||||
@apply bg-accent h-[2px];
|
||||
}
|
||||
|
||||
.hv-separator--vertical {
|
||||
@apply bg-accent w-[2px];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Separator 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/separator.css)):
|
||||
|
||||
#### 基础类与方向类 [!toc]
|
||||
|
||||
- `.hv-separator` - 基础 Separator 样式,默认水平方向
|
||||
- `.hv-separator--horizontal` - 水平方向(全宽,高度 1px)
|
||||
- `.hv-separator--vertical` - 垂直方向(全高,宽度 1px)
|
||||
|
||||
#### 变体类 [!toc]
|
||||
|
||||
- `.hv-separator--default` - 默认变体,标准对比度
|
||||
- `.hv-separator--secondary` - 次要变体,中等对比度
|
||||
- `.hv-separator--tertiary` - 第三级变体,较弱对比度
|
||||
|
||||
## API 参考
|
||||
|
||||
### Separator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------- | ---------------------------------------- | -------------- | -------------------------------- |
|
||||
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Separator 的方向 |
|
||||
| `variant` | `'default' \| 'secondary' \| 'tertiary'` | `'default'` | Separator 的视觉变体 |
|
||||
| `decorative` | `boolean` | `false` | 装饰性分隔线,使用 `role="none"` |
|
||||
| `as` | `string` | `'hr'` | 自定义根元素标签 |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到默认插槽唯一根元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件基础类合并;不要使用 React 的 `className`。
|
||||
|
||||
默认渲染为 `hr`,带 `role="separator"` 与 `data-orientation`。`orientation` 为 `vertical` 时附加 `aria-orientation="vertical"`。上游 `render` 由 `as-child` 适配。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Surface 表面](./surface) · [Card 卡片](./card)
|
||||
@@ -1,5 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { Avatar, AvatarImage, AvatarFallback } from "@heroui-vue/components";
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Separator,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconUser } from "@tabler/icons-vue";
|
||||
|
||||
const colors = ["accent", "default", "success", "warning", "danger"] as const;
|
||||
@@ -44,7 +49,7 @@ const variants = [
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-px w-full bg-separator" />
|
||||
<Separator />
|
||||
|
||||
<!-- 变体行 -->
|
||||
<div
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { Chip } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Chip>默认</Chip>
|
||||
<Chip color="accent">强调</Chip>
|
||||
<Chip color="success">成功</Chip>
|
||||
<Chip color="warning">警告</Chip>
|
||||
<Chip color="danger">危险</Chip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { Chip } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Chip
|
||||
class="rounded-full bg-default-soft px-3 text-default-soft-foreground"
|
||||
>
|
||||
草稿
|
||||
</Chip>
|
||||
<Chip
|
||||
class="rounded-full bg-warning-soft px-3 text-warning-soft-foreground"
|
||||
>
|
||||
审核中
|
||||
</Chip>
|
||||
<Chip
|
||||
class="rounded-full bg-success-soft px-3 text-success-soft-foreground"
|
||||
>
|
||||
已发布
|
||||
</Chip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { Chip, ChipLabel } from "@heroui-vue/components";
|
||||
import {
|
||||
IconBan,
|
||||
IconCheck,
|
||||
IconCircleFilled,
|
||||
IconInfoCircle,
|
||||
IconAlertTriangle,
|
||||
} from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Chip variant="primary">
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>默认</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="success" variant="primary">
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>活跃</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="warning" variant="primary">
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>待处理</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="danger" variant="primary">
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>未激活</ChipLabel>
|
||||
</Chip>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Chip>
|
||||
<IconInfoCircle :size="12" aria-hidden="true" />
|
||||
<ChipLabel>新功能</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="success">
|
||||
<IconCheck :size="12" aria-hidden="true" />
|
||||
<ChipLabel>可用</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="warning">
|
||||
<IconAlertTriangle :size="12" aria-hidden="true" />
|
||||
<ChipLabel>测试版</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="danger">
|
||||
<IconBan :size="12" aria-hidden="true" />
|
||||
<ChipLabel>已弃用</ChipLabel>
|
||||
</Chip>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
import { Chip, ChipLabel, Separator } from "@heroui-vue/components";
|
||||
import { IconCircleDashed } from "@tabler/icons-vue";
|
||||
|
||||
const sizes = ["lg", "md", "sm"] as const;
|
||||
|
||||
const SIZE_LABELS: Record<(typeof sizes)[number], string> = {
|
||||
lg: "大",
|
||||
md: "中",
|
||||
sm: "小",
|
||||
};
|
||||
|
||||
const variants = ["primary", "secondary", "tertiary", "soft"] as const;
|
||||
|
||||
const VARIANT_LABELS: Record<(typeof variants)[number], string> = {
|
||||
primary: "主要",
|
||||
secondary: "次要",
|
||||
soft: "柔和",
|
||||
tertiary: "第三",
|
||||
};
|
||||
|
||||
const colors = ["accent", "default", "success", "warning", "danger"] as const;
|
||||
|
||||
const COLOR_LABELS: Record<(typeof colors)[number], string> = {
|
||||
accent: "强调",
|
||||
danger: "危险",
|
||||
default: "默认",
|
||||
success: "成功",
|
||||
warning: "警告",
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-8 overflow-x-auto">
|
||||
<template v-for="(size, index) in sizes" :key="size">
|
||||
<div class="flex flex-col gap-4">
|
||||
<h3 class="text-sm font-semibold text-muted">
|
||||
{{ SIZE_LABELS[size] }}
|
||||
</h3>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-24 shrink-0" />
|
||||
<div
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
class="flex shrink-0 items-center justify-center"
|
||||
style="width: 130px"
|
||||
>
|
||||
<span class="text-xs text-muted">{{ COLOR_LABELS[color] }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-3">
|
||||
<div
|
||||
v-for="variant in variants"
|
||||
:key="variant"
|
||||
class="flex items-center gap-3"
|
||||
>
|
||||
<div class="w-24 shrink-0 text-sm text-muted">
|
||||
{{ VARIANT_LABELS[variant] }}
|
||||
</div>
|
||||
<div
|
||||
v-for="color in colors"
|
||||
:key="color"
|
||||
class="flex shrink-0 items-center justify-center"
|
||||
style="width: 130px"
|
||||
>
|
||||
<Chip :color="color" :size="size" :variant="variant">
|
||||
<IconCircleDashed aria-hidden="true" />
|
||||
<ChipLabel>标签</ChipLabel>
|
||||
<IconCircleDashed aria-hidden="true" />
|
||||
</Chip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Separator v-if="index < sizes.length - 1" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { Chip, ChipLabel } from "@heroui-vue/components";
|
||||
import {
|
||||
IconChevronDown,
|
||||
IconCircleCheckFilled,
|
||||
IconCircleFilled,
|
||||
IconClock,
|
||||
IconX,
|
||||
} from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Chip>
|
||||
<IconCircleFilled :size="6" aria-hidden="true" />
|
||||
<ChipLabel>信息</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="success">
|
||||
<IconCircleCheckFilled :size="12" aria-hidden="true" />
|
||||
<ChipLabel>已完成</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="warning">
|
||||
<IconClock :size="12" aria-hidden="true" />
|
||||
<ChipLabel>待处理</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="danger">
|
||||
<IconX :size="12" aria-hidden="true" />
|
||||
<ChipLabel>失败</ChipLabel>
|
||||
</Chip>
|
||||
<Chip color="accent">
|
||||
<ChipLabel>标签</ChipLabel>
|
||||
<IconChevronDown :size="12" aria-hidden="true" />
|
||||
</Chip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="shift" />
|
||||
<KbdContent>P</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="ctrl" />
|
||||
<KbdContent>C</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="option" />
|
||||
<KbdContent>D</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-3">
|
||||
<Kbd class="rounded-lg bg-accent-soft px-2.5 text-accent-soft-foreground">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd class="rounded-lg bg-default px-2.5 text-muted">
|
||||
<KbdAbbr key-value="shift" />
|
||||
<KbdContent>P</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<p class="text-sm">
|
||||
按
|
||||
<Kbd>
|
||||
<KbdContent>Esc</KbdContent>
|
||||
</Kbd>
|
||||
关闭对话框。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
使用
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
打开命令面板。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
使用
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="up" />
|
||||
</Kbd>
|
||||
和
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="down" />
|
||||
</Kbd>
|
||||
方向键进行导航。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
使用
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>S</KbdContent>
|
||||
</Kbd>
|
||||
定期保存你的工作。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-3">
|
||||
<div class="rounded-lg bg-surface p-4">
|
||||
<h4 class="mb-2 text-sm font-semibold">快捷操作</h4>
|
||||
<ul class="space-y-2 text-sm">
|
||||
<li>
|
||||
• 打开搜索:
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
</li>
|
||||
<li>
|
||||
• 切换侧边栏:
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>B</KbdContent>
|
||||
</Kbd>
|
||||
</li>
|
||||
<li>
|
||||
• 新建文件:
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>N</KbdContent>
|
||||
</Kbd>
|
||||
</li>
|
||||
<li>
|
||||
• 快速保存:
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>S</KbdContent>
|
||||
</Kbd>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-sm text-muted">方向键:</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="up" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="down" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="left" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="right" />
|
||||
</Kbd>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-sm text-muted">页面导航:</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="pageup" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="pagedown" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="home" />
|
||||
</Kbd>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="end" />
|
||||
</Kbd>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-3">
|
||||
<p class="text-sm">
|
||||
按
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="enter" />
|
||||
</Kbd>
|
||||
确认,或按
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="escape" />
|
||||
</Kbd>
|
||||
取消。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
使用
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="tab" />
|
||||
</Kbd>
|
||||
在表单字段间切换,使用
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="shift" />
|
||||
<KbdAbbr key-value="tab" />
|
||||
</Kbd>
|
||||
返回上一项。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
按住
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="space" />
|
||||
</Kbd>
|
||||
可临时启用平移模式。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { Kbd, KbdAbbr, KbdContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span>复制:</span>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>C</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd variant="light">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>C</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span>粘贴:</span>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>V</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd variant="light">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>V</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span>剪切:</span>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>X</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd variant="light">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>X</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span>撤销:</span>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>Z</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd variant="light">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>Z</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span>重做:</span>
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdAbbr key-value="shift" />
|
||||
<KbdContent>Z</KbdContent>
|
||||
</Kbd>
|
||||
<Kbd variant="light">
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdAbbr key-value="shift" />
|
||||
<KbdContent>Z</KbdContent>
|
||||
</Kbd>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-w-md">
|
||||
<div class="space-y-1">
|
||||
<h4 class="text-medium font-medium">HeroUI v3 组件</h4>
|
||||
<p class="text-small text-default-400">
|
||||
美观、快速、现代的 React UI 库。
|
||||
</p>
|
||||
</div>
|
||||
<Separator class="my-4" />
|
||||
<div class="text-small flex h-5 items-center space-x-4">
|
||||
<div>博客</div>
|
||||
<Separator orientation="vertical" />
|
||||
<div>文档</div>
|
||||
<Separator orientation="vertical" />
|
||||
<div>源码</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-w-xs space-y-4">
|
||||
<p class="text-sm font-medium text-foreground">账户设置</p>
|
||||
<Separator class="bg-separator-secondary" />
|
||||
<div class="flex items-center gap-3 text-sm text-muted">
|
||||
<span>个人资料</span>
|
||||
<Separator class="h-4 bg-separator" orientation="vertical" />
|
||||
<span>账单</span>
|
||||
<Separator class="h-4 bg-separator" orientation="vertical" />
|
||||
<span>安全</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-w-md">
|
||||
<div class="space-y-1">
|
||||
<h4 class="text-medium font-medium">HeroUI v3 组件</h4>
|
||||
<p class="text-small text-default-400">
|
||||
美观、快速、现代的 React UI 库。
|
||||
</p>
|
||||
</div>
|
||||
<Separator class="my-4" as-child>
|
||||
<div data-custom="foo"></div>
|
||||
</Separator>
|
||||
<div class="text-small flex h-5 items-center space-x-4">
|
||||
<div>博客</div>
|
||||
<Separator orientation="vertical" as-child>
|
||||
<div data-custom="foo"></div>
|
||||
</Separator>
|
||||
<div>文档</div>
|
||||
<Separator orientation="vertical" as-child>
|
||||
<div data-custom="foo"></div>
|
||||
</Separator>
|
||||
<div>源码</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-md flex-col items-center gap-3">
|
||||
<div>默认变体</div>
|
||||
<Separator variant="default" />
|
||||
<div>次要变体</div>
|
||||
<Separator variant="secondary" />
|
||||
<div>第三变体</div>
|
||||
<Separator variant="tertiary" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="text-small flex h-5 items-center space-x-4">
|
||||
<div>博客</div>
|
||||
<Separator orientation="vertical" />
|
||||
<div>文档</div>
|
||||
<Separator orientation="vertical" />
|
||||
<div>源码</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator } from "@heroui-vue/components";
|
||||
|
||||
const items = [
|
||||
{
|
||||
iconUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/bell-small.png",
|
||||
subtitle: "接收账户活动更新",
|
||||
title: "设置通知",
|
||||
},
|
||||
{
|
||||
iconUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/compass-small.png",
|
||||
subtitle: "将浏览器连接到你的账户",
|
||||
title: "设置浏览器扩展",
|
||||
},
|
||||
{
|
||||
iconUrl:
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/3dicons/mint-collective-small.png",
|
||||
subtitle: "创建你的第一件收藏品",
|
||||
title: "铸造收藏品",
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-w-md space-y-4">
|
||||
<div v-for="(item, index) in items" :key="item.title">
|
||||
<div class="flex items-center gap-3">
|
||||
<img :alt="item.title" class="size-12" :src="item.iconUrl" />
|
||||
<div class="flex-1 space-y-0">
|
||||
<h4 class="text-small font-medium">{{ item.title }}</h4>
|
||||
<p class="text-sm text-muted">{{ item.subtitle }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Separator v-if="index < items.length - 1" class="my-4" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { Separator, Surface } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-8">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Surface
|
||||
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
|
||||
variant="default"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-foreground">默认表面</h3>
|
||||
<Separator />
|
||||
<p class="text-sm text-muted">表面内容</p>
|
||||
</Surface>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Surface
|
||||
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
|
||||
variant="secondary"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-foreground">次要表面</h3>
|
||||
<Separator variant="secondary" />
|
||||
<p class="text-sm text-muted">表面内容</p>
|
||||
</Surface>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Surface
|
||||
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
|
||||
variant="tertiary"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-foreground">第三表面</h3>
|
||||
<Separator variant="tertiary" />
|
||||
<p class="text-sm text-muted">表面内容</p>
|
||||
</Surface>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Surface
|
||||
class="flex min-w-[320px] flex-col gap-3 rounded-3xl border p-6"
|
||||
variant="transparent"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-foreground">透明表面</h3>
|
||||
<Separator />
|
||||
<p class="text-sm text-muted">表面内容</p>
|
||||
</Surface>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+13
-6
@@ -16,7 +16,7 @@
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| checkbox-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| chip | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -35,11 +35,11 @@
|
||||
| disclosure | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| scroll-shadow | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| separator | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
@@ -100,13 +100,20 @@ React Aria 专属 rac 导出与 React 图标类型不移植;Vue 版 ConfigProv
|
||||
|
||||
## 已实现组件的文档清单复核
|
||||
|
||||
Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||
Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||
|
||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。
|
||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。
|
||||
|
||||
框架适配差异:Avatar 使用 Reka 组合,表单使用 Input/TextArea;链接原生锚点由 Link 组件封装;图标使用 Tabler 官方 Vue 组件(Link 自定义图标、CloseButton 自定义图标、Avatar 图标回退等示例);演示不提供认证、支付等业务服务。完整 React Aria 事件模型、全库字段上下文及自动视觉回归仍不在本批完成范围。
|
||||
|
||||
上游 Link 的 `underline-offset` 与 `underline-variants` 演示文件未出现在中英文文档预览清单,本批仅迁移文档引用的 6 个示例。Link `onPress`/`PressEvent` 与 `render` 由 `click` 与 `asChild` 适配;Spinner 与 CloseButton 默认图标为移植的基线 SVG,非 Tabler。上游 `close-button/variants.tsx`、`skeleton/card.tsx` 未进入文档预览清单,未迁移。Avatar 变体示例中的 Separator 以分隔线 div 适配(Separator 组件未迁移)。
|
||||
上游 Link 的 `underline-offset` 与 `underline-variants` 演示文件未出现在中英文文档预览清单,本批仅迁移文档引用的 6 个示例。Link `onPress`/`PressEvent` 与 `render` 由 `click` 与 `asChild` 适配;Spinner 与 CloseButton 默认图标为移植的基线 SVG,非 Tabler。上游 `close-button/variants.tsx`、`skeleton/card.tsx`、`chip/release-vibrant-palette.tsx` 未进入文档预览清单,未迁移。Avatar 变体示例中的分隔线已改用公共 Separator。
|
||||
|
||||
## M07–M09 说明
|
||||
|
||||
- Separator:基于 Reka Separator,默认 `as="hr"` 与 `role="separator"`;`orientation=vertical` 时附加 `aria-orientation`;`decorative` 映射 `role="none"`;上游 `render` 由 `as-child` 适配,需唯一自定义根元素。
|
||||
- Kbd:`KbdAbbr` 的 `keyValue` 映射符号与 `title`,不开放覆盖符号的插槽(与上游一致);`KbdContent` 为内容包装层;上下文提供 abbr/content 类名。上游文档表写作 `Kbd.Key`/`title`/`children`,以实现与全部演示为准。
|
||||
- Chip:纯文本/数字默认插槽在渲染时包装为 `ChipLabel`;显式 `ChipLabel` 或图标等组合内容不重复包装;Fragment/Comment/空白文本不参与判定。文本与组合内容可在运行时切换。
|
||||
- Chip 演示图标由上游 `@gravity-ui/icons` 替换为 Tabler 官方 Vue 组件(`IconCircleFilled`/`IconCheck`/`IconClock` 等),尺寸以 `:size` 保留。
|
||||
|
||||
## M04–M06 说明
|
||||
|
||||
|
||||
@@ -13,12 +13,13 @@
|
||||
## 当前起点
|
||||
|
||||
| 范围 | 当前事实 | 不应作出的推断 |
|
||||
| ---------------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------- |
|
||||
| ---------------------------------------------- | ------------------------------------------------------- | -------------------------------------------------- |
|
||||
| Button / Card / Input / Switch | 已有实现和文档,基线演示分别为 14 / 7 / 7 / 15 个 | 不代表 React Aria 的全部行为已兼容 |
|
||||
| SwitchGroup / Label / Description / FieldError | 已有部分组合能力;FieldError 当前仅接入 Switch | 不代表完整字段、表单与分组体系已完成 |
|
||||
| CloseButton | CSS 与 closeButtonVariants 已移植,Card 演示使用原生 button 组合 | Vue CloseButton 组件尚未实现 |
|
||||
| Surface / Link / Spinner | M01–M03 已提交,代码与构建复核通过 | 不代表所有浏览器与视觉兼容性已完成 |
|
||||
| CloseButton / Avatar / AvatarGroup / Skeleton | M04–M06 已提交,Card 已使用公共组件;动态更新问题已修复 | 仍有已披露的底座差异及视觉/水合等未验证边界 |
|
||||
| 主题与图标 | 已有默认浅深主题;演示与文档采用 Tabler 官方 Vue 图标 | 不能自行换品牌配色或自绘 SVG |
|
||||
| 验证 | 当前有 34 项测试、SSR 冒烟及部分手动浏览器记录 | 尚无完整自动浏览器、视觉、独立安装和 Nuxt 水合验收 |
|
||||
| 验证 | 本轮提交时有 98 项测试、SSR 冒烟及部分手动浏览器记录 | 尚无完整自动浏览器、视觉、独立安装和 Nuxt 水合验收 |
|
||||
|
||||
这些数字是本次快照。接手时先检查代码和兼容矩阵,不用旧数字作为验收目标。
|
||||
|
||||
@@ -89,6 +90,7 @@
|
||||
所有演示使用同一份 Vue SFC 渲染、复制和高亮;图标用 @tabler/icons-vue,不自绘 SVG。
|
||||
文档表格统一铺满正文内容区,长内容自动换行,不横向滚动、不缩小字号、不截断内容;
|
||||
复用公共样式,按本文“文档表格排版与验收”检查长类型 API 表和短内容插槽表。
|
||||
落实本文“两批迁移的反复缺陷与回归要求”,按组件适用性验证动态 attrs、插槽、class、类型及事件。
|
||||
禁止用近似控件、占位内容或未生效的 Tailwind 类名充数。
|
||||
新增依赖或共享协议变更先说明缺口与影响,不擅自替换全库架构。
|
||||
|
||||
@@ -142,6 +144,26 @@
|
||||
- 文档表格按下节检查:长表不溢出,短表不收缩,换行不丢失信息;公共样式改动需回归其他页面。
|
||||
- 模块加载/SSR 不访问 window/document;ID、水合、Teleport 等检查与 SSR 冒烟分开。生产构建必须验证包导出的 dist,不只验证开发源码。
|
||||
|
||||
### 两批迁移的反复缺陷与回归要求
|
||||
|
||||
以下来自 M01–M03 与 M04–M06 的实际返工,作为后续实现与独立复核的要求。按组件的真实能力选择适用项,不给展示组件凭空增加交互。
|
||||
|
||||
| 容易遗漏的问题 | 实现约束 | 必须能复现的回归场景 |
|
||||
| -------------------------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||
| 组件实例被当成 DOM ref | 解析真实根元素后再 focus;不要假定 Primitive 实例就是 HTMLElement | autofocus 挂载不抛错且实际获得焦点;卸载与根节点替换后清理监听 |
|
||||
| 键盘重复激活、无法取消 | 不在 capture、keydown、keyup 重复执行同一激活;保留调用者取消顺序,不重复模拟原生行为 | 完整 Enter 序列只激活一次;capture/bubble 的 preventDefault 可取消;禁用时不激活 |
|
||||
| 直接执行回调代替 click | 需要合成激活时通过真实 DOM 事件路径,保留目标、插槽与祖先传播;处理器可为数组 | target/currentTarget 正确;插槽与祖先各收到一次;数组监听器遵守 stopImmediatePropagation;preventDefault 不等于停止冒泡 |
|
||||
| attrs 快照与空键集合缓存 | 不在 setup 解构长期快照,也不依赖 computed 枚举空 attrs 的失效;渲染时读取当前属性 | 空→新增→修改→删除→再次新增 ARIA/class/style/事件;新回调执行、旧回调不再执行 |
|
||||
| class 或变体覆盖错误 | h() 对象展开后显式合并调用者 class;子变体通过槽函数单次求值替换父级变体 | 字符串/数组/对象及动态 class 保留基础类;旧类移除;子 color 仅有一个有效颜色变体 |
|
||||
| 插槽与成员列表不更新 | 在渲染时读取当前插槽,保留成员 key;跳过 Comment/Text,递归处理 Fragment | 父级先捕获当前成员数组再提供新插槽闭包;成员替换/重排;v-if 注释与空白不占 max;自动/显式计数正确 |
|
||||
| 类型检查通过却丢失公开约束 | 使用 PropType 与准确的公共类型;不使用 as never / any 抹掉契约 | 合法 props 可用,非法 size/color/variant 等必须报错;对本次 dist 声明再次做类型探针 |
|
||||
|
||||
- 修复必须回归相邻能力:从模板改成渲染函数后重新检查 class/style/事件透传;修复变体合并后回归属性动态更新;不能只让最初的失败断言变绿。
|
||||
- 运行时测试通过不能证明类型约束存在;类型探针必须由 vue-tsc 实际检查,`@ts-expect-error` 失效应使检查失败。不要仅把类型用例放进 Vitest 而不执行类型检查。
|
||||
- 私有 Vue `_vts` 是现有 Link 的维护边界,不是新组件的通用模板。不要为复用事件逻辑引入更多私有字段依赖;升级 Vue 时专项回归事件目标、取消与传播。
|
||||
- 新发现的底座缺口先验证能否局部补偿;只能在明确差异与影响后记录限制,不能以文档备注替代本来可实现的契约。已有 delayMs=0 等限制保留原记录,本节不追溯扩大既有验收结论。
|
||||
- 交接报告逐项写“适用/不适用、实际测试及结果”。独立复核人追加当前结论,实施者写修复记录,不自行把集成人的“待复核”改成“已验收”。
|
||||
|
||||
### 文档表格排版与验收
|
||||
|
||||
适用于文档正文中的属性 API、事件、插槽、作用域状态及其他说明表格。宽度以正文内容区为准,不占用侧栏或右侧目录;演示区内的组件表格按组件自身契约处理。
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# M07–M09 迁移任务提示词
|
||||
|
||||
以下内容可直接发给接手的 AI;不代表任务已派发或已实现。
|
||||
|
||||
```text
|
||||
请在独立 heroui-vue 仓库迁移以下组件,完成后交给集成人复核,不自行提交或推送:
|
||||
M07 Separator、M08 Kbd(含 KbdAbbr / KbdContent)、M09 Chip(含 ChipLabel)。
|
||||
|
||||
工作目录:/Users/maoyingjie/Documents/OpenSourceProjects/heroui/heroui-vue
|
||||
参考仓库:../heroui,只读。
|
||||
上游基线:HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960。
|
||||
本批从 3d05fea 之后开始;先检查实际 HEAD 和工作区,记录起点,保留已有修改。
|
||||
|
||||
先读 AGENTS.md、docs/migration-handoff.md(尤其“两批迁移的反复缺陷与回归要求”)、
|
||||
docs/compatibility.md、docs/upstream.md。不要运行 React 包装 Vue。
|
||||
|
||||
先读上游目标组件、CSS/变体、中文文档及全部演示,列出 API、默认值、状态、子部件和示例清单。
|
||||
文档位于 apps/docs/content/docs/cn/react/components/,演示位于 apps/docs/src/demos/cn/。
|
||||
基线预览:Separator 7、Kbd 7、Chip 5,共 19 个;再次核对名称、顺序和内容,数量不是验收替代品。
|
||||
|
||||
重点:
|
||||
1. Separator:横竖方向、变体、语义与装饰用途、带内容布局、自定义根节点适配;
|
||||
用公共 Separator 替换现有 Avatar 变体示例中的临时分隔线,保持视觉一致。
|
||||
2. Kbd:准确迁移按键映射、keyValue 类型、abbr 的 title、内容部件、变体与上下文;
|
||||
keyValue、变体、插槽内容和调用方属性动态变化都应更新。
|
||||
3. Chip:尺寸、颜色、变体、ChipLabel、图标组合;纯文本/数字默认插槽自动包装,
|
||||
显式 ChipLabel 或组合内容不能重复包装;测试内容在文本与组合节点间切换。
|
||||
|
||||
按现有目录交付组件、样式、类型、导出、文档、全部演示和适用行为测试。
|
||||
允许本批必要的共享导出、导航、样式入口及记录更新,不重写现有主题、布局或构建链路。
|
||||
组件和文档样式、布局、文案、API 与主题对齐固定基线;复用现有 Vue 能力与已安装底座。
|
||||
图标使用 @tabler/icons-vue,不自绘,不把文档图标依赖加入基础组件包。
|
||||
预览、复制、高亮必须使用同一份 Vue SFC。
|
||||
正文表格铺满内容区,长内容自动换行,不横向滚动、不缩字号、不截断信息;复用公共样式。
|
||||
|
||||
避免已发生的返工:
|
||||
- attrs 在渲染时读取;测试空→新增→修改→删除→再次新增,覆盖 ARIA/class/style/事件。
|
||||
- h() 渲染显式合并调用方 class,支持字符串、数组、对象及动态移除;基础类不能丢。
|
||||
- 子变体覆盖父级时单次调用槽函数,不能同时拼接冲突的父子颜色类。
|
||||
- 不用 computed 缓存 slots.default();测试替换插槽闭包、内容增删和重排。
|
||||
- Fragment、Comment、Text 按语义处理,不把条件占位或空白当成组合成员。
|
||||
- 不用 as never / any 掩盖 props 错误;用 PropType,测试合法与非法值,并核对 dist 声明。
|
||||
- 需要交互适配时保留原生事件语义,不直接执行回调冒充 DOM click;
|
||||
完整键盘序列只激活一次,支持取消、数组监听器中断、插槽与祖先传播。
|
||||
- 上述项目按组件适用性验证,不给展示组件增加无关的键盘交互。
|
||||
|
||||
执行 pnpm test、pnpm test:unit、pnpm typecheck、pnpm build:docs、pnpm format。
|
||||
新增测试文件时同步 test:unit 显式列表;类型负例需由 vue-tsc 真正检查。
|
||||
在真实浏览器验证 5173 的本批示例、浅深主题、动态属性、展开复制高亮、桌面及窄屏表格;
|
||||
记录视口、操作、计算样式和截图。占用端口先确认服务用途,不擅自结束其他项目或换端口。
|
||||
不能执行的检查明确列出原因,不伪称浏览器、视觉、独立安装或水合已通过。
|
||||
|
||||
更新 compatibility.md、upstream.md、verification.md;提交交接报告文件
|
||||
docs/migrations/M07-M09-separator-kbd-chip.md
|
||||
写明起始版本、改动范围、19 个示例逐项对照、公开 API/差异、回归场景、命令结果、
|
||||
浏览器证据、未验证项、来源许可及最短复核步骤。实施者记录自测,验收结论由集成人填写。
|
||||
发现阻断先给出可复现场景与局部解决方案,不删除能力或扩大到其他组件家族。
|
||||
```
|
||||
@@ -0,0 +1,51 @@
|
||||
# M07–M09 集成人复核(Separator / Kbd / Chip)
|
||||
|
||||
日期:2026-10-21。基线:HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。Vue 起点:`3d05fea`。
|
||||
|
||||
当前状态以末尾「返工复核通过」为准,前文保留问题与检查历史。
|
||||
|
||||
## 当前结论
|
||||
|
||||
**待修正文档。** 本轮未发现组件代码层的新阻塞问题,但公开 API 表有一项会误导实际使用的框架适配遗漏。修正文档后可再确认本批代码与构建复核结论;不扩大为完整视觉或水合验收。
|
||||
|
||||
## [P2] 六处 API 表仍使用 React 的 className,实际只接受 Vue class
|
||||
|
||||
位置:
|
||||
|
||||
- `apps/docs/components/separator.md:97`
|
||||
- `apps/docs/components/kbd.md:105`、`:112`、`:119`
|
||||
- `apps/docs/components/chip.md:145`、`:152`
|
||||
|
||||
这些行把 className 声明为附加 CSS 类的 API,但组件没有 className prop 或兼容转换;实现是将 Vue attrs.class 合并到根元素。用户照表写 `<Chip className="docs-class">`,该值不会进入 DOM class,自定义样式不生效。同样影响 Separator、Kbd、KbdAbbr、KbdContent、ChipLabel 的说明。
|
||||
|
||||
独立复现:mount(Chip, { attrs: { className: 'docs-class' } }) 后断言根 classes 包含 docs-class,失败;正常 class 透传与动态合并通过。
|
||||
|
||||
修复要求:六处 API 名称统一为 `class`,说明遵循 Vue class 绑定,可接收字符串、数组和对象。同步核对表格类型描述与框架适配说明;无需为保留 React 文档而给 Vue 实现增加 className 别名。回归检查三页全部子部件的 API 表与实际演示用法一致。
|
||||
|
||||
## 已通过的检查
|
||||
|
||||
- 本批 diff 范围与交接基本一致;保留既有 AGENTS、迁移规范和提示词修改;上游只作参考。
|
||||
- 上游 KbdKey、符号及 title 映射与本库一致;Separator/Kbd/Chip 变体与默认值适配已核对。Chip 显式 md 的文档/上游样式差异已披露。
|
||||
- 三份组件 CSS 去掉来源注释、hv- 前缀及空白后与固定上游一致;来源与许可有登记。
|
||||
- 19 个基线示例清单及顺序测试通过;Avatar 临时分隔线已替换为公共 Separator。清单通过不代替逐页视觉验收。
|
||||
- 独立行为探针:所有六个组件/部件的 attrs 从空新增、删除、再次新增,事件替换,数组/对象 class 合并及旧类移除通过;Chip 捕获新插槽闭包、Fragment 纯文本自动包装、文本与组合内容切换通过;KbdAbbr keyValue/title 动态更新与 Separator orientation/decorative 更新通过。
|
||||
- 独立类型探针直接导入本轮 dist 中的 ChipProps、SeparatorProps、KbdProps、KbdAbbrProps,合法值通过,非法尺寸/方向/变体/按键值被拒绝。
|
||||
|
||||
## 命令与证据
|
||||
|
||||
- `pnpm test`:9 文件 / 126 项通过(含 SSR)。
|
||||
- `pnpm test:unit`:8 文件 / 125 项通过;交接报告写“同上”应改成实际数量,避免与含 SSR 的入口混淆。
|
||||
- `pnpm typecheck`、`pnpm build:docs`、`pnpm format` 通过。
|
||||
- 独立临时行为探针 4 项中 3 项通过、1 项复现 className 文档契约错误;dist 类型探针通过。临时文件均已删除。
|
||||
- 本轮未重做逐页浏览器点击与位图视觉检查。实施者已披露的浅深切换交互、窄于 400px 表格、截图、Nuxt 水合、读屏、触屏、独立安装等未验证边界继续保留;不把对方的浏览器记录冒充本轮独立证据。
|
||||
- 本轮只新增此复核报告,未改组件实现、未提交。最终运行 Prettier 与 git diff --check。
|
||||
|
||||
## 返工复核通过(2026-10-21)
|
||||
|
||||
结论:**通过本批代码、文档 API 与构建复核,可提交。**
|
||||
|
||||
- 三个页面六处 API 表均改为 Vue `class`,类型与说明覆盖字符串、数组、对象;未添加无必要的 className 兼容属性。
|
||||
- 新增文档回归用例通过;交接报告已明确区分 unit 与含 SSR 的测试入口。上文 126 / 125 是修复前计数;本轮新增一项后全量为 127 项。
|
||||
- 本轮重新运行 `pnpm test`:9 文件 / 127 项通过;`pnpm typecheck`、`pnpm build:docs`、`pnpm format` 与 `git diff --check` 通过。
|
||||
- 未发现新的阻塞问题;前轮独立动态属性、事件、插槽及 dist 类型检查结论保留。未重做浏览器视觉验收,既有未验证边界保持,不宣称全组件兼容验收完成。
|
||||
- 提交包含本批组件、19 份演示、文档与测试,以及此前已授权编写的迁移经验、规范和 M07–M09 提示词。
|
||||
@@ -0,0 +1,183 @@
|
||||
# M07–M09 Separator / Kbd / Chip 交接报告
|
||||
|
||||
实施日期:2026-10-21。状态:实施者自测完成,待集成人复核。**未提交、未推送。**
|
||||
|
||||
## 1. 起点与改动范围
|
||||
|
||||
| 项 | 值 |
|
||||
| ---------- | -------------------------------------------------------------------------------------------------------------- |
|
||||
| 起始 HEAD | `3d05fea`(feat: add CloseButton Avatar and Skeleton components) |
|
||||
| 工作区起点 | 保留未提交修改:`AGENTS.md`、`docs/migration-handoff.md`;未跟踪 `docs/migrations/M07-M09-prompt.md`(未改写) |
|
||||
| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui`,只读) |
|
||||
| 最终差异 | 见下方文件清单;无其他组件家族重构 |
|
||||
|
||||
### 新增
|
||||
|
||||
- 样式:`packages/styles/components/{separator,kbd,chip}.css`
|
||||
- 变体:`packages/styles/src/index.ts` 增加 `separatorVariants` / `kbdVariants` / `chipVariants`
|
||||
- 组件:
|
||||
- `packages/vue/src/components/separator/Separator.vue`
|
||||
- `packages/vue/src/components/kbd/{Kbd,KbdAbbr,KbdContent}.vue` + `context.ts` + `constants.ts`
|
||||
- `packages/vue/src/components/chip/{Chip,ChipLabel}.vue` + `context.ts`
|
||||
- 演示 19 个:`apps/docs/demos/{separator,kbd,chip}-*.vue`
|
||||
- 文档:`apps/docs/components/{separator,kbd,chip}.md`
|
||||
- 测试:`tests/separator-kbd-chip.test.ts`(28 项)
|
||||
|
||||
### 修改(共享)
|
||||
|
||||
- `packages/styles/index.css`:导入三个组件 CSS
|
||||
- `packages/vue/src/{index.ts,types.ts}`:组件、变体、类型、常量导出
|
||||
- `apps/docs/.vitepress/theme/Layout.vue`:导航增加 Chip / Kbd / Separator
|
||||
- `apps/docs/components.md`:索引链接
|
||||
- `apps/docs/demos/avatar-variants.vue`:临时分隔线 div → 公共 `<Separator />`
|
||||
- `package.json`:`test:unit` 加入新测试文件
|
||||
- `docs/{compatibility,upstream,verification}.md`
|
||||
- 本文件
|
||||
|
||||
## 2. 上游来源
|
||||
|
||||
| 上游路径 | 用途 |
|
||||
| ---------------------------------------------------------------------- | ------------------------------------------- |
|
||||
| `packages/react/src/components/{separator,kbd,chip}/*` | 组件结构、部件、上下文、按键映射 |
|
||||
| `packages/styles/components/{separator,kbd,chip}.css` | BEM 类与视觉数值(仅加 `hv-` 前缀) |
|
||||
| `packages/styles/src/components/{separator,kbd,chip}/*.styles.ts` | tv 变体映射 |
|
||||
| `apps/docs/content/docs/cn/react/components/(layout)/separator.mdx` 等 | 中文标题、示例次序、API 表 |
|
||||
| `apps/docs/src/demos/cn/{separator,kbd,chip}/` | 演示文案与布局(19 个文档引用示例) |
|
||||
| `packages/react/src/components/kbd/kbd.constants.ts` | KbdKey / 符号 / title 映射 |
|
||||
| `third-party/HEROUI-LICENSE` | 根许可证 Apache-2.0;样式文件头保留来源声明 |
|
||||
|
||||
未迁移(不在文档预览清单):`chip/release-vibrant-palette.tsx`。
|
||||
|
||||
## 3. API 对照
|
||||
|
||||
### Separator
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ---------------------------------- | ---------------------------------------------------------------- | ---------------------- |
|
||||
| `orientation` default `horizontal` | 同名,`horizontal \| vertical` | 一致 |
|
||||
| `variant` default `default` | `default \| secondary \| tertiary` | 一致 |
|
||||
| RAC Separator 语义 | Reka Separator:`role=separator`,vertical 时 `aria-orientation` | 底座替换 |
|
||||
| `render` 自定义根 | `asChild` + 唯一默认插槽根元素 | render prop 不搬入 Vue |
|
||||
| (无) | `decorative` → `role=none`;`as` 默认 `hr` | 与 Reka/RAC 对齐 |
|
||||
| `className` | `class`(Vue 习惯) | 合并进根类 |
|
||||
|
||||
### Kbd
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ------------------------------------------- | ----------------------------------------- | -------------------------------- |
|
||||
| `Kbd.Root` / `variant` | `Kbd` + `KbdAbbr` + `KbdContent` 命名导出 | 不用 `Kbd.Abbr` 对象模式 |
|
||||
| `KbdAbbr.keyValue` → 符号 + `title` | 同名 `keyValue: KbdKey` | 符号不开放覆盖插槽(与上游一致) |
|
||||
| `Kbd.Content` | `KbdContent` | 一致 |
|
||||
| 文档表 `Kbd.Key` / `title` / `children` | 以实现为准:`KbdAbbr.keyValue` | 上游文档与实现不一致,已记录 |
|
||||
| `kbdKeysMap` / `kbdKeysLabelMap` / `KbdKey` | 从 `@heroui-vue/components` 再导出 | 一致 |
|
||||
|
||||
### Chip
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ------------------------------------------------ | --------------------------------------- | -------------------------------------------------- |
|
||||
| `color/size/variant` 默认 `default/md/secondary` | 同名;`size` 默认 `md` | 上游 tv 未写 size 默认值,文档表为 md;本库默认 md |
|
||||
| 纯文本/数字 children 自动包 `<Chip.Label>` | 渲染时判定纯文本/数字插槽 → `ChipLabel` | 同时忽略 Fragment 展开后的 Comment/空白 |
|
||||
| `Chip.Label` | `ChipLabel`,`data-slot=chip-label` | 一致 |
|
||||
| `className` | `class` | 合并 |
|
||||
|
||||
受控/非受控:三组件均为展示组件,无内部状态模型。
|
||||
|
||||
## 4. 示例逐项对照(19 / 19)
|
||||
|
||||
| 文档预览名 | 上游文件 | Vue 文件 | 内容核对 |
|
||||
| ------------------------- | --------------------- | ------------------------------- | ------------------------------- |
|
||||
| separator-basic | `separator/basic.tsx` | `separator-basic.vue` | 标题/说明 + 水平 + 三垂直链 |
|
||||
| separator-variants | `variants.tsx` | `separator-variants.vue` | default/secondary/tertiary 文案 |
|
||||
| separator-with-surface | `with-surface.tsx` | `separator-with-surface.vue` | 4 种 Surface + 对应 Separator |
|
||||
| separator-vertical | `vertical.tsx` | `separator-vertical.vue` | 博客/文档/源码 |
|
||||
| separator-with-content | `with-content.tsx` | `separator-with-content.vue` | 3 条 3D 图标列表 + 间隔分隔 |
|
||||
| separator-render-function | `render-function.tsx` | `separator-render-function.vue` | 自定义根 div + data-custom=foo |
|
||||
| separator-custom-styles | `custom-styles.tsx` | `separator-custom-styles.vue` | 账户设置 + 垂直 h-4 |
|
||||
| kbd-basic | `kbd/basic.tsx` | `kbd-basic.vue` | ⌘K ⇧P ⌃C ⌥D |
|
||||
| kbd-variants | `variants.tsx` | `kbd-variants.vue` | 复制/粘贴/剪切/撤销/重做 双变体 |
|
||||
| kbd-navigation-keys | `navigation.tsx` | `kbd-navigation-keys.vue` | 方向键 + 页面导航 |
|
||||
| kbd-inline-usage | `inline.tsx` | `kbd-inline-usage.vue` | 四句行内快捷键 |
|
||||
| kbd-instructional-text | `instructional.tsx` | `kbd-instructional-text.vue` | 快捷操作列表 |
|
||||
| kbd-special-keys | `special.tsx` | `kbd-special-keys.vue` | Enter/Esc/Tab/Shift+Tab/Space |
|
||||
| kbd-custom-styles | `custom-styles.tsx` | `kbd-custom-styles.vue` | accent-soft / default 两个 |
|
||||
| chip-basic | `chip/basic.tsx` | `chip-basic.vue` | 默认/强调/成功/警告/危险 |
|
||||
| chip-variants | `variants.tsx` | `chip-variants.vue` | 3 尺寸 × 4 变体 × 5 色 + 双图标 |
|
||||
| chip-statuses | `statuses.tsx` | `chip-statuses.vue` | 两行状态点/图标 |
|
||||
| chip-with-icon | `with-icon.tsx` | `chip-with-icon.vue` | 前置图标 ×4 + 尾置 Chevron |
|
||||
| chip-custom-styles | `custom-styles.tsx` | `chip-custom-styles.vue` | 草稿/审核中/已发布 |
|
||||
|
||||
名称与顺序与中文文档一致。图标见 §2/上游记录。
|
||||
|
||||
## 5. 回归场景(两批反复缺陷要求)
|
||||
|
||||
| 要求 | 适用性 | 实际测试 | 结果 |
|
||||
| --------------------------------------------------------------------- | -------------- | -------------------------------------------------------------- | ------------------ |
|
||||
| attrs 渲染期读取:空→新增→修改→删除→再次新增(ARIA/class/style/事件) | 适用(三组件) | Separator / Kbd / Chip 动态 attrs 用例;Chip 事件处理器切换 | 通过 |
|
||||
| h()/渲染显式合并调用方 class(字符串/数组/对象/动态移除) | 适用 | Separator class 三形态;Chip class 动态更新保留 hv-chip 基础类 | 通过 |
|
||||
| 子变体覆盖父级不拼接冲突色类 | 部分适用 | Chip color/variant 单次 tv 求值;无父子色覆盖场景 | 通过(无冲突场景) |
|
||||
| 不用 computed 缓存 slots.default() | 适用(Chip) | 文本↔组合切换、插槽闭包替换 | 通过 |
|
||||
| Fragment/Comment/Text 处理 | 适用(Chip) | 注释+空白+文本;空注释不包装 | 通过 |
|
||||
| 不用 as never/any;合法+非法类型 + dist 声明 | 适用 | `@ts-expect-error` 由 vue-tsc 检查;dist 探针 tsc 通过 | 通过 |
|
||||
| 键盘/事件适配 | 不适用 | 展示组件无激活逻辑 | 未增加无关交互 |
|
||||
| 组件实例当 DOM ref | 不适用 | 无 focus 转发 | — |
|
||||
|
||||
## 6. 命令结果
|
||||
|
||||
| 命令 | 结果 |
|
||||
| ----------------- | ------------------------------------------------ |
|
||||
| `pnpm test` | 126 通过(9 文件;本批 +28) |
|
||||
| `pnpm test:unit` | 125 通过(8 文件,不含 SSR;已列入显式文件列表) |
|
||||
| `pnpm typecheck` | 通过 |
|
||||
| `pnpm build:docs` | 通过 |
|
||||
| `pnpm format` | 通过 |
|
||||
| dist 类型探针 | 通过 |
|
||||
|
||||
未建立/未执行:`test:browser`、`test:visual`、`test:package`。
|
||||
|
||||
## 7. 浏览器证据(127.0.0.1:5173)
|
||||
|
||||
- 视口:自动化会话约 996→574 CSS px;主题:当前 `html.dark`。
|
||||
- Separator:水平 `h=1px`、`w` 随 `max-w-md`;垂直 `1×20px`;`data-orientation`/`role`/`aria-orientation` 正确;asChild 三处 `div[data-custom=foo]`。
|
||||
- Kbd:映射符号与 title 正确;light/default 计数 5/33。
|
||||
- Chip:自动包装 8 个纯文本 Chip;组合内容 `svg+chip-label+svg`;primary-accent 背景 `oklch(0.6204 0.195 253.83)`,soft-accent 半透明 `oklab(.../0.12)`,tertiary 透明。
|
||||
- Avatar:临时分隔线已替换。
|
||||
- 展开/复制/高亮:可用。
|
||||
- API 表:等于父容器宽,无水平溢出(含 Kbd 的 9 行 keyValue 表)。
|
||||
|
||||
限制:主题切换按钮在自动化视口 x=-66 不可点击,浅/深一键切换未形成交互证据;浅/深变量均在样式表中。IAB 截图接口仍无位图。
|
||||
|
||||
## 8. 未验证项
|
||||
|
||||
Nuxt 水合、RTL、触屏、读屏、独立安装 dist 消费、`<400px` 窄屏表格、浅/深切换交互、逐像素视觉对比、`test:browser/visual/package`。
|
||||
|
||||
## 9. 最短复核步骤
|
||||
|
||||
1. `pnpm test && pnpm typecheck && pnpm build:docs`。
|
||||
2. 打开 `http://127.0.0.1:5173/components/separator`:看基本/变体/Surface/垂直/带内容/渲染函数(div 根)/自定义样式;检查 API 表不横向滚动。
|
||||
3. `/components/kbd`:⌘K 标题为 Command;变体页 light 无背景;keyValue 表完整。
|
||||
4. `/components/chip`:基本 5 个标签;变体矩阵图标前后;状态页小圆点;自定义样式三个;展开 chip-basic 复制代码。
|
||||
5. `/components/avatar` 变体区应看到 `hr.hv-separator` 而非临时 div。
|
||||
6. 动态行为以 `tests/separator-kbd-chip.test.ts` 为准;浏览器主题切换与窄屏请人工补测。
|
||||
|
||||
## 10. 需集成人确认
|
||||
|
||||
- 导航顺序(英文字母序插入 Chip/Kbd/Separator)是否符合产品导航约定。
|
||||
- Chip `size` 默认值显式为 `md`(上游 tv 未声明、文档表为 md)。
|
||||
- 上游 Kbd 文档 `Kbd.Key`/`title` 与实现 `KbdAbbr.keyValue` 的差异说明是否足够。
|
||||
|
||||
## 11. 复核返工记录(实施者,2026-10-21)
|
||||
|
||||
独立复核「待修正」唯一问题:
|
||||
|
||||
1. [P2] Separator / Kbd / Chip 三页共 6 处 API 表误写 React `className`,实际只接受 Vue `class`。
|
||||
|
||||
处理:
|
||||
|
||||
- 六处统一改为 `class`,类型写为 `string | Array | Object`,说明遵循 Vue class 绑定并可与基础类合并。
|
||||
- 三页各增加一句「不要使用 React 的 className」;未给实现加 `className` 别名。
|
||||
- 修正本文 `pnpm test:unit` 数量:125(8 文件,不含 SSR),不再写「同上」。
|
||||
- 回归:`tests/separator-kbd-chip.test.ts` 新增「documents Vue class binding instead of React className」,断言三页 API 表无 `className` 行、演示无 `className`、含 Vue class 说明。
|
||||
|
||||
复核人已验证的动态属性/事件/class/插槽/类型结论不重开;浏览器视觉验收仍未由本轮重做。
|
||||
|
||||
实施者不将本文标为“验收通过”。
|
||||
+8
-5
@@ -7,12 +7,13 @@
|
||||
|
||||
## 已移植
|
||||
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton,separator,kbd,chip}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/themes/default/variables.css、themes/shared/theme.css:主题变量、OKLCH 颜色、派生公式和圆角尺寸。
|
||||
- packages/styles/utilities、variants:焦点、禁用、减少动画等构建规则。
|
||||
- packages/styles/src/components/{button,card,input,textarea,switch,surface,link,spinner,close-button,avatar,avatar-group,skeleton}/*.styles.ts:变体与类名映射,增加命名空间。
|
||||
- apps/docs/content/docs/cn/react/components 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton 的标题、说明、示例顺序和 API 描述;React 特有部分转换为 Vue 用法。
|
||||
- apps/docs/src/demos/cn 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton 文档引用的基线示例文案与布局;文档由新项目 SFC 实现。
|
||||
- packages/styles/src/components/{button,card,input,textarea,switch,surface,link,spinner,close-button,avatar,avatar-group,skeleton,separator,kbd,chip}/*.styles.ts:变体与类名映射,增加命名空间。
|
||||
- apps/docs/content/docs/cn/react/components 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip 的标题、说明、示例顺序和 API 描述;React 特有部分转换为 Vue 用法。
|
||||
- apps/docs/src/demos/cn 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip 文档引用的基线示例文案与布局;文档由新项目 SFC 实现。
|
||||
- packages/react/src/components/kbd/kbd.constants.ts 的 KbdKey、kbdKeysMap、kbdKeysLabelMap:按键符号与无障碍 title 映射。
|
||||
- packages/react/src/components/icons.tsx 的 ExternalLinkIcon:LinkIcon 默认外部箭头图标;CloseIcon:CloseButton 默认关闭图标。
|
||||
- packages/react/src/components/spinner/spinner.tsx 的 SpinnerPrimitive SVG(渐变路径)。
|
||||
- apps/docs/public/fonts/Inter-{Regular,Medium,Bold}.ttf:文档字体资源。
|
||||
@@ -34,6 +35,8 @@
|
||||
- Link 自定义图标示例将上游 `@gravity-ui/icons` 的 ArrowUpRightFromSquare / Link 替换为 Tabler `IconExternalLink` / `IconLink`(MIT),与项目图标约定一致。
|
||||
- Spinner 内部 SVG 来自基线 SpinnerPrimitive,不属于演示图标;Button 加载示例改用 Spinner(`color="current" size="sm"`),与上游 CN loading 示例一致。
|
||||
- CloseButton 自定义图标示例将上游 `@gravity-ui/icons` 的 CircleXmark / Xmark 替换为 Tabler `IconCircleX` / `IconX`;默认关闭图标为移植的基线 CloseIcon。
|
||||
- Avatar 回退/变体与 AvatarGroup 自定义样式示例中的 Person 图标替换为 Tabler `IconUser`。Avatar 自定义图片组件示例以本地 FrameworkImage 演示 asChild,对应上游 Next.js Image 组合。Avatar 变体示例中的 Separator 以分隔线 div 适配。
|
||||
- Avatar 回退/变体与 AvatarGroup 自定义样式示例中的 Person 图标替换为 Tabler `IconUser`。Avatar 自定义图片组件示例以本地 FrameworkImage 演示 asChild,对应上游 Next.js Image 组合。Avatar 变体示例中的分隔线使用公共 Separator。
|
||||
- Skeleton 演示沿用上游 `shadow-panel` 与 `animate-shine` 类名,并在文档 utilities.css 中提供对应定义(上游放在 docs global.css)。
|
||||
- Separator `render` 示例改用 Vue `as-child` + 自定义 `div` 根节点,保留 `data-custom="foo"`。
|
||||
- Chip 演示将上游 `@gravity-ui/icons` 的 CircleFill / CircleInfo / Check / TriangleExclamation / Ban / CircleCheckFill / Clock / Xmark / ChevronDown / CircleDashed 替换为 Tabler `IconCircleFilled` / `IconInfoCircle` / `IconCheck` / `IconAlertTriangle` / `IconBan` / `IconCircleCheckFilled` / `IconClock` / `IconX` / `IconChevronDown` / `IconCircleDashed`(MIT)。
|
||||
- 图标统一使用 @tabler/icons-vue(MIT)的官方组件,未移植 React 图标依赖;尚未完成自动逐像素对比。
|
||||
|
||||
@@ -131,3 +131,33 @@
|
||||
3. AvatarGroup props 使用 PropType,非法 size/color/overlap 被 vue-tsc 拒绝。
|
||||
|
||||
`pnpm test` 98 项、typecheck、build:docs、format 通过;浏览器确认自定义 class 保留。文档服务曾退出,已重启于 127.0.0.1:5173。
|
||||
|
||||
## M07–M09 Separator / Kbd / Chip(2026-10-21)
|
||||
|
||||
起始 HEAD `3d05fea`,工作区保留既有 AGENTS.md / migration-handoff.md 修改与 M07-M09-prompt.md。上游只读 `../heroui` @ `ce90ea3`。
|
||||
|
||||
### 命令
|
||||
|
||||
- `pnpm test`:126 项通过(原 98 + 本批 28)。
|
||||
- `pnpm typecheck`:通过(含 `@ts-expect-error` 非法 props 负例)。
|
||||
- `pnpm build:docs`:通过。
|
||||
- `pnpm format`:通过。
|
||||
- dist 类型探针:对 `packages/vue/dist/index.d.ts` 的 Separator/Kbd/Chip 合法与非法值由 tsc 检查通过。
|
||||
|
||||
### 浏览器(127.0.0.1:5173,IAB)
|
||||
|
||||
- Separator 页:`hr` + `role=separator`;垂直 `aria-orientation=vertical`;变体类 `hv-separator--{default,secondary,tertiary}` 与方向类正确;asChild 根为 `div[data-custom=foo]` 且合并组件类;计算样式 1px 高、`--separator` 色、圆角 4px。
|
||||
- Kbd 页:39 个 kbd / 40 个 abbr;`⌘/⇧/⌃/⌥` 等映射与 title(Command/Shift/Control/Option)正确;`hv-kbd--default` 33、`hv-kbd--light` 5。
|
||||
- Chip 页:81 个 chip 均含 1 个 chip-label;基本/自定义样式纯文本自动包装(子节点仅 chip-label);变体矩阵为 icon+label+icon 不重复包装;primary-accent 实色、soft-accent 半透明、tertiary 透明(计算样式记录在交接报告)。
|
||||
- Avatar 页:临时 `div.bg-separator` 已消失,改用 `data-slot=separator`。
|
||||
- 展开/复制:`展开chip-basic`→`收起`;复制后出现已复制反馈;Shiki `--shiki-light` 存在。
|
||||
- 表格:Separator/Kbd/Chip 页 API 表宽等于父容器(534px @ 视口 574),`scrollWidth==clientWidth`,无水平溢出。
|
||||
- 主题:样式表同时含浅色 `--separator: oklch(92%…)` 与深色 `oklch(25%…)` 变量。主题切换按钮在自动化视口中位于 x=-66(不可点击),本轮未完成一键浅/深切换的交互证据;组件类在当前深色下已按变量取色。
|
||||
|
||||
### 未验证
|
||||
|
||||
- 浅/深主题一键切换交互、窄屏(<400px)表格、IAB 位图截图(compositor 限制)、Nuxt 水合、RTL、触屏、读屏、独立安装 dist 消费、`test:browser/visual/package`(未建立)。
|
||||
|
||||
## M07–M09 文档 className 返工(2026-10-21)
|
||||
|
||||
独立复核 1 项 P2:三页 API 表 6 处写 `className`,实现只合并 Vue `class`。已统一改为 `class`(`string | Array | Object`,Vue class 绑定),并注明勿用 React `className`。未加别名。`pnpm test` 127 项(+1 文档契约回归)、typecheck、build:docs、format 通过。复核报告见 `docs/migrations/M07-M09-review.md`;浏览器视觉未重做。
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts",
|
||||
"test:unit": "vitest run tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Base styles */
|
||||
.hv-chip {
|
||||
@apply inline-flex w-fit shrink-0 items-center gap-0.5 rounded-2xl px-2 py-0.5 text-xs leading-5 font-medium;
|
||||
|
||||
/* Default tokens */
|
||||
--chip-bg: var(--default);
|
||||
--chip-fg: currentColor;
|
||||
|
||||
background-color: var(--chip-bg);
|
||||
color: var(--chip-fg);
|
||||
}
|
||||
|
||||
.hv-chip__label {
|
||||
@apply px-0.5;
|
||||
}
|
||||
|
||||
/* Color variants - set foreground color */
|
||||
.hv-chip--accent {
|
||||
--chip-fg: var(--accent-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--danger {
|
||||
--chip-fg: var(--danger-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--default {
|
||||
--chip-fg: var(--default-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--success {
|
||||
--chip-fg: var(--success-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--warning {
|
||||
--chip-fg: var(--warning-soft-foreground);
|
||||
}
|
||||
|
||||
/* Variant styles */
|
||||
.hv-chip--primary {
|
||||
}
|
||||
|
||||
.hv-chip--secondary {
|
||||
/* No additional styles for secondary variant */
|
||||
}
|
||||
|
||||
.hv-chip--tertiary {
|
||||
--chip-bg: transparent;
|
||||
}
|
||||
|
||||
/* Size variants */
|
||||
.hv-chip--sm {
|
||||
@apply px-1 py-0 text-xs;
|
||||
}
|
||||
|
||||
.hv-chip--md {
|
||||
@apply text-xs;
|
||||
}
|
||||
|
||||
.hv-chip--lg {
|
||||
@apply px-3 py-1 text-sm font-medium;
|
||||
}
|
||||
|
||||
/* ====================== */
|
||||
/* = Compound variants = */
|
||||
/* ====================== */
|
||||
|
||||
/* Primary variants - solid backgrounds */
|
||||
.hv-chip--primary.hv-chip--accent {
|
||||
--chip-bg: var(--accent);
|
||||
--chip-fg: var(--accent-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--primary.hv-chip--success {
|
||||
--chip-bg: var(--success);
|
||||
--chip-fg: var(--success-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--primary.hv-chip--warning {
|
||||
--chip-bg: var(--warning);
|
||||
--chip-fg: var(--warning-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--primary.hv-chip--danger {
|
||||
--chip-bg: var(--danger);
|
||||
--chip-fg: var(--danger-foreground);
|
||||
}
|
||||
|
||||
/* Soft variants - muted backgrounds */
|
||||
.hv-chip--accent.hv-chip--soft {
|
||||
--chip-bg: var(--accent-soft);
|
||||
--chip-fg: var(--accent-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--success.hv-chip--soft {
|
||||
--chip-bg: var(--success-soft);
|
||||
--chip-fg: var(--success-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--warning.hv-chip--soft {
|
||||
--chip-bg: var(--warning-soft);
|
||||
--chip-fg: var(--warning-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--danger.hv-chip--soft {
|
||||
--chip-bg: var(--danger-soft);
|
||||
--chip-fg: var(--danger-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-chip--default.hv-chip--soft {
|
||||
--chip-bg: var(--default-soft);
|
||||
--chip-fg: var(--default-soft-foreground);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Base styles */
|
||||
.hv-kbd {
|
||||
@apply inline-flex h-6 items-center space-x-0.5 rounded-lg bg-default px-2 text-center font-sans text-sm font-medium whitespace-nowrap text-muted rtl:space-x-reverse;
|
||||
word-spacing: -0.25rem;
|
||||
}
|
||||
|
||||
/* Key abbreviation styles */
|
||||
.hv-kbd__abbr {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Content wrapper */
|
||||
.hv-kbd__content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Variant styles */
|
||||
.hv-kbd--light {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Base separator with default horizontal orientation */
|
||||
.hv-separator {
|
||||
@apply shrink-0 rounded-sm border-t-0 border-b-0 bg-separator;
|
||||
|
||||
/* Default size - horizontal orientation */
|
||||
@apply h-px w-full;
|
||||
}
|
||||
|
||||
/* Orientation variants */
|
||||
.hv-separator--horizontal {
|
||||
@apply h-px w-full;
|
||||
}
|
||||
|
||||
.hv-separator--vertical {
|
||||
@apply h-auto min-h-2 w-px self-stretch;
|
||||
}
|
||||
|
||||
/* Color variants */
|
||||
.hv-separator--default {
|
||||
@apply bg-separator;
|
||||
}
|
||||
|
||||
.hv-separator--secondary {
|
||||
@apply bg-separator-secondary;
|
||||
}
|
||||
|
||||
.hv-separator--tertiary {
|
||||
@apply bg-separator-tertiary;
|
||||
}
|
||||
@@ -20,6 +20,9 @@
|
||||
@import "./components/avatar.css" layer(components);
|
||||
@import "./components/avatar-group.css" layer(components);
|
||||
@import "./components/skeleton.css" layer(components);
|
||||
@import "./components/separator.css" layer(components);
|
||||
@import "./components/kbd.css" layer(components);
|
||||
@import "./components/chip.css" layer(components);
|
||||
/* The Vue Switch uses Reka's native button for its clickable content. */
|
||||
@layer components {
|
||||
.hv-switch:has(.hv-switch__content:focus-visible) .hv-switch__control {
|
||||
|
||||
@@ -295,3 +295,101 @@ export const skeletonVariants = tv({
|
||||
});
|
||||
|
||||
export type SkeletonVariants = VariantProps<typeof skeletonVariants>;
|
||||
|
||||
export const separatorVariants = tv({
|
||||
base: "hv-separator",
|
||||
defaultVariants: {
|
||||
orientation: "horizontal",
|
||||
variant: "default",
|
||||
},
|
||||
variants: {
|
||||
orientation: {
|
||||
horizontal: "hv-separator--horizontal",
|
||||
vertical: "hv-separator--vertical",
|
||||
},
|
||||
variant: {
|
||||
default: "hv-separator--default",
|
||||
secondary: "hv-separator--secondary",
|
||||
tertiary: "hv-separator--tertiary",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type SeparatorVariants = VariantProps<typeof separatorVariants>;
|
||||
|
||||
export const kbdVariants = tv({
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
slots: {
|
||||
abbr: "hv-kbd__abbr",
|
||||
base: "hv-kbd",
|
||||
content: "hv-kbd__content",
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hv-kbd--default",
|
||||
light: "hv-kbd--light",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type KbdVariants = VariantProps<typeof kbdVariants>;
|
||||
|
||||
export const chipVariants = tv({
|
||||
defaultVariants: {
|
||||
color: "default",
|
||||
size: "md",
|
||||
variant: "secondary",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-chip",
|
||||
label: "hv-chip__label",
|
||||
},
|
||||
variants: {
|
||||
color: {
|
||||
accent: {
|
||||
base: "hv-chip--accent",
|
||||
},
|
||||
danger: {
|
||||
base: "hv-chip--danger",
|
||||
},
|
||||
default: {
|
||||
base: "hv-chip--default",
|
||||
},
|
||||
success: {
|
||||
base: "hv-chip--success",
|
||||
},
|
||||
warning: {
|
||||
base: "hv-chip--warning",
|
||||
},
|
||||
},
|
||||
size: {
|
||||
lg: {
|
||||
base: "hv-chip--lg",
|
||||
},
|
||||
md: {
|
||||
base: "hv-chip--md",
|
||||
},
|
||||
sm: {
|
||||
base: "hv-chip--sm",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
primary: {
|
||||
base: "hv-chip--primary",
|
||||
},
|
||||
secondary: {
|
||||
base: "hv-chip--secondary",
|
||||
},
|
||||
soft: {
|
||||
base: "hv-chip--soft",
|
||||
},
|
||||
tertiary: {
|
||||
base: "hv-chip--tertiary",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type ChipVariants = VariantProps<typeof chipVariants>;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
isVNode,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
type VNode,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { chipVariants, type ChipVariants } from "@heroui-vue/styles";
|
||||
import { chipContextKey } from "./context";
|
||||
import ChipLabel from "./ChipLabel.vue";
|
||||
|
||||
function flattenChildren(
|
||||
nodes: VNodeChild[],
|
||||
out: VNodeChild[] = [],
|
||||
): VNodeChild[] {
|
||||
for (const child of nodes) {
|
||||
if (Array.isArray(child)) {
|
||||
flattenChildren(child, out);
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
isVNode(child) &&
|
||||
child.type === Fragment &&
|
||||
Array.isArray(child.children)
|
||||
) {
|
||||
flattenChildren(child.children as VNodeChild[], out);
|
||||
continue;
|
||||
}
|
||||
out.push(child);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function isIgnorable(node: VNodeChild): boolean {
|
||||
if (node == null || node === false || node === true) return true;
|
||||
if (typeof node === "string") return node.trim() === "";
|
||||
if (typeof node === "number") return false;
|
||||
if (!isVNode(node)) return true;
|
||||
if (node.type === Comment) return true;
|
||||
if (node.type === Text && String(node.children ?? "").trim() === "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** True when the slot is only plain text/number content (auto-wrapped in ChipLabel). */
|
||||
function isPlainTextSlot(nodes: VNodeChild[]): boolean {
|
||||
const meaningful = flattenChildren(nodes).filter(
|
||||
(node) => !isIgnorable(node),
|
||||
);
|
||||
if (meaningful.length === 0) return false;
|
||||
return meaningful.every((node) => {
|
||||
if (typeof node === "number" || typeof node === "string") return true;
|
||||
return isVNode(node) && node.type === Text;
|
||||
});
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "Chip",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
color: {
|
||||
type: String as PropType<ChipVariants["color"]>,
|
||||
default: "default",
|
||||
},
|
||||
size: {
|
||||
type: String as PropType<ChipVariants["size"]>,
|
||||
default: "md",
|
||||
},
|
||||
variant: {
|
||||
type: String as PropType<ChipVariants["variant"]>,
|
||||
default: "secondary",
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const variantSlots = computed(() =>
|
||||
chipVariants({
|
||||
color: props.color,
|
||||
size: props.size,
|
||||
variant: props.variant,
|
||||
}),
|
||||
);
|
||||
|
||||
provide(chipContextKey, { slots: variantSlots });
|
||||
|
||||
/**
|
||||
* Re-read the default slot on every render so text ↔ composed content
|
||||
* switches and parent slot-swap updates stay in sync. Slot-function
|
||||
* identity is not a reactive dependency.
|
||||
*/
|
||||
function render() {
|
||||
const children = (slots.default?.() ?? []) as VNodeChild[];
|
||||
const content: VNodeChild[] = isPlainTextSlot(children)
|
||||
? [
|
||||
h(
|
||||
ChipLabel,
|
||||
{ key: "chip-auto-label" },
|
||||
{ default: () => children },
|
||||
),
|
||||
]
|
||||
: children;
|
||||
|
||||
return h(
|
||||
"span",
|
||||
{
|
||||
...attrs,
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"data-slot": "chip",
|
||||
},
|
||||
content,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, useAttrs } from "vue";
|
||||
import { chipContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(chipContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-bind="attrs" :class="ctx?.slots.value.label()" data-slot="chip-label">
|
||||
<slot />
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { chipVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type ChipSlots = ReturnType<typeof chipVariants>;
|
||||
|
||||
export interface ChipContextValue {
|
||||
slots: ComputedRef<ChipSlots>;
|
||||
}
|
||||
|
||||
export const chipContextKey: InjectionKey<ChipContextValue> =
|
||||
Symbol("HeroUIVue.Chip");
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, useAttrs } from "vue";
|
||||
import { kbdVariants, type KbdVariants } from "@heroui-vue/styles";
|
||||
import { kbdContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant?: KbdVariants["variant"];
|
||||
}>(),
|
||||
{ variant: "default" },
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
|
||||
const slots = computed(() => kbdVariants({ variant: props.variant }));
|
||||
|
||||
provide(kbdContextKey, { slots });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<kbd v-bind="attrs" :class="slots.base()">
|
||||
<slot />
|
||||
</kbd>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { kbdContextKey } from "./context";
|
||||
import { kbdKeysLabelMap, kbdKeysMap, type KbdKey } from "./constants";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
/** The keyboard key to display. */
|
||||
keyValue: KbdKey;
|
||||
}>();
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(kbdContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<abbr
|
||||
v-bind="attrs"
|
||||
:class="ctx?.slots.value.abbr()"
|
||||
:title="kbdKeysLabelMap[props.keyValue]"
|
||||
>
|
||||
{{ kbdKeysMap[props.keyValue] }}
|
||||
</abbr>
|
||||
</template>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { kbdContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(kbdContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-bind="attrs" :class="ctx?.slots.value.content()">
|
||||
<slot />
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
/** Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. */
|
||||
|
||||
export type KbdKey =
|
||||
| "command"
|
||||
| "shift"
|
||||
| "ctrl"
|
||||
| "option"
|
||||
| "enter"
|
||||
| "delete"
|
||||
| "escape"
|
||||
| "tab"
|
||||
| "capslock"
|
||||
| "up"
|
||||
| "right"
|
||||
| "down"
|
||||
| "left"
|
||||
| "pageup"
|
||||
| "pagedown"
|
||||
| "home"
|
||||
| "end"
|
||||
| "help"
|
||||
| "space"
|
||||
| "fn"
|
||||
| "win"
|
||||
| "alt";
|
||||
|
||||
export const kbdKeysMap: Record<KbdKey, string> = {
|
||||
command: "⌘",
|
||||
shift: "⇧",
|
||||
ctrl: "⌃",
|
||||
option: "⌥",
|
||||
enter: "↵",
|
||||
delete: "⌫",
|
||||
escape: "⎋",
|
||||
tab: "⇥",
|
||||
capslock: "⇪",
|
||||
up: "↑",
|
||||
right: "→",
|
||||
down: "↓",
|
||||
left: "←",
|
||||
pageup: "⇞",
|
||||
pagedown: "⇟",
|
||||
home: "↖",
|
||||
end: "↘",
|
||||
help: "?",
|
||||
space: "␣",
|
||||
fn: "Fn",
|
||||
win: "⌘",
|
||||
alt: "⌥",
|
||||
};
|
||||
|
||||
export const kbdKeysLabelMap: Record<KbdKey, string> = {
|
||||
command: "Command",
|
||||
shift: "Shift",
|
||||
ctrl: "Control",
|
||||
option: "Option",
|
||||
enter: "Enter",
|
||||
delete: "Delete",
|
||||
escape: "Escape",
|
||||
tab: "Tab",
|
||||
capslock: "Caps Lock",
|
||||
up: "Up",
|
||||
right: "Right",
|
||||
down: "Down",
|
||||
left: "Left",
|
||||
pageup: "Page Up",
|
||||
pagedown: "Page Down",
|
||||
home: "Home",
|
||||
end: "End",
|
||||
help: "Help",
|
||||
space: "Space",
|
||||
fn: "Fn",
|
||||
win: "Win",
|
||||
alt: "Alt",
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { KbdVariants, kbdVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type KbdSlots = ReturnType<typeof kbdVariants>;
|
||||
|
||||
export interface KbdContextValue {
|
||||
slots: ComputedRef<KbdSlots>;
|
||||
}
|
||||
|
||||
export const kbdContextKey: InjectionKey<KbdContextValue> =
|
||||
Symbol("HeroUIVue.Kbd");
|
||||
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, useAttrs } from "vue";
|
||||
import { Separator as SeparatorPrimitive } from "reka-ui";
|
||||
import { separatorVariants, type SeparatorVariants } from "@heroui-vue/styles";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
orientation?: SeparatorVariants["orientation"];
|
||||
variant?: SeparatorVariants["variant"];
|
||||
/** When true, the separator is decorative (role="none"). */
|
||||
decorative?: boolean;
|
||||
/** Render the root as a custom element instead of `hr`. */
|
||||
as?: string;
|
||||
/** Merge separator props onto the single default-slot element. */
|
||||
asChild?: boolean;
|
||||
}>(),
|
||||
{
|
||||
orientation: "horizontal",
|
||||
variant: "default",
|
||||
decorative: false,
|
||||
as: "hr",
|
||||
asChild: false,
|
||||
},
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
|
||||
const baseClass = computed(() =>
|
||||
separatorVariants({
|
||||
orientation: props.orientation,
|
||||
variant: props.variant,
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SeparatorPrimitive
|
||||
v-bind="attrs"
|
||||
:as="as"
|
||||
:as-child="asChild"
|
||||
:orientation="orientation"
|
||||
:decorative="decorative"
|
||||
:class="baseClass"
|
||||
data-slot="separator"
|
||||
>
|
||||
<slot />
|
||||
</SeparatorPrimitive>
|
||||
</template>
|
||||
@@ -26,6 +26,9 @@ export {
|
||||
avatarVariants,
|
||||
avatarGroupVariants,
|
||||
skeletonVariants,
|
||||
separatorVariants,
|
||||
kbdVariants,
|
||||
chipVariants,
|
||||
type ButtonVariants,
|
||||
type CardVariants,
|
||||
type InputVariants,
|
||||
@@ -38,6 +41,9 @@ export {
|
||||
type AvatarVariants,
|
||||
type AvatarGroupVariants,
|
||||
type SkeletonVariants,
|
||||
type SeparatorVariants,
|
||||
type KbdVariants,
|
||||
type ChipVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ButtonProps,
|
||||
@@ -58,6 +64,12 @@ export type {
|
||||
AvatarGroupProps,
|
||||
AvatarGroupCountProps,
|
||||
SkeletonProps,
|
||||
SeparatorProps,
|
||||
KbdProps,
|
||||
KbdAbbrProps,
|
||||
KbdContentProps,
|
||||
ChipProps,
|
||||
ChipLabelProps,
|
||||
} from "./types";
|
||||
|
||||
export { tv, cn, type VariantProps } from "@heroui-vue/styles";
|
||||
@@ -91,3 +103,25 @@ export {
|
||||
type AvatarSlots,
|
||||
} from "./components/avatar/context";
|
||||
export { default as Skeleton } from "./components/skeleton/Skeleton.vue";
|
||||
|
||||
export { default as Separator } from "./components/separator/Separator.vue";
|
||||
export { default as Kbd } from "./components/kbd/Kbd.vue";
|
||||
export { default as KbdAbbr } from "./components/kbd/KbdAbbr.vue";
|
||||
export { default as KbdContent } from "./components/kbd/KbdContent.vue";
|
||||
export {
|
||||
kbdKeysMap,
|
||||
kbdKeysLabelMap,
|
||||
type KbdKey,
|
||||
} from "./components/kbd/constants";
|
||||
export {
|
||||
kbdContextKey,
|
||||
type KbdContextValue,
|
||||
type KbdSlots,
|
||||
} from "./components/kbd/context";
|
||||
export { default as Chip } from "./components/chip/Chip.vue";
|
||||
export { default as ChipLabel } from "./components/chip/ChipLabel.vue";
|
||||
export {
|
||||
chipContextKey,
|
||||
type ChipContextValue,
|
||||
type ChipSlots,
|
||||
} from "./components/chip/context";
|
||||
|
||||
@@ -38,3 +38,17 @@ import type SwitchGroup from "./components/switch/SwitchGroup.vue";
|
||||
import type Label from "./components/label/Label.vue";
|
||||
export type SwitchGroupProps = InstanceType<typeof SwitchGroup>["$props"];
|
||||
export type LabelProps = InstanceType<typeof Label>["$props"];
|
||||
|
||||
import type Separator from "./components/separator/Separator.vue";
|
||||
import type Kbd from "./components/kbd/Kbd.vue";
|
||||
import type KbdAbbr from "./components/kbd/KbdAbbr.vue";
|
||||
import type KbdContent from "./components/kbd/KbdContent.vue";
|
||||
import type Chip from "./components/chip/Chip.vue";
|
||||
import type ChipLabel from "./components/chip/ChipLabel.vue";
|
||||
|
||||
export type SeparatorProps = InstanceType<typeof Separator>["$props"];
|
||||
export type KbdProps = InstanceType<typeof Kbd>["$props"];
|
||||
export type KbdAbbrProps = InstanceType<typeof KbdAbbr>["$props"];
|
||||
export type KbdContentProps = InstanceType<typeof KbdContent>["$props"];
|
||||
export type ChipProps = InstanceType<typeof Chip>["$props"];
|
||||
export type ChipLabelProps = InstanceType<typeof ChipLabel>["$props"];
|
||||
|
||||
@@ -0,0 +1,682 @@
|
||||
import { describe, it, expect, vi, afterEach } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import {
|
||||
createCommentVNode,
|
||||
createTextVNode,
|
||||
defineComponent,
|
||||
h,
|
||||
nextTick,
|
||||
ref,
|
||||
} from "vue";
|
||||
import { readFileSync } from "node:fs";
|
||||
import {
|
||||
Chip,
|
||||
ChipLabel,
|
||||
Kbd,
|
||||
KbdAbbr,
|
||||
KbdContent,
|
||||
Separator,
|
||||
} from "../packages/vue/src";
|
||||
import { kbdKeysLabelMap, kbdKeysMap } from "../packages/vue/src";
|
||||
import ChipBasicDemo from "../apps/docs/demos/chip-basic.vue";
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
describe("Separator", () => {
|
||||
it("renders a horizontal hr with baseline classes and semantics", () => {
|
||||
const w = mount(Separator);
|
||||
const root = w.get("[data-slot=separator]");
|
||||
expect(root.element.tagName).toBe("HR");
|
||||
expect(root.attributes("role")).toBe("separator");
|
||||
expect(root.attributes("data-orientation")).toBe("horizontal");
|
||||
expect(root.attributes("aria-orientation")).toBeUndefined();
|
||||
expect(root.classes()).toContain("hv-separator");
|
||||
expect(root.classes()).toContain("hv-separator--horizontal");
|
||||
expect(root.classes()).toContain("hv-separator--default");
|
||||
});
|
||||
|
||||
it("applies vertical orientation and variant classes", () => {
|
||||
const w = mount(Separator, {
|
||||
props: { orientation: "vertical", variant: "secondary" },
|
||||
});
|
||||
const root = w.get("[data-slot=separator]");
|
||||
expect(root.attributes("data-orientation")).toBe("vertical");
|
||||
expect(root.attributes("aria-orientation")).toBe("vertical");
|
||||
expect(root.classes()).toContain("hv-separator--vertical");
|
||||
expect(root.classes()).toContain("hv-separator--secondary");
|
||||
});
|
||||
|
||||
it("supports decorative separators and custom as roots", () => {
|
||||
const decorative = mount(Separator, { props: { decorative: true } });
|
||||
expect(decorative.get("[data-slot=separator]").attributes("role")).toBe(
|
||||
"none",
|
||||
);
|
||||
|
||||
const custom = mount(Separator, { props: { as: "div" } });
|
||||
expect(custom.get("[data-slot=separator]").element.tagName).toBe("DIV");
|
||||
});
|
||||
|
||||
it("merges attrs onto the root and updates them dynamically", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Separator },
|
||||
setup() {
|
||||
return { extra };
|
||||
},
|
||||
template: `<Separator v-bind="extra" class="base-sep" />`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
|
||||
let root = w.get("[data-slot=separator]");
|
||||
expect(root.classes()).toContain("hv-separator");
|
||||
expect(root.classes()).toContain("base-sep");
|
||||
expect(root.attributes("aria-label")).toBeUndefined();
|
||||
|
||||
extra.value = { "aria-label": "section", "data-testid": "sep-1" };
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=separator]");
|
||||
expect(root.attributes("aria-label")).toBe("section");
|
||||
expect(root.attributes("data-testid")).toBe("sep-1");
|
||||
|
||||
extra.value = { "aria-label": "updated" };
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=separator]");
|
||||
expect(root.attributes("aria-label")).toBe("updated");
|
||||
expect(root.attributes("data-testid")).toBeUndefined();
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=separator]");
|
||||
expect(root.attributes("aria-label")).toBeUndefined();
|
||||
|
||||
extra.value = { title: "again" };
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=separator]");
|
||||
expect(root.attributes("title")).toBe("again");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("merges caller class strings, arrays and objects", async () => {
|
||||
const classValue = ref<unknown>("extra-a");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Separator },
|
||||
setup() {
|
||||
return { classValue };
|
||||
},
|
||||
template: `<Separator :class="classValue" />`,
|
||||
}),
|
||||
);
|
||||
let classes = w.get("[data-slot=separator]").classes();
|
||||
expect(classes).toContain("hv-separator");
|
||||
expect(classes).toContain("extra-a");
|
||||
|
||||
classValue.value = ["extra-b", { "extra-c": true, "extra-a": false }];
|
||||
await nextTick();
|
||||
classes = w.get("[data-slot=separator]").classes();
|
||||
expect(classes).toContain("hv-separator");
|
||||
expect(classes).toContain("extra-b");
|
||||
expect(classes).toContain("extra-c");
|
||||
expect(classes).not.toContain("extra-a");
|
||||
|
||||
classValue.value = undefined;
|
||||
await nextTick();
|
||||
classes = w.get("[data-slot=separator]").classes();
|
||||
expect(classes).toContain("hv-separator");
|
||||
expect(classes).not.toContain("extra-b");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps orientation and variant classes in sync when props change", async () => {
|
||||
const orientation = ref<"horizontal" | "vertical">("horizontal");
|
||||
const variant = ref<"default" | "secondary" | "tertiary">("default");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Separator },
|
||||
setup() {
|
||||
return { orientation, variant };
|
||||
},
|
||||
template: `<Separator :orientation="orientation" :variant="variant" />`,
|
||||
}),
|
||||
);
|
||||
expect(w.get("[data-slot=separator]").classes()).toContain(
|
||||
"hv-separator--horizontal",
|
||||
);
|
||||
orientation.value = "vertical";
|
||||
variant.value = "tertiary";
|
||||
await nextTick();
|
||||
const classes = w.get("[data-slot=separator]").classes();
|
||||
expect(classes).toContain("hv-separator--vertical");
|
||||
expect(classes).toContain("hv-separator--tertiary");
|
||||
expect(classes).not.toContain("hv-separator--horizontal");
|
||||
expect(classes).not.toContain("hv-separator--default");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("supports asChild custom roots with data attributes", () => {
|
||||
const w = mount(Separator, {
|
||||
props: { asChild: true },
|
||||
slots: { default: () => h("div", { "data-custom": "foo" }) },
|
||||
});
|
||||
const root = w.get("[data-slot=separator]");
|
||||
expect(root.element.tagName).toBe("DIV");
|
||||
expect(root.attributes("data-custom")).toBe("foo");
|
||||
expect(root.classes()).toContain("hv-separator");
|
||||
expect(root.attributes("data-orientation")).toBe("horizontal");
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { Separator: Sep } = await import("../packages/vue/src");
|
||||
// @ts-expect-error orientation must be horizontal | vertical
|
||||
const badOrientation: InstanceType<typeof Sep>["$props"]["orientation"] =
|
||||
"diagonal";
|
||||
// @ts-expect-error variant must be default | secondary | tertiary
|
||||
const badVariant: InstanceType<typeof Sep>["$props"]["variant"] = "ghost";
|
||||
void badOrientation;
|
||||
void badVariant;
|
||||
const ok: InstanceType<typeof Sep>["$props"] = {
|
||||
orientation: "vertical",
|
||||
variant: "tertiary",
|
||||
decorative: true,
|
||||
};
|
||||
expect(ok.orientation).toBe("vertical");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kbd", () => {
|
||||
it("renders default kbd with abbr mapping and content wrapper", () => {
|
||||
const w = mount(Kbd, {
|
||||
slots: {
|
||||
default: () => [
|
||||
h(KbdAbbr, { keyValue: "command" }),
|
||||
h(KbdContent, {}, { default: () => "K" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
const root = w.get("kbd");
|
||||
expect(root.classes()).toContain("hv-kbd");
|
||||
expect(root.classes()).toContain("hv-kbd--default");
|
||||
const abbr = w.get("abbr");
|
||||
expect(abbr.text()).toBe("⌘");
|
||||
expect(abbr.attributes("title")).toBe("Command");
|
||||
expect(abbr.classes()).toContain("hv-kbd__abbr");
|
||||
const content = w.get("span");
|
||||
expect(content.text()).toBe("K");
|
||||
expect(content.classes()).toContain("hv-kbd__content");
|
||||
});
|
||||
|
||||
it("maps every documented keyValue to a symbol and title", () => {
|
||||
for (const [key, symbol] of Object.entries(kbdKeysMap)) {
|
||||
const w = mount(Kbd, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(KbdAbbr, { keyValue: key as keyof typeof kbdKeysMap }),
|
||||
},
|
||||
});
|
||||
expect(w.get("abbr").text()).toBe(symbol);
|
||||
expect(w.get("abbr").attributes("title")).toBe(
|
||||
kbdKeysLabelMap[key as keyof typeof kbdKeysLabelMap],
|
||||
);
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("updates variant and keyValue dynamically", async () => {
|
||||
const variant = ref<"default" | "light">("default");
|
||||
const keyValue = ref<"command" | "shift">("command");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Kbd, KbdAbbr },
|
||||
setup() {
|
||||
return { variant, keyValue };
|
||||
},
|
||||
template: `<Kbd :variant="variant"><KbdAbbr :key-value="keyValue" /></Kbd>`,
|
||||
}),
|
||||
);
|
||||
expect(w.get("kbd").classes()).toContain("hv-kbd--default");
|
||||
expect(w.get("abbr").text()).toBe("⌘");
|
||||
expect(w.get("abbr").attributes("title")).toBe("Command");
|
||||
|
||||
variant.value = "light";
|
||||
keyValue.value = "shift";
|
||||
await nextTick();
|
||||
expect(w.get("kbd").classes()).toContain("hv-kbd--light");
|
||||
expect(w.get("kbd").classes()).not.toContain("hv-kbd--default");
|
||||
expect(w.get("abbr").text()).toBe("⇧");
|
||||
expect(w.get("abbr").attributes("title")).toBe("Shift");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("passes attrs to the right element and updates them dynamically", async () => {
|
||||
const rootExtra = ref<Record<string, unknown>>({});
|
||||
const abbrExtra = ref<Record<string, unknown>>({});
|
||||
const contentExtra = ref<Record<string, unknown>>({});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Kbd, KbdAbbr, KbdContent },
|
||||
setup() {
|
||||
return { rootExtra, abbrExtra, contentExtra };
|
||||
},
|
||||
template: `
|
||||
<Kbd v-bind="rootExtra">
|
||||
<KbdAbbr key-value="enter" v-bind="abbrExtra" />
|
||||
<KbdContent v-bind="contentExtra">Y</KbdContent>
|
||||
</Kbd>
|
||||
`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
|
||||
expect(w.get("kbd").attributes("data-testid")).toBeUndefined();
|
||||
rootExtra.value = { "data-testid": "kbd-root", "aria-label": "shortcut" };
|
||||
abbrExtra.value = { "data-testid": "kbd-abbr" };
|
||||
contentExtra.value = { "data-testid": "kbd-content", title: "letter" };
|
||||
await nextTick();
|
||||
expect(w.get("kbd").attributes("data-testid")).toBe("kbd-root");
|
||||
expect(w.get("kbd").attributes("aria-label")).toBe("shortcut");
|
||||
expect(w.get("abbr").attributes("data-testid")).toBe("kbd-abbr");
|
||||
expect(w.get("span").attributes("data-testid")).toBe("kbd-content");
|
||||
expect(w.get("span").attributes("title")).toBe("letter");
|
||||
|
||||
rootExtra.value = {};
|
||||
await nextTick();
|
||||
expect(w.get("kbd").attributes("data-testid")).toBeUndefined();
|
||||
expect(w.get("kbd").attributes("aria-label")).toBeUndefined();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("merges caller class on all three parts", () => {
|
||||
const w = mount(Kbd, {
|
||||
attrs: { class: "kbd-custom" },
|
||||
slots: {
|
||||
default: () => [
|
||||
h(KbdAbbr, { keyValue: "tab", class: "abbr-custom" }),
|
||||
h(KbdContent, { class: "content-custom" }, { default: () => "T" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(w.get("kbd").classes()).toContain("hv-kbd");
|
||||
expect(w.get("kbd").classes()).toContain("kbd-custom");
|
||||
expect(w.get("abbr").classes()).toContain("hv-kbd__abbr");
|
||||
expect(w.get("abbr").classes()).toContain("abbr-custom");
|
||||
expect(w.get("span").classes()).toContain("hv-kbd__content");
|
||||
expect(w.get("span").classes()).toContain("content-custom");
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { KbdAbbr: Abbr, Kbd: Root } = await import("../packages/vue/src");
|
||||
// @ts-expect-error keyValue must be a known KbdKey
|
||||
const badKey: InstanceType<typeof Abbr>["$props"]["keyValue"] = "nope";
|
||||
// @ts-expect-error variant must be default | light
|
||||
const badVariant: InstanceType<typeof Root>["$props"]["variant"] = "solid";
|
||||
void badKey;
|
||||
void badVariant;
|
||||
const okKey: InstanceType<typeof Abbr>["$props"] = { keyValue: "pageup" };
|
||||
const okRoot: InstanceType<typeof Root>["$props"] = { variant: "light" };
|
||||
expect(okKey.keyValue).toBe("pageup");
|
||||
expect(okRoot.variant).toBe("light");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Chip", () => {
|
||||
it("auto-wraps plain text and number default slots in ChipLabel", () => {
|
||||
const text = mount(Chip, { slots: { default: () => "默认" } });
|
||||
const label = text.get("[data-slot=chip-label]");
|
||||
expect(label.text()).toBe("默认");
|
||||
expect(label.classes()).toContain("hv-chip__label");
|
||||
expect(text.get("[data-slot=chip]").element.childNodes).toHaveLength(1);
|
||||
|
||||
const number = mount(Chip, {
|
||||
slots: { default: () => createTextVNode("42") },
|
||||
});
|
||||
expect(number.get("[data-slot=chip-label]").text()).toBe("42");
|
||||
});
|
||||
|
||||
it("does not double-wrap explicit ChipLabel or composed content", () => {
|
||||
const explicit = mount(Chip, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(ChipLabel, { class: "custom-label" }, { default: () => "标签" }),
|
||||
},
|
||||
});
|
||||
expect(explicit.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(explicit.get("[data-slot=chip-label]").text()).toBe("标签");
|
||||
expect(explicit.get("[data-slot=chip-label]").classes()).toContain(
|
||||
"custom-label",
|
||||
);
|
||||
|
||||
const composed = mount(Chip, {
|
||||
slots: {
|
||||
default: () => [
|
||||
h("span", { class: "icon" }, "•"),
|
||||
h(ChipLabel, {}, { default: () => "组合" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(composed.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(composed.find(".icon").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("switches between plain text and composed slot content dynamically", async () => {
|
||||
const mode = ref<"text" | "composed">("text");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Chip, ChipLabel },
|
||||
setup() {
|
||||
return { mode };
|
||||
},
|
||||
template: `
|
||||
<Chip>
|
||||
<template v-if="mode === 'text'">纯文本</template>
|
||||
<template v-else>
|
||||
<span class="dot">•</span>
|
||||
<ChipLabel>组合</ChipLabel>
|
||||
</template>
|
||||
</Chip>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(w.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("纯文本");
|
||||
expect(w.find(".dot").exists()).toBe(false);
|
||||
|
||||
mode.value = "composed";
|
||||
await nextTick();
|
||||
expect(w.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("组合");
|
||||
expect(w.find(".dot").exists()).toBe(true);
|
||||
|
||||
mode.value = "text";
|
||||
await nextTick();
|
||||
expect(w.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("纯文本");
|
||||
expect(w.find(".dot").exists()).toBe(false);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("ignores comments and whitespace when deciding auto-wrap", () => {
|
||||
const w = mount(Chip, {
|
||||
slots: {
|
||||
default: () => [
|
||||
createCommentVNode("cond"),
|
||||
createTextVNode(" "),
|
||||
createTextVNode("可见文本"),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(w.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("可见文本");
|
||||
|
||||
const empty = mount(Chip, {
|
||||
slots: { default: () => [createCommentVNode("only-comment")] },
|
||||
});
|
||||
expect(empty.findAll("[data-slot=chip-label]")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("applies color, size and variant classes without conflicting overrides", () => {
|
||||
const w = mount(Chip, {
|
||||
props: { color: "accent", size: "lg", variant: "primary" },
|
||||
slots: { default: () => "强调" },
|
||||
});
|
||||
const classes = w.get("[data-slot=chip]").classes();
|
||||
expect(classes).toContain("hv-chip");
|
||||
expect(classes).toContain("hv-chip--accent");
|
||||
expect(classes).toContain("hv-chip--lg");
|
||||
expect(classes).toContain("hv-chip--primary");
|
||||
});
|
||||
|
||||
it("updates variant classes when props change and merges caller class", async () => {
|
||||
const color = ref<"default" | "danger">("default");
|
||||
const classValue = ref<unknown>("chip-custom");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Chip },
|
||||
setup() {
|
||||
return { color, classValue };
|
||||
},
|
||||
template: `<Chip :color="color" :class="classValue">状态</Chip>`,
|
||||
}),
|
||||
);
|
||||
let classes = w.get("[data-slot=chip]").classes();
|
||||
expect(classes).toContain("hv-chip--default");
|
||||
expect(classes).toContain("chip-custom");
|
||||
expect(classes).toContain("hv-chip");
|
||||
|
||||
color.value = "danger";
|
||||
classValue.value = ["chip-custom", { "chip-extra": true }];
|
||||
await nextTick();
|
||||
classes = w.get("[data-slot=chip]").classes();
|
||||
expect(classes).toContain("hv-chip--danger");
|
||||
expect(classes).not.toContain("hv-chip--default");
|
||||
expect(classes).toContain("chip-custom");
|
||||
expect(classes).toContain("chip-extra");
|
||||
expect(classes).toContain("hv-chip");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("passes attrs to the root and updates them dynamically", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Chip },
|
||||
setup() {
|
||||
return { extra };
|
||||
},
|
||||
template: `<Chip v-bind="extra">属性</Chip>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const root = () => w.get("[data-slot=chip]");
|
||||
expect(root().attributes("data-x")).toBeUndefined();
|
||||
|
||||
extra.value = { "data-x": "1", "aria-hidden": "true", title: "t1" };
|
||||
await nextTick();
|
||||
expect(root().attributes("data-x")).toBe("1");
|
||||
expect(root().attributes("aria-hidden")).toBe("true");
|
||||
expect(root().attributes("title")).toBe("t1");
|
||||
|
||||
extra.value = { "data-x": "2" };
|
||||
await nextTick();
|
||||
expect(root().attributes("data-x")).toBe("2");
|
||||
expect(root().attributes("title")).toBeUndefined();
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
expect(root().attributes("data-x")).toBeUndefined();
|
||||
|
||||
extra.value = { "data-y": "again" };
|
||||
await nextTick();
|
||||
expect(root().attributes("data-y")).toBe("again");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("wires events through attrs and switches handlers dynamically", async () => {
|
||||
const first = vi.fn();
|
||||
const second = vi.fn();
|
||||
const handler = ref<((e: Event) => void) | undefined>(first);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Chip },
|
||||
setup() {
|
||||
return { handler };
|
||||
},
|
||||
template: `<Chip @click="handler">事件</Chip>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await w.get("[data-slot=chip]").trigger("click");
|
||||
expect(first).toHaveBeenCalledTimes(1);
|
||||
|
||||
handler.value = second;
|
||||
await nextTick();
|
||||
await w.get("[data-slot=chip]").trigger("click");
|
||||
expect(first).toHaveBeenCalledTimes(1);
|
||||
expect(second).toHaveBeenCalledTimes(1);
|
||||
|
||||
handler.value = undefined;
|
||||
await nextTick();
|
||||
await w.get("[data-slot=chip]").trigger("click");
|
||||
expect(second).toHaveBeenCalledTimes(1);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("replaces the default slot closure and keeps auto-wrap accurate", async () => {
|
||||
const content = ref<"a" | "b" | "composed">("a");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Chip, ChipLabel },
|
||||
setup() {
|
||||
return { content };
|
||||
},
|
||||
template: `
|
||||
<Chip>
|
||||
<template v-if="content === 'a'">A文本</template>
|
||||
<template v-else-if="content === 'b'">B文本</template>
|
||||
<template v-else>
|
||||
<ChipLabel>显式</ChipLabel>
|
||||
</template>
|
||||
</Chip>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("A文本");
|
||||
content.value = "b";
|
||||
await nextTick();
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("B文本");
|
||||
content.value = "composed";
|
||||
await nextTick();
|
||||
expect(w.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=chip-label]").text()).toBe("显式");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("renders the chip-basic demo with auto-wrapped labels", () => {
|
||||
const w = mount(ChipBasicDemo);
|
||||
const chips = w.findAll("[data-slot=chip]");
|
||||
expect(chips).toHaveLength(5);
|
||||
for (const chip of chips) {
|
||||
expect(chip.findAll("[data-slot=chip-label]")).toHaveLength(1);
|
||||
}
|
||||
expect(chips[0].classes()).toContain("hv-chip--default");
|
||||
expect(chips[1].classes()).toContain("hv-chip--accent");
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { Chip: ChipComp } = await import("../packages/vue/src");
|
||||
// @ts-expect-error color must be a known chip color
|
||||
const badColor: InstanceType<typeof ChipComp>["$props"]["color"] = "neon";
|
||||
// @ts-expect-error variant must be a known chip variant
|
||||
const badVariant: InstanceType<typeof ChipComp>["$props"]["variant"] =
|
||||
"ghost";
|
||||
// @ts-expect-error size must be sm | md | lg
|
||||
const badSize: InstanceType<typeof ChipComp>["$props"]["size"] = "xl";
|
||||
void badColor;
|
||||
void badVariant;
|
||||
void badSize;
|
||||
const ok: InstanceType<typeof ChipComp>["$props"] = {
|
||||
color: "success",
|
||||
variant: "soft",
|
||||
size: "sm",
|
||||
};
|
||||
expect(ok.color).toBe("success");
|
||||
});
|
||||
});
|
||||
|
||||
describe("M07–M09 demo inventory", () => {
|
||||
const expected: Record<string, string[]> = {
|
||||
separator: [
|
||||
"basic",
|
||||
"variants",
|
||||
"with-surface",
|
||||
"vertical",
|
||||
"with-content",
|
||||
"render-function",
|
||||
"custom-styles",
|
||||
],
|
||||
kbd: [
|
||||
"basic",
|
||||
"variants",
|
||||
"navigation-keys",
|
||||
"inline-usage",
|
||||
"instructional-text",
|
||||
"special-keys",
|
||||
"custom-styles",
|
||||
],
|
||||
chip: ["basic", "variants", "statuses", "with-icon", "custom-styles"],
|
||||
};
|
||||
|
||||
it("includes every preview from the pinned upstream documents", () => {
|
||||
for (const [docName, names] of Object.entries(expected)) {
|
||||
const document = readFileSync(
|
||||
`apps/docs/components/${docName}.md`,
|
||||
"utf8",
|
||||
);
|
||||
const previewNames = [
|
||||
...document.matchAll(
|
||||
new RegExp(`<ComponentPreview name="${docName}-([^"]+)"`, "g"),
|
||||
),
|
||||
].map((match) => match[1]);
|
||||
expect(previewNames).toEqual(names);
|
||||
for (const name of names) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/${docName}-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
expect(source).toContain("<template>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("uses Tabler icons and library components without self-drawn SVG", () => {
|
||||
const chipDemo = readFileSync("apps/docs/demos/chip-with-icon.vue", "utf8");
|
||||
expect(chipDemo).toContain("@tabler/icons-vue");
|
||||
expect(chipDemo).not.toContain("<path");
|
||||
expect(chipDemo).toContain("ChipLabel");
|
||||
|
||||
const statuses = readFileSync("apps/docs/demos/chip-statuses.vue", "utf8");
|
||||
expect(statuses).toContain("@tabler/icons-vue");
|
||||
expect(statuses).not.toContain("@gravity-ui/icons");
|
||||
|
||||
const kbdDemo = readFileSync("apps/docs/demos/kbd-basic.vue", "utf8");
|
||||
expect(kbdDemo).toContain("KbdAbbr");
|
||||
expect(kbdDemo).toContain("KbdContent");
|
||||
|
||||
const avatar = readFileSync("apps/docs/demos/avatar-variants.vue", "utf8");
|
||||
expect(avatar).toContain("<Separator");
|
||||
expect(avatar).not.toContain('class="h-px w-full bg-separator"');
|
||||
});
|
||||
|
||||
it("keeps chip matrix demos on the library Separator", () => {
|
||||
const variants = readFileSync("apps/docs/demos/chip-variants.vue", "utf8");
|
||||
expect(variants).toContain("Separator");
|
||||
expect(variants).toContain("ChipLabel");
|
||||
expect(variants).not.toContain("@gravity-ui/icons");
|
||||
});
|
||||
|
||||
it("documents Vue class binding instead of React className", () => {
|
||||
for (const docName of ["separator", "kbd", "chip"]) {
|
||||
const document = readFileSync(
|
||||
`apps/docs/components/${docName}.md`,
|
||||
"utf8",
|
||||
);
|
||||
expect(document).not.toMatch(/\|\s*`className`\s*\|/);
|
||||
expect(document).toContain("`class`");
|
||||
expect(document).toContain("Vue class 绑定");
|
||||
expect(document).toMatch(/string\s*\\\|\s*Array\s*\\\|\s*Object/);
|
||||
}
|
||||
for (const name of [
|
||||
"separator-basic",
|
||||
"kbd-basic",
|
||||
"chip-basic",
|
||||
"chip-variants",
|
||||
]) {
|
||||
const source = readFileSync(`apps/docs/demos/${name}.vue`, "utf8");
|
||||
expect(source).not.toContain("className");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user