feat: add ProgressBar ProgressCircle and Meter
This commit is contained in:
@@ -8,3 +8,5 @@ coverage/
|
|||||||
*.tgz
|
*.tgz
|
||||||
**/.vitepress/cache/
|
**/.vitepress/cache/
|
||||||
**/.vitepress/dist/
|
**/.vitepress/dist/
|
||||||
|
|
||||||
|
.playwright-cli/
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ node_modules
|
|||||||
.vitepress/dist
|
.vitepress/dist
|
||||||
**/.vitepress/cache/**
|
**/.vitepress/cache/**
|
||||||
**/.vitepress/dist/**
|
**/.vitepress/dist/**
|
||||||
|
|
||||||
|
.playwright-cli/
|
||||||
|
|||||||
@@ -319,3 +319,10 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
|||||||
- 组 required 不等于每项必选;组无名约束代理不得进入 FormData/Tab。测试实际同名多值、禁用省略、取消 reset、受控拒绝、空组聚焦与新的服务端错误响应。成员 Description/FieldError 必须隔离,同时引用组说明;组 Label 不用 for 指向 div。
|
- 组 required 不等于每项必选;组无名约束代理不得进入 FormData/Tab。测试实际同名多值、禁用省略、取消 reset、受控拒绝、空组聚焦与新的服务端错误响应。成员 Description/FieldError 必须隔离,同时引用组说明;组 Label 不用 for 指向 div。
|
||||||
- CSS 状态属性需要与存在选择器对应,尤其 Radio 的 [data-selected] 未选中时必须移除;默认 RadioIndicator 真实 DOM 要满足 :empty,不能留下插槽注释/空文本导致默认圆点消失。定制 Content 的 data-selected/indeterminate/focus-visible 标记也需验证。
|
- CSS 状态属性需要与存在选择器对应,尤其 Radio 的 [data-selected] 未选中时必须移除;默认 RadioIndicator 真实 DOM 要满足 :empty,不能留下插槽注释/空文本导致默认圆点消失。定制 Content 的 data-selected/indeterminate/focus-visible 标记也需验证。
|
||||||
- Tailwind 嵌套伪元素下 motion-reduce 如生成无效 :not(:is()),采用等价原生 media,保留动效数值和减少动画语义,并记录源样式适配差异。构建 CSS 警告不能忽略。
|
- Tailwind 嵌套伪元素下 motion-reduce 如生成无效 :not(:is()),采用等价原生 media,保留动效数值和减少动画语义,并记录源样式适配差异。构建 CSS 警告不能忽略。
|
||||||
|
|
||||||
|
## M18–M20 之后的标签桥接约定(2026-10-22)
|
||||||
|
|
||||||
|
- 指标类组件的显式 aria-labelledby 必须保留,不能在 v-bind 后绑定 undefined 将其删除。内部 Label 仅作缺省关联,动态引用与多个 ID 都检查真实 DOM。
|
||||||
|
- Label 的显式 ID 优先,自动 ID 按实例唯一;标签注册需清理陈旧引用。标签 ID/for 与组件类型在渲染时读取,不缓存 setup 快照;验证增删、重排、卸载及 SSR/实际水合。
|
||||||
|
- 不同上下文的 Label 有明确所有者。indicator 桥接保存创建时的 fieldScope:当前 indicator 的标签屏蔽外围字段状态,嵌套字段拥有自己的标签。新增其他组合组件前先验证不会让内部 TextField/Choice 标签污染外层名称。
|
||||||
|
- 新组件页同时加入实际 Layout 导航,回归侧栏/移动菜单、选中态和相邻页面;只改 components.md 总览不算导航接入。
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ const groups = [
|
|||||||
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
||||||
{ title: "Label 标签", url: "/components/label" },
|
{ title: "Label 标签", url: "/components/label" },
|
||||||
{ title: "Link 链接", url: "/components/link" },
|
{ title: "Link 链接", url: "/components/link" },
|
||||||
|
{ title: "Meter 计量条", url: "/components/meter" },
|
||||||
|
{ title: "ProgressBar 进度条", url: "/components/progress-bar" },
|
||||||
|
{
|
||||||
|
title: "ProgressCircle 环形进度条",
|
||||||
|
url: "/components/progress-circle",
|
||||||
|
},
|
||||||
{ title: "RadioGroup 单选框组", url: "/components/radio-group" },
|
{ title: "RadioGroup 单选框组", url: "/components/radio-group" },
|
||||||
{ title: "SearchField 搜索框", url: "/components/search-field" },
|
{ title: "SearchField 搜索框", url: "/components/search-field" },
|
||||||
{ title: "Separator 分隔符", url: "/components/separator" },
|
{ title: "Separator 分隔符", url: "/components/separator" },
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ description: 已迁移组件及文档
|
|||||||
- [Kbd 键盘按键](./components/kbd)
|
- [Kbd 键盘按键](./components/kbd)
|
||||||
- [Label 标签](./components/label)
|
- [Label 标签](./components/label)
|
||||||
- [Link 链接](./components/link)
|
- [Link 链接](./components/link)
|
||||||
|
- [Meter 计量条](./components/meter)
|
||||||
|
- [ProgressBar 进度条](./components/progress-bar)
|
||||||
|
- [ProgressCircle 环形进度条](./components/progress-circle)
|
||||||
- [Separator 分隔符](./components/separator)
|
- [Separator 分隔符](./components/separator)
|
||||||
- [Skeleton 骨架屏](./components/skeleton)
|
- [Skeleton 骨架屏](./components/skeleton)
|
||||||
- [Spinner 加载指示器](./components/spinner)
|
- [Spinner 加载指示器](./components/spinner)
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
---
|
||||||
|
title: Meter 计量条
|
||||||
|
description: Meter 表示已知范围内的数量,或一个比例值。
|
||||||
|
component: meter
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter aria-label="存储空间" class="w-64" :value="60">
|
||||||
|
<Label>存储空间</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-basic" />
|
||||||
|
|
||||||
|
## 组件结构
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter :value="60">
|
||||||
|
<Label>Storage</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
`Meter` 渲染为 `role="meter progressbar"` 的容器(与 React Aria Meter 一致,兼容不支持 `meter` 角色的浏览器)。Meter 始终有值,没有不确定进度状态。
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-sizes" />
|
||||||
|
|
||||||
|
### 颜色
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-colors" />
|
||||||
|
|
||||||
|
### 无可见标签
|
||||||
|
|
||||||
|
无需可见标签时,使用 `aria-label` 提供无障碍标签。
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-without-label" />
|
||||||
|
|
||||||
|
### 自定义取值范围与格式
|
||||||
|
|
||||||
|
使用 `minValue`、`maxValue` 与 `formatOptions` 自定义取值范围与显示格式。
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-custom-value" />
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="meter-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
若要自定义组件类,可使用 `@layer components` 指令。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-meter {
|
||||||
|
@apply w-full gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__track {
|
||||||
|
@apply h-3 rounded-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__fill {
|
||||||
|
@apply rounded-full;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
Meter 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/meter.css)):
|
||||||
|
|
||||||
|
#### 基础与元素类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-meter` — 基础容器(grid 布局)
|
||||||
|
- `.hv-meter__output` — 数值文本展示
|
||||||
|
- `.hv-meter__track` — 轨道背景
|
||||||
|
- `.hv-meter__fill` — 轨道已填充部分
|
||||||
|
|
||||||
|
#### 尺寸类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-meter--sm` — 小尺寸变体(更细的轨道)
|
||||||
|
- `.hv-meter--md` — 中等尺寸变体(默认)
|
||||||
|
- `.hv-meter--lg` — 大尺寸变体(更粗的轨道)
|
||||||
|
|
||||||
|
#### 颜色类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-meter--default` — 默认颜色变体
|
||||||
|
- `.hv-meter--accent` — 强调色变体
|
||||||
|
- `.hv-meter--success` — 成功色变体
|
||||||
|
- `.hv-meter--warning` — 警告色变体
|
||||||
|
- `.hv-meter--danger` — 危险色变体
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### Meter
|
||||||
|
|
||||||
|
取值语义与 ProgressBar 相同,但没有 `isIndeterminate`。`role` 为 `meter progressbar`。
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| --------------- | ------------------------------------------------------------- | ---------------------- | -------------------- |
|
||||||
|
| `value` | `number` | `0` | 当前值 |
|
||||||
|
| `minValue` | `number` | `0` | 最小值 |
|
||||||
|
| `maxValue` | `number` | `100` | 最大值 |
|
||||||
|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Meter 轨道尺寸 |
|
||||||
|
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` | 填充条颜色 |
|
||||||
|
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` | 数值展示的格式化选项 |
|
||||||
|
| `valueLabel` | `string \| number` | - | 自定义数值标签内容 |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到根元素 |
|
||||||
|
| 默认插槽 | `{ percentage, valueText }` | - | 内容或作用域插槽 |
|
||||||
|
|
||||||
|
### MeterRenderProps
|
||||||
|
|
||||||
|
| 属性 | 类型 | 描述 |
|
||||||
|
| ------------ | -------- | --------------------- |
|
||||||
|
| `percentage` | `number` | Meter 百分比(0–100) |
|
||||||
|
| `valueText` | `string` | 格式化后的数值文本 |
|
||||||
|
|
||||||
|
作用域插槽同时提供 `isIndeterminate: false`,便于与 ProgressBar 插槽结构复用。
|
||||||
|
|
||||||
|
### MeterOutput
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| -------- | --------------------------- | ------ | --------------------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `span` |
|
||||||
|
| 默认插槽 | - | - | 覆盖默认的 `valueText` 展示 |
|
||||||
|
|
||||||
|
渲染为 `span[data-slot="meter-output"]`。
|
||||||
|
|
||||||
|
### MeterTrack
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| -------- | --------------------------- | ------ | ------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
|
||||||
|
| 默认插槽 | - | - | 通常放置 Fill |
|
||||||
|
|
||||||
|
渲染为 `div[data-slot="meter-track"]`。
|
||||||
|
|
||||||
|
### MeterFill
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ------- | --------------------------- | ------ | -------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
|
||||||
|
| `style` | `StyleValue` | - | 与计算宽度合并 |
|
||||||
|
|
||||||
|
渲染为 `div[data-slot="meter-fill"]`,宽度为 `percentage%`。
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [ProgressBar 进度条](./progress-bar)
|
||||||
|
- [ProgressCircle 环形进度条](./progress-circle)
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
---
|
||||||
|
title: ProgressBar 进度条
|
||||||
|
description: 进度条用于展示某项操作随时间变化的确定或不确定进度。
|
||||||
|
component: progress-bar
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar aria-label="加载中" class="w-64" :value="60">
|
||||||
|
<Label>加载中</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-basic" />
|
||||||
|
|
||||||
|
## 组件结构
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar :value="60">
|
||||||
|
<Label>Loading</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
`ProgressBar` 渲染为 `role="progressbar"` 的容器。默认插槽为作用域插槽,可读取 `percentage`、`valueText`、`isIndeterminate`。`ProgressBarOutput` 在未提供内容时展示格式化后的数值文本。
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-sizes" />
|
||||||
|
|
||||||
|
### 颜色
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-colors" />
|
||||||
|
|
||||||
|
### 无可见标签
|
||||||
|
|
||||||
|
无需可见标签时,使用 `aria-label` 提供无障碍标签。
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-without-label" />
|
||||||
|
|
||||||
|
### 不确定进度
|
||||||
|
|
||||||
|
无法确定进度时使用 `isIndeterminate`。此时不输出 `aria-valuenow`,填充条进入不确定动画。
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-indeterminate" />
|
||||||
|
|
||||||
|
### 自定义数值范围
|
||||||
|
|
||||||
|
使用 `minValue`、`maxValue` 与 `formatOptions` 自定义取值范围与显示格式。
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-custom-value" />
|
||||||
|
|
||||||
|
> 基线差异:上游示例使用 `NumberField` 与 `Select` 调节数值与格式;这两个组件尚未迁移。本示例以原生 `input[type=number]` / `select` 搭配 `hv-input` 样式临时替代,交互与布局对齐基线,控件本身不是本库已发布的 NumberField/Select。
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-bar-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
若要自定义组件类,可使用 `@layer components` 指令。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-progress-bar {
|
||||||
|
@apply w-full gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__track {
|
||||||
|
@apply h-3 rounded-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__fill {
|
||||||
|
@apply rounded-full;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
ProgressBar 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/progress-bar.css)):
|
||||||
|
|
||||||
|
#### 基础与元素类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-bar` - 基础容器(网格布局)
|
||||||
|
- `.hv-progress-bar__output` - 数值文本展示
|
||||||
|
- `.hv-progress-bar__track` - 轨道背景
|
||||||
|
- `.hv-progress-bar__fill` - 轨道上已填充部分
|
||||||
|
|
||||||
|
#### 尺寸类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-bar--sm` - 小尺寸变体(更细的轨道)
|
||||||
|
- `.hv-progress-bar--md` - 中等尺寸变体(默认)
|
||||||
|
- `.hv-progress-bar--lg` - 大尺寸变体(更粗的轨道)
|
||||||
|
|
||||||
|
#### 颜色类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-bar--default` - 默认颜色变体
|
||||||
|
- `.hv-progress-bar--accent` - 强调色变体
|
||||||
|
- `.hv-progress-bar--success` - 成功色变体
|
||||||
|
- `.hv-progress-bar--warning` - 警告色变体
|
||||||
|
- `.hv-progress-bar--danger` - 危险色变体
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### ProgressBar
|
||||||
|
|
||||||
|
进度取值与格式化语义对齐 React Aria ProgressBar:`value` 会夹在 `[minValue, maxValue]`;`formatOptions.style` 为 `percent` 时格式化 0–1 比例,否则格式化夹紧后的原值。
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ----------------- | ------------------------------------------------------------- | ---------------------- | -------------------------------------------------- |
|
||||||
|
| `value` | `number` | `0` | 当前值 |
|
||||||
|
| `minValue` | `number` | `0` | 最小值 |
|
||||||
|
| `maxValue` | `number` | `100` | 最大值 |
|
||||||
|
| `isIndeterminate` | `boolean` | `false` | 是否为不确定进度;为 true 时不输出 `aria-valuenow` |
|
||||||
|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 进度轨道尺寸 |
|
||||||
|
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` | 填充条颜色 |
|
||||||
|
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` | 数值展示的数字格式 |
|
||||||
|
| `valueLabel` | `string \| number` | - | 自定义数值标签内容,覆盖默认格式化文本 |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到根元素 |
|
||||||
|
| 默认插槽 | `{ percentage, valueText, isIndeterminate }` | - | 内容或作用域插槽 |
|
||||||
|
|
||||||
|
`$attrs` 落到根元素。无 `aria-label` / `aria-labelledby` 时,根元素通过 `aria-labelledby` 关联内部 `Label`。
|
||||||
|
|
||||||
|
### ProgressBarRenderProps
|
||||||
|
|
||||||
|
默认作用域插槽提供:
|
||||||
|
|
||||||
|
| 属性 | 类型 | 描述 |
|
||||||
|
| ----------------- | --------------------- | ------------------------------------------- |
|
||||||
|
| `percentage` | `number \| undefined` | 进度百分比(0–100);不确定时为 `undefined` |
|
||||||
|
| `valueText` | `string \| undefined` | 格式化后的数值文本 |
|
||||||
|
| `isIndeterminate` | `boolean` | 是否为不确定进度 |
|
||||||
|
|
||||||
|
### ProgressBarOutput
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| -------- | --------------------------- | ------ | --------------------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `span` |
|
||||||
|
| 默认插槽 | - | - | 覆盖默认的 `valueText` 展示 |
|
||||||
|
|
||||||
|
渲染为 `span[data-slot="progress-bar-output"]`。
|
||||||
|
|
||||||
|
### ProgressBarTrack
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| -------- | --------------------------- | ------ | ------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
|
||||||
|
| 默认插槽 | - | - | 通常放置 Fill |
|
||||||
|
|
||||||
|
渲染为 `div[data-slot="progress-bar-track"]`。
|
||||||
|
|
||||||
|
### ProgressBarFill
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ------- | --------------------------- | ------ | -------------- |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
|
||||||
|
| `style` | `StyleValue` | - | 与计算宽度合并 |
|
||||||
|
|
||||||
|
渲染为 `div[data-slot="progress-bar-fill"]`。确定进度时宽度为 `percentage%`;不确定进度时不设置宽度,由 CSS 动画驱动。
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [ProgressCircle 环形进度条](./progress-circle)
|
||||||
|
- [Meter 计量条](./meter)
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
---
|
||||||
|
title: ProgressCircle 环形进度条
|
||||||
|
description: 环形进度指示器,用于展示确定或不确定的进度。
|
||||||
|
component: progress-circle
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle aria-label="加载中" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-basic" />
|
||||||
|
|
||||||
|
## 组件结构
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle aria-label="Loading" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
`ProgressCircle` 渲染为 `role="progressbar"` 的容器。`ProgressCircleTrack` 是 SVG 轨道,`TrackCircle` / `FillCircle` 分别为背景圆环与进度弧。默认几何为 viewBox `0 0 36 36`、圆心 18、半径 16、描边 4。
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-sizes" />
|
||||||
|
|
||||||
|
### 颜色
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-colors" />
|
||||||
|
|
||||||
|
### 不确定进度
|
||||||
|
|
||||||
|
无法确定进度时使用 `isIndeterminate`。此时不输出 `aria-valuenow`,轨道进入旋转动画。
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-indeterminate" />
|
||||||
|
|
||||||
|
### 带标签
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-with-label" />
|
||||||
|
|
||||||
|
### 自定义 SVG 属性
|
||||||
|
|
||||||
|
各子部分均为可组合组件,可直接覆盖 `strokeWidth`、`r`、`cx`、`cy`、`viewBox` 等 SVG 属性。
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-custom-svg" />
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="progress-circle-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
若要自定义组件类,可使用 `@layer components` 指令。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-progress-circle {
|
||||||
|
@apply inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle__track {
|
||||||
|
@apply size-12;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle__fill-circle {
|
||||||
|
stroke: purple;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
ProgressCircle 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/progress-circle.css)):
|
||||||
|
|
||||||
|
#### 基础与元素类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-circle` - 基础容器
|
||||||
|
- `.hv-progress-circle__track` - SVG 元素
|
||||||
|
- `.hv-progress-circle__track-circle` - 背景圆环
|
||||||
|
- `.hv-progress-circle__fill-circle` - 进度弧
|
||||||
|
|
||||||
|
#### 尺寸类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-circle--sm` - 小尺寸
|
||||||
|
- `.hv-progress-circle--md` - 中等尺寸(默认)
|
||||||
|
- `.hv-progress-circle--lg` - 大尺寸
|
||||||
|
|
||||||
|
#### 颜色类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-progress-circle--default` - 默认颜色
|
||||||
|
- `.hv-progress-circle--accent` - 强调色
|
||||||
|
- `.hv-progress-circle--success` - 成功色
|
||||||
|
- `.hv-progress-circle--warning` - 警告色
|
||||||
|
- `.hv-progress-circle--danger` - 危险色
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### ProgressCircle
|
||||||
|
|
||||||
|
取值与格式化语义与 ProgressBar 相同。`children` 的渲染 prop 在 Vue 中改为默认作用域插槽。
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ----------------- | ------------------------------------------------------------- | ---------------------- | ------------------ |
|
||||||
|
| `value` | `number` | `0` | 当前值 |
|
||||||
|
| `minValue` | `number` | `0` | 最小值 |
|
||||||
|
| `maxValue` | `number` | `100` | 最大值 |
|
||||||
|
| `isIndeterminate` | `boolean` | `false` | 是否为不确定进度 |
|
||||||
|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 圆环尺寸 |
|
||||||
|
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` | 进度弧颜色 |
|
||||||
|
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` | 数值展示格式 |
|
||||||
|
| `valueLabel` | `string \| number` | - | 自定义数值标签内容 |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到根元素 |
|
||||||
|
| 默认插槽 | `{ percentage, valueText, isIndeterminate }` | - | 内容或作用域插槽 |
|
||||||
|
|
||||||
|
### ProgressBarRenderProps
|
||||||
|
|
||||||
|
| 属性 | 类型 | 描述 |
|
||||||
|
| ----------------- | --------------------- | ------------------- |
|
||||||
|
| `percentage` | `number \| undefined` | 进度百分比(0–100) |
|
||||||
|
| `valueText` | `string \| undefined` | 格式化后的数值文案 |
|
||||||
|
| `isIndeterminate` | `boolean` | 是否为不确定进度 |
|
||||||
|
|
||||||
|
### ProgressCircleTrack
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| --------- | --------------------------- | ------------- | -------------- |
|
||||||
|
| `viewBox` | `string` | `"0 0 36 36"` | SVG 视口 |
|
||||||
|
| `fill` | `string` | `"none"` | SVG fill |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `svg` |
|
||||||
|
| 默认插槽 | - | - | 放置圆环子部件 |
|
||||||
|
|
||||||
|
渲染为 `svg[data-slot="progress-circle-track"]`。
|
||||||
|
|
||||||
|
### ProgressCircleTrackCircle
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ------------- | --------------------------- | ------ | --------------- |
|
||||||
|
| `cx` / `cy` | `string \| number` | `18` | 圆心 |
|
||||||
|
| `r` | `string \| number` | `16` | 半径 |
|
||||||
|
| `strokeWidth` | `string \| number` | `4` | 描边宽度 |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `circle` |
|
||||||
|
|
||||||
|
渲染为 `circle[data-slot="progress-circle-track-circle"]`。
|
||||||
|
|
||||||
|
### ProgressCircleFillCircle
|
||||||
|
|
||||||
|
| 属性 | 类型 | 默认值 | 描述 |
|
||||||
|
| ------------------ | --------------------------- | --------- | ------------------------------ |
|
||||||
|
| `cx` / `cy` | `string \| number` | `18` | 圆心 |
|
||||||
|
| `r` | `string \| number` | `16` | 半径 |
|
||||||
|
| `strokeWidth` | `string \| number` | `4` | 描边宽度 |
|
||||||
|
| `strokeDasharray` | `string \| number` | 周长 | 虚线数组 |
|
||||||
|
| `strokeDashoffset` | `string \| number` | 按进度 | 虚线偏移;不确定时为周长的 75% |
|
||||||
|
| `strokeLinecap` | `string` | `"round"` | 线帽 |
|
||||||
|
| `transform` | `string` | 旋转 -90° | 变换 |
|
||||||
|
| `class` | `string \| Array \| Object` | - | 合并到 `circle` |
|
||||||
|
|
||||||
|
渲染为 `circle[data-slot="progress-circle-fill-circle"]`。
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [ProgressBar 进度条](./progress-bar)
|
||||||
|
- [Meter 计量条](./meter)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter aria-label="存储空间" class="w-64" :value="60">
|
||||||
|
<Label>存储空间</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const colors = ["default", "accent", "success", "warning", "danger"] as const;
|
||||||
|
|
||||||
|
const colorLabels: Record<(typeof colors)[number], string> = {
|
||||||
|
accent: "强调",
|
||||||
|
danger: "危险",
|
||||||
|
default: "默认",
|
||||||
|
success: "成功",
|
||||||
|
warning: "警告",
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-64 flex-col gap-6">
|
||||||
|
<Meter v-for="color in colors" :key="color" :color="color" :value="50">
|
||||||
|
<Label>{{ colorLabels[color] }}</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter aria-label="已用存储空间" class="w-64" :value="68">
|
||||||
|
<Label class="font-medium text-foreground">已用存储空间</Label>
|
||||||
|
<MeterOutput class="text-muted tabular-nums" />
|
||||||
|
<MeterTrack class="rounded-full bg-default">
|
||||||
|
<MeterFill class="rounded-full bg-warning" />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter
|
||||||
|
class="w-64"
|
||||||
|
:format-options="{ currency: 'USD', style: 'currency' }"
|
||||||
|
:max-value="1000"
|
||||||
|
:min-value="0"
|
||||||
|
:value="750"
|
||||||
|
>
|
||||||
|
<Label>收入</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const sizeRows = [
|
||||||
|
{ color: "success" as const, label: "小", size: "sm" as const, value: 40 },
|
||||||
|
{ color: "accent" as const, label: "中", size: "md" as const, value: 60 },
|
||||||
|
{ color: "warning" as const, label: "大", size: "lg" as const, value: 80 },
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-64 flex-col gap-6">
|
||||||
|
<Meter
|
||||||
|
v-for="row in sizeRows"
|
||||||
|
:key="row.size"
|
||||||
|
:color="row.color"
|
||||||
|
:size="row.size"
|
||||||
|
:value="row.value"
|
||||||
|
>
|
||||||
|
<Label>{{ row.label }}</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Meter, MeterFill, MeterTrack } from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter aria-label="存储空间用量" class="w-64" :value="45">
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar aria-label="加载中" class="w-64" :value="60">
|
||||||
|
<Label>加载中</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const colors = ["default", "accent", "success", "warning", "danger"] as const;
|
||||||
|
|
||||||
|
const colorLabels: Record<(typeof colors)[number], string> = {
|
||||||
|
accent: "强调",
|
||||||
|
danger: "危险",
|
||||||
|
default: "默认",
|
||||||
|
success: "成功",
|
||||||
|
warning: "警告",
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-64 flex-col gap-6">
|
||||||
|
<ProgressBar
|
||||||
|
v-for="color in colors"
|
||||||
|
:key="color"
|
||||||
|
:aria-label="colorLabels[color]"
|
||||||
|
:color="color"
|
||||||
|
:value="50"
|
||||||
|
>
|
||||||
|
<Label>{{ colorLabels[color] }}</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar aria-label="上传进度" class="w-64" :value="45">
|
||||||
|
<Label class="font-medium text-foreground">正在上传 resume.pdf</Label>
|
||||||
|
<ProgressBarOutput class="text-xs text-muted tabular-nums" />
|
||||||
|
<ProgressBarTrack class="rounded-full bg-default">
|
||||||
|
<ProgressBarFill class="rounded-full bg-accent" />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from "vue";
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
Separator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const value = ref(750);
|
||||||
|
const minValue = ref(0);
|
||||||
|
const maxValue = ref(1000);
|
||||||
|
const format = ref("percent");
|
||||||
|
|
||||||
|
const formatStyleOptions = [
|
||||||
|
{ label: "货币", value: "currency" },
|
||||||
|
{ label: "百分比", value: "percent" },
|
||||||
|
{ label: "小数", value: "decimal" },
|
||||||
|
{ label: "单位", value: "unit" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const formatOptionsMap: Record<string, Intl.NumberFormatOptions> = {
|
||||||
|
currency: { currency: "USD", style: "currency" },
|
||||||
|
decimal: { style: "decimal" },
|
||||||
|
percent: { style: "percent" },
|
||||||
|
unit: { style: "unit", unit: "mile" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatOptions = computed(() => formatOptionsMap[format.value]);
|
||||||
|
|
||||||
|
function onValueChange(event: Event) {
|
||||||
|
const next = Number((event.target as HTMLInputElement).value);
|
||||||
|
value.value = Math.min(Math.max(next, minValue.value), maxValue.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMinChange(event: Event) {
|
||||||
|
const next = Number((event.target as HTMLInputElement).value);
|
||||||
|
minValue.value = Math.min(next, maxValue.value - 1);
|
||||||
|
if (value.value < minValue.value) value.value = minValue.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMaxChange(event: Event) {
|
||||||
|
const next = Number((event.target as HTMLInputElement).value);
|
||||||
|
maxValue.value = Math.max(next, minValue.value + 1);
|
||||||
|
if (value.value > maxValue.value) value.value = maxValue.value;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6 md:flex-row md:items-center md:gap-10">
|
||||||
|
<div class="flex w-full max-w-md flex-1 justify-center">
|
||||||
|
<ProgressBar
|
||||||
|
aria-label="收入"
|
||||||
|
class="w-full max-w-52"
|
||||||
|
:format-options="formatOptions"
|
||||||
|
:max-value="maxValue"
|
||||||
|
:min-value="minValue"
|
||||||
|
:value="value"
|
||||||
|
>
|
||||||
|
<Label>进度</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator class="md:hidden" />
|
||||||
|
<Separator class="hidden md:block" orientation="vertical" />
|
||||||
|
|
||||||
|
<div class="flex max-w-52 flex-col gap-3">
|
||||||
|
<Label class="text-xs font-medium text-muted">选项</Label>
|
||||||
|
|
||||||
|
<Label for="pb-cv-value">值</Label>
|
||||||
|
<input
|
||||||
|
id="pb-cv-value"
|
||||||
|
class="hv-input hv-input--secondary hv-input--full-width"
|
||||||
|
type="number"
|
||||||
|
:min="minValue"
|
||||||
|
:max="maxValue"
|
||||||
|
:value="value"
|
||||||
|
@change="onValueChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label for="pb-cv-min">最小值</Label>
|
||||||
|
<input
|
||||||
|
id="pb-cv-min"
|
||||||
|
class="hv-input hv-input--secondary hv-input--full-width"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
:max="maxValue - 1"
|
||||||
|
:value="minValue"
|
||||||
|
@change="onMinChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label for="pb-cv-max">最大值</Label>
|
||||||
|
<input
|
||||||
|
id="pb-cv-max"
|
||||||
|
class="hv-input hv-input--secondary hv-input--full-width"
|
||||||
|
type="number"
|
||||||
|
:min="minValue + 1"
|
||||||
|
max="2000"
|
||||||
|
:value="maxValue"
|
||||||
|
@change="onMaxChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label for="pb-cv-format">格式</Label>
|
||||||
|
<select
|
||||||
|
id="pb-cv-format"
|
||||||
|
v-model="format"
|
||||||
|
class="hv-input hv-input--secondary hv-input--full-width"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
v-for="option in formatStyleOptions"
|
||||||
|
:key="option.value"
|
||||||
|
:value="option.value"
|
||||||
|
>
|
||||||
|
{{ option.label }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar is-indeterminate aria-label="加载中" class="w-64">
|
||||||
|
<Label>加载中…</Label>
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const sizeRows = [
|
||||||
|
{ label: "小", size: "sm" as const, value: 40 },
|
||||||
|
{ label: "中", size: "md" as const, value: 60 },
|
||||||
|
{ label: "大", size: "lg" as const, value: 80 },
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-64 flex-col gap-6">
|
||||||
|
<ProgressBar
|
||||||
|
v-for="row in sizeRows"
|
||||||
|
:key="row.size"
|
||||||
|
:aria-label="row.label"
|
||||||
|
:size="row.size"
|
||||||
|
:value="row.value"
|
||||||
|
>
|
||||||
|
<Label>{{ row.label }}</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar aria-label="加载进度" class="w-64" :value="45">
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle aria-label="加载中" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const colors = ["default", "accent", "success", "warning", "danger"] as const;
|
||||||
|
|
||||||
|
const colorLabels: Record<(typeof colors)[number], string> = {
|
||||||
|
accent: "强调",
|
||||||
|
danger: "危险",
|
||||||
|
default: "默认",
|
||||||
|
success: "成功",
|
||||||
|
warning: "警告",
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-6">
|
||||||
|
<ProgressCircle
|
||||||
|
v-for="color in colors"
|
||||||
|
:key="color"
|
||||||
|
:aria-label="colorLabels[color]"
|
||||||
|
:color="color"
|
||||||
|
:value="60"
|
||||||
|
>
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle
|
||||||
|
aria-label="同步进度"
|
||||||
|
class="size-14 text-neutral-700 dark:text-neutral-300"
|
||||||
|
:value="68"
|
||||||
|
>
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle
|
||||||
|
class="stroke-neutral-200 dark:stroke-neutral-800"
|
||||||
|
/>
|
||||||
|
<ProgressCircleFillCircle
|
||||||
|
class="stroke-neutral-700 dark:stroke-neutral-300"
|
||||||
|
stroke-linecap="round"
|
||||||
|
/>
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex items-end gap-6">
|
||||||
|
<ProgressCircle aria-label="细圆环" :value="60">
|
||||||
|
<ProgressCircleTrack :stroke-width="2" view-box="0 0 36 36">
|
||||||
|
<ProgressCircleTrackCircle
|
||||||
|
:cx="18"
|
||||||
|
:cy="18"
|
||||||
|
:r="17"
|
||||||
|
:stroke-width="2"
|
||||||
|
/>
|
||||||
|
<ProgressCircleFillCircle :cx="18" :cy="18" :r="17" :stroke-width="2" />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
|
||||||
|
<ProgressCircle aria-label="默认圆环" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
|
||||||
|
<ProgressCircle aria-label="粗圆环" :value="60">
|
||||||
|
<ProgressCircleTrack :stroke-width="6" view-box="0 0 36 36">
|
||||||
|
<ProgressCircleTrackCircle
|
||||||
|
:cx="18"
|
||||||
|
:cy="18"
|
||||||
|
:r="15"
|
||||||
|
:stroke-width="6"
|
||||||
|
/>
|
||||||
|
<ProgressCircleFillCircle :cx="18" :cy="18" :r="15" :stroke-width="6" />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle is-indeterminate aria-label="加载中">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const sizeRows = [
|
||||||
|
{ ariaLabel: "小", size: "sm" as const, value: 40 },
|
||||||
|
{ ariaLabel: "中", size: "md" as const, value: 60 },
|
||||||
|
{ ariaLabel: "大", size: "lg" as const, value: 80 },
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-6">
|
||||||
|
<ProgressCircle
|
||||||
|
v-for="row in sizeRows"
|
||||||
|
:key="row.size"
|
||||||
|
:aria-label="row.ariaLabel"
|
||||||
|
:size="row.size"
|
||||||
|
:value="row.value"
|
||||||
|
>
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<ProgressCircle aria-label="加载中" :value="75">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
<Label>已完成 75%</Label>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| drawer | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| drawer | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| progress-bar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||||
| progress-circle | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| disclosure | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| disclosure | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| disclosure-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| disclosure-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
| number-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| number-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| pagination | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| pagination | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| select | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| select | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| meter | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||||
| slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# M18–M20 集成人复核(2026-10-22)
|
||||||
|
|
||||||
|
范围:e4d817c 后的 ProgressBar / ProgressCircle / Meter。初次复核未改实现;返工后集成人补充了标签作用域隔离与三项回归测试。未逐页打开浏览器。
|
||||||
|
|
||||||
|
当前结论:返工后四项 P2 已关闭,额外发现的嵌套字段标签污染也已修复。最终验证见文末。
|
||||||
|
|
||||||
|
## 初次复核结论(历史)
|
||||||
|
|
||||||
|
暂不通过,四项 P2 需返工。现有 307 项测试和构建通过,但未覆盖以下命名关联、共享 Label 回归与导航集成场景。
|
||||||
|
|
||||||
|
### P2-1:显式 aria-labelledby 被三个 Root 删除
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/{progress-bar/ProgressBar,progress-circle/ProgressCircle,meter/Meter}.vue` 的 ariaLabelledby 计算与模板绑定;例如 ProgressBar.vue:60–64、77。
|
||||||
|
|
||||||
|
计算逻辑发现 attrs 中已有 aria-labelledby 时返回 undefined,模板却在 v-bind=attrs 后再次绑定 aria-labelledby=undefined,覆盖并删除调用方的属性。独立用例分别验证了三个 Root,传 aria-labelledby="external-label" 后 DOM 属性均为 undefined。这使外部标签命名失效,违反文档的 attrs 透传契约。
|
||||||
|
|
||||||
|
修复时保留显式 ARIA 引用;内部 Label 仅作缺省关联。测试静态显式 ID、多个引用 ID、aria-label/aria-labelledby 的优先级,以及空→增→改→删→再增。不要只验证 aria-label。
|
||||||
|
|
||||||
|
### P2-2:indicator 标签 ID 管理忽略调用方 id,并产生重复 ID
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/label/Label.vue:21–25、39` 与 `progress/value.ts` 的 indicatorLabelContextKey/provideIndicatorLabel。
|
||||||
|
|
||||||
|
当前每个 Label 都无条件使用同一个 indicatorLabel.labelId,优先级还高于 attrs.id。独立验证 `<ProgressBar><Label id="my-label">...</Label></ProgressBar>`,真实 id 变成自动 v-0,用户 ID 被忽略;两个 Label 同处一根时实际出现两个相同 ID。hasLabel 布尔值不是每实例注册表,且 Root 并未使用它,移除 Label 后引用也没有清理依据。
|
||||||
|
|
||||||
|
保留显式 id,自动 ID 按实例唯一;Root 关联实际存在的 Label,考虑多个标签的合并、动态 id 和卸载清理。若仅支持一个 Label,必须有清晰约束/诊断,不能静默生成重复 ID。SSR 首屏也要验证实际 for/ARIA 引用均可解析,不能只正则判断“存在某个 id”。不得用每次挂载后换 ID 的方式制造水合差异。跨组件桥接改动需要回归现有 Label/字段场景。
|
||||||
|
|
||||||
|
### P2-3:Label 的标签类型变成 setup 快照,破坏已有动态 for
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/label/Label.vue:27–32`。
|
||||||
|
|
||||||
|
原先 tag 判断在模板中每次渲染读取 attrs.for,本批改成 setup 常量 tag。独立用例:Checkbox 的 Content 旁有 Label,初始无 for 为 span;父组件随后增加 for="target",Label 仍为 SPAN,没有恢复原生 label/for 激活语义。该问题属于已有组件回归,不只是进度组件的新能力差异。
|
||||||
|
|
||||||
|
恢复渲染时读取 attrs.for 的判断,并验证 for 空→新增→修改→删除→再增、真实元素类型及关联激活。不要在无响应式依赖的 computed 中再次缓存 attrs 快照;保持 TextField/Choice/Switch 既有语义。
|
||||||
|
|
||||||
|
### P2-4:三页未接入实际文档导航
|
||||||
|
|
||||||
|
位置:`apps/docs/.vitepress/theme/Layout.vue` 的 groups/items(组件列表约第 48–81 行)。
|
||||||
|
|
||||||
|
仅在 apps/docs/components.md 总览添加链接,Layout 的实际侧栏/移动导航仍无 Meter、ProgressBar、ProgressCircle。相邻页导航也复用这份列表,当前三页 currentIndex=-1,无法提供正确的上一页/下一页。交接报告把总览增量描述为“导航”,但没有完成默认文档入口集成。
|
||||||
|
|
||||||
|
把三页加入实际导航,保持既有排序,检查桌面侧栏/移动菜单、选中态和相邻页目标;不需要重写布局。增加导航契约检查,避免新增页面只在总览可见。
|
||||||
|
|
||||||
|
## 独立验证
|
||||||
|
|
||||||
|
- `pnpm test`:18 文件 / 307 项通过,包含 node SSR 7 项;`pnpm typecheck` 通过。
|
||||||
|
- `pnpm build:docs` 通过,仅既有 chunk >500kB 提醒。
|
||||||
|
- 三份 CSS 还原 hv- 类名前缀和关键帧名、去注释与空白后,与固定 ce90ea3 基线一致。
|
||||||
|
- 临时专项 6 项均复现预期失败:三种 Root 的显式 aria-labelledby、重复 Label ID、显式 Label ID、已有 Checkbox Label 动态 for。探针验证后移除,不计入正式 307 项。
|
||||||
|
- `pnpm format` 与 `git diff --check` 通过。
|
||||||
|
|
||||||
|
没有据实施者浏览器记录宣称集成人完成视觉、读屏、RTL、触屏、Nuxt 或独立安装验收。本轮不因现有套件通过就提交。
|
||||||
|
|
||||||
|
## 交回要求
|
||||||
|
|
||||||
|
修复四项,补真实 DOM/ARIA/ID/激活与导航回归,同步三个交接报告和 verification 最终计数。新旧标签协议需保持清楚的优先级与作用域,不能让进度上下文污染内层 TextField/Choice 标签。保留原有 NumberField/Select 临时替代与未验证项说明。
|
||||||
|
|
||||||
|
## 返工后独立复核与集成修正(2026-10-22)
|
||||||
|
|
||||||
|
- 显式 aria-labelledby 在三个 Root 保留;多个引用、内部 Label 自动 ID 与显式 ID 的原文行为已核对。
|
||||||
|
- Label 的 for 在渲染时读取,动态 span/label 切换恢复;真实侧栏列表及相邻页顺序已加入三页,契约测试通过。
|
||||||
|
- 独立验证标签动态 ID 删除/替换、稳定 key 重排、移除全部标签再添加:ARIA 引用与实际 ID 集合一致,无陈旧引用或重复 ID。
|
||||||
|
- 额外发现:Label 不分字段所有权注册到 indicator 时,嵌套 TextField 的标签会进入进度名称。集成人在 indicator 注册上下文捕获外层 fieldScope,以引用身份判断最近的标签所有者:indicator 的标签不继承外围 TextField/Choice 状态,嵌套字段的标签仍归自己的字段,不向外层 indicator 注册。
|
||||||
|
- 新增三项正式回归:标签重排/移除/改 ID、内外层字段作用域隔离、实际 SSR→水合后的引用解析与标签移除。覆盖三个 indicator Root,水合 console warn/error 为空。
|
||||||
|
- 最终 `pnpm test`:18 文件 / 316 项,含 node SSR 7 项;`pnpm test:unit`:17 文件 / 309 项,不含 node SSR,包含 jsdom 实际水合。
|
||||||
|
- typecheck、build:docs、format、diff-check 通过。build:docs 仅既有文档 chunk 大小提醒。
|
||||||
|
- 20 份演示挂载、6 份 Markdown 原文 SFC 与 fixture 一致性/编译挂载由正式测试覆盖。dist 公共类型正反消费探针另行通过后移除,不计入测试数量。
|
||||||
|
|
||||||
|
本轮没有新增逐页浏览器、逐像素、读屏/RTL/触屏、Nuxt 或独立安装验收。上方初次“暂不通过”和失败结果作为历史保留,不代表仍有未修的 P2。
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
# M18 ProgressBar 交接报告
|
||||||
|
|
||||||
|
实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。**
|
||||||
|
|
||||||
|
## 1. 起点与范围
|
||||||
|
|
||||||
|
| 项 | 值 |
|
||||||
|
| ---------- | ----------------------------------------------------------------------------- |
|
||||||
|
| 起始 HEAD | `e4d817c`(feat: add Typography EmptyState and Breadcrumbs) |
|
||||||
|
| 工作区起点 | 干净;无未提交修改 |
|
||||||
|
| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) |
|
||||||
|
| 范围 | ProgressBar、Output、Track、Fill、样式/tv、导出/类型、7 个示例、文档与测试 |
|
||||||
|
|
||||||
|
未修改 field/\*、choice/\*、Form、Fieldset、SearchField、Switch、Button、Link 核心协议。`Label.vue` 仅增加可选的 indicator 标签关联(见下文),不影响字段协议。
|
||||||
|
|
||||||
|
## 2. 上游核对
|
||||||
|
|
||||||
|
- 实际导出:对象式 `ProgressBar` 带 `Root` / `Output` / `Track` / `Fill`,同时命名导出 `ProgressBarRoot` 等。Vue 使用四个具名导出:`ProgressBar`、`ProgressBarOutput`、`ProgressBarTrack`、`ProgressBarFill`。
|
||||||
|
- 底座为 RAC `ProgressBar`。取值语义来自 `@react-aria/progress` 的 `useProgressBar`:
|
||||||
|
- `value` 夹紧到 `[minValue, maxValue]`(默认 0–100)。
|
||||||
|
- `percentage = (value - min) / (max - min) * 100`(不确定时无百分比)。
|
||||||
|
- `formatOptions` 默认 `{ style: "percent" }`;percent 格式化 0–1 比例,其他 style 格式化夹紧后的原值。
|
||||||
|
- `aria-valuenow` 为夹紧后的原值;不确定时省略 `aria-valuenow` / `aria-valuetext`。
|
||||||
|
- `role="progressbar"`。
|
||||||
|
- tv:`progressBarVariants` 提供 `base` / `output` / `track` / `fill`,变体 `size`(sm/md/lg)与 `color`(default/accent/success/warning/danger)。
|
||||||
|
- CSS:`packages/styles/components/progress-bar.css` 的网格布局、轨道高度、填充色、不确定动画 `translateX`、`motion-reduce` 与禁用状态均按基线移植为 `hv-` 命名空间;关键帧改名为 `hv-progress-bar-indeterminate`。
|
||||||
|
- 文档/示例:CN `progress-bar.mdx`,7 个示例:`basic`、`sizes`、`colors`、`without-label`、`indeterminate`、`custom-value`、`custom-styles`。
|
||||||
|
|
||||||
|
## 3. Vue 实现与 API 对照
|
||||||
|
|
||||||
|
| 上游 | Vue |
|
||||||
|
| ------------------------ | ----------------------------------------------------------- |
|
||||||
|
| `ProgressBar` / `.Root` | `ProgressBar` |
|
||||||
|
| `ProgressBar.Output` | `ProgressBarOutput` |
|
||||||
|
| `ProgressBar.Track` | `ProgressBarTrack` |
|
||||||
|
| `ProgressBar.Fill` | `ProgressBarFill` |
|
||||||
|
| `children` / render prop | 默认作用域插槽 `{ percentage, valueText, isIndeterminate }` |
|
||||||
|
| `valueLabel: ReactNode` | `valueLabel?: string \| number` |
|
||||||
|
| `className` | `class` |
|
||||||
|
| RAC `formatOptions` | 同名属性 `Intl.NumberFormatOptions` |
|
||||||
|
|
||||||
|
公共属性:
|
||||||
|
|
||||||
|
| ProgressBar | 类型 | 默认值 |
|
||||||
|
| ----------------- | ------------------------------------------------------------- | ---------------------- |
|
||||||
|
| `value` | `number` | `0` |
|
||||||
|
| `minValue` | `number` | `0` |
|
||||||
|
| `maxValue` | `number` | `100` |
|
||||||
|
| `isIndeterminate` | `boolean` | `false` |
|
||||||
|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` |
|
||||||
|
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` |
|
||||||
|
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` |
|
||||||
|
| `valueLabel` | `string \| number` | - |
|
||||||
|
| `class` | `string \| Array \| Object` | - |
|
||||||
|
| 默认插槽 | `{ percentage, valueText, isIndeterminate }` | - |
|
||||||
|
|
||||||
|
行为落点:
|
||||||
|
|
||||||
|
- 根 `div[data-slot="progress-bar"]`,`role="progressbar"`,始终输出 `aria-valuemin` / `aria-valuemax`;确定进度输出 `aria-valuenow`(夹紧值)与 `aria-valuetext`;不确定进度省略二者,CSS `&:not([aria-valuenow])` 启用动画。
|
||||||
|
- 无 `aria-label` / `aria-labelledby` 时,根通过 `aria-labelledby` 关联内部 `Label` 的 `id`。显式 `aria-label` 优先,不输出 `aria-labelledby`。
|
||||||
|
- `ProgressBarOutput` 默认展示 `valueText`;默认插槽可覆盖。`ProgressBarFill` 在确定进度设置 `width: percentage%`,不确定时不设宽度。
|
||||||
|
- 调用方 `class` 由 Vue 与根/子部件基础类合并;`$attrs` 落到对应根元素。
|
||||||
|
|
||||||
|
## 4. 示例对照
|
||||||
|
|
||||||
|
| 基线 | Vue 演示 | 状态 |
|
||||||
|
| ------------- | -------------------------------- | ---------------------------------------------------------------------------- |
|
||||||
|
| basic | `progress-bar-basic.vue` | 已迁移;Label + aria-label + Output/Track/Fill |
|
||||||
|
| sizes | `progress-bar-sizes.vue` | 已迁移;sm/md/lg 三行 |
|
||||||
|
| colors | `progress-bar-colors.vue` | 已迁移;五色 |
|
||||||
|
| without-label | `progress-bar-without-label.vue` | 已迁移;仅 aria-label |
|
||||||
|
| indeterminate | `progress-bar-indeterminate.vue` | 已迁移;无 Output,不确定动画 |
|
||||||
|
| custom-value | `progress-bar-custom-value.vue` | **部分差异**:NumberField/Select 未迁移,改用原生 number/select + `hv-input` |
|
||||||
|
| custom-styles | `progress-bar-custom-styles.vue` | 已迁移 |
|
||||||
|
|
||||||
|
custom-value 保留了同一布局(左预览 + 分隔符 + 右侧选项面板)、文案、默认值 750/0/1000 与四种格式;控件本身不是本库已发布的 NumberField/Select,文档已标注。
|
||||||
|
|
||||||
|
## 5. 变更文件
|
||||||
|
|
||||||
|
新增:
|
||||||
|
|
||||||
|
- `packages/vue/src/components/progress/value.ts`(共享取值/标签上下文)
|
||||||
|
- `packages/vue/src/components/progress-bar/{ProgressBar,ProgressBarOutput,ProgressBarTrack,ProgressBarFill}.vue`
|
||||||
|
- `packages/styles/components/progress-bar.css`
|
||||||
|
- `apps/docs/components/progress-bar.md`
|
||||||
|
- `apps/docs/demos/progress-bar-*.vue`(7)
|
||||||
|
- `tests/fixtures/m18m20-progress-bar-doc-{0,1}.vue`(文档 SFC 提取)
|
||||||
|
|
||||||
|
共享增量:
|
||||||
|
|
||||||
|
- `packages/styles/src/index.ts`:`progressBarVariants`
|
||||||
|
- `packages/styles/index.css`:progress-bar / progress-circle / meter 入口
|
||||||
|
- `packages/vue/src/index.ts`、`packages/vue/src/types.ts`:组件与 Props 导出
|
||||||
|
- `packages/vue/src/components/label/Label.vue`:可选 indicator 标签关联(span + id)
|
||||||
|
- `apps/docs/components.md`:导航
|
||||||
|
- `tests/progress-meter.test.ts`:M18–M20 行为与演示测试
|
||||||
|
- `tests/ssr.test.ts`:进度/计量 SSR 用例
|
||||||
|
- `package.json`:`test:unit` 增加 `progress-meter.test.ts`
|
||||||
|
- `.gitignore` / `.prettierignore`:忽略 `.playwright-cli/`
|
||||||
|
|
||||||
|
## 6. 验证结果
|
||||||
|
|
||||||
|
| 入口 | 文件数 | 通过数 | 含 SSR |
|
||||||
|
| ---------------- | ------ | ------ | ----------- |
|
||||||
|
| `pnpm test` | 18 | 307 | 是(SSR 7) |
|
||||||
|
| `pnpm test:unit` | 17 | 300 | 否 |
|
||||||
|
|
||||||
|
- `pnpm typecheck` 通过。
|
||||||
|
- `pnpm build:docs` 通过,仅既有 chunk >500kB 提醒。
|
||||||
|
- `pnpm format`、`git diff --check` 通过。
|
||||||
|
- 本批新增:`tests/progress-meter.test.ts` 16 项(组件行为 + 20 演示挂载 + 文档 SFC 提取编译挂载),`ssr.test.ts` +1。
|
||||||
|
- 浏览器 127.0.0.1:5173(实施者自测):13 个 ProgressBar 实例 ARIA/宽度正确;不确定进度无 `aria-valuenow` 且动画名为 `hv-progress-bar-indeterminate`;sm/lg 轨道计算高度 4px/12px;custom-value 交互 250→25%、currency 格式生效;深色下 track 背景切换。API 表桌面 736px / 窄屏 350px,无横向溢出。
|
||||||
|
|
||||||
|
## 7. 已知差异与未验证项
|
||||||
|
|
||||||
|
- custom-value 的 NumberField/Select 为原生临时控件,不是已迁移组件。
|
||||||
|
- `valueLabel` 为 `string | number`,不是任意 ReactNode;复杂内容用 Output 默认插槽。
|
||||||
|
- 输出文本随 `Intl` 运行时 locale 变化(如 USD 在非 en-US 下为 `US$750.00`),与 React Aria 一致。
|
||||||
|
- 未验证:逐像素视觉、读屏、RTL、触屏、Nuxt 水合、独立安装 dist、`test:browser`/`test:visual`/`test:package`。
|
||||||
|
- 未使用 Reka Progress:其 `modelValue`/`max` 无 `minValue`/`formatOptions`/`valueLabel`,且默认 `aria-label` 覆盖调用方标签;差异见 M18–M20 共同说明。
|
||||||
|
|
||||||
|
## 8. 供集成人复核的最短路径
|
||||||
|
|
||||||
|
1. 打开 `http://127.0.0.1:5173/components/progress-bar`。
|
||||||
|
2. 确认 basic 的 Output 为 `60%`,填充宽度约 60%;indeterminate 无 `aria-valuenow` 且在动。
|
||||||
|
3. 在 custom-value 将值改为 250,输出变为 `25%`(percent)或 `US$250.00`(currency,随 locale)。
|
||||||
|
4. 运行 `npx --yes pnpm@11.25.0 test` 与 `test:unit`,核对 307 / 300。
|
||||||
|
|
||||||
|
## 返工记录(2026-10-22,对照 M18-M20-review.md)
|
||||||
|
|
||||||
|
四项 P2 已修复,未提交/推送:
|
||||||
|
|
||||||
|
1. **显式 aria-labelledby 不再被删除**:Root 仅在解析结果非 `undefined` 时写入该属性;调用方显式值原样保留。空→增→改→删→再增 有回归。
|
||||||
|
2. **Label ID**:显式 `id` 优先;自动 ID 为每实例 `useId()`(多 Label 唯一)。Root 在渲染时遍历默认插槽为 Label 分配稳定 ID(显式 ID 保留),并与嵌套注册表合并写入 `aria-labelledby`。SSR 首屏引用可解析,不依赖挂载后换 ID。
|
||||||
|
3. **Label 动态 `for`**:标签类型在渲染时读取 `attrs.for`,不再用 setup 快照。`for` 空→增→改→删→再增 时在 `span`/`label` 间正确切换;字段/Choice/Switch 既有场景全量回归通过。
|
||||||
|
4. **文档导航**:三页已加入 `Layout.vue` 组件组(Link → Meter → ProgressBar → ProgressCircle → RadioGroup),桌面侧栏/移动菜单与上一页/下一页生效。
|
||||||
|
|
||||||
|
计数:`pnpm test` 18 文件 / **313**(SSR 7);`pnpm test:unit` 17 文件 / **306**。typecheck / build:docs / format / git diff --check 通过。
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
# M19 ProgressCircle 交接报告
|
||||||
|
|
||||||
|
实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。**
|
||||||
|
|
||||||
|
与 M18/M20 同批交付,共享取值语义见 [M18-progress-bar.md](./M18-progress-bar.md) 第 2–3 节。本报告只写环形特有部分。
|
||||||
|
|
||||||
|
## 1. 起点与范围
|
||||||
|
|
||||||
|
| 项 | 值 |
|
||||||
|
| --------- | ----------------------------------------------------------------------------- |
|
||||||
|
| 起始 HEAD | `e4d817c` |
|
||||||
|
| 范围 | ProgressCircle、Track、TrackCircle、FillCircle、样式/tv、7 个示例、文档与测试 |
|
||||||
|
|
||||||
|
## 2. 上游核对
|
||||||
|
|
||||||
|
- 底座同为 RAC `ProgressBar`,视觉为 SVG 圆环。
|
||||||
|
- 几何常量(`progress-circle.tsx`):`STROKE_WIDTH=4`、`CENTER=18`、`RADIUS=16`、`CIRCUMFERENCE=2πR`。
|
||||||
|
- FillCircle:`strokeDasharray=C`,`strokeDashoffset = C - percentage/100 * C`;不确定时 offset=`0.75C`;`strokeLinecap="round"`;`transform="rotate(-90 18 18)"`。
|
||||||
|
- Track 默认 `viewBox="0 0 36 36"`、`fill="none"`。
|
||||||
|
- 不确定时对 `.progress-circle__track` 应用 `progress-circle-spin` 旋转动画(CSS `&:not([aria-valuenow])`)。
|
||||||
|
- tv:`progressCircleVariants` slots `base` / `track` / `trackCircle` / `fillCircle`;size/color 与 ProgressBar 相同。
|
||||||
|
- 文档/示例:CN `progress-circle.mdx`,7 个示例:`basic`、`sizes`、`colors`、`indeterminate`、`with-label`、`custom-svg`、`custom-styles`。
|
||||||
|
|
||||||
|
## 3. Vue 实现与 API 对照
|
||||||
|
|
||||||
|
| 上游 | Vue |
|
||||||
|
| ---------------------------- | ----------------------------------------------------------- |
|
||||||
|
| `ProgressCircle` / `.Root` | `ProgressCircle` |
|
||||||
|
| `ProgressCircle.Track` | `ProgressCircleTrack` |
|
||||||
|
| `ProgressCircle.TrackCircle` | `ProgressCircleTrackCircle` |
|
||||||
|
| `ProgressCircle.FillCircle` | `ProgressCircleFillCircle` |
|
||||||
|
| render prop children | 默认作用域插槽 `{ percentage, valueText, isIndeterminate }` |
|
||||||
|
| SVG props 透传 | 同名 `cx`/`cy`/`r`/`strokeWidth`/`viewBox` 等 attrs |
|
||||||
|
|
||||||
|
公共属性与 ProgressBar 的 value/minValue/maxValue/isIndeterminate/formatOptions/valueLabel/size/color/class 相同。ProgressCircle 没有 Output 子部件;`valueLabel` 仍影响 `aria-valuetext`。
|
||||||
|
|
||||||
|
子部件默认几何均可被 attrs 覆盖(custom-svg 示例的 r=17/15、strokeWidth=2/6 已验证)。`strokeDasharray` / `strokeDashoffset` / `transform` / `strokeLinecap` 同样可覆盖。
|
||||||
|
|
||||||
|
## 4. 示例对照
|
||||||
|
|
||||||
|
| 基线 | Vue 演示 | 状态 |
|
||||||
|
| ------------- | ----------------------------------- | ------------------------ |
|
||||||
|
| basic | `progress-circle-basic.vue` | 已迁移 |
|
||||||
|
| sizes | `progress-circle-sizes.vue` | 已迁移 |
|
||||||
|
| colors | `progress-circle-colors.vue` | 已迁移 |
|
||||||
|
| indeterminate | `progress-circle-indeterminate.vue` | 已迁移 |
|
||||||
|
| with-label | `progress-circle-with-label.vue` | 已迁移;Label 为兄弟节点 |
|
||||||
|
| custom-svg | `progress-circle-custom-svg.vue` | 已迁移;三组几何覆盖 |
|
||||||
|
| custom-styles | `progress-circle-custom-styles.vue` | 已迁移 |
|
||||||
|
|
||||||
|
## 5. 变更文件
|
||||||
|
|
||||||
|
新增:`packages/vue/src/components/progress-circle/{ProgressCircle,ProgressCircleTrack,ProgressCircleTrackCircle,ProgressCircleFillCircle,constants}.vue`(constants.ts)、`packages/styles/components/progress-circle.css`、`apps/docs/components/progress-circle.md`、`apps/docs/demos/progress-circle-*.vue`(7)、`tests/fixtures/m18m20-progress-circle-doc-{0,1}.vue`。共享增量同 M18。
|
||||||
|
|
||||||
|
## 6. 验证结果
|
||||||
|
|
||||||
|
同批计数:`pnpm test` 18 文件 / 307(SSR 7);`pnpm test:unit` 17 文件 / 300。typecheck / build:docs / format 通过。
|
||||||
|
|
||||||
|
浏览器自测(127.0.0.1:5173):默认几何 r=16 / stroke-width=4;60% 的 dashoffset≈40.21(0.4C);不确定 ≈75.40(0.75C)且无 `aria-valuenow`;custom-svg 的 r=17/15 生效;fill stroke 为 accent、track stroke 为 default;`size-7` 轨道计算宽 28px。
|
||||||
|
|
||||||
|
## 7. 已知差异与未验证项
|
||||||
|
|
||||||
|
- SVG 属性在 SSR HTML 中可能小写序列化(如 `viewbox`),HTML 解析仍识别为 `viewBox`;客户端属性名正确。
|
||||||
|
- with-label 示例的 Label 是兄弟节点,不走根内 `aria-labelledby` 关联(示例自带 `aria-label`)。
|
||||||
|
- 其余未验证项与 M18 相同(逐像素、读屏、RTL、Nuxt、独立安装等)。
|
||||||
|
|
||||||
|
## 8. 供集成人复核的最短路径
|
||||||
|
|
||||||
|
1. 打开 `/components/progress-circle`。
|
||||||
|
2. 确认 indeterminate 在旋转且无 `aria-valuenow`;custom-svg 三环粗细不同。
|
||||||
|
3. 运行同批测试命令核对 307 / 300。
|
||||||
|
|
||||||
|
## 返工记录(2026-10-22,对照 M18-M20-review.md)
|
||||||
|
|
||||||
|
四项 P2 已修复,未提交/推送:
|
||||||
|
|
||||||
|
1. **显式 aria-labelledby 不再被删除**:Root 仅在解析结果非 `undefined` 时写入该属性;调用方显式值原样保留。空→增→改→删→再增 有回归。
|
||||||
|
2. **Label ID**:显式 `id` 优先;自动 ID 为每实例 `useId()`(多 Label 唯一)。Root 在渲染时遍历默认插槽为 Label 分配稳定 ID(显式 ID 保留),并与嵌套注册表合并写入 `aria-labelledby`。SSR 首屏引用可解析,不依赖挂载后换 ID。
|
||||||
|
3. **Label 动态 `for`**:标签类型在渲染时读取 `attrs.for`,不再用 setup 快照。`for` 空→增→改→删→再增 时在 `span`/`label` 间正确切换;字段/Choice/Switch 既有场景全量回归通过。
|
||||||
|
4. **文档导航**:三页已加入 `Layout.vue` 组件组(Link → Meter → ProgressBar → ProgressCircle → RadioGroup),桌面侧栏/移动菜单与上一页/下一页生效。
|
||||||
|
|
||||||
|
计数:`pnpm test` 18 文件 / **313**(SSR 7);`pnpm test:unit` 17 文件 / **306**。typecheck / build:docs / format / git diff --check 通过。
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
# M20 Meter 交接报告
|
||||||
|
|
||||||
|
实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。**
|
||||||
|
|
||||||
|
与 M18/M19 同批交付,共享取值语义见 [M18-progress-bar.md](./M18-progress-bar.md)。本报告只写测量语义与差异。
|
||||||
|
|
||||||
|
## 1. 起点与范围
|
||||||
|
|
||||||
|
| 项 | 值 |
|
||||||
|
| --------- | --------------------------------------------------------- |
|
||||||
|
| 起始 HEAD | `e4d817c` |
|
||||||
|
| 范围 | Meter、Output、Track、Fill、样式/tv、6 个示例、文档与测试 |
|
||||||
|
|
||||||
|
## 2. 上游核对
|
||||||
|
|
||||||
|
- 底座为 RAC `Meter`;实现上复用 `useProgressBar` 后覆盖 `role`。
|
||||||
|
- `useMeter` 的真实 role 为 **`meter progressbar`**(兼容不支持 `meter` 的浏览器),不是纯 `meter`。
|
||||||
|
- **没有 `isIndeterminate`**:Meter 始终有值,始终输出 `aria-valuenow` / `aria-valuetext`。
|
||||||
|
- 取值夹紧、percentage、formatOptions 语义与 ProgressBar 相同。
|
||||||
|
- tv:`meterVariants` slots `base` / `output` / `track` / `fill`;size/color 同 ProgressBar。
|
||||||
|
- CSS 与 ProgressBar 布局一致(网格 label/output/track),但无不确定动画;填充变量为 `--meter-fill`。
|
||||||
|
- 文档/示例:CN `meter.mdx`,6 个示例:`basic`、`sizes`、`colors`、`without-label`、`custom-value`、`custom-styles`。
|
||||||
|
|
||||||
|
## 3. Vue 实现与 API 对照
|
||||||
|
|
||||||
|
| 上游 | Vue |
|
||||||
|
| ----------------------- | ------------------------------------------------------------------ |
|
||||||
|
| `Meter` / `.Root` | `Meter` |
|
||||||
|
| `Meter.Output` | `MeterOutput` |
|
||||||
|
| `Meter.Track` | `MeterTrack` |
|
||||||
|
| `Meter.Fill` | `MeterFill` |
|
||||||
|
| render prop children | 默认作用域插槽 `{ percentage, valueText, isIndeterminate: false }` |
|
||||||
|
| `valueLabel: ReactNode` | `valueLabel?: string \| number` |
|
||||||
|
|
||||||
|
公共属性:
|
||||||
|
|
||||||
|
| Meter | 类型 | 默认值 |
|
||||||
|
| --------------- | ------------------------------------------------------------- | ---------------------- |
|
||||||
|
| `value` | `number` | `0` |
|
||||||
|
| `minValue` | `number` | `0` |
|
||||||
|
| `maxValue` | `number` | `100` |
|
||||||
|
| `size` | `"sm" \| "md" \| "lg"` | `"md"` |
|
||||||
|
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` |
|
||||||
|
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` |
|
||||||
|
| `valueLabel` | `string \| number` | - |
|
||||||
|
| `class` | `string \| Array \| Object` | - |
|
||||||
|
| 默认插槽 | `{ percentage, valueText, isIndeterminate }` | - |
|
||||||
|
|
||||||
|
行为落点:
|
||||||
|
|
||||||
|
- 根 `div[data-slot="meter"]`,`role="meter progressbar"`。
|
||||||
|
- 始终输出 `aria-valuenow`(夹紧值)与 `aria-valuetext`;无不确定状态。
|
||||||
|
- Label 关联与 ProgressBar 相同(无显式 aria-label 时用 `aria-labelledby`)。
|
||||||
|
- Fill 宽度始终为 `percentage%`。
|
||||||
|
|
||||||
|
与 Progress 的语义边界(按任务要求核对):
|
||||||
|
|
||||||
|
| 维度 | ProgressBar / ProgressCircle | Meter |
|
||||||
|
| ---------- | -------------------------------- | ------------------- |
|
||||||
|
| 语义 | 任务完成进度(可未知) | 已知范围内的量/比例 |
|
||||||
|
| 未知进度 | `isIndeterminate`,省略 valuenow | 不支持 |
|
||||||
|
| role | `progressbar` | `meter progressbar` |
|
||||||
|
| 不确定动画 | 有 | 无 |
|
||||||
|
|
||||||
|
## 4. 示例对照
|
||||||
|
|
||||||
|
| 基线 | Vue 演示 | 状态 |
|
||||||
|
| ------------- | ------------------------- | --------------------------------------- |
|
||||||
|
| basic | `meter-basic.vue` | 已迁移 |
|
||||||
|
| sizes | `meter-sizes.vue` | 已迁移;sm=success/md=accent/lg=warning |
|
||||||
|
| colors | `meter-colors.vue` | 已迁移 |
|
||||||
|
| without-label | `meter-without-label.vue` | 已迁移 |
|
||||||
|
| custom-value | `meter-custom-value.vue` | 已迁移;currency 750/1000 |
|
||||||
|
| custom-styles | `meter-custom-styles.vue` | 已迁移 |
|
||||||
|
|
||||||
|
Meter 的 custom-value 无 NumberField/Select,全部原样迁移。
|
||||||
|
|
||||||
|
## 5. 变更文件
|
||||||
|
|
||||||
|
新增:`packages/vue/src/components/meter/{Meter,MeterOutput,MeterTrack,MeterFill}.vue`、`packages/styles/components/meter.css`、`apps/docs/components/meter.md`、`apps/docs/demos/meter-*.vue`(6)、`tests/fixtures/m18m20-meter-doc-{0,1}.vue`。共享增量同 M18。
|
||||||
|
|
||||||
|
## 6. 验证结果
|
||||||
|
|
||||||
|
同批计数:`pnpm test` 18 文件 / 307(SSR 7);`pnpm test:unit` 17 文件 / 300。
|
||||||
|
|
||||||
|
浏览器自测:12 个 Meter 实例均为 `role="meter progressbar"`;percent 输出 `60%` 等;currency 输出随 locale(`US$750.00`);custom-value 的 `aria-valuenow=750`、`aria-valuemax=1000`、宽度 75%;五色/三尺寸类名正确;无 `isIndeterminate` 路径。
|
||||||
|
|
||||||
|
## 7. 已知差异与未验证项
|
||||||
|
|
||||||
|
- role 使用 `meter progressbar` 双角色(与 React Aria 一致),不是单独 `meter`。
|
||||||
|
- 作用域插槽附带 `isIndeterminate: false` 以便与 ProgressBar 插槽结构复用;这不是公开的 Meter 状态。
|
||||||
|
- format 输出依赖运行时 locale。
|
||||||
|
- 其余未验证项与 M18 相同。
|
||||||
|
|
||||||
|
## 8. 供集成人复核的最短路径
|
||||||
|
|
||||||
|
1. 打开 `/components/meter`。
|
||||||
|
2. 确认 basic 输出 `60%`,role 为 `meter progressbar`;custom-value 输出货币且宽度 75%。
|
||||||
|
3. 运行同批测试命令核对 307 / 300。
|
||||||
|
|
||||||
|
## 返工记录(2026-10-22,对照 M18-M20-review.md)
|
||||||
|
|
||||||
|
四项 P2 已修复,未提交/推送:
|
||||||
|
|
||||||
|
1. **显式 aria-labelledby 不再被删除**:Root 仅在解析结果非 `undefined` 时写入该属性;调用方显式值原样保留。空→增→改→删→再增 有回归。
|
||||||
|
2. **Label ID**:显式 `id` 优先;自动 ID 为每实例 `useId()`(多 Label 唯一)。Root 在渲染时遍历默认插槽为 Label 分配稳定 ID(显式 ID 保留),并与嵌套注册表合并写入 `aria-labelledby`。SSR 首屏引用可解析,不依赖挂载后换 ID。
|
||||||
|
3. **Label 动态 `for`**:标签类型在渲染时读取 `attrs.for`,不再用 setup 快照。`for` 空→增→改→删→再增 时在 `span`/`label` 间正确切换;字段/Choice/Switch 既有场景全量回归通过。
|
||||||
|
4. **文档导航**:三页已加入 `Layout.vue` 组件组(Link → Meter → ProgressBar → ProgressCircle → RadioGroup),桌面侧栏/移动菜单与上一页/下一页生效。
|
||||||
|
|
||||||
|
计数:`pnpm test` 18 文件 / **313**(SSR 7);`pnpm test:unit` 17 文件 / **306**。typecheck / build:docs / format / git diff --check 通过。
|
||||||
@@ -78,3 +78,16 @@ CSS 仅 hv- 命名空间及 reduced-motion 的等价原生 media 适配(避免
|
|||||||
- CN `(typography)/typography.mdx` 与 6 个示例;CN `(navigation)/breadcrumbs.mdx` 与 7 个示例。EmptyState 在固定基线没有独立中文页和示例,Vue 页与 4 个示例明确标注为自编。
|
- CN `(typography)/typography.mdx` 与 6 个示例;CN `(navigation)/breadcrumbs.mdx` 与 7 个示例。EmptyState 在固定基线没有独立中文页和示例,Vue 页与 4 个示例明确标注为自编。
|
||||||
- 默认 Breadcrumbs 分隔符来自基线 `icons.tsx` 的 ChevronRight SVG;自定义分隔符示例把上游手写 SVG 替换为 Tabler `IconCaretRightFilled`,遵守演示图标约定。
|
- 默认 Breadcrumbs 分隔符来自基线 `icons.tsx` 的 ChevronRight SVG;自定义分隔符示例把上游手写 SVG 替换为 Tabler `IconCaretRightFilled`,遵守演示图标约定。
|
||||||
- Typography 的 `render`、Breadcrumbs 的 `render` 与 `onAction`、React 对象子部件访问方式改为 Vue `as`、具名导出、插槽与原生链接事件;差异见各迁移报告。
|
- Typography 的 `render`、Breadcrumbs 的 `render` 与 `onAction`、React 对象子部件访问方式改为 Vue `as`、具名导出、插槽与原生链接事件;差异见各迁移报告。
|
||||||
|
|
||||||
|
## M18–M20 来源(2026-10-22)
|
||||||
|
|
||||||
|
固定 ce90ea3 / HeroUI 3.2.6:
|
||||||
|
|
||||||
|
- `packages/react/src/components/{progress-bar,progress-circle,meter}`:部件结构、RAC ProgressBar/Meter 语义、圆环几何常量。
|
||||||
|
- `packages/styles/components/{progress-bar,progress-circle,meter}.css` 与 `packages/styles/src/components/*/*.styles.ts`:移植为 hv- 命名空间;关键帧改名为 `hv-progress-bar-indeterminate` / `hv-progress-circle-spin`;保留 Apache-2.0 来源头与 third-party/HEROUI-LICENSE。
|
||||||
|
- CN `(feedback)/{progress-bar,progress-circle,meter}.mdx` 与 `apps/docs/src/demos/cn/{progress-bar,progress-circle,meter}/`:共 20 个文档引用示例。
|
||||||
|
- 取值语义按 `@react-aria/progress` 的 `useProgressBar` 与 `@react-aria/meter` 的 `useMeter` 实现(clamp、percent 比例格式化、valuenow 为原值、Meter role=`meter progressbar`)。
|
||||||
|
- ProgressCircle 默认 SVG 几何来自 progress-circle.tsx 常量(CENTER=18, STROKE_WIDTH=4, RADIUS=16);无额外图标。
|
||||||
|
- progress-bar 的 custom-value 示例上游使用 NumberField/Select;Vue 侧以原生 number/select + hv-input 临时替代并在文档标注,不冒充已迁移组件。
|
||||||
|
|
||||||
|
M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生/Fragment 标签预规划实现。显式 ID 优先,每个自动 ID 唯一,Root 引用真实标签;fieldScope 区分外围字段、当前 indicator 与嵌套字段的标签所有者。任意自定义 Vue 包装内部的标签仍需在 SSR 显式提供 ID/aria-labelledby;未声称所有包装都可静态展开。
|
||||||
|
|||||||
@@ -334,3 +334,49 @@ CheckboxGroup 底座行为临时探针单独验证了禁用值仍提交与 reset
|
|||||||
[复核报告](./migrations/M15-M17-review.md#返工后独立复核2026-10-22):两项 P2 已关闭。独立验证首个 Legend 的禁用例外、嵌套 disabled=false 不逃逸、稳定 key 的实际重排、真实 a/span/href/aria-current 和事件取消;原文 5 份完整 SFC 提取后通过 vue-tsc 并实际挂载,17 份演示无警告挂载,dist Props 正反类型探针通过。
|
[复核报告](./migrations/M15-M17-review.md#返工后独立复核2026-10-22):两项 P2 已关闭。独立验证首个 Legend 的禁用例外、嵌套 disabled=false 不逃逸、稳定 key 的实际重排、真实 a/span/href/aria-current 和事件取消;原文 5 份完整 SFC 提取后通过 vue-tsc 并实际挂载,17 份演示无警告挂载,dist Props 正反类型探针通过。
|
||||||
|
|
||||||
正式 `pnpm test` 为 17 文件 / 290 项(含 node SSR 6);`pnpm test:unit` 为 16 文件 / 284 项(不含 node SSR)。typecheck/build:docs/format/diff-check 通过。临时额外 3 项探针已移除,不计入正式计数。本轮未逐页浏览器复测,也未新增自动视觉、读屏/RTL/触屏、Nuxt 或独立安装验收。
|
正式 `pnpm test` 为 17 文件 / 290 项(含 node SSR 6);`pnpm test:unit` 为 16 文件 / 284 项(不含 node SSR)。typecheck/build:docs/format/diff-check 通过。临时额外 3 项探针已移除,不计入正式计数。本轮未逐页浏览器复测,也未新增自动视觉、读屏/RTL/触屏、Nuxt 或独立安装验收。
|
||||||
|
|
||||||
|
## M18–M20 ProgressBar / ProgressCircle / Meter(2026-10-22,实施者自测)
|
||||||
|
|
||||||
|
起始 HEAD `e4d817c`。未提交、未推送、未宣布集成验收通过。
|
||||||
|
|
||||||
|
### 命令
|
||||||
|
|
||||||
|
| 命令 | 文件数 | 通过数 | 含 SSR |
|
||||||
|
| ---------------- | ------ | ------ | ------- |
|
||||||
|
| `pnpm test` | 18 | 307 | 是(7) |
|
||||||
|
| `pnpm test:unit` | 17 | 300 | 否 |
|
||||||
|
|
||||||
|
`typecheck` / `build:docs` / `format` / `git diff --check` 通过。`build:docs` 仅既有 chunk >500kB 提醒。新增 `tests/progress-meter.test.ts` 16 项并进入 `test:unit`;`ssr.test.ts` 新增 1 项进度/计量 SSR。
|
||||||
|
|
||||||
|
### 实施者浏览器自测(127.0.0.1:5173)
|
||||||
|
|
||||||
|
- ProgressBar:13 个实例。确定进度 `aria-valuenow`/`aria-valuetext`/宽度一致;不确定进度省略 valuenow,fill 动画 `hv-progress-bar-indeterminate`;sm/lg 轨道计算高度 4px/12px;accent 填充 `oklch(0.6204 0.195 253.83)`。
|
||||||
|
- custom-value:值 250 → 输出 `25%`、宽度 25%;切 currency 后输出随 locale(本机 `US$250.00`)。NumberField/Select 为原生临时控件。
|
||||||
|
- ProgressCircle:默认 r=16/stroke-width=4;60% dashoffset≈40.21,不确定≈75.40;custom-svg r=17/15 生效;轨道 28px。
|
||||||
|
- Meter:12 个实例 role 均为 `meter progressbar`;percent/currency 输出正确;无不确定路径。
|
||||||
|
- API 表:progress-bar 页 5 张表,桌面宽 736px(内容区 824px)、窄屏 390 视口 350px,`scrollWidth==clientWidth`,无横向溢出。
|
||||||
|
- 深色:track 背景切到深色 `--default`;填充色变量保持 accent。
|
||||||
|
- 控制台仅既有 favicon 404。
|
||||||
|
|
||||||
|
### 未验证
|
||||||
|
|
||||||
|
- 逐像素视觉对比、完整读屏/RTL/触屏、Nuxt 水合、独立安装 dist。
|
||||||
|
- `test:browser` / `test:visual` / `test:package` 尚未建立。
|
||||||
|
- 标签关联在显式 `aria-label` 下不输出 `aria-labelledby`(与 RAC 一致);仅 Label 无 aria-label 时的读屏播报未实测。
|
||||||
|
|
||||||
|
## M18–M20 复核返工(2026-10-22)
|
||||||
|
|
||||||
|
对照 [M18-M20-review.md](./migrations/M18-M20-review.md) 四项 P2 已关闭:
|
||||||
|
|
||||||
|
- 显式 `aria-labelledby` 在 ProgressBar / ProgressCircle / Meter 上保留;动态增删改有回归。
|
||||||
|
- Label 显式 id 保留,多 Label 自动 id 唯一;Root `aria-labelledby` 合并实际 Label id;SSR 引用可解析。
|
||||||
|
- Label 的 `for` 渲染时读取,动态增删可在 `span`/`label` 间切换;字段标签场景回归通过。
|
||||||
|
- `Layout.vue` 侧栏与相邻页导航包含 Meter / ProgressBar / ProgressCircle。
|
||||||
|
|
||||||
|
`pnpm test` 18 文件 / **313**(含 SSR 7);`pnpm test:unit` 17 文件 / **306**。typecheck / build:docs / format / git diff --check 通过。浏览器确认侧栏三项、Meter 页上一页 Link/下一页 ProgressBar。未新增逐像素、读屏、RTL、Nuxt 或独立安装验收。
|
||||||
|
|
||||||
|
## M18–M20 返工后集成人复核(2026-10-22)
|
||||||
|
|
||||||
|
[完整报告](./migrations/M18-M20-review.md#返工后独立复核与集成修正2026-10-22)。四项 P2 已关闭;集成人另外修复共享 Label 的内外层字段作用域隔离,并新增标签 ID 动态变化/重排/卸载、嵌套字段标签所有权、实际 SSR 水合三项正式测试。
|
||||||
|
|
||||||
|
最终 test 18 文件 / 316 项(node SSR 7),unit 17 文件 / 309 项(不含 node SSR,含 jsdom 实际水合)。typecheck/build:docs/format/diff-check 通过。dist Props 正反消费探针通过后移除;20 个演示和 6 份原文 SFC 编译挂载回归通过。未新增逐页浏览器、逐像素、完整读屏/触屏/RTL、Nuxt 或独立安装验收。
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||||
"typecheck": "vue-tsc --noEmit",
|
"typecheck": "vue-tsc --noEmit",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts 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 tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts",
|
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts 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 tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts",
|
||||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||||
"format": "prettier --check .",
|
"format": "prettier --check .",
|
||||||
"format:fix": "prettier --write .",
|
"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; Vue state adapters. */
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Meter - A quantity indicator within a known range
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
.hv-meter {
|
||||||
|
@apply grid w-full gap-1;
|
||||||
|
grid-template-areas:
|
||||||
|
"label output"
|
||||||
|
"track track";
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
|
||||||
|
/* Default color tokens (accent) */
|
||||||
|
--meter-fill: var(--accent);
|
||||||
|
|
||||||
|
[data-slot="label"] {
|
||||||
|
@apply w-fit text-sm font-medium;
|
||||||
|
|
||||||
|
grid-area: label;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__output {
|
||||||
|
@apply text-sm font-medium tabular-nums;
|
||||||
|
|
||||||
|
grid-area: output;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__track {
|
||||||
|
@apply relative overflow-hidden rounded-sm bg-default;
|
||||||
|
|
||||||
|
grid-area: track;
|
||||||
|
|
||||||
|
/* Default height (matches --md) */
|
||||||
|
@apply h-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__fill {
|
||||||
|
@apply absolute start-0 top-0 h-full rounded-sm;
|
||||||
|
|
||||||
|
background-color: var(--meter-fill);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition: width 300ms var(--ease-out);
|
||||||
|
@apply motion-reduce:transition-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disabled state */
|
||||||
|
&:disabled,
|
||||||
|
&[data-disabled="true"],
|
||||||
|
&[aria-disabled="true"] {
|
||||||
|
@apply status-disabled;
|
||||||
|
|
||||||
|
[data-slot="label"] {
|
||||||
|
@apply opacity-100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Size variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-meter--sm {
|
||||||
|
.hv-meter__track {
|
||||||
|
@apply h-1 rounded-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__fill {
|
||||||
|
@apply rounded-xs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--md {
|
||||||
|
/* No styles as this is the default size */
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--lg {
|
||||||
|
.hv-meter__track {
|
||||||
|
@apply h-3 rounded-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter__fill {
|
||||||
|
@apply rounded-md;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Color variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-meter--default {
|
||||||
|
--meter-fill: var(--default-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--accent {
|
||||||
|
--meter-fill: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--success {
|
||||||
|
--meter-fill: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--warning {
|
||||||
|
--meter-fill: var(--warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-meter--danger {
|
||||||
|
--meter-fill: var(--danger);
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||||
|
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
ProgressBar - Shows determinate or indeterminate progress
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
.hv-progress-bar {
|
||||||
|
@apply grid w-full gap-1;
|
||||||
|
grid-template-areas:
|
||||||
|
"label output"
|
||||||
|
"track track";
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
|
||||||
|
/* Default color token (accent) */
|
||||||
|
--progress-bar-fill: var(--accent);
|
||||||
|
|
||||||
|
[data-slot="label"] {
|
||||||
|
@apply w-fit text-sm font-medium;
|
||||||
|
|
||||||
|
grid-area: label;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__output {
|
||||||
|
@apply text-sm font-medium tabular-nums;
|
||||||
|
|
||||||
|
grid-area: output;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__track {
|
||||||
|
@apply relative overflow-hidden rounded-sm bg-default;
|
||||||
|
|
||||||
|
grid-area: track;
|
||||||
|
|
||||||
|
/* Default height (matches --md) */
|
||||||
|
@apply h-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__fill {
|
||||||
|
@apply absolute start-0 top-0 h-full rounded-sm;
|
||||||
|
|
||||||
|
background-color: var(--progress-bar-fill);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition: width 300ms var(--ease-out);
|
||||||
|
@apply motion-reduce:transition-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Indeterminate state - when no aria-valuenow is set */
|
||||||
|
&:not([aria-valuenow]) {
|
||||||
|
.hv-progress-bar__fill {
|
||||||
|
@apply w-2/5;
|
||||||
|
|
||||||
|
animation: hv-progress-bar-indeterminate 1.5s
|
||||||
|
cubic-bezier(0.65, 0, 0.35, 1) infinite;
|
||||||
|
|
||||||
|
@apply motion-reduce:animate-none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disabled state */
|
||||||
|
&:disabled,
|
||||||
|
&[data-disabled="true"],
|
||||||
|
&[aria-disabled="true"] {
|
||||||
|
@apply status-disabled;
|
||||||
|
|
||||||
|
[data-slot="label"] {
|
||||||
|
@apply opacity-100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Indeterminate animation
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
@keyframes hv-progress-bar-indeterminate {
|
||||||
|
0% {
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateX(350%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Size variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-progress-bar--sm {
|
||||||
|
.hv-progress-bar__track {
|
||||||
|
@apply h-1 rounded-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__fill {
|
||||||
|
@apply rounded-xs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--md {
|
||||||
|
/* No styles as this is the default size */
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--lg {
|
||||||
|
.hv-progress-bar__track {
|
||||||
|
@apply h-3 rounded-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar__fill {
|
||||||
|
@apply rounded-md;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Color variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-progress-bar--default {
|
||||||
|
--progress-bar-fill: var(--default-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--accent {
|
||||||
|
--progress-bar-fill: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--success {
|
||||||
|
--progress-bar-fill: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--warning {
|
||||||
|
--progress-bar-fill: var(--warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-bar--danger {
|
||||||
|
--progress-bar-fill: var(--danger);
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||||
|
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
ProgressCircle - Circular progress indicator
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
.hv-progress-circle {
|
||||||
|
@apply inline-flex items-center justify-center;
|
||||||
|
|
||||||
|
/* Default color token (accent) */
|
||||||
|
--progress-circle-stroke: var(--accent);
|
||||||
|
--progress-circle-track-stroke: var(--default);
|
||||||
|
|
||||||
|
.hv-progress-circle__track {
|
||||||
|
/* Default size (matches --md) */
|
||||||
|
@apply size-7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle__track-circle {
|
||||||
|
stroke: var(--progress-circle-track-stroke);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle__fill-circle {
|
||||||
|
stroke: var(--progress-circle-stroke);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition: stroke-dashoffset 300ms var(--ease-out);
|
||||||
|
@apply motion-reduce:transition-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Indeterminate state - when no aria-valuenow is set */
|
||||||
|
&:not([aria-valuenow]) {
|
||||||
|
.hv-progress-circle__track {
|
||||||
|
animation: hv-progress-circle-spin 1s linear infinite;
|
||||||
|
|
||||||
|
@apply motion-reduce:animate-none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disabled state */
|
||||||
|
&:disabled,
|
||||||
|
&[data-disabled="true"],
|
||||||
|
&[aria-disabled="true"] {
|
||||||
|
@apply status-disabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Indeterminate animation
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
@keyframes hv-progress-circle-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Size variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-progress-circle--sm {
|
||||||
|
.hv-progress-circle__track {
|
||||||
|
@apply size-5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--md {
|
||||||
|
/* No styles as this is the default size */
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--lg {
|
||||||
|
.hv-progress-circle__track {
|
||||||
|
@apply size-9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Color variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-progress-circle--default {
|
||||||
|
--progress-circle-stroke: var(--default-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--accent {
|
||||||
|
--progress-circle-stroke: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--success {
|
||||||
|
--progress-circle-stroke: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--warning {
|
||||||
|
--progress-circle-stroke: var(--warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-progress-circle--danger {
|
||||||
|
--progress-circle-stroke: var(--danger);
|
||||||
|
}
|
||||||
@@ -108,3 +108,9 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@import "./components/progress-bar.css" layer(components);
|
||||||
|
|
||||||
|
@import "./components/progress-circle.css" layer(components);
|
||||||
|
|
||||||
|
@import "./components/meter.css" layer(components);
|
||||||
|
|||||||
@@ -703,3 +703,140 @@ export const emptyStateVariants = tv({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export type EmptyStateVariants = VariantProps<typeof emptyStateVariants>;
|
export type EmptyStateVariants = VariantProps<typeof emptyStateVariants>;
|
||||||
|
|
||||||
|
export const progressBarVariants = tv({
|
||||||
|
defaultVariants: {
|
||||||
|
color: "accent",
|
||||||
|
size: "md",
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
base: "hv-progress-bar",
|
||||||
|
fill: "hv-progress-bar__fill",
|
||||||
|
output: "hv-progress-bar__output",
|
||||||
|
track: "hv-progress-bar__track",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
color: {
|
||||||
|
accent: {
|
||||||
|
base: "hv-progress-bar--accent",
|
||||||
|
},
|
||||||
|
danger: {
|
||||||
|
base: "hv-progress-bar--danger",
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
base: "hv-progress-bar--default",
|
||||||
|
},
|
||||||
|
success: {
|
||||||
|
base: "hv-progress-bar--success",
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
base: "hv-progress-bar--warning",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
lg: {
|
||||||
|
base: "hv-progress-bar--lg",
|
||||||
|
},
|
||||||
|
md: {
|
||||||
|
base: "hv-progress-bar--md",
|
||||||
|
},
|
||||||
|
sm: {
|
||||||
|
base: "hv-progress-bar--sm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ProgressBarVariants = VariantProps<typeof progressBarVariants>;
|
||||||
|
|
||||||
|
export const progressCircleVariants = tv({
|
||||||
|
defaultVariants: {
|
||||||
|
color: "accent",
|
||||||
|
size: "md",
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
base: "hv-progress-circle",
|
||||||
|
fillCircle: "hv-progress-circle__fill-circle",
|
||||||
|
track: "hv-progress-circle__track",
|
||||||
|
trackCircle: "hv-progress-circle__track-circle",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
color: {
|
||||||
|
accent: {
|
||||||
|
base: "hv-progress-circle--accent",
|
||||||
|
},
|
||||||
|
danger: {
|
||||||
|
base: "hv-progress-circle--danger",
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
base: "hv-progress-circle--default",
|
||||||
|
},
|
||||||
|
success: {
|
||||||
|
base: "hv-progress-circle--success",
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
base: "hv-progress-circle--warning",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
lg: {
|
||||||
|
base: "hv-progress-circle--lg",
|
||||||
|
},
|
||||||
|
md: {
|
||||||
|
base: "hv-progress-circle--md",
|
||||||
|
},
|
||||||
|
sm: {
|
||||||
|
base: "hv-progress-circle--sm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ProgressCircleVariants = VariantProps<
|
||||||
|
typeof progressCircleVariants
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const meterVariants = tv({
|
||||||
|
defaultVariants: {
|
||||||
|
color: "accent",
|
||||||
|
size: "md",
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
base: "hv-meter",
|
||||||
|
fill: "hv-meter__fill",
|
||||||
|
output: "hv-meter__output",
|
||||||
|
track: "hv-meter__track",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
color: {
|
||||||
|
accent: {
|
||||||
|
base: "hv-meter--accent",
|
||||||
|
},
|
||||||
|
danger: {
|
||||||
|
base: "hv-meter--danger",
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
base: "hv-meter--default",
|
||||||
|
},
|
||||||
|
success: {
|
||||||
|
base: "hv-meter--success",
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
base: "hv-meter--warning",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
lg: {
|
||||||
|
base: "hv-meter--lg",
|
||||||
|
},
|
||||||
|
md: {
|
||||||
|
base: "hv-meter--md",
|
||||||
|
},
|
||||||
|
sm: {
|
||||||
|
base: "hv-meter--sm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type MeterVariants = VariantProps<typeof meterVariants>;
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { inject, useAttrs } from "vue";
|
import { inject, onUnmounted, useAttrs, useId, watch } from "vue";
|
||||||
import { useFieldPart } from "../field/useFieldPart";
|
import { useFieldPart } from "../field/useFieldPart";
|
||||||
import { useInheritedDisabled } from "../field/disabled";
|
import { useInheritedDisabled } from "../field/disabled";
|
||||||
import { fieldContextKey } from "../field/context";
|
import { fieldContextKey } from "../field/context";
|
||||||
|
import { injectIndicatorLabel } from "../progress/value";
|
||||||
|
|
||||||
defineOptions({ inheritAttrs: false });
|
defineOptions({ inheritAttrs: false });
|
||||||
const field = inject(fieldContextKey, undefined);
|
const inheritedField = inject(fieldContextKey, undefined);
|
||||||
|
const indicatorCandidate = injectIndicatorLabel();
|
||||||
|
// The nearest owner wins: an indicator overrides its surrounding field,
|
||||||
|
// while a field nested inside that indicator keeps its own labels.
|
||||||
|
const indicatorLabel =
|
||||||
|
indicatorCandidate?.fieldScope === inheritedField
|
||||||
|
? indicatorCandidate
|
||||||
|
: undefined;
|
||||||
|
const field = indicatorLabel ? undefined : inheritedField;
|
||||||
const attrs = useAttrs();
|
const attrs = useAttrs();
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
@@ -16,16 +26,45 @@ const labelPart =
|
|||||||
const disabled = useInheritedDisabled(
|
const disabled = useInheritedDisabled(
|
||||||
() => props.isDisabled || field?.disabled.value,
|
() => props.isDisabled || field?.disabled.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Unique fallback so multiple labels under one indicator never share an id. */
|
||||||
|
const autoId = useId();
|
||||||
|
|
||||||
|
function resolveId(): string {
|
||||||
|
const explicit = attrs.id;
|
||||||
|
if (typeof explicit === "string" && explicit) return explicit;
|
||||||
|
return labelPart?.id.value ?? autoId;
|
||||||
|
}
|
||||||
|
|
||||||
|
let unregister: (() => void) | undefined;
|
||||||
|
watch(
|
||||||
|
resolveId,
|
||||||
|
(id, prevId) => {
|
||||||
|
if (!indicatorLabel || id === prevId) return;
|
||||||
|
unregister?.();
|
||||||
|
unregister = indicatorLabel.registerLabel(id);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
onUnmounted(() => {
|
||||||
|
unregister?.();
|
||||||
|
unregister = undefined;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component
|
<component
|
||||||
:is="
|
:is="
|
||||||
(field?.kind === 'toggle' || field?.kind === 'group') && !attrs.for
|
attrs.for
|
||||||
|
? 'label'
|
||||||
|
: field?.kind === 'toggle' || field?.kind === 'group'
|
||||||
|
? 'span'
|
||||||
|
: indicatorLabel && !field
|
||||||
? 'span'
|
? 'span'
|
||||||
: 'label'
|
: 'label'
|
||||||
"
|
"
|
||||||
v-bind="attrs"
|
v-bind="attrs"
|
||||||
:id="labelPart?.id.value ?? attrs.id"
|
:id="resolveId()"
|
||||||
:for="
|
:for="
|
||||||
attrs.for ?? (field?.kind === 'text' ? field.controlId.value : undefined)
|
attrs.for ?? (field?.kind === 'text' ? field.controlId.value : undefined)
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
h,
|
||||||
|
provide,
|
||||||
|
useAttrs,
|
||||||
|
type PropType,
|
||||||
|
} from "vue";
|
||||||
|
import { meterVariants, type MeterVariants } from "@heroui-vue/styles";
|
||||||
|
import {
|
||||||
|
assignIndicatorLabelIds,
|
||||||
|
indicatorContextKey,
|
||||||
|
useIndicatorLabelAssociation,
|
||||||
|
useIndicatorValue,
|
||||||
|
type IndicatorFormatOptions,
|
||||||
|
} from "../progress/value";
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "Meter",
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
value: { type: Number, default: 0 },
|
||||||
|
minValue: { type: Number, default: 0 },
|
||||||
|
maxValue: { type: Number, default: 100 },
|
||||||
|
valueLabel: {
|
||||||
|
type: [String, Number] as PropType<string | number>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
formatOptions: {
|
||||||
|
type: Object as PropType<IndicatorFormatOptions>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String as PropType<MeterVariants["size"]>,
|
||||||
|
default: "md",
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String as PropType<MeterVariants["color"]>,
|
||||||
|
default: "accent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props, { slots }) {
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const { clampedValue, percentage, valueText } = useIndicatorValue(() => ({
|
||||||
|
...props,
|
||||||
|
isIndeterminate: false,
|
||||||
|
}));
|
||||||
|
const { baseId, resolveAriaLabelledby } = useIndicatorLabelAssociation();
|
||||||
|
|
||||||
|
const slotClasses = computed(() => {
|
||||||
|
const s = meterVariants({ color: props.color, size: props.size });
|
||||||
|
return {
|
||||||
|
base: s.base(),
|
||||||
|
fill: s.fill(),
|
||||||
|
output: s.output(),
|
||||||
|
track: s.track(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const state = computed(() => ({
|
||||||
|
percentage: percentage.value,
|
||||||
|
valueText: valueText.value,
|
||||||
|
isIndeterminate: false as boolean,
|
||||||
|
}));
|
||||||
|
|
||||||
|
provide(indicatorContextKey, { slots: slotClasses, state });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const rawChildren = slots.default?.(state.value) ?? [];
|
||||||
|
const { nodes, ids } = assignIndicatorLabelIds(
|
||||||
|
Array.isArray(rawChildren) ? rawChildren : [rawChildren],
|
||||||
|
baseId,
|
||||||
|
);
|
||||||
|
const role =
|
||||||
|
typeof attrs.role === "string" && attrs.role
|
||||||
|
? attrs.role
|
||||||
|
: "meter progressbar";
|
||||||
|
|
||||||
|
const rootProps: Record<string, unknown> = {
|
||||||
|
...attrs,
|
||||||
|
class: [slotClasses.value.base, attrs.class],
|
||||||
|
role,
|
||||||
|
"aria-valuemin": props.minValue,
|
||||||
|
"aria-valuemax": props.maxValue,
|
||||||
|
"aria-valuenow": clampedValue.value,
|
||||||
|
"aria-valuetext": valueText.value,
|
||||||
|
"data-slot": "meter",
|
||||||
|
};
|
||||||
|
const labelledby = resolveAriaLabelledby(attrs, ids);
|
||||||
|
if (labelledby !== undefined) rootProps["aria-labelledby"] = labelledby;
|
||||||
|
return h("div", rootProps, nodes);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs, type StyleValue } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.fill);
|
||||||
|
|
||||||
|
const rootStyle = computed<StyleValue>(() => {
|
||||||
|
const width =
|
||||||
|
ctx?.state.value.percentage == null
|
||||||
|
? undefined
|
||||||
|
: `${ctx.state.value.percentage}%`;
|
||||||
|
return [{ width }, attrs.style];
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-bind="attrs"
|
||||||
|
:class="rootClass"
|
||||||
|
:style="rootStyle"
|
||||||
|
data-slot="meter-fill"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.output);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span v-bind="attrs" :class="rootClass" data-slot="meter-output">
|
||||||
|
<slot>{{ ctx?.state.value.valueText }}</slot>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.track);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-bind="attrs" :class="rootClass" data-slot="meter-track">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
h,
|
||||||
|
provide,
|
||||||
|
useAttrs,
|
||||||
|
type PropType,
|
||||||
|
type StyleValue,
|
||||||
|
} from "vue";
|
||||||
|
import {
|
||||||
|
progressBarVariants,
|
||||||
|
type ProgressBarVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
import {
|
||||||
|
assignIndicatorLabelIds,
|
||||||
|
indicatorContextKey,
|
||||||
|
useIndicatorLabelAssociation,
|
||||||
|
useIndicatorValue,
|
||||||
|
type IndicatorFormatOptions,
|
||||||
|
} from "../progress/value";
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "ProgressBar",
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
value: { type: Number, default: 0 },
|
||||||
|
minValue: { type: Number, default: 0 },
|
||||||
|
maxValue: { type: Number, default: 100 },
|
||||||
|
isIndeterminate: { type: Boolean, default: false },
|
||||||
|
valueLabel: {
|
||||||
|
type: [String, Number] as PropType<string | number>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
formatOptions: {
|
||||||
|
type: Object as PropType<IndicatorFormatOptions>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String as PropType<ProgressBarVariants["size"]>,
|
||||||
|
default: "md",
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String as PropType<ProgressBarVariants["color"]>,
|
||||||
|
default: "accent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props, { slots }) {
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const { clampedValue, percentage, valueText } = useIndicatorValue(
|
||||||
|
() => props,
|
||||||
|
);
|
||||||
|
const { baseId, resolveAriaLabelledby } = useIndicatorLabelAssociation();
|
||||||
|
|
||||||
|
const slotClasses = computed(() => {
|
||||||
|
const s = progressBarVariants({ color: props.color, size: props.size });
|
||||||
|
return {
|
||||||
|
base: s.base(),
|
||||||
|
fill: s.fill(),
|
||||||
|
output: s.output(),
|
||||||
|
track: s.track(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const state = computed(() => ({
|
||||||
|
percentage: percentage.value,
|
||||||
|
valueText: valueText.value,
|
||||||
|
isIndeterminate: props.isIndeterminate,
|
||||||
|
}));
|
||||||
|
|
||||||
|
provide(indicatorContextKey, { slots: slotClasses, state });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const rawChildren = slots.default?.(state.value) ?? [];
|
||||||
|
const { nodes, ids } = assignIndicatorLabelIds(
|
||||||
|
Array.isArray(rawChildren) ? rawChildren : [rawChildren],
|
||||||
|
baseId,
|
||||||
|
);
|
||||||
|
const role =
|
||||||
|
typeof attrs.role === "string" && attrs.role
|
||||||
|
? attrs.role
|
||||||
|
: "progressbar";
|
||||||
|
|
||||||
|
const rootProps: Record<string, unknown> = {
|
||||||
|
...attrs,
|
||||||
|
class: [slotClasses.value.base, attrs.class],
|
||||||
|
role,
|
||||||
|
"aria-valuemin": props.minValue,
|
||||||
|
"aria-valuemax": props.maxValue,
|
||||||
|
"aria-valuenow": props.isIndeterminate ? undefined : clampedValue.value,
|
||||||
|
"aria-valuetext": props.isIndeterminate ? undefined : valueText.value,
|
||||||
|
"data-slot": "progress-bar",
|
||||||
|
};
|
||||||
|
const labelledby = resolveAriaLabelledby(attrs, ids);
|
||||||
|
if (labelledby !== undefined) rootProps["aria-labelledby"] = labelledby;
|
||||||
|
return h("div", rootProps, nodes);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs, type StyleValue } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.fill);
|
||||||
|
|
||||||
|
const rootStyle = computed<StyleValue>(() => {
|
||||||
|
const width =
|
||||||
|
ctx?.state.value.isIndeterminate || ctx?.state.value.percentage == null
|
||||||
|
? undefined
|
||||||
|
: `${ctx.state.value.percentage}%`;
|
||||||
|
return [{ width }, attrs.style];
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-bind="attrs"
|
||||||
|
:class="rootClass"
|
||||||
|
:style="rootStyle"
|
||||||
|
data-slot="progress-bar-fill"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.output);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span v-bind="attrs" :class="rootClass" data-slot="progress-bar-output">
|
||||||
|
<slot>{{ ctx?.state.value.valueText }}</slot>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.track);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-bind="attrs" :class="rootClass" data-slot="progress-bar-track">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
h,
|
||||||
|
provide,
|
||||||
|
useAttrs,
|
||||||
|
type PropType,
|
||||||
|
} from "vue";
|
||||||
|
import {
|
||||||
|
progressCircleVariants,
|
||||||
|
type ProgressCircleVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
import {
|
||||||
|
assignIndicatorLabelIds,
|
||||||
|
indicatorContextKey,
|
||||||
|
useIndicatorLabelAssociation,
|
||||||
|
useIndicatorValue,
|
||||||
|
type IndicatorFormatOptions,
|
||||||
|
} from "../progress/value";
|
||||||
|
import {
|
||||||
|
PROGRESS_CIRCLE_CENTER,
|
||||||
|
PROGRESS_CIRCLE_CIRCUMFERENCE,
|
||||||
|
PROGRESS_CIRCLE_RADIUS,
|
||||||
|
PROGRESS_CIRCLE_STROKE_WIDTH,
|
||||||
|
} from "./constants";
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "ProgressCircle",
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
value: { type: Number, default: 0 },
|
||||||
|
minValue: { type: Number, default: 0 },
|
||||||
|
maxValue: { type: Number, default: 100 },
|
||||||
|
isIndeterminate: { type: Boolean, default: false },
|
||||||
|
valueLabel: {
|
||||||
|
type: [String, Number] as PropType<string | number>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
formatOptions: {
|
||||||
|
type: Object as PropType<IndicatorFormatOptions>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String as PropType<ProgressCircleVariants["size"]>,
|
||||||
|
default: "md",
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String as PropType<ProgressCircleVariants["color"]>,
|
||||||
|
default: "accent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props, { slots }) {
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const { clampedValue, percentage, valueText } = useIndicatorValue(
|
||||||
|
() => props,
|
||||||
|
);
|
||||||
|
const { baseId, resolveAriaLabelledby } = useIndicatorLabelAssociation();
|
||||||
|
|
||||||
|
const slotClasses = computed(() => {
|
||||||
|
const s = progressCircleVariants({
|
||||||
|
color: props.color,
|
||||||
|
size: props.size,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
base: s.base(),
|
||||||
|
fillCircle: s.fillCircle(),
|
||||||
|
track: s.track(),
|
||||||
|
trackCircle: s.trackCircle(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const state = computed(() => ({
|
||||||
|
percentage: percentage.value,
|
||||||
|
valueText: valueText.value,
|
||||||
|
isIndeterminate: props.isIndeterminate,
|
||||||
|
}));
|
||||||
|
|
||||||
|
provide(indicatorContextKey, { slots: slotClasses, state });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const rawChildren = slots.default?.(state.value) ?? [];
|
||||||
|
const { nodes, ids } = assignIndicatorLabelIds(
|
||||||
|
Array.isArray(rawChildren) ? rawChildren : [rawChildren],
|
||||||
|
baseId,
|
||||||
|
);
|
||||||
|
const role =
|
||||||
|
typeof attrs.role === "string" && attrs.role
|
||||||
|
? attrs.role
|
||||||
|
: "progressbar";
|
||||||
|
|
||||||
|
const rootProps: Record<string, unknown> = {
|
||||||
|
...attrs,
|
||||||
|
class: [slotClasses.value.base, attrs.class],
|
||||||
|
role,
|
||||||
|
"aria-valuemin": props.minValue,
|
||||||
|
"aria-valuemax": props.maxValue,
|
||||||
|
"aria-valuenow": props.isIndeterminate ? undefined : clampedValue.value,
|
||||||
|
"aria-valuetext": props.isIndeterminate ? undefined : valueText.value,
|
||||||
|
"data-slot": "progress-circle",
|
||||||
|
};
|
||||||
|
const labelledby = resolveAriaLabelledby(attrs, ids);
|
||||||
|
if (labelledby !== undefined) rootProps["aria-labelledby"] = labelledby;
|
||||||
|
return h("div", rootProps, nodes);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
import {
|
||||||
|
PROGRESS_CIRCLE_CENTER,
|
||||||
|
PROGRESS_CIRCLE_CIRCUMFERENCE,
|
||||||
|
PROGRESS_CIRCLE_RADIUS,
|
||||||
|
PROGRESS_CIRCLE_STROKE_WIDTH,
|
||||||
|
} from "./constants";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
function pick(
|
||||||
|
camel: string,
|
||||||
|
kebab: string,
|
||||||
|
fallback: string | number,
|
||||||
|
): string | number {
|
||||||
|
const value = attrs[camel] ?? attrs[kebab];
|
||||||
|
return value == null || value === "" ? fallback : (value as string | number);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.fillCircle);
|
||||||
|
|
||||||
|
const cx = computed(() => pick("cx", "cx", PROGRESS_CIRCLE_CENTER));
|
||||||
|
const cy = computed(() => pick("cy", "cy", PROGRESS_CIRCLE_CENTER));
|
||||||
|
const r = computed(() => pick("r", "r", PROGRESS_CIRCLE_RADIUS));
|
||||||
|
const strokeWidth = computed(() =>
|
||||||
|
pick("strokeWidth", "stroke-width", PROGRESS_CIRCLE_STROKE_WIDTH),
|
||||||
|
);
|
||||||
|
const strokeDasharray = computed(() =>
|
||||||
|
pick("strokeDasharray", "stroke-dasharray", PROGRESS_CIRCLE_CIRCUMFERENCE),
|
||||||
|
);
|
||||||
|
|
||||||
|
const strokeDashoffset = computed(() => {
|
||||||
|
const explicit = attrs.strokeDashoffset ?? attrs["stroke-dashoffset"];
|
||||||
|
if (explicit != null && explicit !== "") return explicit as string | number;
|
||||||
|
const state = ctx?.state.value;
|
||||||
|
if (!state || state.isIndeterminate || state.percentage == null) {
|
||||||
|
return PROGRESS_CIRCLE_CIRCUMFERENCE * 0.75;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
PROGRESS_CIRCLE_CIRCUMFERENCE -
|
||||||
|
(state.percentage / 100) * PROGRESS_CIRCLE_CIRCUMFERENCE
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const linecap = computed(() => {
|
||||||
|
const value = attrs.strokeLinecap ?? attrs["stroke-linecap"];
|
||||||
|
return (value ?? "round") as "butt" | "round" | "square" | "inherit";
|
||||||
|
});
|
||||||
|
|
||||||
|
const transform = computed(() => {
|
||||||
|
const explicit = attrs.transform;
|
||||||
|
if (explicit != null && explicit !== "") return explicit as string;
|
||||||
|
return `rotate(-90 ${PROGRESS_CIRCLE_CENTER} ${PROGRESS_CIRCLE_CENTER})`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<circle
|
||||||
|
v-bind="attrs"
|
||||||
|
:class="rootClass"
|
||||||
|
:cx="cx"
|
||||||
|
:cy="cy"
|
||||||
|
:r="r"
|
||||||
|
:stroke-width="strokeWidth"
|
||||||
|
:stroke-dasharray="strokeDasharray"
|
||||||
|
:stroke-dashoffset="strokeDashoffset"
|
||||||
|
:stroke-linecap="linecap"
|
||||||
|
:transform="transform"
|
||||||
|
data-slot="progress-circle-fill-circle"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
import { PROGRESS_CIRCLE_CENTER } from "./constants";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.track);
|
||||||
|
|
||||||
|
const viewBox = computed(() => {
|
||||||
|
const explicit = attrs.viewBox;
|
||||||
|
if (explicit != null && explicit !== "") return explicit as string;
|
||||||
|
return `0 0 ${PROGRESS_CIRCLE_CENTER * 2} ${PROGRESS_CIRCLE_CENTER * 2}`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<svg
|
||||||
|
v-bind="attrs"
|
||||||
|
:class="rootClass"
|
||||||
|
:viewBox="viewBox"
|
||||||
|
fill="none"
|
||||||
|
data-slot="progress-circle-track"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { indicatorContextKey } from "../progress/value";
|
||||||
|
import {
|
||||||
|
PROGRESS_CIRCLE_CENTER,
|
||||||
|
PROGRESS_CIRCLE_RADIUS,
|
||||||
|
PROGRESS_CIRCLE_STROKE_WIDTH,
|
||||||
|
} from "./constants";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const ctx = inject(indicatorContextKey, undefined);
|
||||||
|
|
||||||
|
function pick(
|
||||||
|
camel: string,
|
||||||
|
kebab: string,
|
||||||
|
fallback: string | number,
|
||||||
|
): string | number {
|
||||||
|
const value = attrs[camel] ?? attrs[kebab];
|
||||||
|
return value == null || value === "" ? fallback : (value as string | number);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootClass = computed(() => ctx?.slots.value.trackCircle);
|
||||||
|
const cx = computed(() => pick("cx", "cx", PROGRESS_CIRCLE_CENTER));
|
||||||
|
const cy = computed(() => pick("cy", "cy", PROGRESS_CIRCLE_CENTER));
|
||||||
|
const r = computed(() => pick("r", "r", PROGRESS_CIRCLE_RADIUS));
|
||||||
|
const strokeWidth = computed(() =>
|
||||||
|
pick("strokeWidth", "stroke-width", PROGRESS_CIRCLE_STROKE_WIDTH),
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<circle
|
||||||
|
v-bind="attrs"
|
||||||
|
:class="rootClass"
|
||||||
|
:cx="cx"
|
||||||
|
:cy="cy"
|
||||||
|
:r="r"
|
||||||
|
:stroke-width="strokeWidth"
|
||||||
|
data-slot="progress-circle-track-circle"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/** Circle geometry matching the fixed HeroUI baseline (viewBox 0 0 36 36). */
|
||||||
|
export const PROGRESS_CIRCLE_CENTER = 18;
|
||||||
|
export const PROGRESS_CIRCLE_STROKE_WIDTH = 4;
|
||||||
|
export const PROGRESS_CIRCLE_RADIUS =
|
||||||
|
PROGRESS_CIRCLE_CENTER - PROGRESS_CIRCLE_STROKE_WIDTH / 2;
|
||||||
|
export const PROGRESS_CIRCLE_CIRCUMFERENCE =
|
||||||
|
2 * Math.PI * PROGRESS_CIRCLE_RADIUS;
|
||||||
@@ -0,0 +1,231 @@
|
|||||||
|
import {
|
||||||
|
Comment,
|
||||||
|
Fragment,
|
||||||
|
Text,
|
||||||
|
cloneVNode,
|
||||||
|
computed,
|
||||||
|
inject,
|
||||||
|
isVNode,
|
||||||
|
provide,
|
||||||
|
ref,
|
||||||
|
toValue,
|
||||||
|
useId,
|
||||||
|
type ComputedRef,
|
||||||
|
type InjectionKey,
|
||||||
|
type MaybeRefOrGetter,
|
||||||
|
type Ref,
|
||||||
|
type VNode,
|
||||||
|
type VNodeChild,
|
||||||
|
} from "vue";
|
||||||
|
|
||||||
|
import { fieldContextKey, type FieldContext } from "../field/context";
|
||||||
|
|
||||||
|
export type IndicatorFormatOptions = Intl.NumberFormatOptions;
|
||||||
|
|
||||||
|
export interface IndicatorValueProps {
|
||||||
|
value?: number;
|
||||||
|
minValue?: number;
|
||||||
|
maxValue?: number;
|
||||||
|
isIndeterminate?: boolean;
|
||||||
|
valueLabel?: string | number;
|
||||||
|
formatOptions?: IndicatorFormatOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndicatorValue {
|
||||||
|
clampedValue: ComputedRef<number>;
|
||||||
|
/** 0–100, or undefined when indeterminate. */
|
||||||
|
percentage: ComputedRef<number | undefined>;
|
||||||
|
/** Formatted display text, or undefined when indeterminate without valueLabel. */
|
||||||
|
valueText: ComputedRef<string | undefined>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndicatorSlotState {
|
||||||
|
percentage: number | undefined;
|
||||||
|
valueText: string | undefined;
|
||||||
|
isIndeterminate: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_FORMAT: IndicatorFormatOptions = { style: "percent" };
|
||||||
|
|
||||||
|
function clamp(value: number, min: number, max: number): number {
|
||||||
|
return Math.min(Math.max(value, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrors React Aria useProgressBar / useMeter value semantics:
|
||||||
|
* clamp to [minValue, maxValue]; percent format uses the 0–1 ratio;
|
||||||
|
* other styles format the raw clamped value.
|
||||||
|
*/
|
||||||
|
export function useIndicatorValue(
|
||||||
|
getProps: MaybeRefOrGetter<IndicatorValueProps>,
|
||||||
|
): IndicatorValue {
|
||||||
|
const read = (): IndicatorValueProps => toValue(getProps);
|
||||||
|
|
||||||
|
const clampedValue = computed(() => {
|
||||||
|
const p = read();
|
||||||
|
const min = p.minValue ?? 0;
|
||||||
|
const max = p.maxValue ?? 100;
|
||||||
|
return clamp(p.value ?? 0, min, max);
|
||||||
|
});
|
||||||
|
|
||||||
|
const percentage = computed(() => {
|
||||||
|
const p = read();
|
||||||
|
if (p.isIndeterminate) return undefined;
|
||||||
|
const min = p.minValue ?? 0;
|
||||||
|
const max = p.maxValue ?? 100;
|
||||||
|
if (max === min) return 0;
|
||||||
|
return ((clampedValue.value - min) / (max - min)) * 100;
|
||||||
|
});
|
||||||
|
|
||||||
|
const valueText = computed(() => {
|
||||||
|
const p = read();
|
||||||
|
if (p.isIndeterminate) return undefined;
|
||||||
|
if (p.valueLabel != null && p.valueLabel !== "")
|
||||||
|
return String(p.valueLabel);
|
||||||
|
const min = p.minValue ?? 0;
|
||||||
|
const max = p.maxValue ?? 100;
|
||||||
|
const ratio = max === min ? 0 : (clampedValue.value - min) / (max - min);
|
||||||
|
const formatOptions = p.formatOptions ?? DEFAULT_FORMAT;
|
||||||
|
try {
|
||||||
|
const formatter = new Intl.NumberFormat(undefined, formatOptions);
|
||||||
|
return formatter.format(
|
||||||
|
formatOptions.style === "percent" ? ratio : clampedValue.value,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
return String(clampedValue.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { clampedValue, percentage, valueText };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndicatorSlotClasses {
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndicatorContextValue {
|
||||||
|
slots: ComputedRef<IndicatorSlotClasses>;
|
||||||
|
state: ComputedRef<IndicatorSlotState>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const indicatorContextKey: InjectionKey<IndicatorContextValue> =
|
||||||
|
Symbol("hv-indicator");
|
||||||
|
|
||||||
|
export interface IndicatorLabelRegistry {
|
||||||
|
/** Field scope surrounding the indicator; a nested field owns its own labels. */
|
||||||
|
fieldScope: FieldContext | undefined;
|
||||||
|
/** Register a label id present under the indicator root; returns unregister. */
|
||||||
|
registerLabel: (id: string) => () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const indicatorLabelContextKey: InjectionKey<IndicatorLabelRegistry> =
|
||||||
|
Symbol("hv-indicator-label");
|
||||||
|
|
||||||
|
function isLabelVNode(node: VNode): boolean {
|
||||||
|
const type = node.type as { __name?: string; name?: string } | string;
|
||||||
|
if (typeof type === "string") return false;
|
||||||
|
return type?.__name === "Label" || type?.name === "Label";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isExplicitId(value: unknown): value is string {
|
||||||
|
return typeof value === "string" && value.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AssignedLabelIds {
|
||||||
|
nodes: VNodeChild[];
|
||||||
|
ids: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Walk default-slot children, give each Label a stable unique id
|
||||||
|
* (explicit id wins), and return those ids for aria-labelledby.
|
||||||
|
* Runs inside the root render so SSR first paint already has matching ids.
|
||||||
|
*/
|
||||||
|
export function assignIndicatorLabelIds(
|
||||||
|
children: VNodeChild[],
|
||||||
|
baseId: string,
|
||||||
|
): AssignedLabelIds {
|
||||||
|
const ids: string[] = [];
|
||||||
|
let autoIndex = 0;
|
||||||
|
|
||||||
|
function mapNodes(nodes: VNodeChild[]): VNodeChild[] {
|
||||||
|
return nodes.map((node) => {
|
||||||
|
if (Array.isArray(node)) return mapNodes(node);
|
||||||
|
if (!isVNode(node)) return node;
|
||||||
|
if (node.type === Comment || node.type === Text) return node;
|
||||||
|
if (node.type === Fragment) {
|
||||||
|
const cloned = cloneVNode(node);
|
||||||
|
cloned.children = mapNodes((node.children ?? []) as VNodeChild[]);
|
||||||
|
return cloned;
|
||||||
|
}
|
||||||
|
if (isLabelVNode(node)) {
|
||||||
|
const explicit = node.props?.id;
|
||||||
|
if (isExplicitId(explicit)) {
|
||||||
|
if (!ids.includes(explicit)) ids.push(explicit);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
const autoId = autoIndex === 0 ? baseId : `${baseId}-${autoIndex}`;
|
||||||
|
autoIndex += 1;
|
||||||
|
if (!ids.includes(autoId)) ids.push(autoId);
|
||||||
|
return cloneVNode(node, { id: autoId });
|
||||||
|
}
|
||||||
|
if (typeof node.type === "string" && Array.isArray(node.children)) {
|
||||||
|
const cloned = cloneVNode(node);
|
||||||
|
cloned.children = mapNodes(node.children as VNodeChild[]);
|
||||||
|
return cloned;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { nodes: mapNodes(children), ids };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndicatorLabelAssociation {
|
||||||
|
baseId: string;
|
||||||
|
registerLabel: (id: string) => () => void;
|
||||||
|
/** Resolve aria-labelledby: explicit wins, then aria-label disables, else real label ids. */
|
||||||
|
resolveAriaLabelledby: (
|
||||||
|
attrs: Record<string, unknown>,
|
||||||
|
slotIds: string[],
|
||||||
|
) => string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useIndicatorLabelAssociation(): IndicatorLabelAssociation {
|
||||||
|
const baseId = useId();
|
||||||
|
const nestedLabelIds = ref<string[]>([]);
|
||||||
|
|
||||||
|
function registerLabel(id: string): () => void {
|
||||||
|
if (!nestedLabelIds.value.includes(id)) {
|
||||||
|
nestedLabelIds.value = [...nestedLabelIds.value, id];
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
nestedLabelIds.value = nestedLabelIds.value.filter((x) => x !== id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
provide(indicatorLabelContextKey, {
|
||||||
|
fieldScope: inject(fieldContextKey, undefined),
|
||||||
|
registerLabel,
|
||||||
|
});
|
||||||
|
|
||||||
|
function resolveAriaLabelledby(
|
||||||
|
attrs: Record<string, unknown>,
|
||||||
|
slotIds: string[],
|
||||||
|
): string | undefined {
|
||||||
|
// Never drop a caller-supplied reference — return it so callers re-apply it.
|
||||||
|
const explicit = attrs["aria-labelledby"];
|
||||||
|
if (typeof explicit === "string" && explicit) return explicit;
|
||||||
|
if (typeof attrs["aria-label"] === "string" && attrs["aria-label"]) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const all = [...new Set([...slotIds, ...nestedLabelIds.value])];
|
||||||
|
return all.length > 0 ? all.join(" ") : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { baseId, registerLabel, resolveAriaLabelledby };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function injectIndicatorLabel(): IndicatorLabelRegistry | undefined {
|
||||||
|
return inject(indicatorLabelContextKey, undefined);
|
||||||
|
}
|
||||||
@@ -291,3 +291,45 @@ export {
|
|||||||
type BreadcrumbsVariants,
|
type BreadcrumbsVariants,
|
||||||
type EmptyStateVariants,
|
type EmptyStateVariants,
|
||||||
} from "@heroui-vue/styles";
|
} from "@heroui-vue/styles";
|
||||||
|
|
||||||
|
export { default as ProgressBar } from "./components/progress-bar/ProgressBar.vue";
|
||||||
|
export { default as ProgressBarOutput } from "./components/progress-bar/ProgressBarOutput.vue";
|
||||||
|
export { default as ProgressBarTrack } from "./components/progress-bar/ProgressBarTrack.vue";
|
||||||
|
export { default as ProgressBarFill } from "./components/progress-bar/ProgressBarFill.vue";
|
||||||
|
export type {
|
||||||
|
ProgressBarProps,
|
||||||
|
ProgressBarOutputProps,
|
||||||
|
ProgressBarTrackProps,
|
||||||
|
ProgressBarFillProps,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export { default as ProgressCircle } from "./components/progress-circle/ProgressCircle.vue";
|
||||||
|
export { default as ProgressCircleTrack } from "./components/progress-circle/ProgressCircleTrack.vue";
|
||||||
|
export { default as ProgressCircleTrackCircle } from "./components/progress-circle/ProgressCircleTrackCircle.vue";
|
||||||
|
export { default as ProgressCircleFillCircle } from "./components/progress-circle/ProgressCircleFillCircle.vue";
|
||||||
|
export type {
|
||||||
|
ProgressCircleProps,
|
||||||
|
ProgressCircleTrackProps,
|
||||||
|
ProgressCircleTrackCircleProps,
|
||||||
|
ProgressCircleFillCircleProps,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export { default as Meter } from "./components/meter/Meter.vue";
|
||||||
|
export { default as MeterOutput } from "./components/meter/MeterOutput.vue";
|
||||||
|
export { default as MeterTrack } from "./components/meter/MeterTrack.vue";
|
||||||
|
export { default as MeterFill } from "./components/meter/MeterFill.vue";
|
||||||
|
export type {
|
||||||
|
MeterProps,
|
||||||
|
MeterOutputProps,
|
||||||
|
MeterTrackProps,
|
||||||
|
MeterFillProps,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export {
|
||||||
|
progressBarVariants,
|
||||||
|
progressCircleVariants,
|
||||||
|
meterVariants,
|
||||||
|
type ProgressBarVariants,
|
||||||
|
type ProgressCircleVariants,
|
||||||
|
type MeterVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
|||||||
@@ -191,3 +191,42 @@ import type RadioControl from "./components/radio/RadioControl.vue";
|
|||||||
export type RadioControlProps = InstanceType<typeof RadioControl>["$props"];
|
export type RadioControlProps = InstanceType<typeof RadioControl>["$props"];
|
||||||
import type RadioIndicator from "./components/radio/RadioIndicator.vue";
|
import type RadioIndicator from "./components/radio/RadioIndicator.vue";
|
||||||
export type RadioIndicatorProps = InstanceType<typeof RadioIndicator>["$props"];
|
export type RadioIndicatorProps = InstanceType<typeof RadioIndicator>["$props"];
|
||||||
|
|
||||||
|
import type ProgressBar from "./components/progress-bar/ProgressBar.vue";
|
||||||
|
import type ProgressBarOutput from "./components/progress-bar/ProgressBarOutput.vue";
|
||||||
|
import type ProgressBarTrack from "./components/progress-bar/ProgressBarTrack.vue";
|
||||||
|
import type ProgressBarFill from "./components/progress-bar/ProgressBarFill.vue";
|
||||||
|
export type ProgressBarProps = InstanceType<typeof ProgressBar>["$props"];
|
||||||
|
export type ProgressBarOutputProps = InstanceType<
|
||||||
|
typeof ProgressBarOutput
|
||||||
|
>["$props"];
|
||||||
|
export type ProgressBarTrackProps = InstanceType<
|
||||||
|
typeof ProgressBarTrack
|
||||||
|
>["$props"];
|
||||||
|
export type ProgressBarFillProps = InstanceType<
|
||||||
|
typeof ProgressBarFill
|
||||||
|
>["$props"];
|
||||||
|
|
||||||
|
import type ProgressCircle from "./components/progress-circle/ProgressCircle.vue";
|
||||||
|
import type ProgressCircleTrack from "./components/progress-circle/ProgressCircleTrack.vue";
|
||||||
|
import type ProgressCircleTrackCircle from "./components/progress-circle/ProgressCircleTrackCircle.vue";
|
||||||
|
import type ProgressCircleFillCircle from "./components/progress-circle/ProgressCircleFillCircle.vue";
|
||||||
|
export type ProgressCircleProps = InstanceType<typeof ProgressCircle>["$props"];
|
||||||
|
export type ProgressCircleTrackProps = InstanceType<
|
||||||
|
typeof ProgressCircleTrack
|
||||||
|
>["$props"];
|
||||||
|
export type ProgressCircleTrackCircleProps = InstanceType<
|
||||||
|
typeof ProgressCircleTrackCircle
|
||||||
|
>["$props"];
|
||||||
|
export type ProgressCircleFillCircleProps = InstanceType<
|
||||||
|
typeof ProgressCircleFillCircle
|
||||||
|
>["$props"];
|
||||||
|
|
||||||
|
import type Meter from "./components/meter/Meter.vue";
|
||||||
|
import type MeterOutput from "./components/meter/MeterOutput.vue";
|
||||||
|
import type MeterTrack from "./components/meter/MeterTrack.vue";
|
||||||
|
import type MeterFill from "./components/meter/MeterFill.vue";
|
||||||
|
export type MeterProps = InstanceType<typeof Meter>["$props"];
|
||||||
|
export type MeterOutputProps = InstanceType<typeof MeterOutput>["$props"];
|
||||||
|
export type MeterTrackProps = InstanceType<typeof MeterTrack>["$props"];
|
||||||
|
export type MeterFillProps = InstanceType<typeof MeterFill>["$props"];
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter aria-label="存储空间" class="w-64" :value="60">
|
||||||
|
<Label>存储空间</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Meter :value="60">
|
||||||
|
<Label>Storage</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
</template>
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar aria-label="加载中" class="w-64" :value="60">
|
||||||
|
<Label>加载中</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressBar :value="60">
|
||||||
|
<Label>Loading</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
</template>
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle aria-label="加载中" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ProgressCircle aria-label="Loading" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,843 @@
|
|||||||
|
import { describe, it, expect, afterEach, vi } from "vitest";
|
||||||
|
import { renderToString } from "@vue/server-renderer";
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { mount } from "@vue/test-utils";
|
||||||
|
import { createSSRApp, defineComponent, h, nextTick, ref } from "vue";
|
||||||
|
import {
|
||||||
|
Label,
|
||||||
|
TextField,
|
||||||
|
Input,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} from "../packages/vue/src";
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ProgressBar", () => {
|
||||||
|
it("renders with progressbar role and Label accessible name", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
Label,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
ProgressBarFill,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<ProgressBar :value="60">
|
||||||
|
<Label>Loading</Label>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(root.attributes("role")).toBe("progressbar");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("60");
|
||||||
|
expect(root.attributes("aria-valuemin")).toBe("0");
|
||||||
|
expect(root.attributes("aria-valuemax")).toBe("100");
|
||||||
|
await nextTick();
|
||||||
|
const label = w.get("[data-slot=label]");
|
||||||
|
expect(root.attributes("aria-labelledby")).toBe(label.attributes("id"));
|
||||||
|
expect(label.attributes("id")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes BEM block, color/size modifiers and data-slots", () => {
|
||||||
|
const w = mount(ProgressBar, {
|
||||||
|
props: { color: "success", size: "lg", value: 50 },
|
||||||
|
attrs: { "aria-label": "Loading", "data-foo": "bar" },
|
||||||
|
slots: {
|
||||||
|
default: () => [
|
||||||
|
h(ProgressBarOutput),
|
||||||
|
h(ProgressBarTrack, null, { default: () => h(ProgressBarFill) }),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(root.attributes("data-foo")).toBe("bar");
|
||||||
|
expect(root.attributes("aria-label")).toBe("Loading");
|
||||||
|
expect(root.classes()).toContain("hv-progress-bar");
|
||||||
|
expect(root.classes()).toContain("hv-progress-bar--success");
|
||||||
|
expect(root.classes()).toContain("hv-progress-bar--lg");
|
||||||
|
expect(w.find("[data-slot=progress-bar-output]").exists()).toBe(true);
|
||||||
|
expect(w.find("[data-slot=progress-bar-track]").exists()).toBe(true);
|
||||||
|
expect(w.find("[data-slot=progress-bar-fill]").exists()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits aria-valuenow and width when indeterminate", () => {
|
||||||
|
const w = mount(ProgressBar, {
|
||||||
|
props: { isIndeterminate: true },
|
||||||
|
attrs: { "aria-label": "Loading" },
|
||||||
|
slots: {
|
||||||
|
default: () =>
|
||||||
|
h(ProgressBarTrack, null, {
|
||||||
|
default: () => h(ProgressBarFill, { "data-testid": "fill" }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBeUndefined();
|
||||||
|
expect(root.attributes("aria-valuetext")).toBeUndefined();
|
||||||
|
const fill = w.get("[data-slot=progress-bar-fill]");
|
||||||
|
expect((fill.element as HTMLElement).style.width).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("formats percent text and custom ranges", async () => {
|
||||||
|
const percent = mount(ProgressBar, {
|
||||||
|
props: { value: 60 },
|
||||||
|
attrs: { "aria-label": "p" },
|
||||||
|
slots: { default: () => h(ProgressBarOutput) },
|
||||||
|
});
|
||||||
|
expect(percent.get("[data-slot=progress-bar-output]").text()).toBe("60%");
|
||||||
|
|
||||||
|
const currency = mount(ProgressBar, {
|
||||||
|
props: {
|
||||||
|
value: 750,
|
||||||
|
minValue: 0,
|
||||||
|
maxValue: 1000,
|
||||||
|
formatOptions: { style: "currency", currency: "USD" },
|
||||||
|
},
|
||||||
|
attrs: { "aria-label": "p" },
|
||||||
|
slots: {
|
||||||
|
default: () => [
|
||||||
|
h(ProgressBarOutput),
|
||||||
|
h(ProgressBarFill, { "data-testid": "fill" }),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(currency.get("[data-slot=progress-bar-output]").text()).toBe(
|
||||||
|
"$750.00",
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
(currency.get("[data-slot=progress-bar-fill]").element as HTMLElement)
|
||||||
|
.style.width,
|
||||||
|
).toBe("75%");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("clamps value and supports valueLabel override", () => {
|
||||||
|
const w = mount(ProgressBar, {
|
||||||
|
props: { value: 150, minValue: 0, maxValue: 100, valueLabel: "自定义" },
|
||||||
|
attrs: { "aria-label": "p" },
|
||||||
|
slots: {
|
||||||
|
default: () => [
|
||||||
|
h(ProgressBarOutput),
|
||||||
|
h(ProgressBarFill, { "data-testid": "fill" }),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("100");
|
||||||
|
expect(root.attributes("aria-valuetext")).toBe("自定义");
|
||||||
|
expect(w.get("[data-slot=progress-bar-output]").text()).toBe("自定义");
|
||||||
|
expect(
|
||||||
|
(w.get("[data-slot=progress-bar-fill]").element as HTMLElement).style
|
||||||
|
.width,
|
||||||
|
).toBe("100%");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates DOM when value and indeterminate toggle", async () => {
|
||||||
|
const value = ref(20);
|
||||||
|
const indeterminate = ref(false);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
ProgressBarFill,
|
||||||
|
},
|
||||||
|
setup: () => ({ value, indeterminate }),
|
||||||
|
template: `
|
||||||
|
<ProgressBar
|
||||||
|
:value="value"
|
||||||
|
:is-indeterminate="indeterminate"
|
||||||
|
aria-label="动态"
|
||||||
|
>
|
||||||
|
<ProgressBarOutput />
|
||||||
|
<ProgressBarTrack>
|
||||||
|
<ProgressBarFill data-testid="fill" />
|
||||||
|
</ProgressBarTrack>
|
||||||
|
</ProgressBar>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
const fill = w.get("[data-slot=progress-bar-fill]");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("20");
|
||||||
|
expect((fill.element as HTMLElement).style.width).toBe("20%");
|
||||||
|
|
||||||
|
value.value = 80;
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("80");
|
||||||
|
expect((fill.element as HTMLElement).style.width).toBe("80%");
|
||||||
|
|
||||||
|
indeterminate.value = true;
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-valuenow")).toBeUndefined();
|
||||||
|
expect((fill.element as HTMLElement).style.width).toBe("");
|
||||||
|
|
||||||
|
indeterminate.value = false;
|
||||||
|
value.value = 45;
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("45");
|
||||||
|
expect((fill.element as HTMLElement).style.width).toBe("45%");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("merges caller class arrays/objects and supports scoped default slot", () => {
|
||||||
|
const w = mount(ProgressBar, {
|
||||||
|
props: { value: 30, size: "sm" },
|
||||||
|
attrs: {
|
||||||
|
"aria-label": "p",
|
||||||
|
class: ["custom-a", { "custom-b": true }],
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
default: (scope: {
|
||||||
|
percentage: number | undefined;
|
||||||
|
valueText: string | undefined;
|
||||||
|
isIndeterminate: boolean;
|
||||||
|
}) =>
|
||||||
|
h("span", { "data-testid": "scoped" }, [
|
||||||
|
`${scope.percentage}|${scope.valueText}|${scope.isIndeterminate}`,
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(root.classes()).toContain("hv-progress-bar");
|
||||||
|
expect(root.classes()).toContain("hv-progress-bar--sm");
|
||||||
|
expect(root.classes()).toContain("custom-a");
|
||||||
|
expect(root.classes()).toContain("custom-b");
|
||||||
|
expect(w.get("[data-testid=scoped]").text()).toBe("30|30%|false");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ProgressCircle", () => {
|
||||||
|
it("renders circle geometry and indeterminate dash offset", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<ProgressCircle aria-label="加载中" :value="60">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = w.get("[data-slot=progress-circle]");
|
||||||
|
expect(root.attributes("role")).toBe("progressbar");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("60");
|
||||||
|
const track = w.get("svg[data-slot=progress-circle-track]");
|
||||||
|
expect(track.attributes("viewBox")).toBe("0 0 36 36");
|
||||||
|
expect(track.attributes("fill")).toBe("none");
|
||||||
|
const trackCircle = w.get("[data-slot=progress-circle-track-circle]");
|
||||||
|
expect(trackCircle.attributes("cx")).toBe("18");
|
||||||
|
expect(trackCircle.attributes("cy")).toBe("18");
|
||||||
|
expect(trackCircle.attributes("r")).toBe("16");
|
||||||
|
expect(trackCircle.attributes("stroke-width")).toBe("4");
|
||||||
|
const fillCircle = w.get("[data-slot=progress-circle-fill-circle]");
|
||||||
|
const circumference = 2 * Math.PI * 16;
|
||||||
|
expect(Number(fillCircle.attributes("stroke-dasharray"))).toBeCloseTo(
|
||||||
|
circumference,
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
// 60% → offset = C * 0.4
|
||||||
|
expect(Number(fillCircle.attributes("stroke-dashoffset"))).toBeCloseTo(
|
||||||
|
circumference * 0.4,
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
expect(fillCircle.attributes("stroke-linecap")).toBe("round");
|
||||||
|
expect(fillCircle.attributes("transform")).toBe("rotate(-90 18 18)");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports custom SVG geometry overrides", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<ProgressCircle aria-label="细" :value="60">
|
||||||
|
<ProgressCircleTrack stroke-width="2" view-box="0 0 36 36">
|
||||||
|
<ProgressCircleTrackCircle :cx="18" :cy="18" :r="17" :stroke-width="2" />
|
||||||
|
<ProgressCircleFillCircle :cx="18" :cy="18" :r="17" :stroke-width="2" />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
w.get("[data-slot=progress-circle-track-circle]").attributes("r"),
|
||||||
|
).toBe("17");
|
||||||
|
expect(
|
||||||
|
w
|
||||||
|
.get("[data-slot=progress-circle-track-circle]")
|
||||||
|
.attributes("stroke-width"),
|
||||||
|
).toBe("2");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits aria-valuenow when indeterminate and spins track via CSS hook", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<ProgressCircle is-indeterminate aria-label="加载中">
|
||||||
|
<ProgressCircleTrack>
|
||||||
|
<ProgressCircleTrackCircle />
|
||||||
|
<ProgressCircleFillCircle />
|
||||||
|
</ProgressCircleTrack>
|
||||||
|
</ProgressCircle>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
w.get("[data-slot=progress-circle]").attributes("aria-valuenow"),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Meter", () => {
|
||||||
|
it("renders meter role with Label name and percent output", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
MeterFill,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<Meter :value="60">
|
||||||
|
<Label>Storage</Label>
|
||||||
|
<MeterOutput />
|
||||||
|
<MeterTrack>
|
||||||
|
<MeterFill />
|
||||||
|
</MeterTrack>
|
||||||
|
</Meter>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = w.get("[data-slot=meter]");
|
||||||
|
expect(root.attributes("role")).toBe("meter progressbar");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("60");
|
||||||
|
expect(root.attributes("aria-valuetext")).toBe("60%");
|
||||||
|
await nextTick();
|
||||||
|
const label = w.get("[data-slot=label]");
|
||||||
|
expect(root.attributes("aria-labelledby")).toBe(label.attributes("id"));
|
||||||
|
expect(w.get("[data-slot=meter-output]").text()).toBe("60%");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("always reports a value (no indeterminate) and uses BEM color", () => {
|
||||||
|
const w = mount(Meter, {
|
||||||
|
props: { value: 50, color: "danger" },
|
||||||
|
attrs: { "aria-label": "Storage", "data-foo": "bar" },
|
||||||
|
slots: {
|
||||||
|
default: () => [
|
||||||
|
h(MeterOutput),
|
||||||
|
h(MeterTrack, null, { default: () => h(MeterFill) }),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const root = w.get("[data-slot=meter]");
|
||||||
|
expect(root.attributes("data-foo")).toBe("bar");
|
||||||
|
expect(root.attributes("aria-valuenow")).toBe("50");
|
||||||
|
expect(root.classes()).toContain("hv-meter--danger");
|
||||||
|
expect(root.attributes("role")).toBe("meter progressbar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("formats custom value ranges", () => {
|
||||||
|
const w = mount(Meter, {
|
||||||
|
props: {
|
||||||
|
value: 750,
|
||||||
|
maxValue: 1000,
|
||||||
|
minValue: 0,
|
||||||
|
formatOptions: { style: "currency", currency: "USD" },
|
||||||
|
},
|
||||||
|
attrs: { "aria-label": "Revenue" },
|
||||||
|
slots: {
|
||||||
|
default: () => [h(MeterOutput), h(MeterFill)],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(w.get("[data-slot=meter-output]").text()).toBe("$750.00");
|
||||||
|
expect(
|
||||||
|
(w.get("[data-slot=meter-fill]").element as HTMLElement).style.width,
|
||||||
|
).toBe("75%");
|
||||||
|
expect(w.get("[data-slot=meter]").attributes("aria-valuenow")).toBe("750");
|
||||||
|
expect(w.get("[data-slot=meter]").attributes("aria-valuemin")).toBe("0");
|
||||||
|
expect(w.get("[data-slot=meter]").attributes("aria-valuemax")).toBe("1000");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers explicit aria-label over Label association", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: { Label, Meter },
|
||||||
|
template: `
|
||||||
|
<Meter :value="40" aria-label="显式名称">
|
||||||
|
<Label>内部标签</Label>
|
||||||
|
</Meter>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = w.get("[data-slot=meter]");
|
||||||
|
expect(root.attributes("aria-label")).toBe("显式名称");
|
||||||
|
expect(root.attributes("aria-labelledby")).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("M18–M20 demos", () => {
|
||||||
|
const demoModules = import.meta.glob<{ default: unknown }>(
|
||||||
|
"../apps/docs/demos/{progress-bar,progress-circle,meter}-*.vue",
|
||||||
|
{ eager: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
it("mounts all 20 baseline demos without console errors", async () => {
|
||||||
|
const names = Object.keys(demoModules).sort();
|
||||||
|
expect(names).toHaveLength(20);
|
||||||
|
expect(names.map((n) => n.split("/").pop())).toEqual([
|
||||||
|
"meter-basic.vue",
|
||||||
|
"meter-colors.vue",
|
||||||
|
"meter-custom-styles.vue",
|
||||||
|
"meter-custom-value.vue",
|
||||||
|
"meter-sizes.vue",
|
||||||
|
"meter-without-label.vue",
|
||||||
|
"progress-bar-basic.vue",
|
||||||
|
"progress-bar-colors.vue",
|
||||||
|
"progress-bar-custom-styles.vue",
|
||||||
|
"progress-bar-custom-value.vue",
|
||||||
|
"progress-bar-indeterminate.vue",
|
||||||
|
"progress-bar-sizes.vue",
|
||||||
|
"progress-bar-without-label.vue",
|
||||||
|
"progress-circle-basic.vue",
|
||||||
|
"progress-circle-colors.vue",
|
||||||
|
"progress-circle-custom-styles.vue",
|
||||||
|
"progress-circle-custom-svg.vue",
|
||||||
|
"progress-circle-indeterminate.vue",
|
||||||
|
"progress-circle-sizes.vue",
|
||||||
|
"progress-circle-with-label.vue",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const errors: unknown[] = [];
|
||||||
|
const warn = console.warn;
|
||||||
|
const error = console.error;
|
||||||
|
console.warn = (...args: unknown[]) => {
|
||||||
|
errors.push(args);
|
||||||
|
warn(...args);
|
||||||
|
};
|
||||||
|
console.error = (...args: unknown[]) => {
|
||||||
|
errors.push(args);
|
||||||
|
error(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const [path, mod] of Object.entries(demoModules)) {
|
||||||
|
const w = mount(mod.default as never, { attachTo: document.body });
|
||||||
|
expect(w.html().length).toBeGreaterThan(20);
|
||||||
|
w.unmount();
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
void path;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
console.warn = warn;
|
||||||
|
console.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(errors).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts, compiles and mounts documentation body SFC examples", async () => {
|
||||||
|
const docs = [
|
||||||
|
"apps/docs/components/progress-bar.md",
|
||||||
|
"apps/docs/components/progress-circle.md",
|
||||||
|
"apps/docs/components/meter.md",
|
||||||
|
];
|
||||||
|
const fixturePaths = [
|
||||||
|
"tests/fixtures/m18m20-progress-bar-doc-0.vue",
|
||||||
|
"tests/fixtures/m18m20-progress-bar-doc-1.vue",
|
||||||
|
"tests/fixtures/m18m20-progress-circle-doc-0.vue",
|
||||||
|
"tests/fixtures/m18m20-progress-circle-doc-1.vue",
|
||||||
|
"tests/fixtures/m18m20-meter-doc-0.vue",
|
||||||
|
"tests/fixtures/m18m20-meter-doc-1.vue",
|
||||||
|
];
|
||||||
|
const fixtures = await Promise.all(
|
||||||
|
fixturePaths.map(async (path) => ({
|
||||||
|
path,
|
||||||
|
mod: (await import("./" + path.replace("tests/", ""))).default,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
for (const file of docs) {
|
||||||
|
const source = readFileSync(file, "utf8");
|
||||||
|
const blocks = [...source.matchAll(/```vue\n([\s\S]*?)```/g)].map(
|
||||||
|
(m) => m[1],
|
||||||
|
);
|
||||||
|
expect(blocks.length).toBeGreaterThanOrEqual(2);
|
||||||
|
for (const block of blocks) {
|
||||||
|
const fixture = fixtures[index];
|
||||||
|
expect(fixture).toBeTruthy();
|
||||||
|
expect(readFileSync(fixture.path, "utf8")).toBe(block);
|
||||||
|
const w = mount(fixture.mod as never, { attachTo: document.body });
|
||||||
|
expect(w.html().length).toBeGreaterThan(20);
|
||||||
|
w.unmount();
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(index).toBe(6);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("M18–M20 review regressions", () => {
|
||||||
|
it("keeps explicit aria-labelledby on all three roots", () => {
|
||||||
|
const cases = [
|
||||||
|
{ Comp: ProgressBar, slot: "progress-bar" },
|
||||||
|
{ Comp: ProgressCircle, slot: "progress-circle" },
|
||||||
|
{ Comp: Meter, slot: "meter" },
|
||||||
|
] as const;
|
||||||
|
for (const { Comp, slot } of cases) {
|
||||||
|
const w = mount(Comp, {
|
||||||
|
props: { value: 40 },
|
||||||
|
attrs: { "aria-labelledby": "external-label" },
|
||||||
|
});
|
||||||
|
expect(w.get(`[data-slot=${slot}]`).attributes("aria-labelledby")).toBe(
|
||||||
|
"external-label",
|
||||||
|
);
|
||||||
|
w.unmount();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps dynamic aria-labelledby updates and removals", async () => {
|
||||||
|
const labelledby = ref<string | undefined>("external-label");
|
||||||
|
const w = mount(ProgressBar, {
|
||||||
|
props: { value: 10 },
|
||||||
|
attrs: {
|
||||||
|
get "aria-labelledby"() {
|
||||||
|
return labelledby.value;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// re-render when ref changes
|
||||||
|
});
|
||||||
|
// attrs object getters need a reactive wrapper component instead
|
||||||
|
w.unmount();
|
||||||
|
|
||||||
|
const wrapper = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: { ProgressBar },
|
||||||
|
setup: () => ({ labelledby }),
|
||||||
|
template: `
|
||||||
|
<ProgressBar
|
||||||
|
:value="10"
|
||||||
|
:aria-labelledby="labelledby"
|
||||||
|
data-testid="root"
|
||||||
|
/>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const root = wrapper.get("[data-testid=root]");
|
||||||
|
expect(root.attributes("aria-labelledby")).toBe("external-label");
|
||||||
|
|
||||||
|
labelledby.value = "other-label";
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-labelledby")).toBe("other-label");
|
||||||
|
|
||||||
|
labelledby.value = undefined;
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-labelledby")).toBeUndefined();
|
||||||
|
|
||||||
|
labelledby.value = "external-label";
|
||||||
|
await nextTick();
|
||||||
|
expect(root.attributes("aria-labelledby")).toBe("external-label");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves explicit Label id and unique auto ids for multiple labels", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: { Label, ProgressBar },
|
||||||
|
template: `
|
||||||
|
<ProgressBar :value="50">
|
||||||
|
<Label id="my-label">自定义</Label>
|
||||||
|
<Label>自动甲</Label>
|
||||||
|
<Label>自动乙</Label>
|
||||||
|
</ProgressBar>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
const labels = w.findAll("[data-slot=label]");
|
||||||
|
expect(labels).toHaveLength(3);
|
||||||
|
const ids = labels.map((l) => l.attributes("id"));
|
||||||
|
expect(ids[0]).toBe("my-label");
|
||||||
|
expect(ids[1]).toBeTruthy();
|
||||||
|
expect(ids[2]).toBeTruthy();
|
||||||
|
expect(new Set(ids).size).toBe(3);
|
||||||
|
|
||||||
|
const root = w.get("[data-slot=progress-bar]");
|
||||||
|
const labelledby = root.attributes("aria-labelledby")!.split(/\s+/);
|
||||||
|
expect(labelledby).toContain("my-label");
|
||||||
|
expect(labelledby).toContain(ids[1]);
|
||||||
|
expect(labelledby).toContain(ids[2]);
|
||||||
|
expect(labelledby).toHaveLength(3);
|
||||||
|
// Every referenced id exists in the mounted tree
|
||||||
|
for (const id of labelledby) {
|
||||||
|
expect(w.find(`[id="${id}"]`).exists()).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("restores native label when for is added dynamically and removes it again", async () => {
|
||||||
|
const forAttr = ref<string | undefined>(undefined);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: { Label, ProgressBar },
|
||||||
|
setup: () => ({ forAttr }),
|
||||||
|
template: `
|
||||||
|
<ProgressBar :value="50">
|
||||||
|
<Label :for="forAttr">动态标签</Label>
|
||||||
|
</ProgressBar>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("[data-slot=label]").element.tagName).toBe("SPAN");
|
||||||
|
|
||||||
|
forAttr.value = "target-input";
|
||||||
|
await nextTick();
|
||||||
|
const asLabel = w.get("[data-slot=label]");
|
||||||
|
expect(asLabel.element.tagName).toBe("LABEL");
|
||||||
|
expect(asLabel.attributes("for")).toBe("target-input");
|
||||||
|
|
||||||
|
forAttr.value = "other-input";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("[data-slot=label]").attributes("for")).toBe("other-input");
|
||||||
|
|
||||||
|
forAttr.value = undefined;
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("[data-slot=label]").element.tagName).toBe("SPAN");
|
||||||
|
|
||||||
|
forAttr.value = "target-input";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("[data-slot=label]").element.tagName).toBe("LABEL");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps field labels working when for is present without indicator span override", async () => {
|
||||||
|
// No indicator context: default remains native label without for
|
||||||
|
const w = mount(Label, { slots: { default: "独立标签" } });
|
||||||
|
expect(w.get("[data-slot=label]").element.tagName).toBe("LABEL");
|
||||||
|
|
||||||
|
const withFor = mount(Label, {
|
||||||
|
attrs: { for: "x" },
|
||||||
|
slots: { default: "关联标签" },
|
||||||
|
});
|
||||||
|
expect(withFor.get("[data-slot=label]").element.tagName).toBe("LABEL");
|
||||||
|
expect(withFor.get("[data-slot=label]").attributes("for")).toBe("x");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("M18–M20 docs navigation", () => {
|
||||||
|
it("registers the three pages in Layout sidebar groups", () => {
|
||||||
|
const source = readFileSync(
|
||||||
|
"apps/docs/.vitepress/theme/Layout.vue",
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
for (const url of [
|
||||||
|
"/components/meter",
|
||||||
|
"/components/progress-bar",
|
||||||
|
"/components/progress-circle",
|
||||||
|
]) {
|
||||||
|
expect(source).toContain(`url: "${url}"`);
|
||||||
|
}
|
||||||
|
expect(source).toContain("Meter 计量条");
|
||||||
|
expect(source).toContain("ProgressBar 进度条");
|
||||||
|
expect(source).toContain("ProgressCircle 环形进度条");
|
||||||
|
// Order relative to neighbors used by prev/next
|
||||||
|
const link = source.indexOf('url: "/components/link"');
|
||||||
|
const meter = source.indexOf('url: "/components/meter"');
|
||||||
|
const bar = source.indexOf('url: "/components/progress-bar"');
|
||||||
|
const circle = source.indexOf('url: "/components/progress-circle"');
|
||||||
|
const radio = source.indexOf('url: "/components/radio-group"');
|
||||||
|
expect(link).toBeGreaterThan(-1);
|
||||||
|
expect(meter).toBeGreaterThan(link);
|
||||||
|
expect(bar).toBeGreaterThan(meter);
|
||||||
|
expect(circle).toBeGreaterThan(bar);
|
||||||
|
expect(radio).toBeGreaterThan(circle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes stale label IDs and keeps associations correct after id removal and reordering", async () => {
|
||||||
|
const rows = ref(["a", "b"]);
|
||||||
|
const ids = ref<Record<string, string>>({ a: "first-label" });
|
||||||
|
const w = mount({
|
||||||
|
render: () =>
|
||||||
|
h(ProgressBar, {}, () =>
|
||||||
|
rows.value.map((key) =>
|
||||||
|
h(
|
||||||
|
Label,
|
||||||
|
{ key, ...(ids.value[key] ? { id: ids.value[key] } : {}) },
|
||||||
|
() => key,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
for (const step of [
|
||||||
|
() => {
|
||||||
|
ids.value = { a: "new-first" };
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
ids.value = {};
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
rows.value = ["b", "a"];
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
rows.value = ["a"];
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
rows.value = [];
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
rows.value = ["b"];
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
step();
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
const labelIds = w
|
||||||
|
.findAll("[data-slot=label]")
|
||||||
|
.map((n) => n.attributes("id"));
|
||||||
|
const refs = (w.attributes("aria-labelledby") ?? "")
|
||||||
|
.split(" ")
|
||||||
|
.filter(Boolean);
|
||||||
|
expect([...refs].sort()).toEqual([...labelIds].sort());
|
||||||
|
expect(new Set(labelIds).size).toBe(labelIds.length);
|
||||||
|
}
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("isolates indicator labels from both surrounding and nested field scopes", async () => {
|
||||||
|
const w = mount({
|
||||||
|
render: () =>
|
||||||
|
h(TextField, {}, () => [
|
||||||
|
h(Label, { id: "outer-field" }, () => "Outer"),
|
||||||
|
h(Input),
|
||||||
|
h(ProgressBar, {}, () => [
|
||||||
|
h(Label, { id: "progress-title" }, () => "Progress"),
|
||||||
|
h(TextField, {}, () => [
|
||||||
|
h(Label, { id: "inner-field" }, () => "Inner"),
|
||||||
|
h(Input),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
const indicator = w.get("[data-slot=progress-bar]");
|
||||||
|
expect(indicator.attributes("aria-labelledby")).toBe("progress-title");
|
||||||
|
const label = w.get("#progress-title");
|
||||||
|
expect(label.element.tagName).toBe("SPAN");
|
||||||
|
expect(label.attributes("for")).toBeUndefined();
|
||||||
|
const inputs = w.findAll("[data-slot=input]");
|
||||||
|
expect(w.get("#outer-field").attributes("for")).toBe(
|
||||||
|
inputs[0].attributes("id"),
|
||||||
|
);
|
||||||
|
expect(w.get("#inner-field").attributes("for")).toBe(
|
||||||
|
inputs[1].attributes("id"),
|
||||||
|
);
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hydrates complete label associations with nested field isolation", async () => {
|
||||||
|
const show = ref(true);
|
||||||
|
const Example = defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h("div", {}, [
|
||||||
|
h(ProgressBar, {}, () => [
|
||||||
|
h(Label, {}, () => "Progress"),
|
||||||
|
...(show.value
|
||||||
|
? [h(Label, { id: "extra-progress-label" }, () => "Detail")]
|
||||||
|
: []),
|
||||||
|
h(TextField, {}, () => [h(Label, {}, () => "Field"), h(Input)]),
|
||||||
|
]),
|
||||||
|
h(Meter, {}, () => h(Label, {}, () => "Storage")),
|
||||||
|
h(ProgressCircle, {}, () => h(Label, {}, () => "Loading")),
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
const html = await renderToString(createSSRApp(Example));
|
||||||
|
const host = document.createElement("div");
|
||||||
|
host.innerHTML = html;
|
||||||
|
document.body.append(host);
|
||||||
|
function assertReferences() {
|
||||||
|
const ids = [...host.querySelectorAll("[id]")].map((el) => el.id);
|
||||||
|
expect(new Set(ids).size).toBe(ids.length);
|
||||||
|
for (const el of host.querySelectorAll("[aria-labelledby],[for]")) {
|
||||||
|
for (const id of (
|
||||||
|
el.getAttribute("aria-labelledby") ??
|
||||||
|
el.getAttribute("for") ??
|
||||||
|
""
|
||||||
|
)
|
||||||
|
.split(" ")
|
||||||
|
.filter(Boolean))
|
||||||
|
expect(ids).toContain(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertReferences();
|
||||||
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||||
|
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||||
|
const app = createSSRApp(Example);
|
||||||
|
try {
|
||||||
|
app.mount(host);
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
assertReferences();
|
||||||
|
const progress = host.querySelector("[data-slot=progress-bar]")!;
|
||||||
|
const nestedLabel = host.querySelector(
|
||||||
|
"[data-slot=textfield] [data-slot=label]",
|
||||||
|
)!;
|
||||||
|
expect(progress.getAttribute("aria-labelledby")?.split(" ")).not.toContain(
|
||||||
|
nestedLabel.id,
|
||||||
|
);
|
||||||
|
show.value = false;
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
assertReferences();
|
||||||
|
expect(progress.getAttribute("aria-labelledby")).not.toContain(
|
||||||
|
"extra-progress-label",
|
||||||
|
);
|
||||||
|
expect(warn).not.toHaveBeenCalled();
|
||||||
|
expect(error).not.toHaveBeenCalled();
|
||||||
|
} finally {
|
||||||
|
app.unmount();
|
||||||
|
host.remove();
|
||||||
|
warn.mockRestore();
|
||||||
|
error.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -234,3 +234,64 @@ it("renders typography, empty state and breadcrumbs without browser globals", as
|
|||||||
expect(html).toContain("hv-breadcrumbs__separator");
|
expect(html).toContain("hv-breadcrumbs__separator");
|
||||||
expect(html).toContain("富文本段落");
|
expect(html).toContain("富文本段落");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders progress and meter indicators without browser globals", async () => {
|
||||||
|
const {
|
||||||
|
Label,
|
||||||
|
Meter,
|
||||||
|
MeterFill,
|
||||||
|
MeterOutput,
|
||||||
|
MeterTrack,
|
||||||
|
ProgressBar,
|
||||||
|
ProgressBarFill,
|
||||||
|
ProgressBarOutput,
|
||||||
|
ProgressBarTrack,
|
||||||
|
ProgressCircle,
|
||||||
|
ProgressCircleFillCircle,
|
||||||
|
ProgressCircleTrack,
|
||||||
|
ProgressCircleTrackCircle,
|
||||||
|
} = await import("../packages/vue/src");
|
||||||
|
const html = await renderToString(
|
||||||
|
createSSRApp({
|
||||||
|
render: () =>
|
||||||
|
h("div", {}, [
|
||||||
|
h(ProgressBar, { value: 60 }, () => [
|
||||||
|
h(Label, null, () => "加载中"),
|
||||||
|
h(ProgressBarOutput),
|
||||||
|
h(ProgressBarTrack, null, () => h(ProgressBarFill)),
|
||||||
|
]),
|
||||||
|
h(
|
||||||
|
ProgressCircle,
|
||||||
|
{ isIndeterminate: true, "aria-label": "加载中" },
|
||||||
|
() => [
|
||||||
|
h(ProgressCircleTrack, null, () => [
|
||||||
|
h(ProgressCircleTrackCircle),
|
||||||
|
h(ProgressCircleFillCircle),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
h(Meter, { value: 40, "aria-label": "存储空间" }, () => [
|
||||||
|
h(MeterOutput),
|
||||||
|
h(MeterTrack, null, () => h(MeterFill)),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(html).toContain('role="progressbar"');
|
||||||
|
expect(html).toContain('aria-valuenow="60"');
|
||||||
|
expect(html).toContain('aria-valuetext="60%"');
|
||||||
|
expect(html).toContain("hv-progress-bar__fill");
|
||||||
|
expect(html).toContain("hv-progress-circle__fill-circle");
|
||||||
|
// Indeterminate progress must not expose aria-valuenow.
|
||||||
|
expect(html.match(/aria-valuenow/g)).toHaveLength(2);
|
||||||
|
expect(html).toContain('role="meter progressbar"');
|
||||||
|
expect(html).toContain('aria-valuenow="40"');
|
||||||
|
expect(html).toContain('data-slot="meter-output"');
|
||||||
|
// Label association ids are present in the server HTML and resolve to labels.
|
||||||
|
const labelledby = html.match(/aria-labelledby="([^"]+)"/)?.[1];
|
||||||
|
expect(labelledby).toBeTruthy();
|
||||||
|
for (const id of labelledby!.split(/\s+/)) {
|
||||||
|
expect(html).toMatch(new RegExp(`id="${id}"[^>]*data-slot="label"`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user