From 4f43789f600fedd4743368339dd476b6cb1f88a6 Mon Sep 17 00:00:00 2001 From: maoyingjie Date: Wed, 21 Oct 2026 21:32:40 +0800 Subject: [PATCH] feat: add Badge and Alert components --- AGENTS.md | 3 + apps/docs/.vitepress/theme/Layout.vue | 2 + apps/docs/components.md | 2 + apps/docs/components/alert.md | 148 +++++ apps/docs/components/badge.md | 189 ++++++ apps/docs/demos/alert-basic.vue | 92 +++ apps/docs/demos/alert-custom-styles.vue | 44 ++ apps/docs/demos/badge-basic.vue | 44 ++ apps/docs/demos/badge-colors.vue | 26 + apps/docs/demos/badge-custom-styles.vue | 29 + apps/docs/demos/badge-dot.vue | 26 + apps/docs/demos/badge-placements.vue | 45 ++ apps/docs/demos/badge-sizes.vue | 26 + apps/docs/demos/badge-variants.vue | 45 ++ apps/docs/demos/badge-with-content.vue | 51 ++ docs/compatibility.md | 16 +- docs/migration-handoff.md | 27 +- docs/migrations/M10-M11-badge-alert.md | 146 +++++ docs/migrations/M10-M11-prompt.md | 75 +++ docs/migrations/M10-M11-review.md | 12 + docs/upstream.md | 10 +- docs/verification.md | 28 + package.json | 2 +- packages/styles/components/alert.css | 70 +++ packages/styles/components/badge.css | 148 +++++ packages/styles/index.css | 2 + packages/styles/src/index.ts | 105 ++++ packages/vue/src/components/alert/Alert.vue | 36 ++ .../vue/src/components/alert/AlertContent.vue | 19 + .../src/components/alert/AlertDefaultIcon.vue | 58 ++ .../src/components/alert/AlertDescription.vue | 19 + .../src/components/alert/AlertIndicator.vue | 88 +++ .../vue/src/components/alert/AlertTitle.vue | 15 + packages/vue/src/components/alert/context.ts | 14 + packages/vue/src/components/badge/Badge.vue | 127 ++++ .../vue/src/components/badge/BadgeAnchor.vue | 18 + .../vue/src/components/badge/BadgeLabel.vue | 19 + packages/vue/src/components/badge/context.ts | 11 + packages/vue/src/index.ts | 32 + packages/vue/src/types.ts | 20 + tests/badge-alert.test.ts | 550 ++++++++++++++++++ 41 files changed, 2422 insertions(+), 17 deletions(-) create mode 100644 apps/docs/components/alert.md create mode 100644 apps/docs/components/badge.md create mode 100644 apps/docs/demos/alert-basic.vue create mode 100644 apps/docs/demos/alert-custom-styles.vue create mode 100644 apps/docs/demos/badge-basic.vue create mode 100644 apps/docs/demos/badge-colors.vue create mode 100644 apps/docs/demos/badge-custom-styles.vue create mode 100644 apps/docs/demos/badge-dot.vue create mode 100644 apps/docs/demos/badge-placements.vue create mode 100644 apps/docs/demos/badge-sizes.vue create mode 100644 apps/docs/demos/badge-variants.vue create mode 100644 apps/docs/demos/badge-with-content.vue create mode 100644 docs/migrations/M10-M11-badge-alert.md create mode 100644 docs/migrations/M10-M11-prompt.md create mode 100644 docs/migrations/M10-M11-review.md create mode 100644 packages/styles/components/alert.css create mode 100644 packages/styles/components/badge.css create mode 100644 packages/vue/src/components/alert/Alert.vue create mode 100644 packages/vue/src/components/alert/AlertContent.vue create mode 100644 packages/vue/src/components/alert/AlertDefaultIcon.vue create mode 100644 packages/vue/src/components/alert/AlertDescription.vue create mode 100644 packages/vue/src/components/alert/AlertIndicator.vue create mode 100644 packages/vue/src/components/alert/AlertTitle.vue create mode 100644 packages/vue/src/components/alert/context.ts create mode 100644 packages/vue/src/components/badge/Badge.vue create mode 100644 packages/vue/src/components/badge/BadgeAnchor.vue create mode 100644 packages/vue/src/components/badge/BadgeLabel.vue create mode 100644 packages/vue/src/components/badge/context.ts create mode 100644 tests/badge-alert.test.ts diff --git a/AGENTS.md b/AGENTS.md index ad36627..448cdb4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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` 与样式包许可证,不根据包清单猜测移植许可;新增第三方图标包按其自身许可记录。 diff --git a/apps/docs/.vitepress/theme/Layout.vue b/apps/docs/.vitepress/theme/Layout.vue index 26477b1..035f1b2 100644 --- a/apps/docs/.vitepress/theme/Layout.vue +++ b/apps/docs/.vitepress/theme/Layout.vue @@ -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" }, diff --git a/apps/docs/components.md b/apps/docs/components.md index 2798f02..432c69d 100644 --- a/apps/docs/components.md +++ b/apps/docs/components.md @@ -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) diff --git a/apps/docs/components/alert.md b/apps/docs/components/alert.md new file mode 100644 index 0000000..c3d76b3 --- /dev/null +++ b/apps/docs/components/alert.md @@ -0,0 +1,148 @@ +--- +title: Alert 警告 +description: 向用户展示重要消息与通知,并提供状态指示 +component: alert +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 组件结构 + +```vue + + + +``` + +省略 `AlertIndicator` 默认插槽时显示随 `status` 变化的状态图标;传入自定义内容会替换默认图标。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 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) diff --git a/apps/docs/components/badge.md b/apps/docs/components/badge.md new file mode 100644 index 0000000..273a6bb --- /dev/null +++ b/apps/docs/components/badge.md @@ -0,0 +1,189 @@ +--- +title: Badge 徽章 +description: 相对其他元素定位的小型指示器,常用于通知数量、状态点与标签 +component: badge +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 组件结构 + +Badge 通过 `BadgeAnchor` 相对其他元素定位。纯文本子节点会自动包裹在 `` 中。 + +> 独立标签用法请使用 [Chip](/components/chip) 组件。 + +```vue + + + +``` + +`BadgeAnchor` 是定位容器,不是导航链接。 + +## 示例 + +### 变体 + + + +### 尺寸 + + + +### 颜色 + + + +### 徽章位置 + + + +### 点状徽标 + +空徽章作为状态指示器,适用于在线/离线或活动信号。 + + + +### 带内容 + +Badge 支持文本、数字与图标。无子节点时渲染为点状指示器。 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 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) diff --git a/apps/docs/demos/alert-basic.vue b/apps/docs/demos/alert-basic.vue new file mode 100644 index 0000000..234e4bd --- /dev/null +++ b/apps/docs/demos/alert-basic.vue @@ -0,0 +1,92 @@ + + + diff --git a/apps/docs/demos/alert-custom-styles.vue b/apps/docs/demos/alert-custom-styles.vue new file mode 100644 index 0000000..a78635f --- /dev/null +++ b/apps/docs/demos/alert-custom-styles.vue @@ -0,0 +1,44 @@ + + + diff --git a/apps/docs/demos/badge-basic.vue b/apps/docs/demos/badge-basic.vue new file mode 100644 index 0000000..01f26dc --- /dev/null +++ b/apps/docs/demos/badge-basic.vue @@ -0,0 +1,44 @@ + + + diff --git a/apps/docs/demos/badge-colors.vue b/apps/docs/demos/badge-colors.vue new file mode 100644 index 0000000..da1107b --- /dev/null +++ b/apps/docs/demos/badge-colors.vue @@ -0,0 +1,26 @@ + + + diff --git a/apps/docs/demos/badge-custom-styles.vue b/apps/docs/demos/badge-custom-styles.vue new file mode 100644 index 0000000..df71fe6 --- /dev/null +++ b/apps/docs/demos/badge-custom-styles.vue @@ -0,0 +1,29 @@ + + + diff --git a/apps/docs/demos/badge-dot.vue b/apps/docs/demos/badge-dot.vue new file mode 100644 index 0000000..84e011a --- /dev/null +++ b/apps/docs/demos/badge-dot.vue @@ -0,0 +1,26 @@ + + + diff --git a/apps/docs/demos/badge-placements.vue b/apps/docs/demos/badge-placements.vue new file mode 100644 index 0000000..7e2eb4c --- /dev/null +++ b/apps/docs/demos/badge-placements.vue @@ -0,0 +1,45 @@ + + + diff --git a/apps/docs/demos/badge-sizes.vue b/apps/docs/demos/badge-sizes.vue new file mode 100644 index 0000000..31ca1f8 --- /dev/null +++ b/apps/docs/demos/badge-sizes.vue @@ -0,0 +1,26 @@ + + + diff --git a/apps/docs/demos/badge-variants.vue b/apps/docs/demos/badge-variants.vue new file mode 100644 index 0000000..7926b59 --- /dev/null +++ b/apps/docs/demos/badge-variants.vue @@ -0,0 +1,45 @@ + + + diff --git a/apps/docs/demos/badge-with-content.vue b/apps/docs/demos/badge-with-content.vue new file mode 100644 index 0000000..c0f64af --- /dev/null +++ b/apps/docs/demos/badge-with-content.vue @@ -0,0 +1,51 @@ + + + diff --git a/docs/compatibility.md b/docs/compatibility.md index dc39bd6..df55a3d 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -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。 diff --git a/docs/migration-handoff.md b/docs/migration-handoff.md index 2124910..a561037 100644 --- a/docs/migration-handoff.md +++ b/docs/migration-handoff.md @@ -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、事件、插槽、作用域状态及其他说明表格。宽度以正文内容区为准,不占用侧栏或右侧目录;演示区内的组件表格按组件自身契约处理。 diff --git a/docs/migrations/M10-M11-badge-alert.md b/docs/migrations/M10-M11-badge-alert.md new file mode 100644 index 0000000..82e89e4 --- /dev/null +++ b/docs/migrations/M10-M11-badge-alert.md @@ -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` 的语义是否保持。 + +实施者只记自测与修复,验收结论留给集成人。 diff --git a/docs/migrations/M10-M11-prompt.md b/docs/migrations/M10-M11-prompt.md new file mode 100644 index 0000000..bbc84ea --- /dev/null +++ b/docs/migrations/M10-M11-prompt.md @@ -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与差异、回归场景、各命令结果、 +浏览器证据、来源许可、未验证项和最短复核步骤。实施者只记自测与修复,验收结论留给集成人。 +遇到缺口先给可复现场景和局部方案,不删能力、不无界扩展任务。 +``` diff --git a/docs/migrations/M10-M11-review.md b/docs/migrations/M10-M11-review.md new file mode 100644 index 0000000..5a994b9 --- /dev/null +++ b/docs/migrations/M10-M11-review.md @@ -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 提示词。 diff --git a/docs/upstream.md b/docs/upstream.md index af7b6f6..69e9d87 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -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 图标依赖;尚未完成自动逐像素对比。 diff --git a/docs/verification.md b/docs/verification.md index a2cd912..519f1dd 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -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`(未建立)。 diff --git a/package.json b/package.json index 340f443..a5dafb3 100644 --- a/package.json +++ b/package.json @@ -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 .", diff --git a/packages/styles/components/alert.css b/packages/styles/components/alert.css new file mode 100644 index 0000000..fe0c512 --- /dev/null +++ b/packages/styles/components/alert.css @@ -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; +} diff --git a/packages/styles/components/badge.css b/packages/styles/components/badge.css new file mode 100644 index 0000000..6229ae6 --- /dev/null +++ b/packages/styles/components/badge.css @@ -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); +} diff --git a/packages/styles/index.css b/packages/styles/index.css index c48f614..2701c88 100644 --- a/packages/styles/index.css +++ b/packages/styles/index.css @@ -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 { diff --git a/packages/styles/src/index.ts b/packages/styles/src/index.ts index 9547ebb..d2068fd 100644 --- a/packages/styles/src/index.ts +++ b/packages/styles/src/index.ts @@ -393,3 +393,108 @@ export const chipVariants = tv({ }); export type ChipVariants = VariantProps; + +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; + +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; diff --git a/packages/vue/src/components/alert/Alert.vue b/packages/vue/src/components/alert/Alert.vue new file mode 100644 index 0000000..99e70fb --- /dev/null +++ b/packages/vue/src/components/alert/Alert.vue @@ -0,0 +1,36 @@ + + + diff --git a/packages/vue/src/components/alert/AlertContent.vue b/packages/vue/src/components/alert/AlertContent.vue new file mode 100644 index 0000000..efa8dff --- /dev/null +++ b/packages/vue/src/components/alert/AlertContent.vue @@ -0,0 +1,19 @@ + + + diff --git a/packages/vue/src/components/alert/AlertDefaultIcon.vue b/packages/vue/src/components/alert/AlertDefaultIcon.vue new file mode 100644 index 0000000..8824e45 --- /dev/null +++ b/packages/vue/src/components/alert/AlertDefaultIcon.vue @@ -0,0 +1,58 @@ + diff --git a/packages/vue/src/components/alert/AlertDescription.vue b/packages/vue/src/components/alert/AlertDescription.vue new file mode 100644 index 0000000..4f22d31 --- /dev/null +++ b/packages/vue/src/components/alert/AlertDescription.vue @@ -0,0 +1,19 @@ + + + diff --git a/packages/vue/src/components/alert/AlertIndicator.vue b/packages/vue/src/components/alert/AlertIndicator.vue new file mode 100644 index 0000000..deefbc9 --- /dev/null +++ b/packages/vue/src/components/alert/AlertIndicator.vue @@ -0,0 +1,88 @@ + diff --git a/packages/vue/src/components/alert/AlertTitle.vue b/packages/vue/src/components/alert/AlertTitle.vue new file mode 100644 index 0000000..c8071e9 --- /dev/null +++ b/packages/vue/src/components/alert/AlertTitle.vue @@ -0,0 +1,15 @@ + + + diff --git a/packages/vue/src/components/alert/context.ts b/packages/vue/src/components/alert/context.ts new file mode 100644 index 0000000..862ce5a --- /dev/null +++ b/packages/vue/src/components/alert/context.ts @@ -0,0 +1,14 @@ +import type { ComputedRef, InjectionKey } from "vue"; +import type { AlertVariants, alertVariants } from "@heroui-vue/styles"; + +export type AlertSlots = ReturnType; + +export type AlertStatus = NonNullable; + +export interface AlertContextValue { + slots: ComputedRef; + status: ComputedRef; +} + +export const alertContextKey: InjectionKey = + Symbol("HeroUIVue.Alert"); diff --git a/packages/vue/src/components/badge/Badge.vue b/packages/vue/src/components/badge/Badge.vue new file mode 100644 index 0000000..554779a --- /dev/null +++ b/packages/vue/src/components/badge/Badge.vue @@ -0,0 +1,127 @@ + diff --git a/packages/vue/src/components/badge/BadgeAnchor.vue b/packages/vue/src/components/badge/BadgeAnchor.vue new file mode 100644 index 0000000..4ee20e7 --- /dev/null +++ b/packages/vue/src/components/badge/BadgeAnchor.vue @@ -0,0 +1,18 @@ + + + diff --git a/packages/vue/src/components/badge/BadgeLabel.vue b/packages/vue/src/components/badge/BadgeLabel.vue new file mode 100644 index 0000000..f129645 --- /dev/null +++ b/packages/vue/src/components/badge/BadgeLabel.vue @@ -0,0 +1,19 @@ + + + diff --git a/packages/vue/src/components/badge/context.ts b/packages/vue/src/components/badge/context.ts new file mode 100644 index 0000000..fe63f37 --- /dev/null +++ b/packages/vue/src/components/badge/context.ts @@ -0,0 +1,11 @@ +import type { ComputedRef, InjectionKey } from "vue"; +import type { badgeVariants } from "@heroui-vue/styles"; + +export type BadgeSlots = ReturnType; + +export interface BadgeContextValue { + slots: ComputedRef; +} + +export const badgeContextKey: InjectionKey = + Symbol("HeroUIVue.Badge"); diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index e64b02b..5a47270 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -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"; diff --git a/packages/vue/src/types.ts b/packages/vue/src/types.ts index 725d033..0c66166 100644 --- a/packages/vue/src/types.ts +++ b/packages/vue/src/types.ts @@ -52,3 +52,23 @@ export type KbdAbbrProps = InstanceType["$props"]; export type KbdContentProps = InstanceType["$props"]; export type ChipProps = InstanceType["$props"]; export type ChipLabelProps = InstanceType["$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["$props"]; +export type BadgeAnchorProps = InstanceType["$props"]; +export type BadgeLabelProps = InstanceType["$props"]; +export type AlertProps = InstanceType["$props"]; +export type AlertIndicatorProps = InstanceType["$props"]; +export type AlertContentProps = InstanceType["$props"]; +export type AlertTitleProps = InstanceType["$props"]; +export type AlertDescriptionProps = InstanceType< + typeof AlertDescription +>["$props"]; diff --git a/tests/badge-alert.test.ts b/tests/badge-alert.test.ts new file mode 100644 index 0000000..ef75162 --- /dev/null +++ b/tests/badge-alert.test.ts @@ -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: ` + + + + + `, + }), + ); + 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>({}); + const classValue = ref("badge-extra"); + const w = mount( + defineComponent({ + components: { Badge }, + setup: () => ({ extra, classValue }), + template: `A`, + }), + { 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["$props"]["color"] = "neon"; + // @ts-expect-error placement must be a known corner + const badPlacement: InstanceType["$props"]["placement"] = + "center"; + // @ts-expect-error variant must be primary | secondary | soft + const badVariant: InstanceType["$props"]["variant"] = + "ghost"; + // @ts-expect-error size must be sm | md | lg + const badSize: InstanceType["$props"]["size"] = "xl"; + void badColor; + void badPlacement; + void badVariant; + void badSize; + const ok: InstanceType["$props"] = { + color: "accent", + placement: "bottom-left", + variant: "soft", + size: "sm", + }; + expect(ok.placement).toBe("bottom-left"); + }); +}); + +describe("Alert", () => { + function mountAlert( + props: Record = {}, + slots: Record = {}, + ) { + 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 = {}; + 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: ` + + + + + + + `, + }), + ); + 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(); + 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: ` +
+ + + +
+ `, + }); + // 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: ` + + + + `, + }), + ); + 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>({}); + const classValue = ref("alert-custom"); + const w = mount( + defineComponent({ + components: { Alert }, + setup: () => ({ status, extra, classValue }), + template: `内容`, + }), + { 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["$props"]["status"] = + "info"; + void badStatus; + const ok: InstanceType["$props"] = { status: "warning" }; + expect(ok.status).toBe("warning"); + }); +}); + +describe("M10–M11 demo inventory", () => { + const expected: Record = { + 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(` match[1]); + expect(previewNames).toEqual(names); + for (const name of names) { + const source = readFileSync( + `apps/docs/demos/${docName}-${name}.vue`, + "utf8", + ); + expect(source).toContain("