feat: add Badge and Alert components
This commit is contained in:
@@ -204,6 +204,8 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
- 原始 CSS、语义变量、尺寸、间距、圆角、阴影、动效、data-slot 与状态属性优先移植并适配。使用 hv- 命名空间不改变视觉数值。
|
||||
- 属性名称、默认值和变体集合尽量保留;仅框架机制要求的事件、插槽、响应式值和组合导出改为 Vue 方式。参数不能无记录地删减。
|
||||
- 文档以原中文标题、介绍、示例次序、API 表格和导航层次为基线,使用专门的文档布局,不沿用默认 VitePress 外观。演示代码必须来自被渲染的同一份 SFC。
|
||||
- 移植 API 表须完成框架适配,不能直接保留 React className、children、ReactNode、ComponentProps 或对象式子部件名称作为 Vue API。附加类统一写 `class`,支持字符串、数组、对象并合并基础类;内容写实际插槽,事件按真实 Vue 契约说明。历史对照和差异说明可保留 React 原名。
|
||||
- API 表逐个检查 Root 与全部子部件,并按文档写最小消费场景确认属性确实生效;不能只核对主组件和演示。不得为迁就文档残留增加 className 等无需求别名;补充本批 API 表与演示的文档契约检查。
|
||||
- 默认开发入口是文档站;playground 仅用于回归场景。未迁移的示例与能力明确列出,不以占位内容充数。
|
||||
- 验收分别记录源样式移植、组件行为、文档布局和真实浏览器对比结果。移植了 CSS 不等于已经通过逐像素对比。
|
||||
|
||||
@@ -284,6 +286,7 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
- 按改动运行 `pnpm test`、`pnpm typecheck`、`pnpm build:docs`、`pnpm format`;涉及消费验证页时加 `pnpm build:playground`。当前完整测试为 34 项,此数仅作本轮记录。
|
||||
- 回归优先测试用户可感知行为:重复操作、状态恢复、焦点、表单值、标签关联和只读键盘路径。文档清单测试检查预览名称与顺序;它不能证明示例内容和外观正确。
|
||||
- 单元测试、SSR 冒烟、手动浏览器检查、自动无障碍和自动视觉对比分别记录。测试通过、CSS 移植或示例齐全均不等于整组件完成兼容验收。
|
||||
- 各测试入口记录实际文件数、通过数及是否包含 SSR,不写“同上”。新增测试后同步最终计数;历史结果标明阶段,不让旧数字冒充当前验证结果。
|
||||
- 视觉证据注明版本、视口、主题及状态,必要时附计算样式。未来建立自动对比后,不能通过更新截图掩盖回归。
|
||||
- 同步维护 `docs/compatibility.md`(能力与差异)、`docs/upstream.md`(来源与许可)、`docs/verification.md`(实际验证与限制)。详细历史留在这些文件,AGENTS.md 维护后续可执行的规则。
|
||||
- 上游部分包清单标注 MIT,但本地根许可证实际为 Apache-2.0。保留 `third-party/HEROUI-LICENSE` 与样式包许可证,不根据包清单猜测移植许可;新增第三方图标包按其自身许可记录。
|
||||
|
||||
@@ -44,8 +44,10 @@ const groups = [
|
||||
{
|
||||
title: "组件",
|
||||
items: [
|
||||
{ title: "Alert 警告", url: "/components/alert" },
|
||||
{ title: "Avatar 头像", url: "/components/avatar" },
|
||||
{ title: "AvatarGroup 头像组", url: "/components/avatar-group" },
|
||||
{ title: "Badge 徽章", url: "/components/badge" },
|
||||
{ title: "Button 按钮", url: "/components/button" },
|
||||
{ title: "Card 卡片", url: "/components/card" },
|
||||
{ title: "Chip 标签", url: "/components/chip" },
|
||||
|
||||
@@ -3,8 +3,10 @@ title: 组件
|
||||
description: 已迁移组件及文档
|
||||
---
|
||||
|
||||
- [Alert 警告](./components/alert)
|
||||
- [Avatar 头像](./components/avatar)
|
||||
- [AvatarGroup 头像组](./components/avatar-group)
|
||||
- [Badge 徽章](./components/badge)
|
||||
- [Button 按钮](./components/button)
|
||||
- [Card 卡片](./components/card)
|
||||
- [Chip 标签](./components/chip)
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
title: Alert 警告
|
||||
description: 向用户展示重要消息与通知,并提供状态指示
|
||||
component: alert
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Alert,
|
||||
AlertContent,
|
||||
AlertDescription,
|
||||
AlertIndicator,
|
||||
AlertTitle,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="alert-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Alert,
|
||||
AlertContent,
|
||||
AlertDescription,
|
||||
AlertIndicator,
|
||||
AlertTitle,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Alert>
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle />
|
||||
<AlertDescription />
|
||||
</AlertContent>
|
||||
</Alert>
|
||||
</template>
|
||||
```
|
||||
|
||||
省略 `AlertIndicator` 默认插槽时显示随 `status` 变化的状态图标;传入自定义内容会替换默认图标。
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="alert-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
要自定义 Alert 的组件类,可使用 `@layer components` 指令。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-alert {
|
||||
@apply rounded-2xl shadow-lg;
|
||||
}
|
||||
|
||||
.hv-alert__title {
|
||||
@apply font-bold text-lg;
|
||||
}
|
||||
|
||||
.hv-alert--danger {
|
||||
@apply border-l-4 border-red-600;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Alert 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/alert.css)):
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-alert` - Alert 根容器
|
||||
- `.hv-alert__indicator` - 图标/指示器容器
|
||||
- `.hv-alert__content` - 包裹标题与说明的内容容器
|
||||
- `.hv-alert__title` - Alert 标题文本
|
||||
- `.hv-alert__description` - Alert 说明文本
|
||||
|
||||
#### 状态变体类 [!toc]
|
||||
|
||||
- `.hv-alert--default` - 默认灰色状态
|
||||
- `.hv-alert--accent` - 强调蓝色状态
|
||||
- `.hv-alert--success` - 成功绿色状态
|
||||
- `.hv-alert--warning` - 警告黄/橙色状态
|
||||
- `.hv-alert--danger` - 危险红色状态
|
||||
|
||||
### 交互状态
|
||||
|
||||
Alert 主要用于信息展示,基础组件本身通常没有交互状态;但它可以包含按钮或关闭按钮等交互元素。不会自动获得焦点、弹窗或自动关闭行为。
|
||||
|
||||
## API 参考
|
||||
|
||||
### Alert
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | ------------------------------------------------------------- | ----------- | ----------------------------- |
|
||||
| `status` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | Alert 的视觉状态 |
|
||||
| 默认插槽 | `Component` | - | Alert 内容 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### AlertIndicator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ------------------------------------------------------------ |
|
||||
| 默认插槽 | `Component` | - | 自定义指示图标;省略或内容为空时显示随 status 更新的默认图标 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### AlertContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 内容(通常为 Title 与 Description) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### AlertTitle
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | Alert 标题文本 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### AlertDescription
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | Alert 说明文本 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与对应 slot 的基础类合并;不要使用 React 的 `className`。命名导出为 `Alert` / `AlertIndicator` / `AlertContent` / `AlertTitle` / `AlertDescription`,不使用 `Alert.Indicator` 对象式子部件。
|
||||
|
||||
Alert 会把内部 `surfaceContext` 重置为 `default`,避免嵌套在其他 Surface 中时意外继承外层表面变体。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Button 按钮](./button) · [CloseButton 关闭按钮](./close-button) · [Spinner 加载指示器](./spinner)
|
||||
@@ -0,0 +1,189 @@
|
||||
---
|
||||
title: Badge 徽章
|
||||
description: 相对其他元素定位的小型指示器,常用于通知数量、状态点与标签
|
||||
component: badge
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Badge, BadgeAnchor } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="badge-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
Badge 通过 `BadgeAnchor` 相对其他元素定位。纯文本子节点会自动包裹在 `<BadgeLabel>` 中。
|
||||
|
||||
> 独立标签用法请使用 [Chip](/components/chip) 组件。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Avatar, Badge, BadgeAnchor } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BadgeAnchor>
|
||||
<Avatar />
|
||||
<Badge color="danger">5</Badge>
|
||||
</BadgeAnchor>
|
||||
</template>
|
||||
```
|
||||
|
||||
`BadgeAnchor` 是定位容器,不是导航链接。
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="badge-variants" />
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="badge-sizes" />
|
||||
|
||||
### 颜色
|
||||
|
||||
<ComponentPreview name="badge-colors" />
|
||||
|
||||
### 徽章位置
|
||||
|
||||
<ComponentPreview name="badge-placements" />
|
||||
|
||||
### 点状徽标
|
||||
|
||||
空徽章作为状态指示器,适用于在线/离线或活动信号。
|
||||
|
||||
<ComponentPreview name="badge-dot" />
|
||||
|
||||
### 带内容
|
||||
|
||||
Badge 支持文本、数字与图标。无子节点时渲染为点状指示器。
|
||||
|
||||
<ComponentPreview name="badge-with-content" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="badge-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
可使用 `@layer components` 指令自定义 Badge 组件类。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-badge {
|
||||
@apply rounded-full text-xs;
|
||||
}
|
||||
|
||||
.hv-badge__label {
|
||||
@apply font-semibold;
|
||||
}
|
||||
|
||||
.hv-badge--accent {
|
||||
@apply shadow-sm;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Badge 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/badge.css)):
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-badge` - 基础徽章容器样式
|
||||
- `.hv-badge__label` - 标签文本 slot 样式
|
||||
- `.hv-badge-anchor` - 锚定元素的定位包装器
|
||||
|
||||
#### 颜色类 [!toc]
|
||||
|
||||
- `.hv-badge--accent` - 强调色变体
|
||||
- `.hv-badge--danger` - 危险色变体
|
||||
- `.hv-badge--default` - 默认色变体
|
||||
- `.hv-badge--success` - 成功色变体
|
||||
- `.hv-badge--warning` - 警告色变体
|
||||
|
||||
#### 变体类 [!toc]
|
||||
|
||||
- `.hv-badge--primary` - 填充背景的主变体
|
||||
- `.hv-badge--secondary` - 默认背景的次变体
|
||||
- `.hv-badge--soft` - 浅色背景的 soft 变体
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-badge--sm` - 小尺寸
|
||||
- `.hv-badge--md` - 中尺寸(默认)
|
||||
- `.hv-badge--lg` - 大尺寸
|
||||
|
||||
#### 位置类 [!toc]
|
||||
|
||||
- `.hv-badge--top-right` - 右上角(默认)
|
||||
- `.hv-badge--top-left` - 左上角
|
||||
- `.hv-badge--bottom-right` - 右下角
|
||||
- `.hv-badge--bottom-left` - 左下角
|
||||
|
||||
#### 复合变体类 [!toc]
|
||||
|
||||
Badge 支持组合变体与颜色类(如 `.hv-badge--primary.hv-badge--accent`)。以下组合有默认样式:
|
||||
|
||||
**Primary Variants:**
|
||||
|
||||
- `.hv-badge--primary.hv-badge--accent` - 填充背景的 primary accent
|
||||
- `.hv-badge--primary.hv-badge--default` - 填充背景的 primary default
|
||||
- `.hv-badge--primary.hv-badge--success` - 填充背景的 primary success
|
||||
- `.hv-badge--primary.hv-badge--warning` - 填充背景的 primary warning
|
||||
- `.hv-badge--primary.hv-badge--danger` - 填充背景的 primary danger
|
||||
|
||||
**Soft Variants:**
|
||||
|
||||
- `.hv-badge--soft.hv-badge--accent` - 浅色背景的 soft accent
|
||||
- `.hv-badge--soft.hv-badge--default` - 浅色背景的 soft default
|
||||
- `.hv-badge--soft.hv-badge--success` - 浅色背景的 soft success
|
||||
- `.hv-badge--soft.hv-badge--warning` - 浅色背景的 soft warning
|
||||
- `.hv-badge--soft.hv-badge--danger` - 浅色背景的 soft danger
|
||||
|
||||
## API 参考
|
||||
|
||||
### Badge
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | -------------------------------------------------------------- | ------------- | -------------------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 徽章内容(文本、数字或图标)。省略时渲染为点 |
|
||||
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | 徽章颜色变体 |
|
||||
| `variant` | `'primary' \| 'secondary' \| 'soft'` | `'primary'` | 视觉样式变体 |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 徽章尺寸 |
|
||||
| `placement` | `'top-right' \| 'top-left' \| 'bottom-right' \| 'bottom-left'` | `'top-right'` | 相对锚点的位置 |
|
||||
| `class` | `string \| Array \| Object` | - | 根元素附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
纯文本或数字默认插槽会在渲染时包装为 `BadgeLabel`;显式 `BadgeLabel` 或图标等组合内容不会重复包装。
|
||||
|
||||
### BadgeAnchor
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | --------------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 被锚定元素及 Badge 本身 |
|
||||
| `class` | `string \| Array \| Object` | - | 锚点包装器附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### BadgeLabel
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | --------------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 标签文本内容 |
|
||||
| `class` | `string \| Array \| Object` | - | 标签 slot 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件或 slot 基础类合并;不要使用 React 的 `className`。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Chip 标签](./chip) · [Avatar 头像](./avatar)
|
||||
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Alert,
|
||||
AlertContent,
|
||||
AlertDescription,
|
||||
AlertIndicator,
|
||||
AlertTitle,
|
||||
Button,
|
||||
CloseButton,
|
||||
Spinner,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid w-full max-w-xl gap-4">
|
||||
<!-- 默认 — 一般信息 -->
|
||||
<Alert>
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle>新功能已上线</AlertTitle>
|
||||
<AlertDescription>
|
||||
查看我们的最新更新,包括深色模式支持与改进的无障碍体验。
|
||||
</AlertDescription>
|
||||
</AlertContent>
|
||||
</Alert>
|
||||
|
||||
<!-- 强调 — 重要信息含操作 -->
|
||||
<Alert status="accent">
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle>有可用更新</AlertTitle>
|
||||
<AlertDescription>
|
||||
应用有新版本可用。请刷新页面以获取最新功能与问题修复。
|
||||
</AlertDescription>
|
||||
<Button class="mt-2 sm:hidden" size="sm" variant="primary">刷新</Button>
|
||||
</AlertContent>
|
||||
<Button class="hidden sm:block" size="sm" variant="primary">刷新</Button>
|
||||
</Alert>
|
||||
|
||||
<!-- 危险 — 错误与排查步骤 -->
|
||||
<Alert status="danger">
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle>无法连接到服务器</AlertTitle>
|
||||
<AlertDescription>
|
||||
当前遇到连接问题,请尝试以下操作:
|
||||
<ul class="mt-2 list-inside list-disc space-y-1 text-sm">
|
||||
<li>检查网络连接</li>
|
||||
<li>刷新页面</li>
|
||||
<li>清除浏览器缓存</li>
|
||||
</ul>
|
||||
</AlertDescription>
|
||||
<Button class="mt-2 sm:hidden" size="sm" variant="danger">重试</Button>
|
||||
</AlertContent>
|
||||
<Button class="hidden sm:block" size="sm" variant="danger">重试</Button>
|
||||
</Alert>
|
||||
|
||||
<!-- 无描述 -->
|
||||
<Alert status="success">
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle>个人资料已更新</AlertTitle>
|
||||
</AlertContent>
|
||||
<CloseButton />
|
||||
</Alert>
|
||||
|
||||
<!-- 自定义指示器 — 加载中 -->
|
||||
<Alert status="accent">
|
||||
<AlertIndicator>
|
||||
<Spinner size="sm" />
|
||||
</AlertIndicator>
|
||||
<AlertContent>
|
||||
<AlertTitle>正在处理你的请求</AlertTitle>
|
||||
<AlertDescription>
|
||||
正在同步你的数据,请稍候,这可能需要一点时间。
|
||||
</AlertDescription>
|
||||
</AlertContent>
|
||||
</Alert>
|
||||
|
||||
<!-- 无关闭按钮 -->
|
||||
<Alert status="warning">
|
||||
<AlertIndicator />
|
||||
<AlertContent>
|
||||
<AlertTitle>计划维护</AlertTitle>
|
||||
<AlertDescription>
|
||||
我们将于 UTC 时间 3 月 15 日(周日)凌晨 2:00 至上午 6:00
|
||||
进行计划维护,期间服务将暂时不可用。
|
||||
</AlertDescription>
|
||||
</AlertContent>
|
||||
</Alert>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Alert,
|
||||
AlertContent,
|
||||
AlertDescription,
|
||||
AlertIndicator,
|
||||
AlertTitle,
|
||||
Button,
|
||||
CloseButton,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full max-w-xl">
|
||||
<Alert
|
||||
class="relative overflow-hidden rounded-xl border border-warning/20 bg-linear-to-br from-warning/10 via-surface to-surface-secondary shadow-sm dark:border-warning/30 dark:from-warning/15 dark:via-surface dark:to-warning/5"
|
||||
status="warning"
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute -top-8 -right-8 size-28 rounded-full bg-warning/15 blur-2xl dark:bg-warning/25"
|
||||
/>
|
||||
<AlertIndicator class="relative text-warning" />
|
||||
<AlertContent class="relative">
|
||||
<AlertTitle>支付方式即将过期</AlertTitle>
|
||||
<AlertDescription>
|
||||
您的 Visa 卡(尾号 4242)将于 3 月 28 日过期。请更新账单信息,以免影响
|
||||
Pro 订阅。
|
||||
</AlertDescription>
|
||||
<Button class="mt-3 sm:hidden" size="sm" variant="tertiary">
|
||||
更新账单
|
||||
</Button>
|
||||
</AlertContent>
|
||||
<Button
|
||||
class="relative hidden shrink-0 sm:inline-flex"
|
||||
size="sm"
|
||||
variant="tertiary"
|
||||
>
|
||||
更新账单
|
||||
</Button>
|
||||
<CloseButton class="relative" />
|
||||
</Alert>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const GREEN_AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
const ORANGE_AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg";
|
||||
const BLUE_AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="GREEN_AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="danger" size="sm">5</Badge>
|
||||
</BadgeAnchor>
|
||||
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="ORANGE_AVATAR_URL" />
|
||||
<AvatarFallback>AB</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="accent" size="sm">新</Badge>
|
||||
</BadgeAnchor>
|
||||
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="BLUE_AVATAR_URL" />
|
||||
<AvatarFallback>CD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="success" placement="bottom-right" size="sm" />
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
|
||||
const colors = ["default", "accent", "success", "warning", "danger"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor v-for="color in colors" :key="color">
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge :color="color" size="sm" />
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage
|
||||
alt="凯特·威尔逊"
|
||||
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
|
||||
/>
|
||||
<AvatarFallback>KW</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge
|
||||
class="min-w-5 font-semibold tabular-nums"
|
||||
color="accent"
|
||||
size="sm"
|
||||
variant="soft"
|
||||
>
|
||||
5
|
||||
</Badge>
|
||||
</BadgeAnchor>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
|
||||
const colors = ["accent", "success", "warning", "danger"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor v-for="color in colors" :key="color">
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge :color="color" placement="bottom-right" size="sm" />
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
|
||||
const placements = [
|
||||
"top-right",
|
||||
"top-left",
|
||||
"bottom-right",
|
||||
"bottom-left",
|
||||
] as const;
|
||||
|
||||
const PLACEMENT_LABELS: Record<(typeof placements)[number], string> = {
|
||||
"bottom-left": "左下",
|
||||
"bottom-right": "右下",
|
||||
"top-left": "左上",
|
||||
"top-right": "右上",
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-8">
|
||||
<div
|
||||
v-for="placement in placements"
|
||||
:key="placement"
|
||||
class="flex flex-col items-center gap-2"
|
||||
>
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="accent" :placement="placement" size="sm" />
|
||||
</BadgeAnchor>
|
||||
<span class="text-xs text-muted">{{ PLACEMENT_LABELS[placement] }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
|
||||
const sizes = ["sm", "md", "lg"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor v-for="size in sizes" :key="size">
|
||||
<Avatar :size="size">
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="danger" :size="size">5</Badge>
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
Separator,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
|
||||
const variants = ["primary", "secondary", "soft"] as const;
|
||||
|
||||
const VARIANT_LABELS: Record<(typeof variants)[number], string> = {
|
||||
primary: "主色",
|
||||
secondary: "次色",
|
||||
soft: "柔和",
|
||||
};
|
||||
|
||||
const colors = ["accent", "default", "success", "warning", "danger"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-8">
|
||||
<template v-for="(variant, index) in variants" :key="variant">
|
||||
<div class="flex flex-col gap-4">
|
||||
<h3 class="text-sm font-semibold text-muted">
|
||||
{{ VARIANT_LABELS[variant] }}
|
||||
</h3>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor v-for="color in colors" :key="color">
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge :color="color" size="sm" :variant="variant">5</Badge>
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</div>
|
||||
<Separator v-if="index < variants.length - 1" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconBell } from "@tabler/icons-vue";
|
||||
|
||||
const AVATAR_URL =
|
||||
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="danger" size="sm">5</Badge>
|
||||
</BadgeAnchor>
|
||||
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="danger" size="sm">新</Badge>
|
||||
</BadgeAnchor>
|
||||
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="danger" size="sm">99+</Badge>
|
||||
</BadgeAnchor>
|
||||
|
||||
<BadgeAnchor>
|
||||
<Avatar>
|
||||
<AvatarImage alt="头像" :src="AVATAR_URL" />
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
<Badge color="accent" size="sm">
|
||||
<IconBell class="size-2.5" aria-hidden="true" />
|
||||
</Badge>
|
||||
</BadgeAnchor>
|
||||
</div>
|
||||
</template>
|
||||
+12
-4
@@ -9,7 +9,7 @@
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -69,7 +69,7 @@
|
||||
| radio | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| radio-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| input-otp | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| alert | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| list-box-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| list-box-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -100,9 +100,9 @@ React Aria 专属 rac 导出与 React 图标类型不移植;Vue 版 ConfigProv
|
||||
|
||||
## 已实现组件的文档清单复核
|
||||
|
||||
Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||
Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,Badge 8 / 8,Alert 2 / 2,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||
|
||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。
|
||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。Badge 覆盖基本、变体、尺寸、颜色、四角位置、点状、带内容与自定义样式;Alert 覆盖六种组合的基本示例与自定义样式。
|
||||
|
||||
框架适配差异:Avatar 使用 Reka 组合,表单使用 Input/TextArea;链接原生锚点由 Link 组件封装;图标使用 Tabler 官方 Vue 组件(Link 自定义图标、CloseButton 自定义图标、Avatar 图标回退等示例);演示不提供认证、支付等业务服务。完整 React Aria 事件模型、全库字段上下文及自动视觉回归仍不在本批完成范围。
|
||||
|
||||
@@ -115,6 +115,14 @@ Card 图片、头像、横向布局、表单与自定义样式已补齐;Input
|
||||
- Chip:纯文本/数字默认插槽在渲染时包装为 `ChipLabel`;显式 `ChipLabel` 或图标等组合内容不重复包装;Fragment/Comment/空白文本不参与判定。文本与组合内容可在运行时切换。
|
||||
- Chip 演示图标由上游 `@gravity-ui/icons` 替换为 Tabler 官方 Vue 组件(`IconCircleFilled`/`IconCheck`/`IconClock` 等),尺寸以 `:size` 保留。
|
||||
|
||||
## M10–M11 说明
|
||||
|
||||
- Badge:`BadgeAnchor` 为相对定位 `span`,不是导航链接;纯文本/数字默认插槽包装为 `BadgeLabel`;空内容渲染点状;四角 placement 使用绝对定位与 25% 位移。
|
||||
- Alert:命名导出五个部件;默认指示图标为移植的基线 Info/Success/Warning/Danger SVG,随 `status` 更新;Indicator 插槽为空/注释时回退默认图标。内部 `surfaceContext` 重置为 `default`。
|
||||
- Alert 基本示例保留上游六种组合(默认、强调+响应式按钮、危险+排查列表、无描述+关闭、Spinner 指示器、无关闭按钮),未简化为两个提示框。
|
||||
- API 表全部使用 Vue 契约:`class`(字符串/数组/对象)、默认插槽;无 `className`/`children`/`ReactNode` 声明。
|
||||
- Badge 演示图标 Bell 替换为 Tabler `IconBell`。
|
||||
|
||||
## M04–M06 说明
|
||||
|
||||
- CloseButton:专用 `hv-close-button` CSS;默认插槽回退为基线 CloseIcon;`onPress` 改为 `@click`;isDisabled 设置原生 disabled 与 aria-disabled。
|
||||
|
||||
@@ -12,14 +12,15 @@
|
||||
|
||||
## 当前起点
|
||||
|
||||
| 范围 | 当前事实 | 不应作出的推断 |
|
||||
| ---------------------------------------------- | ------------------------------------------------------- | -------------------------------------------------- |
|
||||
| Button / Card / Input / Switch | 已有实现和文档,基线演示分别为 14 / 7 / 7 / 15 个 | 不代表 React Aria 的全部行为已兼容 |
|
||||
| SwitchGroup / Label / Description / FieldError | 已有部分组合能力;FieldError 当前仅接入 Switch | 不代表完整字段、表单与分组体系已完成 |
|
||||
| Surface / Link / Spinner | M01–M03 已提交,代码与构建复核通过 | 不代表所有浏览器与视觉兼容性已完成 |
|
||||
| CloseButton / Avatar / AvatarGroup / Skeleton | M04–M06 已提交,Card 已使用公共组件;动态更新问题已修复 | 仍有已披露的底座差异及视觉/水合等未验证边界 |
|
||||
| 主题与图标 | 已有默认浅深主题;演示与文档采用 Tabler 官方 Vue 图标 | 不能自行换品牌配色或自绘 SVG |
|
||||
| 验证 | 本轮提交时有 98 项测试、SSR 冒烟及部分手动浏览器记录 | 尚无完整自动浏览器、视觉、独立安装和 Nuxt 水合验收 |
|
||||
| 范围 | 当前事实 | 不应作出的推断 |
|
||||
| ---------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------- |
|
||||
| Button / Card / Input / Switch | 已有实现和文档,基线演示分别为 14 / 7 / 7 / 15 个 | 不代表 React Aria 的全部行为已兼容 |
|
||||
| SwitchGroup / Label / Description / FieldError | 已有部分组合能力;FieldError 当前仅接入 Switch | 不代表完整字段、表单与分组体系已完成 |
|
||||
| Surface / Link / Spinner | M01–M03 已提交,代码与构建复核通过 | 不代表所有浏览器与视觉兼容性已完成 |
|
||||
| CloseButton / Avatar / AvatarGroup / Skeleton | M04–M06 已提交,Card 已使用公共组件;动态更新问题已修复 | 仍有已披露的底座差异及视觉/水合等未验证边界 |
|
||||
| Separator / Kbd / Chip | M07–M09 已提交,19 个示例;API 表已修正为 Vue class | 不代表完整视觉与消费验收 |
|
||||
| 主题与图标 | 已有默认浅深主题;演示与文档采用 Tabler 官方 Vue 图标 | 不能自行换品牌配色或自绘 SVG |
|
||||
| 验证 | M07–M09 提交时全量 127 项测试(含 SSR),另有手动浏览器记录 | 尚无完整自动浏览器、视觉、独立安装和 Nuxt 水合验收 |
|
||||
|
||||
这些数字是本次快照。接手时先检查代码和兼容矩阵,不用旧数字作为验收目标。
|
||||
|
||||
@@ -91,6 +92,7 @@
|
||||
文档表格统一铺满正文内容区,长内容自动换行,不横向滚动、不缩小字号、不截断内容;
|
||||
复用公共样式,按本文“文档表格排版与验收”检查长类型 API 表和短内容插槽表。
|
||||
落实本文“两批迁移的反复缺陷与回归要求”,按组件适用性验证动态 attrs、插槽、class、类型及事件。
|
||||
API 表落实本文“M07–M09 文档契约返工”:className→class,children→插槽,逐部件验证。
|
||||
禁止用近似控件、占位内容或未生效的 Tailwind 类名充数。
|
||||
新增依赖或共享协议变更先说明缺口与影响,不擅自替换全库架构。
|
||||
|
||||
@@ -164,6 +166,15 @@
|
||||
- 新发现的底座缺口先验证能否局部补偿;只能在明确差异与影响后记录限制,不能以文档备注替代本来可实现的契约。已有 delayMs=0 等限制保留原记录,本节不追溯扩大既有验收结论。
|
||||
- 交接报告逐项写“适用/不适用、实际测试及结果”。独立复核人追加当前结论,实施者写修复记录,不自行把集成人的“待复核”改成“已验收”。
|
||||
|
||||
### M07–M09 文档契约返工
|
||||
|
||||
实际问题:Separator / Kbd / Chip 的实现与演示已经使用 Vue class,但三页六处 Root/子部件 API 表仍写 React className。用户照表使用时无法应用 CSS 类。运行时测试和构建均通过,不能发现这种说明与实现分离的问题。
|
||||
|
||||
- API 表按 Vue 实现重新核对字段名、类型、默认值和落点。类名统一为 `class`,说明接受字符串、数组和对象;children / ReactNode 改为实际插槽;组合部件使用本库命名导出;React 事件与 render prop 记录真实替代方式,不能简单改名后宣称等价。
|
||||
- 检查 Root 与每个子部件的 API 表、结构示例和可复制代码,不能只改主组件的一行。历史对照可以写 className,当前 Vue API 表与演示不能误声明它可用;不增加无需求的运行时别名掩盖文档错误。
|
||||
- 增加本批文档契约检查:API 表不把 React 专属名称声明成 Vue 属性,示例采用相同契约;配合实际消费用例确认 class 进入最终 DOM。文档字符串断言不能替代运行时检查。
|
||||
- 报告记录各测试入口的实际结果及是否包含 SSR,不写“同上”。本批返工前全量 126 / unit 125、返工新增测试后全量 127 是不同阶段,不混写为同一次执行结果。
|
||||
|
||||
### 文档表格排版与验收
|
||||
|
||||
适用于文档正文中的属性 API、事件、插槽、作用域状态及其他说明表格。宽度以正文内容区为准,不占用侧栏或右侧目录;演示区内的组件表格按组件自身契约处理。
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
# M10–M11 Badge / Alert 交接报告
|
||||
|
||||
实施日期:2026-10-21。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。**
|
||||
|
||||
## 1. 起点与改动范围
|
||||
|
||||
| 项 | 值 |
|
||||
| ---------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||
| 起始 HEAD | `3515a47`(feat: add Separator Kbd and Chip components) |
|
||||
| 工作区起点 | 保留未提交:`AGENTS.md`、`docs/migration-handoff.md`;未跟踪 `docs/migrations/M10-M11-prompt.md`(未改写) |
|
||||
| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) |
|
||||
| 范围 | Badge、BadgeAnchor、BadgeLabel;Alert、AlertIndicator、AlertContent、AlertTitle、AlertDescription。不含 AlertDialog。 |
|
||||
|
||||
### 新增
|
||||
|
||||
- 样式:`packages/styles/components/{badge,alert}.css`
|
||||
- 变体:`packages/styles/src/index.ts` 增加 `badgeVariants` / `alertVariants`
|
||||
- 组件:
|
||||
- `packages/vue/src/components/badge/{Badge,BadgeAnchor,BadgeLabel}.vue` + `context.ts`
|
||||
- `packages/vue/src/components/alert/{Alert,AlertIndicator,AlertContent,AlertTitle,AlertDescription,AlertDefaultIcon}.vue` + `context.ts`
|
||||
- 演示 10:`apps/docs/demos/badge-{basic,variants,sizes,colors,placements,dot,with-content,custom-styles}.vue`、`alert-{basic,custom-styles}.vue`
|
||||
- 文档:`apps/docs/components/{badge,alert}.md`
|
||||
- 测试:`tests/badge-alert.test.ts`(21 项)
|
||||
|
||||
### 修改(共享)
|
||||
|
||||
- `packages/styles/index.css`
|
||||
- `packages/vue/src/{index.ts,types.ts}`
|
||||
- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`
|
||||
- `package.json`(test:unit)
|
||||
- `docs/{compatibility,upstream,verification}.md`
|
||||
- 本文件
|
||||
|
||||
## 2. 上游来源
|
||||
|
||||
| 路径 | 用途 |
|
||||
| --------------------------------------------------------------------------------------------- | ------------------------------------------- |
|
||||
| `packages/react/src/components/{badge,alert}/*` | 部件、上下文、默认图标选择 |
|
||||
| `packages/styles/components/{badge,alert}.css` | BEM 与视觉数值(hv- 前缀) |
|
||||
| `packages/styles/src/components/{badge,alert}/*.styles.ts` | tv 变体 |
|
||||
| `apps/docs/content/docs/cn/react/components/(data-display)/badge.mdx`、`(feedback)/alert.mdx` | 中文结构与示例次序 |
|
||||
| `apps/docs/src/demos/cn/{badge,alert}/` | 演示文案与布局 |
|
||||
| `packages/react/src/components/icons.tsx` | Alert 默认 Info/Success/Warning/Danger 图标 |
|
||||
| `third-party/HEROUI-LICENSE` | Apache-2.0 来源声明 |
|
||||
|
||||
未迁移:无(文档预览清单内 10 个示例全部迁移)。
|
||||
|
||||
## 3. API 对照(Vue 契约)
|
||||
|
||||
### Badge
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ------------------------------------------------------------------------------- | ------------------------------------------ | --------------------------- |
|
||||
| `Badge.Root` + color/placement/size/variant 默认 `default/top-right/md/primary` | `Badge` 同名 props | 命名导出,不用对象式 |
|
||||
| `Badge.Anchor` | `BadgeAnchor` | 定位容器 span,非链接 |
|
||||
| `Badge.Label` | `BadgeLabel` | 一致 |
|
||||
| children 字符/数字自动包 Label | 默认插槽纯文本/数字自动包 `BadgeLabel` | Fragment/Comment/空白不参与 |
|
||||
| `className` / `ReactNode` | `class`(string\|Array\|Object)/ 默认插槽 | 无 className 别名 |
|
||||
|
||||
### Alert
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ------------------------------------------- | -------------------------------------------------- | ----------------------------- |
|
||||
| `Alert.Root` + status 默认 `default` | `Alert` | 同 |
|
||||
| `Alert.Indicator/Content/Title/Description` | `AlertIndicator` 等命名导出 | Title=`p`,Description=`span` |
|
||||
| `children ?? getDefaultIcon()` | 插槽空/注释回退默认图标 | 渲染期判定 |
|
||||
| SurfaceContext 重置 default | `provide(surfaceContextKey, { variant: default })` | 复用本库类型化上下文 |
|
||||
| `className` / `ReactNode` | `class` / 默认插槽 | 无 React 专属类型 |
|
||||
|
||||
展示组件,无内部状态/表单/键盘激活逻辑。
|
||||
|
||||
## 4. 示例逐项对照(10 / 10)
|
||||
|
||||
| 预览名 | 上游 | Vue | 内容 |
|
||||
| ------------------- | ----------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- |
|
||||
| badge-basic | basic.tsx | badge-basic.vue | 3 头像:数字 5 /「新」/ 空点 bottom-right |
|
||||
| badge-variants | variants.tsx | badge-variants.vue | 3 变体 × 5 色 + Separator |
|
||||
| badge-sizes | sizes.tsx | badge-sizes.vue | sm/md/lg 与 Avatar 同尺寸 |
|
||||
| badge-colors | colors.tsx | badge-colors.vue | 5 色点状 |
|
||||
| badge-placements | placements.tsx | badge-placements.vue | 四角 + 中文标签 |
|
||||
| badge-dot | dot.tsx | badge-dot.vue | 4 色 bottom-right 点 |
|
||||
| badge-with-content | with-content.tsx | badge-with-content.vue | 5 / 新 / 99+ / Bell 图标 |
|
||||
| badge-custom-styles | custom-styles.tsx | badge-custom-styles.vue | soft + min-w-5 等 |
|
||||
| alert-basic | basic.tsx | alert-basic.vue | **六种组合**:默认信息、accent+刷新、danger+排查列表、success 无描述+Close、accent Spinner、warning 无关闭 |
|
||||
| alert-custom-styles | custom-styles.tsx | alert-custom-styles.vue | 警告账单 + 光斑 + 响应式按钮 + Close |
|
||||
|
||||
Alert basic 未简化;文案、列表、sm:hidden/sm:block 响应式按钮均保留。
|
||||
|
||||
## 5. 回归场景
|
||||
|
||||
| 要求 | 适用性 | 测试 | 结果 |
|
||||
| -------------------------------- | ------ | --------------------------------------------- | ------ |
|
||||
| attrs 空→新增→修改→删除→再次新增 | 适用 | Badge / Alert 动态 attrs | 通过 |
|
||||
| class 合并(串/组/对象/移除) | 适用 | Badge、AlertIndicator;修复 h() 覆盖 bug | 通过 |
|
||||
| 子变体不拼接冲突色类 | 适用 | color/variant 单次 tv | 通过 |
|
||||
| 不缓存 slots.default() | 适用 | Badge 文本↔组合切换;Indicator 空/自定义/恢复 | 通过 |
|
||||
| Fragment/Comment/Text | 适用 | 自动包装与 Indicator 回退 | 通过 |
|
||||
| PropType + 合法/非法 + dist | 适用 | `@ts-expect-error` + vue-tsc | 通过 |
|
||||
| 文档契约 class≠className | 适用 | 文档断言 + 演示无 className | 通过 |
|
||||
| class 进入最终 DOM | 适用 | 浏览器:custom Indicator/Alert class | 通过 |
|
||||
| Surface 上下文重置 | 适用 | inject probe = default | 通过 |
|
||||
| 键盘/事件适配 | 不适用 | 展示组件 | 未添加 |
|
||||
|
||||
实施中修复:AlertIndicator 渲染函数曾覆盖调用方 class,已改为 `[indicatorClass, attrs.class]` 并加测试。
|
||||
|
||||
## 6. 命令结果
|
||||
|
||||
| 命令 | 文件数 | 通过 | 含 SSR |
|
||||
| ----------------- | ------ | ---- | ------ |
|
||||
| `pnpm test` | 10 | 148 | 是 |
|
||||
| `pnpm test:unit` | 9 | 147 | 否 |
|
||||
| `pnpm typecheck` | — | 通过 | — |
|
||||
| `pnpm build:docs` | — | 通过 | — |
|
||||
| `pnpm format` | — | 通过 | — |
|
||||
|
||||
`test:browser/visual/package` 未建立,未执行。
|
||||
|
||||
## 7. 浏览器证据(Playwright CLI)
|
||||
|
||||
地址 `http://127.0.0.1:5173`。桌面视口 1280×800,窄屏 390×844。
|
||||
|
||||
- Badge:39 徽标;四角 transform 分别为 (4,-4)/(-4,-4)/(4,4)/(-4,4);点状无 label;custom-styles class 合并。
|
||||
- Alert:7 根(6+1);文案列表完整;`hv-alert__indicator relative text-warning`;表 5 张宽 736/350 均无溢出。
|
||||
- 展开/复制/Shiki 正常。控制台仅 favicon 404。
|
||||
|
||||
限制:IAB 截图未做(改用 Playwright CLI);浅/深一键切换未做交互点击。
|
||||
|
||||
## 8. 未验证项
|
||||
|
||||
浅/深切换交互、位图截图、Nuxt 水合、RTL、触屏、读屏、独立安装 dist、自动视觉对比。
|
||||
|
||||
## 9. 最短复核步骤
|
||||
|
||||
1. `pnpm test && pnpm test:unit && pnpm typecheck && pnpm build:docs`
|
||||
2. `/components/badge`:看基本(数字/文字/点)、四角位置、变体矩阵;确认无横向滚动 API 表。
|
||||
3. `/components/alert`:数 6 个基本告警;danger 含三条排查;Spinner 行无默认图标;自定义样式行 class 生效。
|
||||
4. 运行 `tests/badge-alert.test.ts` 看自动包装、Indicator 回退、SurfaceContext。
|
||||
5. 人工补测浅/深切换。
|
||||
|
||||
## 10. 需集成人确认
|
||||
|
||||
- 导航顺序(Alert/Badge 字母序插入)是否符合产品约定。
|
||||
- Alert 默认图标采用移植基线 SVG(与 CloseButton/Spinner 同策略),未用 Tabler。
|
||||
- 上游 `Alert.Title` 为 `p`、`Description` 为 `span` 的语义是否保持。
|
||||
|
||||
实施者只记自测与修复,验收结论留给集成人。
|
||||
@@ -0,0 +1,75 @@
|
||||
# M10–M11 迁移任务提示词:Badge / Alert
|
||||
|
||||
以下可直接发给接手 AI;只是任务说明,尚未派发或实施。
|
||||
|
||||
```text
|
||||
请在独立 heroui-vue 仓库迁移 M10 Badge 与 M11 Alert,完成后交给集成人复核,
|
||||
不自行提交、推送或宣布验收通过。
|
||||
|
||||
工作目录:/Users/maoyingjie/Documents/OpenSourceProjects/heroui/heroui-vue
|
||||
上游参考 ../heroui 只读。固定 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960。
|
||||
最近基准提交 3515a47;开始时核对实际 HEAD 与工作区,保留已有规范/提示词修改。
|
||||
先读 AGENTS.md、docs/migration-handoff.md、compatibility.md、upstream.md,
|
||||
特别落实历轮动态更新、事件、类型以及“M07–M09 文档契约返工”要求。
|
||||
|
||||
范围与交付:
|
||||
M10:Badge、BadgeAnchor、BadgeLabel。
|
||||
M11:Alert、AlertIndicator、AlertContent、AlertTitle、AlertDescription。
|
||||
交付组件、样式/变体、公开类型与导出、中文文档、全部基线演示、适用测试和来源记录。
|
||||
不迁 AlertDialog,不重构现有字段、弹层、主题或构建链路,不添加业务功能。
|
||||
共享导出、导航、样式入口、测试入口与记录只做本批必要更新。
|
||||
|
||||
先逐项读取上游组件实现、CSS、变体、中文文档及全部示例,列出迁移清单。
|
||||
中文文档:apps/docs/content/docs/cn/react/components/(data-display)/badge.mdx、
|
||||
(feedback)/alert.mdx;演示:apps/docs/src/demos/cn/{badge,alert}/。
|
||||
Badge 8 个:basic、variants、sizes、colors、placements、dot、with-content、custom-styles。
|
||||
Alert 2 个:basic、custom-styles。共10个,重新核对名称、顺序及每例内部全部内容。
|
||||
Alert basic 内含六种组合,不能因为只有两个示例就简化为两个提示框。
|
||||
|
||||
Badge 验收重点:
|
||||
- 默认 color=default、placement=top-right、size=md、variant=primary;完整颜色/尺寸/变体。
|
||||
- BadgeAnchor 是定位容器,不是导航链接;四角定位、圆点、空内容和文本内容均保持基线。
|
||||
- 文本/数字(含0)自动包 BadgeLabel;显式 Label 与图标内容不重复包装。
|
||||
- 验证文本↔组合内容动态切换、条件注释/空白/Fragment、父级替换插槽闭包。
|
||||
- 用已有 Avatar/Button 等组件组合,检查徽标实际定位、遮挡及与头像重叠,不只测类名。
|
||||
|
||||
Alert 验收重点:
|
||||
- status=default/accent/success/warning/danger,默认 default;默认指示图标随 status 动态更新。
|
||||
- 自定义 Indicator 插槽替换默认内容,省略/条件为空/恢复时的回退行为清楚且有测试。
|
||||
- 沿用上游标题/说明 DOM 语义、data-slot 与所有部件;不能套成 AlertDialog。
|
||||
- 对齐上游 Alert 对内部 SurfaceContext 重置为 default 的行为,复用本库类型化上下文;
|
||||
验证放在不同 Surface 中时内部 Button/Input 等组合的主题不意外继承外层表面。
|
||||
- 复用已有 Button、CloseButton、Spinner;保留基本例全部文案、排错列表、响应式操作、
|
||||
无说明/无关闭按钮/加载指示器与自定义样式例,不新增虚假的后端业务反馈。
|
||||
- 不因名为 Alert 就擅自添加未约定的焦点、弹窗或自动关闭行为;ARIA 按基线和实际语义核对。
|
||||
|
||||
视觉与图标:
|
||||
样式、布局、文案、API、主题与固定基线高度一致,CSS仅按规则加hv-前缀并适配状态。
|
||||
演示使用 @tabler/icons-vue,不自绘SVG、不把整套文档图标库加入基础组件依赖。
|
||||
Alert 默认内部图标可按已有 CloseButton/Spinner 方式移植基线 SVG并登记来源;不是自行绘制。
|
||||
优先通过插槽允许替换,图标包保持可选。所有装饰图标隐藏读屏语义。
|
||||
|
||||
防止再次返工:
|
||||
- API 表逐个检查 Root和全部子部件:className→class(字符串/数组/对象)、children→插槽,
|
||||
ReactNode/ComponentProps及对象式子部件名称改为真实Vue契约,不增加无需求兼容别名。
|
||||
- 按文档写最小消费场景,确认样式进入最终DOM;补文档契约检查,不能只复制上游表格。
|
||||
- attrs 在渲染时读取,测试空→新增→修改→删除→再次新增,覆盖ARIA/class/style/事件。
|
||||
- h()合并用户class;子变体单次求值,不拼接冲突色类;不缓存slots.default()结果。
|
||||
- 用准确PropType和字面量联合,合法/非法值均测试,并检查本轮构建dist的公开声明。
|
||||
- 展示组件不添加无关键盘交互;需要事件适配时保留取消、中断、真实目标与传播。
|
||||
- 预览、复制、高亮共用同一SFC;正文API表铺满内容区、长内容换行,不横向滚动、
|
||||
不缩字号、不截断;沿用公共规则,避免污染not-prose演示区。
|
||||
|
||||
检查与交接:
|
||||
运行 pnpm test、pnpm test:unit、pnpm typecheck、pnpm build:docs、pnpm format。
|
||||
新增测试文件时同步test:unit列表;各入口分别记录实际文件数/通过数及是否含SSR,
|
||||
新增用例后更新最终计数,不用旧数字或“同上”代替结果。
|
||||
浏览器固定127.0.0.1:5173,验证浅深切换、桌面/窄屏、徽标定位、Alert响应式组合、
|
||||
复制高亮及API表;记录视口、操作、计算样式和截图。未执行项明确说明,不能伪称通过。
|
||||
|
||||
更新 compatibility.md、upstream.md、verification.md,提供
|
||||
docs/migrations/M10-M11-badge-alert.md
|
||||
包括起点、文件范围、10个示例逐项对照、API与差异、回归场景、各命令结果、
|
||||
浏览器证据、来源许可、未验证项和最短复核步骤。实施者只记自测与修复,验收结论留给集成人。
|
||||
遇到缺口先给可复现场景和局部方案,不删能力、不无界扩展任务。
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
# M10–M11 集成人复核
|
||||
|
||||
日期:2026-10-21。基线 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960。
|
||||
|
||||
结论:通过本批源码、行为与构建复核,未发现新的阻塞问题,可提交。
|
||||
|
||||
- Badge / Alert 全部部件已核对;默认值、状态映射、纯文本包装和 Surface 上下文与基线一致;文档使用 Vue class / 插槽契约。
|
||||
- 两份 CSS 去除来源注释、hv- 前缀和空白后与固定上游一致。10 份基线演示清单与 Alert 基本例六种组合有测试覆盖。
|
||||
- 独立临时行为探针 2 项通过:八个公开部件动态新增/删除 attrs、数组/对象 class 合并、事件清理;Alert status 图标更新、自定义/条件空插槽的图标回退。临时文件已删除。
|
||||
- pnpm test:10 文件 / 148 项通过;pnpm typecheck、pnpm build:docs、pnpm format 通过。
|
||||
- 本轮未逐页重做浏览器视觉、浅深主题切换、位图对比、读屏或 Nuxt 水合验证;不将实施者浏览器记录冒充本轮独立证据。独立安装等未验证边界保留。
|
||||
- 提交包含本批实现、文档、测试与此前授权的 API 迁移规范、M10–M11 提示词。
|
||||
+6
-4
@@ -7,13 +7,14 @@
|
||||
|
||||
## 已移植
|
||||
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton,separator,kbd,chip}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton,separator,kbd,chip,badge,alert}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/themes/default/variables.css、themes/shared/theme.css:主题变量、OKLCH 颜色、派生公式和圆角尺寸。
|
||||
- packages/styles/utilities、variants:焦点、禁用、减少动画等构建规则。
|
||||
- packages/styles/src/components/{button,card,input,textarea,switch,surface,link,spinner,close-button,avatar,avatar-group,skeleton,separator,kbd,chip}/*.styles.ts:变体与类名映射,增加命名空间。
|
||||
- apps/docs/content/docs/cn/react/components 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip 的标题、说明、示例顺序和 API 描述;React 特有部分转换为 Vue 用法。
|
||||
- apps/docs/src/demos/cn 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip 文档引用的基线示例文案与布局;文档由新项目 SFC 实现。
|
||||
- packages/styles/src/components/{button,card,input,textarea,switch,surface,link,spinner,close-button,avatar,avatar-group,skeleton,separator,kbd,chip,badge,alert}/*.styles.ts:变体与类名映射,增加命名空间。
|
||||
- apps/docs/content/docs/cn/react/components 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip/Badge/Alert 的标题、说明、示例顺序和 API 描述;React 特有部分转换为 Vue 用法。
|
||||
- apps/docs/src/demos/cn 下 Button/Card/Input/Switch/Surface/Link/Spinner/CloseButton/Avatar/AvatarGroup/Skeleton/Separator/Kbd/Chip/Badge/Alert 文档引用的基线示例文案与布局;文档由新项目 SFC 实现。
|
||||
- packages/react/src/components/kbd/kbd.constants.ts 的 KbdKey、kbdKeysMap、kbdKeysLabelMap:按键符号与无障碍 title 映射。
|
||||
- packages/react/src/components/icons.tsx 的 InfoIcon/SuccessIcon/WarningIcon/DangerIcon:Alert 默认状态指示图标。
|
||||
- packages/react/src/components/icons.tsx 的 ExternalLinkIcon:LinkIcon 默认外部箭头图标;CloseIcon:CloseButton 默认关闭图标。
|
||||
- packages/react/src/components/spinner/spinner.tsx 的 SpinnerPrimitive SVG(渐变路径)。
|
||||
- apps/docs/public/fonts/Inter-{Regular,Medium,Bold}.ttf:文档字体资源。
|
||||
@@ -39,4 +40,5 @@
|
||||
- Skeleton 演示沿用上游 `shadow-panel` 与 `animate-shine` 类名,并在文档 utilities.css 中提供对应定义(上游放在 docs global.css)。
|
||||
- Separator `render` 示例改用 Vue `as-child` + 自定义 `div` 根节点,保留 `data-custom="foo"`。
|
||||
- Chip 演示将上游 `@gravity-ui/icons` 的 CircleFill / CircleInfo / Check / TriangleExclamation / Ban / CircleCheckFill / Clock / Xmark / ChevronDown / CircleDashed 替换为 Tabler `IconCircleFilled` / `IconInfoCircle` / `IconCheck` / `IconAlertTriangle` / `IconBan` / `IconCircleCheckFilled` / `IconClock` / `IconX` / `IconChevronDown` / `IconCircleDashed`(MIT)。
|
||||
- Badge 带内容示例的 Bell 图标替换为 Tabler `IconBell`。Alert 默认指示图标为移植的基线 SVG,非 Tabler。
|
||||
- 图标统一使用 @tabler/icons-vue(MIT)的官方组件,未移植 React 图标依赖;尚未完成自动逐像素对比。
|
||||
|
||||
@@ -161,3 +161,31 @@
|
||||
## M07–M09 文档 className 返工(2026-10-21)
|
||||
|
||||
独立复核 1 项 P2:三页 API 表 6 处写 `className`,实现只合并 Vue `class`。已统一改为 `class`(`string | Array | Object`,Vue class 绑定),并注明勿用 React `className`。未加别名。`pnpm test` 127 项(+1 文档契约回归)、typecheck、build:docs、format 通过。复核报告见 `docs/migrations/M07-M09-review.md`;浏览器视觉未重做。
|
||||
|
||||
## M10–M11 Badge / Alert(2026-10-21)
|
||||
|
||||
起始 HEAD `3515a47`,保留工作区 AGENTS.md / migration-handoff.md 修改与 M10-M11-prompt.md。上游只读 `../heroui` @ `ce90ea3`。
|
||||
|
||||
### 命令(分别记录)
|
||||
|
||||
| 入口 | 文件数 | 通过数 | 含 SSR |
|
||||
| ----------------- | ------ | ------ | ------------------- |
|
||||
| `pnpm test` | 10 | 148 | 是(ssr.test.ts 1) |
|
||||
| `pnpm test:unit` | 9 | 147 | 否 |
|
||||
| `pnpm typecheck` | — | 通过 | — |
|
||||
| `pnpm build:docs` | — | 通过 | — |
|
||||
| `pnpm format` | — | 通过 | — |
|
||||
|
||||
### 浏览器(Playwright CLI,127.0.0.1:5173)
|
||||
|
||||
- Badge:39 个 badge / anchor;文本自动包装 label;空内容点状;四角 `position:absolute` + ±25% transform(top-right `matrix(…,4,-4)` 等);custom-styles 的 `min-w-5` 等 class 进入 DOM。
|
||||
- Alert:基本示例 6 个根 + 自定义样式 1 个;六种文案齐全;Spinner/CloseButton 存在;默认图标 6 个;自定义 Indicator class 为 `hv-alert__indicator relative text-warning`(修复后合并成功)。
|
||||
- 展开/复制/Shiki:badge-basic 展开→收起,源码含 BadgeAnchor。
|
||||
- 表格:桌面 1280 下 Badge 3 表、Alert 5 表宽 736=父容器,无溢出;窄屏 390 下宽 350,无溢出。
|
||||
- 控制台仅 favicon 404,与组件无关。
|
||||
|
||||
实施中发现并修复:AlertIndicator `h()` 覆盖调用方 class;已加合并回归测试。
|
||||
|
||||
### 未验证
|
||||
|
||||
浅/深一键切换交互、IAB 位图截图、Nuxt 水合、RTL、触屏、读屏、独立安装 dist、`test:browser/visual/package`(未建立)。
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts",
|
||||
"test:unit": "vitest run tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Base alert styles */
|
||||
.hv-alert {
|
||||
@apply flex w-full flex-row items-start justify-start gap-4 bg-surface px-4 py-3 shadow-surface;
|
||||
border-radius: min(32px, var(--radius-3xl));
|
||||
}
|
||||
|
||||
/* Alert elements */
|
||||
.hv-alert__content {
|
||||
@apply flex h-full grow flex-col items-start;
|
||||
}
|
||||
|
||||
.hv-alert__indicator {
|
||||
@apply flex items-center justify-center p-1 select-none;
|
||||
|
||||
[data-slot="alert-default-icon"] {
|
||||
@apply box-content size-4;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-alert__title {
|
||||
@apply text-sm leading-6 font-medium;
|
||||
}
|
||||
|
||||
.hv-alert__description {
|
||||
@apply text-sm text-muted;
|
||||
}
|
||||
|
||||
/* Variant modifiers */
|
||||
.hv-alert--default .hv-alert__indicator {
|
||||
@apply text-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--default .hv-alert__title {
|
||||
@apply text-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--accent .hv-alert__indicator {
|
||||
@apply text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--accent .hv-alert__title {
|
||||
@apply text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--success .hv-alert__indicator {
|
||||
@apply text-success-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--success .hv-alert__title {
|
||||
@apply text-success-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--warning .hv-alert__indicator {
|
||||
@apply text-warning-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--warning .hv-alert__title {
|
||||
@apply text-warning-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--danger .hv-alert__indicator {
|
||||
@apply text-danger-soft-foreground;
|
||||
}
|
||||
|
||||
.hv-alert--danger .hv-alert__title {
|
||||
@apply text-danger-soft-foreground;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Base styles */
|
||||
.hv-badge {
|
||||
@apply inline-flex shrink-0 items-center justify-center gap-0.5 font-medium;
|
||||
|
||||
/* Default size (matches --md) */
|
||||
@apply min-h-7 min-w-7 rounded-3xl text-xs leading-[1.34];
|
||||
|
||||
/* Default tokens */
|
||||
--badge-bg: var(--default);
|
||||
--badge-fg: var(--default-foreground);
|
||||
--badge-border: var(--background);
|
||||
|
||||
background-color: var(--badge-bg);
|
||||
color: var(--badge-fg);
|
||||
border: 1px solid var(--badge-border);
|
||||
background-clip: padding-box;
|
||||
}
|
||||
|
||||
.hv-badge__label {
|
||||
@apply px-0.5;
|
||||
}
|
||||
|
||||
.hv-badge-anchor {
|
||||
@apply relative inline-flex shrink-0;
|
||||
}
|
||||
|
||||
/* Size variants */
|
||||
.hv-badge--lg {
|
||||
@apply min-h-8 min-w-8 rounded-2xl text-sm leading-[1.43];
|
||||
}
|
||||
|
||||
.hv-badge--md {
|
||||
/* No styles as this is the default size */
|
||||
}
|
||||
|
||||
.hv-badge--sm {
|
||||
@apply min-h-4 min-w-4 rounded-xl text-[10px] leading-[1.34];
|
||||
}
|
||||
|
||||
/* Color variants - set foreground color */
|
||||
.hv-badge--accent {
|
||||
--badge-fg: var(--accent-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--default {
|
||||
--badge-fg: var(--default-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--success {
|
||||
--badge-fg: var(--success-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--warning {
|
||||
--badge-fg: var(--warning-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--danger {
|
||||
--badge-fg: var(--danger-soft-foreground);
|
||||
}
|
||||
|
||||
/* Variant styles */
|
||||
.hv-badge--primary {
|
||||
/* Solid background - compound variants below handle bg/fg per color */
|
||||
}
|
||||
|
||||
.hv-badge--secondary {
|
||||
/* Default background with colored text - base behavior */
|
||||
}
|
||||
|
||||
.hv-badge--soft {
|
||||
/* Soft/muted background - compound variants below handle bg/fg per color */
|
||||
}
|
||||
|
||||
/* Placement variants */
|
||||
.hv-badge--top-right {
|
||||
@apply absolute top-0 right-0;
|
||||
transform: translate(25%, -25%);
|
||||
}
|
||||
|
||||
.hv-badge--top-left {
|
||||
@apply absolute top-0 left-0;
|
||||
transform: translate(-25%, -25%);
|
||||
}
|
||||
|
||||
.hv-badge--bottom-right {
|
||||
@apply absolute right-0 bottom-0;
|
||||
transform: translate(25%, 25%);
|
||||
}
|
||||
|
||||
.hv-badge--bottom-left {
|
||||
@apply absolute bottom-0 left-0;
|
||||
transform: translate(-25%, 25%);
|
||||
}
|
||||
|
||||
/* Compound variants - Primary (solid background) */
|
||||
.hv-badge--primary.hv-badge--accent {
|
||||
--badge-bg: var(--accent);
|
||||
--badge-fg: var(--accent-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--primary.hv-badge--default {
|
||||
--badge-bg: var(--default);
|
||||
--badge-fg: var(--default-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--primary.hv-badge--success {
|
||||
--badge-bg: var(--success);
|
||||
--badge-fg: var(--success-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--primary.hv-badge--warning {
|
||||
--badge-bg: var(--warning);
|
||||
--badge-fg: var(--warning-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--primary.hv-badge--danger {
|
||||
--badge-bg: var(--danger);
|
||||
--badge-fg: var(--danger-foreground);
|
||||
}
|
||||
|
||||
/* Compound variants - Soft (muted background) */
|
||||
.hv-badge--soft.hv-badge--accent {
|
||||
--badge-bg: var(--accent-soft);
|
||||
--badge-fg: var(--accent-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--soft.hv-badge--default {
|
||||
--badge-bg: var(--default-soft);
|
||||
--badge-fg: var(--default-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--soft.hv-badge--success {
|
||||
--badge-bg: var(--success-soft);
|
||||
--badge-fg: var(--success-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--soft.hv-badge--warning {
|
||||
--badge-bg: var(--warning-soft);
|
||||
--badge-fg: var(--warning-soft-foreground);
|
||||
}
|
||||
|
||||
.hv-badge--soft.hv-badge--danger {
|
||||
--badge-bg: var(--danger-soft);
|
||||
--badge-fg: var(--danger-soft-foreground);
|
||||
}
|
||||
@@ -23,6 +23,8 @@
|
||||
@import "./components/separator.css" layer(components);
|
||||
@import "./components/kbd.css" layer(components);
|
||||
@import "./components/chip.css" layer(components);
|
||||
@import "./components/badge.css" layer(components);
|
||||
@import "./components/alert.css" layer(components);
|
||||
/* The Vue Switch uses Reka's native button for its clickable content. */
|
||||
@layer components {
|
||||
.hv-switch:has(.hv-switch__content:focus-visible) .hv-switch__control {
|
||||
|
||||
@@ -393,3 +393,108 @@ export const chipVariants = tv({
|
||||
});
|
||||
|
||||
export type ChipVariants = VariantProps<typeof chipVariants>;
|
||||
|
||||
export const badgeVariants = tv({
|
||||
defaultVariants: {
|
||||
color: "default",
|
||||
placement: "top-right",
|
||||
size: "md",
|
||||
variant: "primary",
|
||||
},
|
||||
slots: {
|
||||
anchor: "hv-badge-anchor",
|
||||
base: "hv-badge",
|
||||
label: "hv-badge__label",
|
||||
},
|
||||
variants: {
|
||||
color: {
|
||||
accent: {
|
||||
base: "hv-badge--accent",
|
||||
},
|
||||
danger: {
|
||||
base: "hv-badge--danger",
|
||||
},
|
||||
default: {
|
||||
base: "hv-badge--default",
|
||||
},
|
||||
success: {
|
||||
base: "hv-badge--success",
|
||||
},
|
||||
warning: {
|
||||
base: "hv-badge--warning",
|
||||
},
|
||||
},
|
||||
placement: {
|
||||
"bottom-left": {
|
||||
base: "hv-badge--bottom-left",
|
||||
},
|
||||
"bottom-right": {
|
||||
base: "hv-badge--bottom-right",
|
||||
},
|
||||
"top-left": {
|
||||
base: "hv-badge--top-left",
|
||||
},
|
||||
"top-right": {
|
||||
base: "hv-badge--top-right",
|
||||
},
|
||||
},
|
||||
size: {
|
||||
lg: {
|
||||
base: "hv-badge--lg",
|
||||
},
|
||||
md: {
|
||||
base: "hv-badge--md",
|
||||
},
|
||||
sm: {
|
||||
base: "hv-badge--sm",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
primary: {
|
||||
base: "hv-badge--primary",
|
||||
},
|
||||
secondary: {
|
||||
base: "hv-badge--secondary",
|
||||
},
|
||||
soft: {
|
||||
base: "hv-badge--soft",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type BadgeVariants = VariantProps<typeof badgeVariants>;
|
||||
|
||||
export const alertVariants = tv({
|
||||
defaultVariants: {
|
||||
status: "default",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-alert",
|
||||
content: "hv-alert__content",
|
||||
description: "hv-alert__description",
|
||||
indicator: "hv-alert__indicator",
|
||||
title: "hv-alert__title",
|
||||
},
|
||||
variants: {
|
||||
status: {
|
||||
accent: {
|
||||
base: "hv-alert--accent",
|
||||
},
|
||||
danger: {
|
||||
base: "hv-alert--danger",
|
||||
},
|
||||
default: {
|
||||
base: "hv-alert--default",
|
||||
},
|
||||
success: {
|
||||
base: "hv-alert--success",
|
||||
},
|
||||
warning: {
|
||||
base: "hv-alert--warning",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type AlertVariants = VariantProps<typeof alertVariants>;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, provide, useAttrs } from "vue";
|
||||
import {
|
||||
alertVariants,
|
||||
type AlertVariants,
|
||||
type SurfaceVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
import { surfaceContextKey } from "../surface/context";
|
||||
import { alertContextKey, type AlertStatus } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
status?: AlertVariants["status"];
|
||||
}>(),
|
||||
{ status: "default" },
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
|
||||
const status = computed<AlertStatus>(() => props.status ?? "default");
|
||||
const slots = computed(() => alertVariants({ status: status.value }));
|
||||
|
||||
provide(alertContextKey, { slots, status });
|
||||
// Reset nested Surface context so children do not inherit the outer surface.
|
||||
provide(surfaceContextKey, {
|
||||
variant: computed<SurfaceVariants["variant"]>(() => "default"),
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-bind="attrs" :class="slots.base()" data-slot="alert-root">
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { alertContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(alertContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
:class="ctx?.slots.value.content()"
|
||||
data-slot="alert-content"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, useAttrs, type PropType } from "vue";
|
||||
import type { AlertStatus } from "./context";
|
||||
|
||||
/* Adapted from HeroUI v3, ce90ea3 icons.tsx (Info/Success/Warning/Danger).
|
||||
* Copyright 2025 NextUI Inc. See third-party/HEROUI-LICENSE. */
|
||||
|
||||
const iconPaths: Record<AlertStatus, string> = {
|
||||
default:
|
||||
"M8 13.5a5.5 5.5 0 1 0 0-11a5.5 5.5 0 0 0 0 11M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m1-9.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0m-.25 3a.75.75 0 0 0-1.5 0V11a.75.75 0 0 0 1.5 0z",
|
||||
accent:
|
||||
"M8 13.5a5.5 5.5 0 1 0 0-11a5.5 5.5 0 0 0 0 11M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m1-9.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0m-.25 3a.75.75 0 0 0-1.5 0V11a.75.75 0 0 0 1.5 0z",
|
||||
success:
|
||||
"M13.5 8a5.5 5.5 0 1 1-11 0a5.5 5.5 0 0 1 11 0M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0m-3.9-1.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z",
|
||||
warning:
|
||||
"M7.134 2.994L2.217 11.5a1 1 0 0 0 .866 1.5h9.834a1 1 0 0 0 .866-1.5L8.866 2.993a1 1 0 0 0-1.732 0m3.03-.75c-.962-1.665-3.366-1.665-4.329 0L.918 10.749c-.963 1.666.24 3.751 2.165 3.751h9.834c1.925 0 3.128-2.085 2.164-3.751zM8 5a.75.75 0 0 1 .75.75v2a.75.75 0 0 1-1.5 0v-2A.75.75 0 0 1 8 5m1 5.75a1 1 0 1 1-2 0a1 1 0 0 1 2 0",
|
||||
danger:
|
||||
"M8 13.5a5.5 5.5 0 1 0 0-11a5.5 5.5 0 0 0 0 11M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m1-4.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0M8.75 5a.75.75 0 0 0-1.5 0v2.5a.75.75 0 0 0 1.5 0z",
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
name: "AlertDefaultIcon",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
status: {
|
||||
type: String as PropType<AlertStatus>,
|
||||
default: "default",
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const attrs = useAttrs();
|
||||
const path = computed(() => iconPaths[props.status] ?? iconPaths.default);
|
||||
return () =>
|
||||
h(
|
||||
"svg",
|
||||
{
|
||||
...attrs,
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "alert-default-icon",
|
||||
fill: "none",
|
||||
height: 16,
|
||||
role: "presentation",
|
||||
viewBox: "0 0 16 16",
|
||||
width: 16,
|
||||
xmlns: "http://www.w3.org/2000/svg",
|
||||
},
|
||||
[
|
||||
h("path", {
|
||||
"clip-rule": "evenodd",
|
||||
d: path.value,
|
||||
fill: "currentColor",
|
||||
"fill-rule": "evenodd",
|
||||
}),
|
||||
],
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { alertContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(alertContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-bind="attrs"
|
||||
:class="ctx?.slots.value.description()"
|
||||
data-slot="alert-description"
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,88 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
isVNode,
|
||||
useAttrs,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { alertContextKey } from "./context";
|
||||
import AlertDefaultIcon from "./AlertDefaultIcon.vue";
|
||||
|
||||
function flattenChildren(
|
||||
nodes: VNodeChild[],
|
||||
out: VNodeChild[] = [],
|
||||
): VNodeChild[] {
|
||||
for (const child of nodes) {
|
||||
if (Array.isArray(child)) {
|
||||
flattenChildren(child, out);
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
isVNode(child) &&
|
||||
child.type === Fragment &&
|
||||
Array.isArray(child.children)
|
||||
) {
|
||||
flattenChildren(child.children as VNodeChild[], out);
|
||||
continue;
|
||||
}
|
||||
out.push(child);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function isMeaningful(node: VNodeChild): boolean {
|
||||
if (node == null || node === false || node === true) return false;
|
||||
if (typeof node === "string") return node.trim() !== "";
|
||||
if (typeof node === "number") return true;
|
||||
if (!isVNode(node)) return true;
|
||||
if (node.type === Comment) return false;
|
||||
if (node.type === Text) return String(node.children ?? "").trim() !== "";
|
||||
return true;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "AlertIndicator",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
const ctx = inject(alertContextKey, undefined);
|
||||
|
||||
/**
|
||||
* Empty/conditional slot falls back to the status default icon.
|
||||
* Re-read the slot every render so restore/replacement stays in sync.
|
||||
*/
|
||||
function render() {
|
||||
const children = flattenChildren(
|
||||
(slots.default?.() ?? []) as VNodeChild[],
|
||||
);
|
||||
const content = children.filter(isMeaningful);
|
||||
const body: VNodeChild[] =
|
||||
content.length > 0
|
||||
? children
|
||||
: [
|
||||
h(AlertDefaultIcon, {
|
||||
key: "alert-default-icon",
|
||||
status: ctx?.status.value,
|
||||
}),
|
||||
];
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{
|
||||
...attrs,
|
||||
// Merge caller class with component classes (object spread would drop it).
|
||||
class: [ctx?.slots.value.indicator(), attrs.class],
|
||||
"data-slot": "alert-indicator",
|
||||
},
|
||||
body,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { alertContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(alertContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p v-bind="attrs" :class="ctx?.slots.value.title()" data-slot="alert-title">
|
||||
<slot />
|
||||
</p>
|
||||
</template>
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { AlertVariants, alertVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type AlertSlots = ReturnType<typeof alertVariants>;
|
||||
|
||||
export type AlertStatus = NonNullable<AlertVariants["status"]>;
|
||||
|
||||
export interface AlertContextValue {
|
||||
slots: ComputedRef<AlertSlots>;
|
||||
status: ComputedRef<AlertStatus>;
|
||||
}
|
||||
|
||||
export const alertContextKey: InjectionKey<AlertContextValue> =
|
||||
Symbol("HeroUIVue.Alert");
|
||||
@@ -0,0 +1,127 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Comment,
|
||||
Fragment,
|
||||
Text,
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
isVNode,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { badgeVariants, type BadgeVariants } from "@heroui-vue/styles";
|
||||
import { badgeContextKey } from "./context";
|
||||
import BadgeLabel from "./BadgeLabel.vue";
|
||||
|
||||
function flattenChildren(
|
||||
nodes: VNodeChild[],
|
||||
out: VNodeChild[] = [],
|
||||
): VNodeChild[] {
|
||||
for (const child of nodes) {
|
||||
if (Array.isArray(child)) {
|
||||
flattenChildren(child, out);
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
isVNode(child) &&
|
||||
child.type === Fragment &&
|
||||
Array.isArray(child.children)
|
||||
) {
|
||||
flattenChildren(child.children as VNodeChild[], out);
|
||||
continue;
|
||||
}
|
||||
out.push(child);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function isIgnorable(node: VNodeChild): boolean {
|
||||
if (node == null || node === false || node === true) return true;
|
||||
if (typeof node === "string") return node.trim() === "";
|
||||
if (typeof node === "number") return false;
|
||||
if (!isVNode(node)) return true;
|
||||
if (node.type === Comment) return true;
|
||||
if (node.type === Text && String(node.children ?? "").trim() === "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** True when the slot is only plain text/number content (auto-wrapped in BadgeLabel). */
|
||||
function isPlainTextSlot(nodes: VNodeChild[]): boolean {
|
||||
const meaningful = flattenChildren(nodes).filter(
|
||||
(node) => !isIgnorable(node),
|
||||
);
|
||||
if (meaningful.length === 0) return false;
|
||||
return meaningful.every((node) => {
|
||||
if (typeof node === "number" || typeof node === "string") return true;
|
||||
return isVNode(node) && node.type === Text;
|
||||
});
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "Badge",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
color: {
|
||||
type: String as PropType<BadgeVariants["color"]>,
|
||||
default: "default",
|
||||
},
|
||||
placement: {
|
||||
type: String as PropType<BadgeVariants["placement"]>,
|
||||
default: "top-right",
|
||||
},
|
||||
size: {
|
||||
type: String as PropType<BadgeVariants["size"]>,
|
||||
default: "md",
|
||||
},
|
||||
variant: {
|
||||
type: String as PropType<BadgeVariants["variant"]>,
|
||||
default: "primary",
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const variantSlots = computed(() =>
|
||||
badgeVariants({
|
||||
color: props.color,
|
||||
placement: props.placement,
|
||||
size: props.size,
|
||||
variant: props.variant,
|
||||
}),
|
||||
);
|
||||
|
||||
provide(badgeContextKey, { slots: variantSlots });
|
||||
|
||||
/**
|
||||
* Re-read the default slot on every render so text ↔ composed content
|
||||
* switches and parent slot-swap updates stay in sync.
|
||||
*/
|
||||
function render() {
|
||||
const children = (slots.default?.() ?? []) as VNodeChild[];
|
||||
const content: VNodeChild[] = isPlainTextSlot(children)
|
||||
? [
|
||||
h(
|
||||
BadgeLabel,
|
||||
{ key: "badge-auto-label" },
|
||||
{ default: () => children },
|
||||
),
|
||||
]
|
||||
: children;
|
||||
|
||||
return h(
|
||||
"span",
|
||||
{
|
||||
...attrs,
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"data-slot": "badge",
|
||||
},
|
||||
content,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { useAttrs } from "vue";
|
||||
import { badgeVariants } from "@heroui-vue/styles";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-bind="attrs"
|
||||
:class="badgeVariants().anchor()"
|
||||
data-slot="badge-anchor"
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { badgeContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(badgeContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-bind="attrs"
|
||||
:class="ctx?.slots.value.label()"
|
||||
data-slot="badge-label"
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { badgeVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type BadgeSlots = ReturnType<typeof badgeVariants>;
|
||||
|
||||
export interface BadgeContextValue {
|
||||
slots: ComputedRef<BadgeSlots>;
|
||||
}
|
||||
|
||||
export const badgeContextKey: InjectionKey<BadgeContextValue> =
|
||||
Symbol("HeroUIVue.Badge");
|
||||
@@ -29,6 +29,8 @@ export {
|
||||
separatorVariants,
|
||||
kbdVariants,
|
||||
chipVariants,
|
||||
badgeVariants,
|
||||
alertVariants,
|
||||
type ButtonVariants,
|
||||
type CardVariants,
|
||||
type InputVariants,
|
||||
@@ -44,6 +46,8 @@ export {
|
||||
type SeparatorVariants,
|
||||
type KbdVariants,
|
||||
type ChipVariants,
|
||||
type BadgeVariants,
|
||||
type AlertVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ButtonProps,
|
||||
@@ -70,6 +74,14 @@ export type {
|
||||
KbdContentProps,
|
||||
ChipProps,
|
||||
ChipLabelProps,
|
||||
BadgeProps,
|
||||
BadgeAnchorProps,
|
||||
BadgeLabelProps,
|
||||
AlertProps,
|
||||
AlertIndicatorProps,
|
||||
AlertContentProps,
|
||||
AlertTitleProps,
|
||||
AlertDescriptionProps,
|
||||
} from "./types";
|
||||
|
||||
export { tv, cn, type VariantProps } from "@heroui-vue/styles";
|
||||
@@ -125,3 +137,23 @@ export {
|
||||
type ChipContextValue,
|
||||
type ChipSlots,
|
||||
} from "./components/chip/context";
|
||||
|
||||
export { default as Badge } from "./components/badge/Badge.vue";
|
||||
export { default as BadgeAnchor } from "./components/badge/BadgeAnchor.vue";
|
||||
export { default as BadgeLabel } from "./components/badge/BadgeLabel.vue";
|
||||
export {
|
||||
badgeContextKey,
|
||||
type BadgeContextValue,
|
||||
type BadgeSlots,
|
||||
} from "./components/badge/context";
|
||||
export { default as Alert } from "./components/alert/Alert.vue";
|
||||
export { default as AlertIndicator } from "./components/alert/AlertIndicator.vue";
|
||||
export { default as AlertContent } from "./components/alert/AlertContent.vue";
|
||||
export { default as AlertTitle } from "./components/alert/AlertTitle.vue";
|
||||
export { default as AlertDescription } from "./components/alert/AlertDescription.vue";
|
||||
export {
|
||||
alertContextKey,
|
||||
type AlertContextValue,
|
||||
type AlertSlots,
|
||||
type AlertStatus,
|
||||
} from "./components/alert/context";
|
||||
|
||||
@@ -52,3 +52,23 @@ export type KbdAbbrProps = InstanceType<typeof KbdAbbr>["$props"];
|
||||
export type KbdContentProps = InstanceType<typeof KbdContent>["$props"];
|
||||
export type ChipProps = InstanceType<typeof Chip>["$props"];
|
||||
export type ChipLabelProps = InstanceType<typeof ChipLabel>["$props"];
|
||||
|
||||
import type Badge from "./components/badge/Badge.vue";
|
||||
import type BadgeAnchor from "./components/badge/BadgeAnchor.vue";
|
||||
import type BadgeLabel from "./components/badge/BadgeLabel.vue";
|
||||
import type Alert from "./components/alert/Alert.vue";
|
||||
import type AlertIndicator from "./components/alert/AlertIndicator.vue";
|
||||
import type AlertContent from "./components/alert/AlertContent.vue";
|
||||
import type AlertTitle from "./components/alert/AlertTitle.vue";
|
||||
import type AlertDescription from "./components/alert/AlertDescription.vue";
|
||||
|
||||
export type BadgeProps = InstanceType<typeof Badge>["$props"];
|
||||
export type BadgeAnchorProps = InstanceType<typeof BadgeAnchor>["$props"];
|
||||
export type BadgeLabelProps = InstanceType<typeof BadgeLabel>["$props"];
|
||||
export type AlertProps = InstanceType<typeof Alert>["$props"];
|
||||
export type AlertIndicatorProps = InstanceType<typeof AlertIndicator>["$props"];
|
||||
export type AlertContentProps = InstanceType<typeof AlertContent>["$props"];
|
||||
export type AlertTitleProps = InstanceType<typeof AlertTitle>["$props"];
|
||||
export type AlertDescriptionProps = InstanceType<
|
||||
typeof AlertDescription
|
||||
>["$props"];
|
||||
|
||||
@@ -0,0 +1,550 @@
|
||||
import { describe, it, expect, afterEach } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import {
|
||||
createCommentVNode,
|
||||
createTextVNode,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
nextTick,
|
||||
ref,
|
||||
} from "vue";
|
||||
import { readFileSync } from "node:fs";
|
||||
import {
|
||||
Alert,
|
||||
AlertContent,
|
||||
AlertDescription,
|
||||
AlertIndicator,
|
||||
AlertTitle,
|
||||
Badge,
|
||||
BadgeAnchor,
|
||||
BadgeLabel,
|
||||
surfaceContextKey,
|
||||
} from "../packages/vue/src";
|
||||
import AlertBasicDemo from "../apps/docs/demos/alert-basic.vue";
|
||||
import BadgeBasicDemo from "../apps/docs/demos/badge-basic.vue";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
describe("Badge", () => {
|
||||
it("renders default placement/size/variant and wraps plain text", () => {
|
||||
const w = mount(Badge, { slots: { default: () => "5" } });
|
||||
const root = w.get("[data-slot=badge]");
|
||||
expect(root.classes()).toContain("hv-badge");
|
||||
expect(root.classes()).toContain("hv-badge--default");
|
||||
expect(root.classes()).toContain("hv-badge--top-right");
|
||||
expect(root.classes()).toContain("hv-badge--md");
|
||||
expect(root.classes()).toContain("hv-badge--primary");
|
||||
const label = w.get("[data-slot=badge-label]");
|
||||
expect(label.text()).toBe("5");
|
||||
expect(label.classes()).toContain("hv-badge__label");
|
||||
expect(root.element.childNodes).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("wraps number zero and text, not explicit label or composed content", () => {
|
||||
const zero = mount(Badge, {
|
||||
slots: { default: () => createTextVNode("0") },
|
||||
});
|
||||
expect(zero.get("[data-slot=badge-label]").text()).toBe("0");
|
||||
|
||||
const explicit = mount(Badge, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(BadgeLabel, { class: "custom" }, { default: () => "标签" }),
|
||||
},
|
||||
});
|
||||
expect(explicit.findAll("[data-slot=badge-label]")).toHaveLength(1);
|
||||
expect(explicit.get("[data-slot=badge-label]").classes()).toContain(
|
||||
"custom",
|
||||
);
|
||||
|
||||
const composed = mount(Badge, {
|
||||
slots: {
|
||||
default: () => [
|
||||
h("span", { class: "icon" }, "•"),
|
||||
h(BadgeLabel, {}, { default: () => "新" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(composed.findAll("[data-slot=badge-label]")).toHaveLength(1);
|
||||
expect(composed.find(".icon").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("switches between text and composed slot content dynamically", async () => {
|
||||
const mode = ref<"text" | "composed">("text");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Badge, BadgeLabel },
|
||||
setup: () => ({ mode }),
|
||||
template: `
|
||||
<Badge>
|
||||
<template v-if="mode === 'text'">99+</template>
|
||||
<template v-else>
|
||||
<span class="dot">•</span>
|
||||
<BadgeLabel>新</BadgeLabel>
|
||||
</template>
|
||||
</Badge>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(w.get("[data-slot=badge-label]").text()).toBe("99+");
|
||||
mode.value = "composed";
|
||||
await nextTick();
|
||||
expect(w.findAll("[data-slot=badge-label]")).toHaveLength(1);
|
||||
expect(w.find(".dot").exists()).toBe(true);
|
||||
mode.value = "text";
|
||||
await nextTick();
|
||||
expect(w.get("[data-slot=badge-label]").text()).toBe("99+");
|
||||
expect(w.find(".dot").exists()).toBe(false);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("ignores comments and whitespace when deciding auto-wrap", () => {
|
||||
const w = mount(Badge, {
|
||||
slots: {
|
||||
default: () => [
|
||||
createCommentVNode("c"),
|
||||
createTextVNode(" "),
|
||||
createTextVNode("3"),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(w.findAll("[data-slot=badge-label]")).toHaveLength(1);
|
||||
expect(w.get("[data-slot=badge-label]").text()).toBe("3");
|
||||
|
||||
const empty = mount(Badge, {
|
||||
slots: { default: () => [createCommentVNode("only")] },
|
||||
});
|
||||
expect(empty.findAll("[data-slot=badge-label]")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("applies placement, color, size and variant classes", () => {
|
||||
const w = mount(Badge, {
|
||||
props: {
|
||||
color: "danger",
|
||||
placement: "bottom-left",
|
||||
size: "lg",
|
||||
variant: "soft",
|
||||
},
|
||||
slots: { default: () => "9" },
|
||||
});
|
||||
const classes = w.get("[data-slot=badge]").classes();
|
||||
expect(classes).toContain("hv-badge--danger");
|
||||
expect(classes).toContain("hv-badge--bottom-left");
|
||||
expect(classes).toContain("hv-badge--lg");
|
||||
expect(classes).toContain("hv-badge--soft");
|
||||
});
|
||||
|
||||
it("anchors children without becoming a link", () => {
|
||||
const w = mount(BadgeAnchor, {
|
||||
slots: {
|
||||
default: () => [
|
||||
h("img", { alt: "a" }),
|
||||
h(Badge, {}, { default: () => "1" }),
|
||||
],
|
||||
},
|
||||
});
|
||||
const root = w.get("[data-slot=badge-anchor]");
|
||||
expect(root.element.tagName).toBe("SPAN");
|
||||
expect(root.element.closest("a")).toBeNull();
|
||||
expect(root.classes()).toContain("hv-badge-anchor");
|
||||
expect(w.find("img").exists()).toBe(true);
|
||||
expect(w.find("[data-slot=badge]").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps badge in the basic demo overlapping its avatar anchor", () => {
|
||||
const w = mount(BadgeBasicDemo, { attachTo: document.body });
|
||||
const anchors = w.findAll("[data-slot=badge-anchor]");
|
||||
expect(anchors).toHaveLength(3);
|
||||
for (const anchor of anchors) {
|
||||
expect(anchor.find("[data-slot=avatar]").exists()).toBe(true);
|
||||
expect(anchor.find("[data-slot=badge]").exists()).toBe(true);
|
||||
}
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("updates attrs and class dynamically and merges caller class", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const classValue = ref<unknown>("badge-extra");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Badge },
|
||||
setup: () => ({ extra, classValue }),
|
||||
template: `<Badge v-bind="extra" :class="classValue">A</Badge>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const root = () => w.get("[data-slot=badge]");
|
||||
expect(root().classes()).toContain("hv-badge");
|
||||
expect(root().classes()).toContain("badge-extra");
|
||||
expect(root().attributes("title")).toBeUndefined();
|
||||
|
||||
extra.value = { title: "t1", "data-x": "1" };
|
||||
classValue.value = ["badge-extra", { "badge-more": true }];
|
||||
await nextTick();
|
||||
expect(root().attributes("title")).toBe("t1");
|
||||
expect(root().attributes("data-x")).toBe("1");
|
||||
expect(root().classes()).toContain("badge-more");
|
||||
|
||||
extra.value = { title: "t2" };
|
||||
await nextTick();
|
||||
expect(root().attributes("title")).toBe("t2");
|
||||
expect(root().attributes("data-x")).toBeUndefined();
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
expect(root().attributes("title")).toBeUndefined();
|
||||
|
||||
extra.value = { "aria-label": "count" };
|
||||
await nextTick();
|
||||
expect(root().attributes("aria-label")).toBe("count");
|
||||
expect(root().classes()).toContain("hv-badge");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { Badge: BadgeComp } = await import("../packages/vue/src");
|
||||
// @ts-expect-error color must be a known badge color
|
||||
const badColor: InstanceType<typeof BadgeComp>["$props"]["color"] = "neon";
|
||||
// @ts-expect-error placement must be a known corner
|
||||
const badPlacement: InstanceType<typeof BadgeComp>["$props"]["placement"] =
|
||||
"center";
|
||||
// @ts-expect-error variant must be primary | secondary | soft
|
||||
const badVariant: InstanceType<typeof BadgeComp>["$props"]["variant"] =
|
||||
"ghost";
|
||||
// @ts-expect-error size must be sm | md | lg
|
||||
const badSize: InstanceType<typeof BadgeComp>["$props"]["size"] = "xl";
|
||||
void badColor;
|
||||
void badPlacement;
|
||||
void badVariant;
|
||||
void badSize;
|
||||
const ok: InstanceType<typeof BadgeComp>["$props"] = {
|
||||
color: "accent",
|
||||
placement: "bottom-left",
|
||||
variant: "soft",
|
||||
size: "sm",
|
||||
};
|
||||
expect(ok.placement).toBe("bottom-left");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Alert", () => {
|
||||
function mountAlert(
|
||||
props: Record<string, unknown> = {},
|
||||
slots: Record<string, unknown> = {},
|
||||
) {
|
||||
return mount(Alert, {
|
||||
props,
|
||||
slots: {
|
||||
default: () => [
|
||||
h(AlertIndicator),
|
||||
h(
|
||||
AlertContent,
|
||||
{},
|
||||
{
|
||||
default: () => [
|
||||
h(AlertTitle, {}, { default: () => "标题" }),
|
||||
h(AlertDescription, {}, { default: () => "说明" }),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
...slots,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
it("renders default status with baseline parts and default icon", () => {
|
||||
const w = mountAlert();
|
||||
expect(w.get("[data-slot=alert-root]").classes()).toContain("hv-alert");
|
||||
expect(w.get("[data-slot=alert-root]").classes()).toContain(
|
||||
"hv-alert--default",
|
||||
);
|
||||
expect(w.get("[data-slot=alert-indicator]").classes()).toContain(
|
||||
"hv-alert__indicator",
|
||||
);
|
||||
expect(w.get("[data-slot=alert-content]").classes()).toContain(
|
||||
"hv-alert__content",
|
||||
);
|
||||
expect(w.get("[data-slot=alert-title]").element.tagName).toBe("P");
|
||||
expect(w.get("[data-slot=alert-title]").text()).toBe("标题");
|
||||
expect(w.get("[data-slot=alert-description]").element.tagName).toBe("SPAN");
|
||||
expect(w.get("[data-slot=alert-description]").text()).toBe("说明");
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(true);
|
||||
expect(
|
||||
w.get("[data-slot=alert-default-icon]").attributes("aria-hidden"),
|
||||
).toBe("true");
|
||||
});
|
||||
|
||||
it("updates the default icon path with status", () => {
|
||||
const paths: Record<string, string | undefined> = {};
|
||||
for (const status of [
|
||||
"default",
|
||||
"accent",
|
||||
"success",
|
||||
"warning",
|
||||
"danger",
|
||||
] as const) {
|
||||
const w = mountAlert({ status });
|
||||
paths[status] = w
|
||||
.get("[data-slot=alert-default-icon] path")
|
||||
.attributes("d");
|
||||
expect(w.get("[data-slot=alert-root]").classes()).toContain(
|
||||
`hv-alert--${status}`,
|
||||
);
|
||||
w.unmount();
|
||||
}
|
||||
expect(paths.default).toBe(paths.accent);
|
||||
expect(new Set(Object.values(paths)).size).toBe(4);
|
||||
});
|
||||
|
||||
it("replaces the default icon with custom indicator content", () => {
|
||||
const w = mount(Alert, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(
|
||||
AlertIndicator,
|
||||
{},
|
||||
{ default: () => h("span", { class: "spin" }, "…") },
|
||||
),
|
||||
},
|
||||
});
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(false);
|
||||
expect(w.find(".spin").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("merges caller class on AlertIndicator and keeps base class", () => {
|
||||
const w = mount(Alert, {
|
||||
slots: {
|
||||
default: () =>
|
||||
h(
|
||||
AlertIndicator,
|
||||
{ class: ["relative", { "text-warning": true }] },
|
||||
{ default: () => h("span", "x") },
|
||||
),
|
||||
},
|
||||
});
|
||||
const classes = w.get("[data-slot=alert-indicator]").classes();
|
||||
expect(classes).toContain("hv-alert__indicator");
|
||||
expect(classes).toContain("relative");
|
||||
expect(classes).toContain("text-warning");
|
||||
});
|
||||
|
||||
it("falls back to the default icon for empty or comment-only indicator slots", async () => {
|
||||
const mode = ref<"empty" | "custom" | "comments">("empty");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Alert, AlertIndicator },
|
||||
setup: () => ({ mode }),
|
||||
template: `
|
||||
<Alert status="success">
|
||||
<AlertIndicator>
|
||||
<template v-if="mode === 'custom'">自定义</template>
|
||||
<template v-else-if="mode === 'comments'">
|
||||
<!-- nothing -->
|
||||
</template>
|
||||
</AlertIndicator>
|
||||
</Alert>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(true);
|
||||
expect(
|
||||
w.find("[data-slot=alert-default-icon] path").attributes("d"),
|
||||
).toContain("13.5 8");
|
||||
|
||||
mode.value = "custom";
|
||||
await nextTick();
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(false);
|
||||
expect(w.text()).toContain("自定义");
|
||||
|
||||
mode.value = "comments";
|
||||
await nextTick();
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(true);
|
||||
|
||||
mode.value = "custom";
|
||||
await nextTick();
|
||||
expect(w.find("[data-slot=alert-default-icon]").exists()).toBe(false);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("resets nested SurfaceContext to default", () => {
|
||||
const seen = ref<string | undefined>();
|
||||
const Probe = defineComponent({
|
||||
setup() {
|
||||
const ctx = inject(surfaceContextKey, undefined);
|
||||
seen.value = ctx?.variant.value;
|
||||
return () => h("span", "probe");
|
||||
},
|
||||
});
|
||||
const Outer = defineComponent({
|
||||
components: { Alert, Probe },
|
||||
template: `
|
||||
<div>
|
||||
<Alert>
|
||||
<Probe />
|
||||
</Alert>
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
// Simulate an outer surface providing secondary before Alert.
|
||||
const Wrapped = defineComponent({
|
||||
setup(_, { slots }) {
|
||||
// provide happens in child tree via a local surface-like parent
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
});
|
||||
mount(
|
||||
defineComponent({
|
||||
components: { Alert, Probe, Wrapped },
|
||||
setup() {
|
||||
return {};
|
||||
},
|
||||
template: `
|
||||
<Alert status="accent">
|
||||
<Probe />
|
||||
</Alert>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(seen.value).toBe("default");
|
||||
});
|
||||
|
||||
it("keeps the six combinations in the alert-basic demo", () => {
|
||||
const w = mount(AlertBasicDemo, { attachTo: document.body });
|
||||
const roots = w.findAll("[data-slot=alert-root]");
|
||||
expect(roots).toHaveLength(6);
|
||||
expect(w.text()).toContain("新功能已上线");
|
||||
expect(w.text()).toContain("有可用更新");
|
||||
expect(w.text()).toContain("无法连接到服务器");
|
||||
expect(w.text()).toContain("检查网络连接");
|
||||
expect(w.text()).toContain("个人资料已更新");
|
||||
expect(w.text()).toContain("正在处理你的请求");
|
||||
expect(w.text()).toContain("计划维护");
|
||||
expect(w.findAll("[data-slot=alert-default-icon]").length).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
expect(w.find("[data-slot=spinner]").exists() || w.text()).toBeTruthy();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("updates attrs, class and status dynamically", async () => {
|
||||
const status = ref<"default" | "danger">("default");
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const classValue = ref<unknown>("alert-custom");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Alert },
|
||||
setup: () => ({ status, extra, classValue }),
|
||||
template: `<Alert :status="status" v-bind="extra" :class="classValue">内容</Alert>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const root = () => w.get("[data-slot=alert-root]");
|
||||
expect(root().classes()).toContain("hv-alert--default");
|
||||
expect(root().classes()).toContain("alert-custom");
|
||||
|
||||
status.value = "danger";
|
||||
extra.value = { "aria-live": "polite", "data-x": "1" };
|
||||
classValue.value = ["alert-custom", { "alert-more": true }];
|
||||
await nextTick();
|
||||
expect(root().classes()).toContain("hv-alert--danger");
|
||||
expect(root().classes()).not.toContain("hv-alert--default");
|
||||
expect(root().classes()).toContain("alert-more");
|
||||
expect(root().attributes("aria-live")).toBe("polite");
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
expect(root().attributes("aria-live")).toBeUndefined();
|
||||
expect(root().attributes("data-x")).toBeUndefined();
|
||||
|
||||
extra.value = { role: "status" };
|
||||
await nextTick();
|
||||
expect(root().attributes("role")).toBe("status");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { Alert: AlertComp } = await import("../packages/vue/src");
|
||||
// @ts-expect-error status must be a known alert status
|
||||
const badStatus: InstanceType<typeof AlertComp>["$props"]["status"] =
|
||||
"info";
|
||||
void badStatus;
|
||||
const ok: InstanceType<typeof AlertComp>["$props"] = { status: "warning" };
|
||||
expect(ok.status).toBe("warning");
|
||||
});
|
||||
});
|
||||
|
||||
describe("M10–M11 demo inventory", () => {
|
||||
const expected: Record<string, string[]> = {
|
||||
badge: [
|
||||
"basic",
|
||||
"variants",
|
||||
"sizes",
|
||||
"colors",
|
||||
"placements",
|
||||
"dot",
|
||||
"with-content",
|
||||
"custom-styles",
|
||||
],
|
||||
alert: ["basic", "custom-styles"],
|
||||
};
|
||||
|
||||
it("includes every preview from the pinned upstream documents", () => {
|
||||
for (const [docName, names] of Object.entries(expected)) {
|
||||
const document = readFileSync(
|
||||
`apps/docs/components/${docName}.md`,
|
||||
"utf8",
|
||||
);
|
||||
const previewNames = [
|
||||
...document.matchAll(
|
||||
new RegExp(`<ComponentPreview name="${docName}-([^"]+)"`, "g"),
|
||||
),
|
||||
].map((match) => match[1]);
|
||||
expect(previewNames).toEqual(names);
|
||||
for (const name of names) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/${docName}-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
expect(source).toContain("<template>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("documents Vue class binding instead of React className", () => {
|
||||
for (const docName of ["badge", "alert"]) {
|
||||
const document = readFileSync(
|
||||
`apps/docs/components/${docName}.md`,
|
||||
"utf8",
|
||||
);
|
||||
expect(document).not.toMatch(/\|\s*`className`\s*\|/);
|
||||
expect(document).not.toMatch(/\|\s*`children`\s*\|/);
|
||||
expect(document).toContain("`class`");
|
||||
expect(document).toContain("Vue class 绑定");
|
||||
expect(document).toMatch(/string\s*\\\|\s*Array\s*\\\|\s*Object/);
|
||||
}
|
||||
for (const name of ["badge-basic", "alert-basic", "alert-custom-styles"]) {
|
||||
const source = readFileSync(`apps/docs/demos/${name}.vue`, "utf8");
|
||||
expect(source).not.toContain("className");
|
||||
}
|
||||
});
|
||||
|
||||
it("uses Tabler icons and library components in demos", () => {
|
||||
const withContent = readFileSync(
|
||||
"apps/docs/demos/badge-with-content.vue",
|
||||
"utf8",
|
||||
);
|
||||
expect(withContent).toContain("@tabler/icons-vue");
|
||||
expect(withContent).not.toContain("<path");
|
||||
expect(withContent).not.toContain("@gravity-ui/icons");
|
||||
|
||||
const alertDemo = readFileSync("apps/docs/demos/alert-basic.vue", "utf8");
|
||||
expect(alertDemo).toContain("CloseButton");
|
||||
expect(alertDemo).toContain("Spinner");
|
||||
expect(alertDemo).toContain("Button");
|
||||
expect(alertDemo).not.toContain("className");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user