Files
heroui-vue/docs/migrations/M10-M11-badge-alert.md
T
2026-10-21 21:32:40 +08:00

147 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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` 的语义是否保持。
实施者只记自测与修复,验收结论留给集成人。