diff --git a/apps/docs/.vitepress/theme/Layout.vue b/apps/docs/.vitepress/theme/Layout.vue index cf6123e..619f9b9 100644 --- a/apps/docs/.vitepress/theme/Layout.vue +++ b/apps/docs/.vitepress/theme/Layout.vue @@ -49,6 +49,7 @@ const groups = [ { title: "Avatar 头像", url: "/components/avatar" }, { title: "AvatarGroup 头像组", url: "/components/avatar-group" }, { title: "Badge 徽章", url: "/components/badge" }, + { title: "Breadcrumbs 面包屑", url: "/components/breadcrumbs" }, { title: "Button 按钮", url: "/components/button" }, { title: "Card 卡片", url: "/components/card" }, { title: "Checkbox 复选框", url: "/components/checkbox" }, @@ -56,6 +57,7 @@ const groups = [ { title: "Chip 标签", url: "/components/chip" }, { title: "CloseButton 关闭按钮", url: "/components/close-button" }, { title: "Description 描述", url: "/components/description" }, + { title: "EmptyState 空状态", url: "/components/empty-state" }, { title: "FieldError 字段错误", url: "/components/field-error" }, { title: "Fieldset 字段组", url: "/components/fieldset" }, { title: "Input 输入框", url: "/components/input" }, @@ -72,6 +74,7 @@ const groups = [ { title: "Switch 开关", url: "/components/switch" }, { title: "TextArea 多行文本框", url: "/components/textarea" }, { title: "TextField 文本输入框", url: "/components/text-field" }, + { title: "Typography 排版", url: "/components/typography" }, ], }, ]; diff --git a/apps/docs/.vitepress/theme/style.css b/apps/docs/.vitepress/theme/style.css index ac074c4..be23852 100644 --- a/apps/docs/.vitepress/theme/style.css +++ b/apps/docs/.vitepress/theme/style.css @@ -194,7 +194,7 @@ button { .breadcrumb span { opacity: 0.5; } -h1 { +.docs-main > h1 { font-size: 32px; font-weight: 600; line-height: 1.25; @@ -266,7 +266,7 @@ h1 { .docs-content h3:hover .header-anchor { opacity: 1; } -.docs-content :not(pre) > code { +.docs-content :not(pre) > code:not(:where(.not-prose, .not-prose *)) { background: var(--default); border-radius: 5px; padding: 2px 5px; @@ -549,7 +549,7 @@ a:focus-visible { padding: 20px; min-height: 300px; } - h1 { + .docs-main > h1 { font-size: 28px; } .variant-card { diff --git a/apps/docs/components.md b/apps/docs/components.md index 36167f1..23c1394 100644 --- a/apps/docs/components.md +++ b/apps/docs/components.md @@ -7,11 +7,13 @@ description: 已迁移组件及文档 - [Avatar 头像](./components/avatar) - [AvatarGroup 头像组](./components/avatar-group) - [Badge 徽章](./components/badge) +- [Breadcrumbs 面包屑](./components/breadcrumbs) - [Button 按钮](./components/button) - [Card 卡片](./components/card) - [Chip 标签](./components/chip) - [CloseButton 关闭按钮](./components/close-button) - [Description 描述](./components/description) +- [EmptyState 空状态](./components/empty-state) - [FieldError 字段错误](./components/field-error) - [Input 输入框](./components/input) - [InputGroup 输入框组](./components/input-group) @@ -25,6 +27,7 @@ description: 已迁移组件及文档 - [Switch 开关](./components/switch) - [TextArea 多行文本框](./components/textarea) - [TextField 文本输入框](./components/text-field) +- [Typography 排版](./components/typography) - [Fieldset 字段组](./components/fieldset) - [SearchField 搜索框](./components/search-field) diff --git a/apps/docs/components/breadcrumbs.md b/apps/docs/components/breadcrumbs.md new file mode 100644 index 0000000..c2c7110 --- /dev/null +++ b/apps/docs/components/breadcrumbs.md @@ -0,0 +1,176 @@ +--- +title: Breadcrumbs 面包屑 +description: 导航面包屑,显示当前页面在层级结构中的位置 +component: breadcrumbs +group: 组件 +--- + +## 用法 + +```vue + + + + + 首页 + 产品 + 笔记本电脑 + + +``` + + + +## 组件结构 + +```vue + + + + + 首页 + 分类 + 当前页面 + + +``` + +`Breadcrumbs` 渲染为带可访问名称的 `ol`,`BreadcrumbsItem` 渲染为 `li`。最后一项自动成为当前页:附加 `aria-current="page"`,并作为不可导航的当前项处理。 + +## 示例 + +### 导航层级 + + + + + +### 禁用状态 + + + +`isDisabled` 禁用所有链接,并保留项目文本与分隔符。 + +### 自定义分隔符 + + + +上游通过 `separator` 属性接收自定义分隔符节点;Vue 版使用 `#separator` 具名插槽。自定义元素会获得分隔符尺寸类与 `data-slot="breadcrumbs-separator"`。 + +### 渲染函数 + + + +上游 `render` 用于替换根元素或传递额外属性;Vue 版通过 `as` 更换元素类型,普通属性与 `data-*` 直接透传到对应根元素。示例把 `data-custom` 放在 `ol` 与 `li` 上。 + +## 自定义样式 + +### Tailwind CSS + + + +`BreadcrumbsItem` 的 `class` 同时合并到 `li` 与内部链接,便于定制当前项和悬停颜色;其他属性落在 `li` 根节点。 + +### 全局 CSS + +可使用 `@layer components` 指令自定义 Breadcrumbs 组件类。 + +```css +@layer components { + .hv-breadcrumbs { + @apply gap-4 text-lg; + } + + .hv-breadcrumbs__link { + @apply font-semibold; + } + + .hv-breadcrumbs__separator { + @apply text-blue-500; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/breadcrumbs.css)): + +#### 基础类 [!toc] + +- `.hv-breadcrumbs` - 面包屑根容器 +- `.hv-breadcrumbs__item` - 单个面包屑项包装器 +- `.hv-breadcrumbs__link` - 面包屑链接元素 +- `.hv-breadcrumbs__separator` - 项之间的分隔符图标 + +#### 状态类 [!toc] + +- `.hv-breadcrumbs__link[data-current="true"]` - 当前页指示(不可导航) +- `.hv-breadcrumbs__link[aria-disabled="true"]` - 禁用链接 + +### 交互状态 + +- **Current**:最后一项的链接带有 `data-current="true"`、`aria-current="page"` 与 `aria-disabled="true"`。 +- **Hover**:链接支持标准 hover 与 `data-hovered` 状态。 +- **Disabled**:根级 `isDisabled` 或单项 `isDisabled` 以 `span[role="link"]` 呈现,带 `aria-disabled="true"`、`tabindex="-1"`,不保留 `href` 并阻止点击激活;元素类型与 React Aria Link 一致。共享 Vue Link 为禁用项保留 `tabindex="-1"` 以支持程序化聚焦,RAC 则省略 `tabindex`;两者都不能通过 Tab 聚焦。未提供 `href` 的非当前项同样渲染为 `span[role="link"]`,未禁用时 `tabindex="0"`。 + +固定基线没有自动折叠、省略号或“展开更多”状态机;本实现不额外添加。 + +## API 参考 + +### Breadcrumbs + +| 属性 | 类型 | 默认值 | 描述 | +| ------------ | --------------------------- | --------------- | ------------------------------------------------ | +| `aria-label` | `string` | `'Breadcrumbs'` | 面包屑列表的可访问名称。 | +| `isDisabled` | `boolean` | `false` | 是否禁用所有面包屑链接。 | +| `as` | `string` | `'ol'` | 自定义根元素标签;对应上游 `render` 的元素替换。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 | +| 默认插槽 | - | - | `BreadcrumbsItem` 列表。 | +| `#separator` | - | 默认右箭头图标 | 自定义各项之间的分隔符。 | + +根元素同时接收其余 `$attrs`(`data-*`、`id`、`style`、事件等);`aria-label` 为空字符串时回退为 `Breadcrumbs`。`isDisabled` 通过既有禁用作用域传给内部 `Link`,不复制禁用逻辑。 + +### BreadcrumbsItem + +| 属性 | 类型 | 默认值 | 描述 | +| ------------ | --------------------------- | --------- | -------------------------------------------------------------------------------- | +| `href` | `string` | - | 链接 URL;未提供时渲染不可导航的 `span[role="link"]`,当前项与禁用项也不可导航。 | +| `target` | `string` | `'_self'` | 链接目标;仅在带 `href` 的可导航项输出。 | +| `rel` | `string` | - | 链接关系。 | +| `download` | `boolean \| string` | - | 原生下载属性。 | +| `isDisabled` | `boolean` | `false` | 禁用当前项链接。 | +| `as` | `string` | `'li'` | 自定义项元素标签;对应上游 `render` 的元素替换。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类;同时合并到 `li` 与内部链接。 | +| 默认插槽 | `{ isCurrent, isDisabled }` | - | 项内容;可用作用域状态渲染条件内容。 | + +`li` 根节点接收除事件处理器外的 `$attrs`;`onClick`、`onKeydown`、`onFocus` 等事件绑定到真实链接,从而复用 `Link` 的禁用拦截与事件顺序。`isLast` 和 `separatorSlot` 由 `Breadcrumbs` 自动注入,不列入公开 `BreadcrumbsItemProps` 类型或 API 表,调用方无需设置。 + +### 上游差异 + +| 上游 React 能力 | Vue 实现 | +| ----------------------------- | ------------------------------------------ | +| `Breadcrumbs.Item` 对象子部件 | 独立具名导出 `BreadcrumbsItem` | +| `separator: ReactNode` | `#separator` 插槽,默认图标从基线 SVG 移植 | +| `render` 函数 | `as` 更换元素,属性直接透传 | +| `className` / `children` | `class` / 默认插槽 | +| `onAction` | 未提供;使用链接原生行为或 `@click` | + +## 无障碍 + +- 根元素是 `ol`,默认带 `aria-label="Breadcrumbs"`。固定基线的 React Aria Components `Breadcrumbs` 实际渲染 `ol` 而不是 `nav`;中文文档中的“导航地标”描述与源码 DOM 不完全一致,本实现以固定提交源码为准。需要独立导航地标时,可由应用在外层使用 ``。 +- 默认名称是英文常量,不随 locale 自动本地化;需要本地化时显式传入 `aria-label`。 +- 最后一项自动附加 `aria-current="page"`,并以 `role="link"`、`aria-disabled="true"`、`tabindex="-1"` 的 `span` 呈现,不可 Tab 聚焦或激活。 +- 带 `href` 的可导航非当前项使用原生 `a`,支持标准 Tab、Enter 与浏览器链接行为;未提供 `href` 的非当前项、禁用的非当前项与当前项均以 `span[role="link"]` 呈现。禁用/当前项带 `aria-disabled="true"`、`tabindex="-1"`,不保留 `href`,点击被拦截;未禁用的无 `href` 项保留 `tabindex="0"`。RAC 的禁用 span 省略 `tabindex`,Vue Link 保留 `-1` 供程序化聚焦,两者都不能通过 Tab 聚焦。 +- 分隔符默认标记为 `aria-hidden="true"` 与 `role="presentation"`,不进入可访问名称。 + +## 相关组件 + +[Link 链接](./link) · [Separator 分隔符](./separator) diff --git a/apps/docs/components/empty-state.md b/apps/docs/components/empty-state.md new file mode 100644 index 0000000..b0d59f0 --- /dev/null +++ b/apps/docs/components/empty-state.md @@ -0,0 +1,100 @@ +--- +title: EmptyState 空状态 +description: 在列表、搜索结果或集合为空时展示占位提示。 +component: empty-state +group: 组件 +--- + +## 用法 + +```vue + + + + + +``` + + + +> 基线说明:固定上游提交提供 `EmptyState` 源码与样式,但没有独立中文组件页或官方演示。本页与以下示例由本项目依据真实源码(默认文案 `No results found`)和现有空状态消费场景编写,不是上游官方文档内容。 + +## 组件结构 + +`EmptyState` 是单根展示组件,默认渲染 `div`,样式为基线 `.empty-state` 的 `hv-` 命名空间版本。 + +```vue + + + 没有找到匹配的搜索结果。 + + +``` + +默认插槽为空、仅包含注释或空白文本时,回退到源码默认文案 `No results found`。只要存在有效内容(文本、数字或元素),就渲染调用方内容,不额外包裹结构。 + +## 示例 + +### 默认回退 + +不提供内容时展示源码默认文案。 + + + +### 自定义文案 + + + +### 条件内容 + +插槽内容由 `v-if` 切换;内容为空时自动回退到默认文案。 + + + +### 自定义样式 + +`class` 与 `$attrs` 合并到根元素,可叠加边框、背景、间距与对齐工具类。 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +```css +@layer components { + .hv-empty-state { + @apply py-8 text-center text-base; + } +} +``` + +## 样式参考 + +EmptyState 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/empty-state.css)): + +- `.hv-empty-state` - 基础空状态文本样式(`p-2 text-sm text-muted`) + +基线没有尺寸、颜色、变体或图标插槽等额外 CSS 变体;需要更丰富的空状态布局时,由调用方组合内容与工具类。 + +## API 参考 + +### EmptyState + +| 属性 | 类型 | 默认值 | 描述 | +| -------- | --------------------------- | ------- | ------------------------------------------------ | +| `as` | `string` | `'div'` | 自定义根元素标签;对应上游 `render` 的元素替换。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 | +| 默认插槽 | - | - | 空状态内容;无有效内容时回退默认文案。 | + +`$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)透传至根元素。组件没有受控值、内部状态、事件或暴露方法。 + +## 相关组件 + +[Typography 排版](./typography) · [SearchField 搜索框](./search-field) diff --git a/apps/docs/components/typography.md b/apps/docs/components/typography.md new file mode 100644 index 0000000..5cddf69 --- /dev/null +++ b/apps/docs/components/typography.md @@ -0,0 +1,193 @@ +--- +title: Typography 排版 +description: 面向标题、正文与行内代码的语义化排版原语。 +component: typography +group: 组件 +--- + +## 用法 + +```vue + + + + Heading + +``` + + + +> 示例中的 `pnpm add @heroui/react` 沿用固定基线文案;本 Vue 项目的实际包名与安装命令以[安装指南](../guide)为准。 + +## 组件结构 + +默认情况下,`Typography` 会将视觉上的 `type` 映射到对应的语义化元素。 + +```vue + + + + Heading + +``` + +| `type` | 默认元素 | +| ---------------------------- | ----------- | +| `h1` – `h6` | `h1` – `h6` | +| `body`、`body-sm`、`body-xs` | `p` | +| `code` | `code` | + +需要保留视觉类型但更换语义元素时,使用 `as`。它对应上游的 `render` 自定义渲染能力。 + +```vue +H1 视觉样式,h2 语义元素 +``` + +## 示例 + +### 层级 + + + +### 原语 + + + +- `TypographyHeading` 将 `level`(1–6)映射为 `type="h1"` 至 `type="h6"`。 +- `TypographyParagraph` 将 `size="base" | "sm" | "xs"` 映射为正文样式。 +- `TypographyCode` 映射为行内代码样式。 +- `TypographyProse` 为以常规 HTML 子节点传入的富文本内容提供排版样式。 + +上游以 `Typography.Heading`、`Typography.Paragraph`、`Typography.Code` 和 +`Typography.Prose` 对象属性提供这些原语;Vue 版按本库约定改为独立具名导出。 + +### 富文本排版 + + + +### 渲染属性 + + + +React 的 `render` 由 Vue 的 `as` 属性替代,只更换实际渲染元素,不改变 +`type` 对应的视觉样式与 `data-type`。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +若要自定义 Typography 组件类,可使用 `@layer components` 指令。 + +```css +@layer components { + .hv-typography--h1 { + @apply font-extrabold tracking-tight; + } + + .hv-typography--code { + @apply rounded-md bg-default-100 font-mono dark:bg-default-50/20; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Typography 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/typography.css)): + +#### 基础类 [!toc] + +- `.hv-typography` - 排版基础原语 +- `.hv-typography-prose` - 富文本文章体容器 + +#### 类型类 [!toc] + +- `.hv-typography--h1` 至 `.hv-typography--h6` +- `.hv-typography--body`、`.hv-typography--body-sm`、`.hv-typography--body-xs` +- `.hv-typography--code` + +#### 修饰类 [!toc] + +- `.hv-typography--align-start`、`.hv-typography--align-center`、`.hv-typography--align-end`、`.hv-typography--align-justify` +- `.hv-typography--color-default`、`.hv-typography--color-muted` +- `.hv-typography--truncate` +- `.hv-typography--weight-normal`、`.hv-typography--weight-medium`、`.hv-typography--weight-semibold`、`.hv-typography--weight-bold` + +## API 参考 + +### Typography + +| 属性 | 类型 | 默认值 | 说明 | +| ---------- | -------------------------------------------------------------------------------------------- | -------------- | ----------------------------------------- | +| `type` | `'h1' \| 'h2' \| 'h3' \| 'h4' \| 'h5' \| 'h6' \| 'body' \| 'body-sm' \| 'body-xs' \| 'code'` | `'body'` | 语义化排版样式与默认元素。 | +| `align` | `'start' \| 'center' \| 'end' \| 'justify'` | `'start'` | 文本对齐。 | +| `color` | `'default' \| 'muted'` | `'default'` | 文本颜色。 | +| `weight` | `'normal' \| 'medium' \| 'semibold' \| 'bold'` | - | 字重覆盖。 | +| `truncate` | `boolean` | `false` | 将文本截断为单行并显示省略号。 | +| `as` | `string` | 由 `type` 决定 | 自定义实际渲染的元素;替代上游 `render`。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 | +| 默认插槽 | - | - | 文本内容。 | + +`$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)透传至实际根元素。组件不修改传入内容,也没有内部值或事件。 + +### TypographyHeading + +| 属性 | 类型 | 默认值 | 说明 | +| ---------- | ---------------------------------------------- | --------------- | ----------------------------------- | +| `level` | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | `1` | 映射到 `h1` – `h6` 与对应视觉样式。 | +| `align` | `'start' \| 'center' \| 'end' \| 'justify'` | `'start'` | 文本对齐。 | +| `color` | `'default' \| 'muted'` | `'default'` | 文本颜色。 | +| `weight` | `'normal' \| 'medium' \| 'semibold' \| 'bold'` | - | 字重覆盖。 | +| `truncate` | `boolean` | `false` | 单行截断。 | +| `as` | `string` | 由 `level` 决定 | 自定义实际渲染的元素。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类。 | +| 默认插槽 | - | - | 标题内容。 | + +### TypographyParagraph + +| 属性 | 类型 | 默认值 | 说明 | +| ---------- | ---------------------------------------------- | ----------- | ------------------------------------- | +| `size` | `'base' \| 'sm' \| 'xs'` | `'base'` | 映射到 `body`、`body-sm`、`body-xs`。 | +| `align` | `'start' \| 'center' \| 'end' \| 'justify'` | `'start'` | 文本对齐。 | +| `color` | `'default' \| 'muted'` | `'default'` | 文本颜色。 | +| `weight` | `'normal' \| 'medium' \| 'semibold' \| 'bold'` | - | 字重覆盖。 | +| `truncate` | `boolean` | `false` | 单行截断。 | +| `as` | `string` | `'p'` | 自定义实际渲染的元素。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类。 | +| 默认插槽 | - | - | 正文内容。 | + +### TypographyCode + +| 属性 | 类型 | 默认值 | 说明 | +| ---------- | ---------------------------------------------- | ----------- | ---------------------- | +| `align` | `'start' \| 'center' \| 'end' \| 'justify'` | `'start'` | 文本对齐。 | +| `color` | `'default' \| 'muted'` | `'default'` | 文本颜色。 | +| `weight` | `'normal' \| 'medium' \| 'semibold' \| 'bold'` | - | 字重覆盖。 | +| `truncate` | `boolean` | `false` | 单行截断。 | +| `as` | `string` | `'code'` | 自定义实际渲染的元素。 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类。 | +| 默认插槽 | - | - | 行内代码内容。 | + +### TypographyProse + +| 属性 | 类型 | 默认值 | 说明 | +| -------- | --------------------------- | ------ | ---------------------- | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类。 | +| 默认插槽 | - | - | 常规 HTML 富文本内容。 | + +`TypographyProse` 固定渲染 `div`,内部标题、段落、列表、引用、代码块、链接、图片等使用基线排版规则。`$attrs` 透传至该 `div`。 + +## 相关组件 + +[Card 卡片](./card) · [Kbd 键盘按键](./kbd) diff --git a/apps/docs/demos/breadcrumbs-basic.vue b/apps/docs/demos/breadcrumbs-basic.vue new file mode 100644 index 0000000..d701e29 --- /dev/null +++ b/apps/docs/demos/breadcrumbs-basic.vue @@ -0,0 +1,12 @@ + + + + + 首页 + 产品 + 电子产品 + 笔记本电脑 + + diff --git a/apps/docs/demos/breadcrumbs-custom-separator.vue b/apps/docs/demos/breadcrumbs-custom-separator.vue new file mode 100644 index 0000000..6d643d3 --- /dev/null +++ b/apps/docs/demos/breadcrumbs-custom-separator.vue @@ -0,0 +1,16 @@ + + + + + + + + 首页 + 产品 + 电子产品 + 笔记本电脑 + + diff --git a/apps/docs/demos/breadcrumbs-custom-styles.vue b/apps/docs/demos/breadcrumbs-custom-styles.vue new file mode 100644 index 0000000..2c4c374 --- /dev/null +++ b/apps/docs/demos/breadcrumbs-custom-styles.vue @@ -0,0 +1,17 @@ + + + + + + 首页 + + + 产品 + + + 笔记本电脑 + + + diff --git a/apps/docs/demos/breadcrumbs-disabled.vue b/apps/docs/demos/breadcrumbs-disabled.vue new file mode 100644 index 0000000..82b4f5a --- /dev/null +++ b/apps/docs/demos/breadcrumbs-disabled.vue @@ -0,0 +1,12 @@ + + + + + 首页 + 产品 + 电子产品 + 笔记本电脑 + + diff --git a/apps/docs/demos/breadcrumbs-level-2.vue b/apps/docs/demos/breadcrumbs-level-2.vue new file mode 100644 index 0000000..f8d79f1 --- /dev/null +++ b/apps/docs/demos/breadcrumbs-level-2.vue @@ -0,0 +1,10 @@ + + + + + 首页 + 当前页面 + + diff --git a/apps/docs/demos/breadcrumbs-level-3.vue b/apps/docs/demos/breadcrumbs-level-3.vue new file mode 100644 index 0000000..f57747e --- /dev/null +++ b/apps/docs/demos/breadcrumbs-level-3.vue @@ -0,0 +1,11 @@ + + + + + 首页 + 分类 + 当前页面 + + diff --git a/apps/docs/demos/breadcrumbs-render-function.vue b/apps/docs/demos/breadcrumbs-render-function.vue new file mode 100644 index 0000000..e7f76d2 --- /dev/null +++ b/apps/docs/demos/breadcrumbs-render-function.vue @@ -0,0 +1,12 @@ + + + + + 首页 + 产品 + 电子产品 + 笔记本电脑 + + diff --git a/apps/docs/demos/empty-state-conditional.vue b/apps/docs/demos/empty-state-conditional.vue new file mode 100644 index 0000000..66ac7bc --- /dev/null +++ b/apps/docs/demos/empty-state-conditional.vue @@ -0,0 +1,24 @@ + + + + + + + 没有找到匹配的结果。 + + + + 切换内容 + + + diff --git a/apps/docs/demos/empty-state-custom-content.vue b/apps/docs/demos/empty-state-custom-content.vue new file mode 100644 index 0000000..3e93b62 --- /dev/null +++ b/apps/docs/demos/empty-state-custom-content.vue @@ -0,0 +1,9 @@ + + + + + 没有找到匹配的搜索结果。 + + diff --git a/apps/docs/demos/empty-state-custom-styles.vue b/apps/docs/demos/empty-state-custom-styles.vue new file mode 100644 index 0000000..b708094 --- /dev/null +++ b/apps/docs/demos/empty-state-custom-styles.vue @@ -0,0 +1,11 @@ + + + + + 尚未添加任何项目。 + + diff --git a/apps/docs/demos/empty-state-default.vue b/apps/docs/demos/empty-state-default.vue new file mode 100644 index 0000000..9547c6f --- /dev/null +++ b/apps/docs/demos/empty-state-default.vue @@ -0,0 +1,9 @@ + + + + + + + diff --git a/apps/docs/demos/typography-custom-styles.vue b/apps/docs/demos/typography-custom-styles.vue new file mode 100644 index 0000000..453284a --- /dev/null +++ b/apps/docs/demos/typography-custom-styles.vue @@ -0,0 +1,22 @@ + + + + + + 更新日志 + + + 更快的搜索结果 + + + 得益于改进的索引,查询现在在 200 毫秒内返回。 + + + diff --git a/apps/docs/demos/typography-default.vue b/apps/docs/demos/typography-default.vue new file mode 100644 index 0000000..e2d183e --- /dev/null +++ b/apps/docs/demos/typography-default.vue @@ -0,0 +1,19 @@ + + + + + 打造更出色的界面 + 保持语义化的排版 + 默认可组合 + 小标题 + + HeroUI Typography 提供语义化排版类型与 as 元素多态。 + + + 用于次要说明的较小弱化正文。 + + pnpm add @heroui/react + + diff --git a/apps/docs/demos/typography-primitives.vue b/apps/docs/demos/typography-primitives.vue new file mode 100644 index 0000000..65e5c71 --- /dev/null +++ b/apps/docs/demos/typography-primitives.vue @@ -0,0 +1,21 @@ + + + + + 仪表盘 + + 便捷原语是 Typography + 的薄封装,可在不学习第二套样式系统的情况下选择显式组合。 + + + Paragraph 支持 base、sm 和 xs 尺寸。 + + TypographyCode + + diff --git a/apps/docs/demos/typography-prose.vue b/apps/docs/demos/typography-prose.vue new file mode 100644 index 0000000..10a604d --- /dev/null +++ b/apps/docs/demos/typography-prose.vue @@ -0,0 +1,16 @@ + + + + + 正文标题 + Prose 适用于标记已是语义化、由 HeroUI 应用默认排版节奏的写作型内容。 + 章节标题 + + 行内代码如 + as + 与 Typography 原语获得相同的代码样式处理。 + + + diff --git a/apps/docs/demos/typography-render-props.vue b/apps/docs/demos/typography-render-props.vue new file mode 100644 index 0000000..fec4f6a --- /dev/null +++ b/apps/docs/demos/typography-render-props.vue @@ -0,0 +1,12 @@ + + + + + H1 视觉样式,h2 语义元素 + + as 属性可更换底层元素,同时保留 HeroUI 的 props 与样式。 + + + diff --git a/apps/docs/demos/typography-typography-scale.vue b/apps/docs/demos/typography-typography-scale.vue new file mode 100644 index 0000000..2ba976f --- /dev/null +++ b/apps/docs/demos/typography-typography-scale.vue @@ -0,0 +1,84 @@ + + + + + + + + {{ row.label }} + + {{ row.meta }} + + {{ row.sample }} + + + diff --git a/docs/compatibility.md b/docs/compatibility.md index d23e5aa..b3af9c0 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -2,91 +2,91 @@ 基于固定上游提交的公共组件导出清单。验证中不等于完整兼容;目前没有组件完成视觉、浏览器与完整行为验收。 -| 组件 | 状态 | 当前能力 / 差异 | -| -------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------- | -| accordion | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| alert-dialog | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 | -| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group | -| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 | -| breadcrumbs | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 | -| button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 | -| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 | -| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 | -| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 | -| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 | -| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| date-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| drawer | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| progress-bar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| progress-circle | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| disclosure | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| disclosure-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap | -| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 | -| popover | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| scroll-shadow | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator | -| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 | -| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 | -| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface | -| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| toggle-button | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 | -| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS | -| tabs | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| toggle-button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| toolbar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| tooltip | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 | -| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 | -| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl | -| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) | -| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 | -| typography | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 | -| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 | -| empty-state | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) | -| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 | -| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 | -| header | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 | -| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 | -| input-otp | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default | -| list-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| list-box-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| list-box-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| modal | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| number-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| pagination | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| select | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| meter | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| calendar-year-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| 组件 | 状态 | 当前能力 / 差异 | +| -------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| accordion | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| alert-dialog | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 | +| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group | +| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 | +| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link | +| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 | +| button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 | +| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 | +| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 | +| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 | +| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 | +| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| date-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| drawer | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| progress-bar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| progress-circle | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| disclosure | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| disclosure-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap | +| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 | +| popover | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| scroll-shadow | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator | +| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 | +| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 | +| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface | +| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| toggle-button | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 | +| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS | +| tabs | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| toggle-button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| toolbar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| tooltip | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 | +| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 | +| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl | +| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) | +| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 | +| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as | +| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 | +| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 | +| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 | +| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) | +| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 | +| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 | +| header | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 | +| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 | +| input-otp | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default | +| list-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| list-box-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| list-box-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| modal | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| number-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| pagination | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| select | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| meter | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| table | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | +| calendar-year-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | ## 公共导出差异 @@ -171,3 +171,14 @@ Fieldset 3/3、SearchField 15/15 预览已迁移,另有 Fieldset disabled 基 10 个具名部件、四份样式与 tv、三个文档页、37/37 基线预览。使用原生 label/input 与共享 choice 状态层,接入既有 Form/Fieldset/Label/Description/FieldError,不运行 Reka 重复隐藏值层。详细差异、测试和浏览器记录见 [FORM-03 报告](./migrations/FORM-03-checkbox-radio.md)。 React render 自定义根类型不支持;原生 attrs/具名部件/作用域插槽替代框架机制;校验暂同步,不提供 validationDetails。RadioGroup 在同一表单的不同组需不同 name,遵循原生 HTML 分组规则。任意自定义 Vue 包装内部的 SSR 静态关联仍需显式 ID/ARIA。未宣称完整读屏、RTL、触屏、Nuxt、独立安装或逐像素一致。 + +## M15–M17 Typography / EmptyState / Breadcrumbs(2026-10-22) + +起始 HEAD `bcadbea`,固定上游 HeroUI 3.2.6 / `ce90ea3`。三批均实现组件、tv、CSS、导出/类型、中文文档、示例与行为测试;详细差异、命令和浏览器证据分别见 [M15](./migrations/M15-typography.md)、[M16](./migrations/M16-empty-state.md)、[M17](./migrations/M17-breadcrumbs.md)。 + +- Typography:`Typography` + `Heading` / `Paragraph` / `Code` / `Prose` 的 Vue 具名版本;6 个基线示例、6 张 API 表。`render` 元素替换改为 `as`,React 对象子部件改为独立具名导出;其余 type/align/color/weight/truncate 变体与基线样式一致。 +- EmptyState:基线只有源码与样式,没有独立中文页或示例。Vue 页与 4 个示例明确标注为自编;默认 fallback 为 `No results found`。插槽按有效节点判断,`0`、空数组和纯空白的行为与 React 的 `children ||` 真值判断不同,以免出现空白区域。 +- Breadcrumbs:7/7 基线示例、3 张 API 表。根为 `ol[aria-label]`,末项 current、禁用项与无 `href` 的非当前项按基线 RAC 渲染为 `span[role=link]`;默认分隔符从基线 SVG 移植,自定义分隔符使用 `#separator`。`onAction` 未提供;`class` 同时合并到 `li` 与内部链接,是相对 React 的明确差异。禁用/当前 span 保留 `tabindex="-1"`(RAC 省略,均不可 Tab);`isLast`/`separatorSlot` 不列入公开类型。 +- 共享 Link 只做了一个最小修正:无 `href` 时不再输出 `target`。文档隔离修复把全局 `h1` 作用域收回到 `.docs-main > h1`,并让预览内联代码不再被文档正文样式覆盖。 + +以上三页验证中,不代表整库完成;逐像素自动对比、真实键盘 Tab、读屏、RTL、触屏、Nuxt 水合、独立安装 dist 与 `test:browser/visual/package` 尚未建立。 diff --git a/docs/migrations/M15-M17-review.md b/docs/migrations/M15-M17-review.md new file mode 100644 index 0000000..c5da388 --- /dev/null +++ b/docs/migrations/M15-M17-review.md @@ -0,0 +1,71 @@ +# M15–M17 集成人复核(2026-10-22) + +范围:`bcadbea` 之后未提交的 Typography、EmptyState、Breadcrumbs。集成人未修改组件实现、未提交。未重新逐页打开浏览器,实施者的浏览器记录不算本次独立复测。 + +**当前结论:返工后复核通过。** 上次两项 P2 已关闭,修复与独立验证记录见文末;下方初次结论保留为历史。 + +## 初次复核结论(历史) + +暂不通过,存在两处 P2,均已用独立 Vitest + Vue Test Utils 行为探针复现。现有套件 284 项通过没有覆盖这两个场景。 + +### P2:Breadcrumbs 覆盖祖先禁用作用域 + +位置:`packages/vue/src/components/breadcrumbs/Breadcrumbs.vue:64–67`。 + +Root 直接 provide `computed(() => props.isDisabled)`,默认 false 会遮蔽 Fieldset 或外层禁用作用域。复现:将含有非末项 `href` 和 `@click` 的 Breadcrumbs 放进 ``,该项实际仍是 ``,没有 aria-disabled,点击处理器实际执行一次。继承不是只缺视觉标记,激活也没有拦截。 + +修复方向:先通过既有 `useInheritedDisabled(() => props.isDisabled)` 合并父级,再 provide 合并结果;遵守 Fieldset 首个直接 Legend 的例外。不要复制一份禁用状态,也不能允许内层 false 解除祖先 true。 + +必要回归:祖先 Fieldset 禁用/动态启用/再禁用、根 isDisabled、自身禁用、嵌套作用域及 Legend 例外。断言真实链接 DOM、ARIA、Tab 属性和点击/键盘激活,不能只检查 li 的 data-disabled。 + +### P2:当前项变成中间项后,链接 DOM 消失 + +位置:`packages/vue/src/components/breadcrumbs/BreadcrumbsItem.vue:145–162`,重点是动态 `asChild: nonNavigable` 与切换的默认插槽结构。 + +复现:稳定 key 的 Home(href)、Products(href) 两项,Products 初始是末项 span。动态追加 Detail 后,Products 应恢复为 ``,但实际只剩 li 内的裸文本 `Products` 和分隔符,无法聚焦或导航。等待两个 nextTick 仍如此。删除 Detail 时 Products 又恢复为当前项 span。 + +原因已定位:安装版本的 `reka-ui/src/Primitive/Primitive.ts` 在 setup 中一次性计算 `asTag = props.asChild ? 'template' : props.as` 并选定 Slot/元素渲染分支。复用同一个 Link 实例只动态切 asChild 不能换掉这个分支;此时给 Slot 的内容已经变成纯文本,原有链接壳被去掉。 + +修复方向:在 BreadcrumbsItem 的可导航/不可导航结构切换时明确重建对应 Link/Primitive(例如为实际结构模式提供稳定的不同 key),或由集成人修复共享 Link 的动态多态适配。不要改 node_modules。若改共享 Link,必须单独回归既有使用场景。 + +必要回归:两项→追加末项→删除末项→重排;disabled true→false;href 无→有→无。断言实际 a/span 元素、href、role、aria-current 唯一性、tabindex、事件与导航可用性。现有条件项测试只检查 li.data-current,因此漏检。 + +关键失败断言: + +```ts +// Fieldset disabled 内非末项 click 不应触发,但实际触发一次。 +expect(click).not.toHaveBeenCalled(); + +// Products 从当前页变为中间项后应有真实链接,实际找不到 a。 +expect( + wrapper.get("[data-slot=breadcrumbs-item]:nth-child(2) a").attributes("href"), +).toBe("#products"); +``` + +## 已完成的独立检查 + +- `pnpm test`:17 文件 / 284 项通过,含 node SSR 6 项。 +- `pnpm typecheck` 通过。 +- `pnpm build:docs` 通过,仅既有 chunk >500kB 提醒。 +- Typography、EmptyState、Breadcrumbs 三份 CSS 去掉注释/空白并还原 hv- 命名空间后,与固定 ce90ea3 基线一致。 +- `pnpm format`、`git diff --check` 通过;探针验证后已删除,不计入正式测试数量。期间格式检查曾只因临时探针未格式化失败,删除后重新检查。 +- 阅读了三个交接报告、组件实现、API 页面、演示、共享 Link 修改及文档隔离规则。本次未声称完成浏览器、逐像素、Nuxt、读屏或独立安装验收。 + +## 交回修正范围 + +先修上面两项并补行为测试,然后更新 M17/verification 的最终计数。Typography、EmptyState 暂未发现同级别实现阻断;未完成检查不能推断为完整验收。默认分隔符是基线图标,文档自定义图标继续使用 Tabler。保留其他 AI 未提交改动,不自行提交/推送。 + +## 返工后独立复核(2026-10-22) + +上次两项 P2 均已关闭,本轮未发现新的阻断问题;当前仍未提交/推送。 + +- Root 通过 `useInheritedDisabled` 合并父级禁用后 provide;Item 向 Link 传递合并状态。独立探针确认 Fieldset 首个直接 Legend 内的链接可激活,而嵌套 disabled=false 的普通区域链接仍禁用,Enter/click 均被拦截。 +- Item 对可导航/不可导航模式提供稳定的不同 key,使 Reka Primitive 在结构切换时重建。独立使用稳定 key 做实际三次重排,确认所有非末项均有正确的 a/href,末项为 span,aria-current 始终唯一;事件处理器数组、取消与点击在重建后仍保留。实施者新增的条件项、href 双向变化和祖先动态禁用等六项测试通过。 +- 共享 Link 相对基线仅保留本批“无 href 不输出 target”的小改动,未重写其 asChild/事件实现;原有 Link 测试全量回归通过。 +- `pnpm test`:17 文件 / 290 项,含 node SSR 6 项;`pnpm test:unit`:16 文件 / 284 项,不含 node SSR。 +- `pnpm typecheck`、`pnpm build:docs`、`pnpm format`、`git diff --check` 通过。文档构建仅既有大 chunk 提醒。 +- 从三页 Markdown 原文提取 5 份含 script/setup 与 template 的完整 SFC,经 vue-tsc 检查并实际挂载;17 份新增演示全部实际挂载,无 console warn/error。其余仅模板片段不冒充独立完整 SFC。 +- dist 公开 Props 正反例通过 vue-tsc:合法 Typography/Heading/Paragraph/Breadcrumbs/Item/EmptyState 可用;非法 type、level、size、disabled、href 与公开 Props 别名中的内部 separatorSlot 均被拒绝。 +- 本轮临时独立探针 3 项通过(两项边界行为 + 一项 17 演示/5 原文 SFC 挂载),类型探针与提取文件验证后全部删除,不计入正式 290 项。 + +未新增浏览器、逐像素、完整读屏/RTL/触屏、Nuxt 或独立安装验收;这些边界保持原有记录。上方初次失败结果和交回要求仅保留为历史,不代表当前仍有待修 P2。 diff --git a/docs/migrations/M15-typography.md b/docs/migrations/M15-typography.md new file mode 100644 index 0000000..00d9097 --- /dev/null +++ b/docs/migrations/M15-typography.md @@ -0,0 +1,105 @@ +# M15 Typography 交接报告 + +实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。** + +## 1. 起点与范围 + +| 项 | 值 | +| ---------- | ------------------------------------------------------------------------------------------ | +| 起始 HEAD | `bcadbea`(feat: add Checkbox and Radio field families) | +| 工作区起点 | 干净;无未提交修改 | +| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) | +| 范围 | Typography、TypographyHeading、TypographyParagraph、TypographyCode、TypographyProse 及文档 | + +本轮实现 M15,按顺序继续 M16 EmptyState、M17 Breadcrumbs;三批共享入口只做必要增量。 + +## 2. 上游核对 + +- 实际导出:`Typography` 是带 `Root`、`Heading`、`Paragraph`、`Code`、`Prose` 的对象;同时命名导出 `TypographyRoot`、`Heading`、`Paragraph`、`Code`、`Prose`。 +- 实现:`TypographyRoot` 基于 React Aria Components `Text`,`type` 默认 `body`,映射到 `p`;`h1`–`h6` 映射到同名标题,`code` 映射到 `code`。默认 `align="start"`、`color="default"`,`truncate` 与 `weight` 未指定。 +- 子部件:`Heading` 的 `level` 默认 `1`;`Paragraph` 的 `size` 默认 `base`,映射 `body` / `body-sm` / `body-xs`;`Code` 固定 `type="code"`;`Prose` 固定 `div`。 +- tv:`typographyVariants` 提供 `type`(10 项)、`align`(start/center/end/justify)、`color`(default/muted)、`truncate`、`weight`(normal/medium/semibold/bold),另有 `prose` slot。 +- CSS:`packages/styles/components/typography.css` 的标题、正文、代码、prose 后代元素和修饰类全部按基线数值移植。 +- 文档/示例:固定基线有 1 个中文 Typography 页和 6 个示例:`default`、`typography-scale`、`primitives`、`prose`、`render-props`、`custom-styles`。 + +## 3. Vue 实现与 API 对照 + +Vue 使用独立命名组件,替代 React 的对象子部件: + +| 上游 | Vue | +| ------------------------ | ------------------------------------------------------------ | +| `Typography` / `.Root` | `Typography` | +| `Typography.Heading` | `TypographyHeading` | +| `Typography.Paragraph` | `TypographyParagraph` | +| `Typography.Code` | `TypographyCode` | +| `Typography.Prose` | `TypographyProse` | +| `render` 元素替换 | `as` 字符串 | +| `className` / `children` | `class` / 默认插槽 | +| React 属性与事件 | Vue `$attrs`、原生属性和事件;`inheritAttrs: false` 显式透传 | + +公共属性保持基线名称与默认值:`type='body'`、`align='start'`、`color='default'`、`truncate=false`,`weight` 未指定;Heading `level=1`,Paragraph `size='base'`。`TypographyProse` 固定 `div`,不提供 `as`,与上游一致。 + +DOM/类名:根元素 `data-slot="typography"`、`data-type`;tv 类为 `hv-typography--{type}`、`--align-*`、`--color-*`、`--weight-*`、`--truncate`。`TypographyProse` 根类为 `hv-typography-prose`,`data-slot="prose"`。 + +## 4. 变更文件 + +新增: + +- `packages/styles/components/typography.css` +- `packages/vue/src/components/typography/Typography.vue` +- `packages/vue/src/components/typography/TypographyHeading.vue` +- `packages/vue/src/components/typography/TypographyParagraph.vue` +- `packages/vue/src/components/typography/TypographyCode.vue` +- `packages/vue/src/components/typography/TypographyProse.vue` +- `apps/docs/components/typography.md` +- `apps/docs/demos/typography-default.vue` +- `apps/docs/demos/typography-typography-scale.vue` +- `apps/docs/demos/typography-primitives.vue` +- `apps/docs/demos/typography-prose.vue` +- `apps/docs/demos/typography-render-props.vue` +- `apps/docs/demos/typography-custom-styles.vue` + +共享增量: + +- `packages/styles/src/index.ts`:`typographyVariants` / `TypographyVariants` +- `packages/styles/index.css`:Typography CSS 入口 +- `packages/vue/src/index.ts`、`packages/vue/src/types.ts`:组件与 Props 导出 +- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`:导航与总览 +- `tests/typography-empty-breadcrumbs.test.ts`:三批共用的行为测试文件(本批含 Typography 用例) +- `tests/ssr.test.ts`:三批共用的组合 SSR 用例 + +## 5. 验证结果 + +| 入口 | 文件数 | 通过数 | 含 SSR | +| ----------------- | ------ | ------ | ------------------- | +| `pnpm test` | 17 | 284 | 是(ssr.test.ts 6) | +| `pnpm test:unit` | 16 | 278 | 否 | +| `pnpm test:ssr` | 1 | 6 | 是 | +| `pnpm typecheck` | — | 通过 | — | +| `pnpm build:docs` | — | 通过 | — | +| `pnpm format` | — | 通过 | — | + +`build:docs` 仅有 VitePress chunk >500 kB 提示。新增测试文件 `tests/typography-empty-breadcrumbs.test.ts` 共 24 项,已加入 `test:unit`;其中覆盖 Typography 的默认元素映射、五个具名部件、全部变体、`as`、动态 attrs/class 和 SSR 组合。 + +浏览器(127.0.0.1:5173,桌面 800×655 与 390×900 同源 iframe,浅色/深色): + +- Typography 页 6 个预览、6 张表(类型映射 + 5 个 API 表);桌面表宽 724px,窄屏 350px,`table-layout:fixed`、`scrollWidth == clientWidth`,无水平溢出。 +- 浅色计算样式:h1 36/40、h2 30/36、body 16/28、body-sm 14/24、body-xs 12/20、code 14/20;深色颜色切换到主题深色变量。 +- 窄屏组件 h1 保持 36px;此前文档全局 `h1` 媒体规则会把预览 h1 压到 28px,已把规则收回 `.docs-main > h1`。 +- 预览内 `code` 保持 14px,不被文档正文的 12px 内联代码样式覆盖。 + +## 6. 差异与限制 + +- React 对象子部件访问方式改为独立具名导出;名称加 `Typography` 前缀以避免公共命名冲突,这是 Vue 适配差异。 +- `render` 函数可由任意 React 元素/组件返回;Vue 仅支持 `as` 字符串标签。需要组件级多态时应由调用方使用插槽或包装组件。 +- `TypographyProse` 固定 `div`,与上游一致;没有额外的 `as`。 +- 未做自动逐像素对比;截图接口返回 “Screenshot needs a visible tab”,本条只有 DOM/计算样式证据。 +- 未验证读屏、RTL、触屏、Nuxt 水合和独立安装 dist。 +- 未提交、未推送,不能据本报告宣称集成验收通过。 + +## 7. 最短复核步骤 + +1. `git diff -- packages/styles/components/typography.css packages/styles/src/index.ts packages/vue/src/components/typography apps/docs/components/typography.md apps/docs/demos/typography-*.vue` +2. 运行 `npx --yes pnpm@11.25.0 typecheck && npx --yes pnpm@11.25.0 test:unit && npx --yes pnpm@11.25.0 test:ssr && npx --yes pnpm@11.25.0 format`。 +3. 打开 `http://127.0.0.1:5173/components/typography`,核对 6 个示例、6 张表、浅/深色和 390px 宽度;重点检查 h1 36px 与预览 code 14px。 +4. 复核 `render-props` 示例已明确改写为 `as`,并确认文档没有把 React 对象访问方式写成 Vue API。 diff --git a/docs/migrations/M16-empty-state.md b/docs/migrations/M16-empty-state.md new file mode 100644 index 0000000..277f480 --- /dev/null +++ b/docs/migrations/M16-empty-state.md @@ -0,0 +1,99 @@ +# M16 EmptyState 交接报告 + +实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。** + +## 1. 起点与范围 + +| 项 | 值 | +| ---------- | ----------------------------------------------------------------------------- | +| 起始 HEAD | `bcadbea`(feat: add Checkbox and Radio field families) | +| 工作区起点 | 干净;无未提交修改 | +| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) | +| 范围 | EmptyState 单根组件、样式/tv、导出/类型、自编文档与 4 个示例、测试 | + +EmptyState 在固定基线只有源码和样式,没有独立中文组件页,也没有独立示例目录;本报告不把 4 个示例写成上游官方内容。 + +## 2. 上游核对 + +- `packages/react/src/components/empty-state/empty-state.tsx`:`EmptyStateRoot` 是单根 `div`,`data-slot="empty-state"`,class 来自 `emptyStateVariants({className})`;children 为 `children || "No results found"`。 +- `index.ts`:对象式 `EmptyState` 带 `Root` 别名,同时命名导出 `EmptyStateRoot`;没有子部件。 +- CSS:`packages/styles/components/empty-state.css` 只有 `.empty-state { @apply p-2 text-sm text-muted; }`。 +- tv:`emptyStateVariants` 只有 base 类,没有 size/color/variant 组合。 +- 文档/示例:固定基线没有 EmptyState 中文页,也没有 `apps/docs/src/demos/cn/empty-state`。因此本页的基线说明、4 个示例和 API 表均由本项目按源码与常见空状态消费场景编写,并已明确标注。 + +## 3. Vue 实现与 API 对照 + +| 上游 | Vue | +| ---------------------------------- | ------------------------- | +| `EmptyState` / `.Root` | 单个 `EmptyState` 组件 | +| `children` | 默认插槽 | +| `className` | `class` | +| DOM render 自定义根元素 | `as` 字符串(默认 `div`) | +| 其他 DOM 属性 | `$attrs` 透传 | +| `children \|\| "No results found"` | 按有效插槽节点判断后回退 | + +对外属性: + +| 属性 | 类型 | 默认值 | 行为 | +| -------- | --------------------------- | ------- | ------------------------------------------------- | +| `as` | `string` | `'div'` | 自定义根标签 | +| `class` | `string \| Array \| Object` | - | 与 `hv-empty-state` 合并 | +| 默认插槽 | - | - | 空状态内容;无可渲染内容时输出 `No results found` | + +默认 fallback 文案与基线完全一致,仍为英文 `No results found`。组件没有受控值、内部状态、事件或暴露方法。 + +## 4. 变更文件 + +新增: + +- `packages/styles/components/empty-state.css` +- `packages/vue/src/components/empty-state/EmptyState.vue` +- `apps/docs/components/empty-state.md` +- `apps/docs/demos/empty-state-default.vue` +- `apps/docs/demos/empty-state-custom-content.vue` +- `apps/docs/demos/empty-state-conditional.vue` +- `apps/docs/demos/empty-state-custom-styles.vue` + +共享增量: + +- `packages/styles/src/index.ts`:`emptyStateVariants` / `EmptyStateVariants` +- `packages/styles/index.css`:EmptyState CSS 入口 +- `packages/vue/src/index.ts`、`packages/vue/src/types.ts`:组件与 Props 导出 +- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`:导航与总览 +- `tests/typography-empty-breadcrumbs.test.ts`:三批共用的行为测试文件(本批含 EmptyState 用例) +- `tests/ssr.test.ts`:三批共用的组合 SSR 用例 + +## 5. 验证结果 + +| 入口 | 文件数 | 通过数 | 含 SSR | +| ----------------- | ------ | ------ | ------------------- | +| `pnpm test` | 17 | 284 | 是(ssr.test.ts 6) | +| `pnpm test:unit` | 16 | 278 | 否 | +| `pnpm test:ssr` | 1 | 6 | 是 | +| `pnpm typecheck` | — | 通过 | — | +| `pnpm build:docs` | — | 通过 | — | +| `pnpm format` | — | 通过 | — | + +浏览器(127.0.0.1:5173,桌面 800×655 与 390×900 同源 iframe,浅色/深色): + +- 4 个自编示例,页面内共 6 个预览实例(自定义样式在“示例”和“自定义样式”区重复展示);1 张 API 表,桌面 724px、窄屏 350px,无水平溢出。 +- 默认回退渲染为 `div.hv-empty-state`,文本 `No results found`,计算样式 14/20、8px padding、muted 色。 +- 条件示例实际点击“切换内容”:`没有找到匹配的结果。` → `No results found` → 恢复前者,动态回退生效。 +- 自定义内容、`section` 根元素、`class` 与 `aria-*` / `data-*` 动态增删均由单元测试覆盖;根元素和合并 class 也在浏览器检查。 + +## 6. 差异与限制 + +- 上游 `children ||` 使用 React 真值判断:`0` 会回退,空数组(真值)可能渲染空白。Vue 插槽每次渲染都返回数组,本实现改用有效节点判断:空白文本、注释、空 Fragment 回退;`0` 作为内容渲染,空数组回退。该差异已写入兼容矩阵,属于 Vue 插槽适配,不伪装成逐字一致。 +- 上游对象式 `EmptyState.Root` 和命名 `EmptyStateRoot` 在本项目统一为单个 `EmptyState` 具名导出;这与项目既有 Card 等组件的命名策略一致。 +- `as` 只接受字符串标签;不能像 React `render` 一样返回任意 Vue 组件。 +- 上游没有 EmptyState 官方页面,本页 4 个示例是自编内容;文档已显著标注,不应计作基示例迁移数量。 +- 未做自动逐像素对比;截图接口返回 “Screenshot needs a visible tab”,本条只有 DOM/计算样式证据。 +- 未验证读屏、RTL、触屏、Nuxt 水合和独立安装 dist。 +- 未提交、未推送,不能据本报告宣称集成验收通过。 + +## 7. 最短复核步骤 + +1. `git diff -- packages/styles/components/empty-state.css packages/styles/src/index.ts packages/vue/src/components/empty-state/EmptyState.vue apps/docs/components/empty-state.md apps/docs/demos/empty-state-*.vue` +2. 运行 `npx --yes pnpm@11.25.0 typecheck && npx --yes pnpm@11.25.0 test:unit && npx --yes pnpm@11.25.0 test:ssr && npx --yes pnpm@11.25.0 format`。 +3. 打开 `http://127.0.0.1:5173/components/empty-state`,核对 4 个示例、1 张表、默认英文回退文案,并点击“切换内容”验证双向回退。 +4. 确认文档明确写明“基线无独立页面/示例,本页示例为自编”。 diff --git a/docs/migrations/M17-breadcrumbs.md b/docs/migrations/M17-breadcrumbs.md new file mode 100644 index 0000000..fa05c07 --- /dev/null +++ b/docs/migrations/M17-breadcrumbs.md @@ -0,0 +1,155 @@ +# M17 Breadcrumbs 交接报告 + +实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。** + +## 1. 起点与范围 + +| 项 | 值 | +| ---------- | -------------------------------------------------------------------------------------- | +| 起始 HEAD | `bcadbea`(feat: add Checkbox and Radio field families) | +| 工作区起点 | 干净;无未提交修改 | +| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) | +| 范围 | Breadcrumbs、BreadcrumbsItem、默认 separator、样式/tv、导出/类型、7 个示例、文档与测试 | + +未修改 field/TextField/Form/Fieldset/SearchField/Switch 核心协议;只对共享 Link 做了一处无 `href` 时不输出 `target` 的最小修正。 + +## 2. 上游核对 + +- 实际导出:对象式 `Breadcrumbs` 带 `Root` / `Item`,同时命名导出 `BreadcrumbsRoot`、`BreadcrumbsItem`;Vue 使用 `Breadcrumbs` / `BreadcrumbsItem` 两个具名导出。 +- RAC 根元素是 `ol`,由 `useBreadcrumbs` 提供默认 `aria-label`(英文 `Breadcrumbs`,可本地化);中文文档写“导航地标”,但源码实际不是 `nav`。本实现以固定提交源码为准。 +- RAC `Breadcrumb` 通过 `node.nextKey == null` 判定末项:末项设置 `aria-current="page"`、`isDisabled`,并在 `li` 上设置 `data-current` / `data-disabled`;没有自动折叠、省略号或“展开更多”状态。 +- RAC Link 在禁用或无 `href` 时渲染 `span`(`role="link"`);禁用链接不保留 `href`,带 `aria-disabled` 与不可 Tab 的 `tabindex`。 +- tv:`breadcrumbsVariants` 提供 `base`、`item`、`link`、`separator` 四个 slot,没有尺寸/颜色变体。 +- CSS:`packages/styles/components/breadcrumbs.css` 的 flex 布局、间距、链接颜色/下划线、当前项颜色、分隔符尺寸与 RTL 旋转全部按基线移植。 +- 文档/示例:1 个中文页,7 个示例:`basic`、`level-2`、`level-3`、`disabled`、`custom-separator`、`render-function`、`custom-styles`。 + +## 3. Vue 实现与 API 对照 + +| 上游 | Vue | +| --------------------------------- | --------------------------------------------------------------------- | +| `Breadcrumbs` / `.Root` | `Breadcrumbs` | +| `Breadcrumbs.Item` | `BreadcrumbsItem` | +| `separator: ReactNode` | `#separator` 具名插槽 | +| `render` 自定义根元素 | `as` 字符串(默认 `ol` / `li`) | +| `className` | `class` | +| `children` | 默认插槽 | +| React Aria 的 collection/onAction | 不提供 `onAction`;使用原生链接事件 | +| 末项/分隔符上下文 | Root 自动注入内部 `isLast` / `separatorSlot`,不列入公开类型与 API 表 | + +公共属性: + +| Breadcrumbs | 类型 | 默认值 | +| ------------ | --------------------------- | --------------- | +| `aria-label` | `string` | `'Breadcrumbs'` | +| `isDisabled` | `boolean` | `false` | +| `as` | `string` | `'ol'` | +| `class` | `string \| Array \| Object` | - | +| 默认插槽 | - | - | +| `#separator` | - | 默认右箭头图标 | + +| BreadcrumbsItem | 类型 | 默认值 | +| --------------- | --------------------------- | --------- | +| `href` | `string` | - | +| `target` | `string` | `'_self'` | +| `rel` | `string` | - | +| `download` | `boolean \| string` | - | +| `isDisabled` | `boolean` | `false` | +| `as` | `string` | `'li'` | +| `class` | `string \| Array \| Object` | - | +| 默认插槽 | `{ isCurrent, isDisabled }` | - | + +行为落点: + +- 根渲染 `ol[data-slot="breadcrumbs"]`,默认 `aria-label="Breadcrumbs"`;其余 `$attrs` 落到根。 +- 每个 `BreadcrumbsItem` 渲染 `li[data-slot="breadcrumbs-item"]`,最后一项带 `data-current="true"` / `data-disabled="true"`。 +- 当前项、禁用项以及未提供 `href` 的非当前项通过共享 Link 的 `asChild` 渲染为 `span[role="link"]`;当前/禁用项无 `href`/`target`,带 `aria-disabled`、`tabindex="-1"`(RAC 省略该属性,均不可 Tab),当前项额外带 `aria-current="page"`。未禁用的无 `href` 项保留 `tabindex="0"`,与 RAC Link 一致。 +- 带 `href` 的可导航项渲染原生 `a`,禁用/当前项由 Link 拦截点击;分隔符只出现在非末项,默认 SVG 带 `aria-hidden`、`role="presentation"`、`data-slot="breadcrumbs-separator"`。 +- 调用方 `class` 同时合并到 `li` 和内部链接;非事件属性落 `li`,`on*` 事件落真实链接。这是相对 React 的明确差异,便于自定义当前项和悬停颜色。 + +## 4. 变更文件 + +新增: + +- `packages/styles/components/breadcrumbs.css` +- `packages/vue/src/components/breadcrumbs/Breadcrumbs.vue` +- `packages/vue/src/components/breadcrumbs/BreadcrumbsItem.vue` +- `packages/vue/src/components/breadcrumbs/BreadcrumbsSeparatorIcon.vue` +- `apps/docs/components/breadcrumbs.md` +- `apps/docs/demos/breadcrumbs-basic.vue` +- `apps/docs/demos/breadcrumbs-level-2.vue` +- `apps/docs/demos/breadcrumbs-level-3.vue` +- `apps/docs/demos/breadcrumbs-disabled.vue` +- `apps/docs/demos/breadcrumbs-custom-separator.vue` +- `apps/docs/demos/breadcrumbs-render-function.vue` +- `apps/docs/demos/breadcrumbs-custom-styles.vue` + +共享增量: + +- `packages/styles/src/index.ts`:`breadcrumbsVariants` / `BreadcrumbsVariants` +- `packages/styles/index.css`:Breadcrumbs CSS 入口;按基线顺序放在 `link.css` **之前**,让 Link 禁用透明度对非当前项生效 +- `packages/vue/src/index.ts`、`packages/vue/src/types.ts`:组件与 Props 导出 +- `packages/vue/src/components/link/Link.vue`:无 `href` 时不再输出 `target` +- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`:导航与总览 +- `apps/docs/.vitepress/theme/style.css`:文档标题/内联代码隔离修复 +- `tests/typography-empty-breadcrumbs.test.ts`:三批共用的行为测试文件(本批含 Breadcrumbs 用例) +- `tests/ssr.test.ts`:三批共用的组合 SSR 用例 + +## 5. 验证结果 + +| 入口 | 文件数 | 通过数 | 含 SSR | +| ----------------- | ------ | ------ | ------------------- | +| `pnpm test` | 17 | 284 | 是(ssr.test.ts 6) | +| `pnpm test:unit` | 16 | 278 | 否 | +| `pnpm test:ssr` | 1 | 6 | 是 | +| `pnpm typecheck` | — | 通过 | — | +| `pnpm build:docs` | — | 通过 | — | +| `pnpm format` | — | 通过 | — | + +浏览器(127.0.0.1:5173,桌面 800×655 与 390×900 同源 iframe,浅色/深色): + +- 7 个预览、3 张 API 表;桌面表宽 724px、窄屏 350px,无水平溢出;窄屏列表最大宽度 248px,无溢出。 +- 基本示例根为 `OL`,`aria-label="Breadcrumbs"`;末项为 `SPAN[role=link]`,`aria-current="page"`、`aria-disabled="true"`、`tabindex="-1"`、无 `href`/`target`,opacity 1。 +- 禁用示例:0 个 `a`,4 个 `span[role=link]`;前三项 opacity 0.5,当前项 opacity 1;所有禁用项 `tabindex="-1"`、`aria-disabled="true"`。 +- 默认分隔符 12×12,`data-slot` 与尺寸类正确;自定义分隔符示例克隆调用方节点并合并 `hv-breadcrumbs__separator`。 +- 自定义样式和 `render-function` 示例的 `data-custom` / class 均落到对应根节点;无 `href` 的 `render-function` 项为 `span[role="link"][tabindex="0"]`,不是无 `href` 的 `a`。7 个预览全部渲染。 +- 回归 `/components/button`:35 个按钮,文档标题桌面 32px、窄屏 28px,正文内联代码 12px,表格 724/350px 无溢出。 + +修复记录: + +- 初次接入把 `breadcrumbs.css` 放在 `link.css` 之后,禁用的非当前项被 `.hv-breadcrumbs__link` 的 `opacity:1` 覆盖。已按固定基线顺序前移;浏览器复测恢复 0.5。 +- 当前项与禁用项原先仍有 `target="_self"`;共享 Link 改为仅在存在 `href` 时输出 `target`,当前/禁用 span 不再有无效属性。 +- 文档隔离:全局 `h1` 与窄屏媒体规则收回到 `.docs-main > h1`;预览内联代码排除 `.not-prose`,避免 14px Typography code 被文档 12px 覆盖。 + +## 6. 差异与限制 + +- React 对象子部件改为具名导出;末项/分隔符由 Root 自动注入,`isLast`、`separatorSlot` 不列入公开 `BreadcrumbsItemProps` 或 API 表。 +- `separator` 属性改为 `#separator` 插槽;`render` 改为 `as` 字符串,不能返回任意 Vue 组件。 +- 不提供 RAC 的 `onAction`;使用原生链接、`@click` 或路由适配。 +- 可导航链接使用共享 Link 的默认 `target="_self"`,上游未显式输出该属性;导航行为相同,但 DOM 属性存在差异。 +- RAC 的禁用/当前 `span` 不输出 `tabindex`;共享 Vue Link 输出 `tabindex="-1"` 以保留程序化聚焦能力。两者都不能通过 Tab 聚焦,这是 Link 既有禁用策略的差异。 +- 默认 `aria-label` 是英文常量,未接入 RAC 的 locale 本地化;调用方需显式传入 `aria-label`。 +- `class` 同时作用于 `li` 和内部链接;上游只作用于 `li`。这是为了让基线自定义样式示例中的文字颜色、hover 颜色真正落到链接上,已文档化。 +- 没有自动折叠/省略号;固定基线也没有该状态机。 +- 未做自动逐像素对比;截图接口返回 “Screenshot needs a visible tab”,本条只有 DOM/计算样式证据。 +- 隐藏浏览器窗口下发送 Tab 键未移动焦点,未取得真实键盘 Tab 轨迹;改用 `tabindex`/ARIA 与单元测试验证,读屏未验证。 +- 未验证 RTL、触屏、Nuxt 水合和独立安装 dist。 +- 未提交、未推送,不能据本报告宣称集成验收通过。 + +## 7. 最短复核步骤 + +1. `git diff -- packages/styles/index.css packages/styles/components/breadcrumbs.css packages/styles/src/index.ts packages/vue/src/components/breadcrumbs packages/vue/src/components/link/Link.vue apps/docs/components/breadcrumbs.md apps/docs/demos/breadcrumbs-*.vue` +2. 运行 `npx --yes pnpm@11.25.0 typecheck && npx --yes pnpm@11.25.0 test:unit && npx --yes pnpm@11.25.0 test:ssr && npx --yes pnpm@11.25.0 format`。 +3. 打开 `http://127.0.0.1:5173/components/breadcrumbs`,核对 7 个示例、3 张表;重点检查末项/禁用项是否为 `span[role=link]` 且无 `href`,禁用项 opacity 0.5、当前项 1。 +4. 在 390px 宽度检查表格 350px、无水平溢出;浅/深主题各看一次。 +5. 确认文档已说明 `ol` 而非 `nav`、默认名称未本地化、`onAction` 未提供以及 `class` 双落点差异。 + +## 8. 独立复核返工(实施者,2026-10-22) + +M15-M17 复核两项 P2 已修: + +1. **禁用继承**:Root 原先 `provide(computed(() => props.isDisabled))` 会遮蔽 Fieldset/祖先禁用作用域。改为 `useInheritedDisabled(() => props.isDisabled)` 合并后再 provide;`isDisabled` 传给 Link 时使用合并后的 `disabled.value`,内层 `isDisabled=false` 不能解除祖先 true。 +2. **动态 asChild 切换**:Reka Primitive 在 setup 一次性选定 Slot/元素分支。`BreadcrumbsItem` 为可导航/不可导航两种结构使用稳定且不同的 `key`,切换时重建 Link,中间项恢复真实 ``。 + +回归(+6):Fieldset 禁用下真实链接/ARIA/tabindex/点击与 Enter 不激活;祖先动态启用→再禁用;`isDisabled=false` 不逃逸;末项→中间项→再末项时 `a`/`span` 切换;href 无→有→无;重排后 `aria-current` 唯一且中间项可导航。 + +`pnpm test` 17 文件 / **290**(含 SSR 6);`pnpm test:unit` 16 文件 / **284**;typecheck、format 通过。未改 node_modules 与共享 Link 的 asChild 实现。 diff --git a/docs/upstream.md b/docs/upstream.md index 856dcbe..61934a8 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -67,3 +67,14 @@ CSS 仅 hv- 命名空间及 reduced-motion 的等价原生 media 适配(避免 Tailwind 嵌套伪元素生成无效 :not(:is()));规范化后其余样式与基线相同。原生输入与组约束代理的隐藏样式在 index.css 明确维护。Vue 行为实现见 selection-field-foundation.md,不移植 RAC runtime。 37 个文档引用预览全部迁移。自定义图标使用 Tabler(Heart/Plus/Minus/X/Mail/Message/Bell/Check 与三种支付品牌图标),没有复制 React 图标依赖或在示例内自绘 SVG。表单 alert 改为 role=status 的真实 FormData 反馈;水平 Radio 示例补外部 Label 的显式 aria-labelledby;固定宽度卡片在窄屏解除最小宽度,保留桌面基线布局。Demo 仅补 align/isBgSolid 可选配置,对应上游配送支付预览配置。 + +## M15–M17 来源(2026-10-22) + +固定 ce90ea3 / HeroUI 3.2.6: + +- `packages/react/src/components/{typography,breadcrumbs,empty-state}`:组件结构、默认元素、末项 current、禁用与 separator 行为。 +- `packages/styles/components/{typography,breadcrumbs,empty-state}.css`:移植为 hv- 命名空间;保留 Apache-2.0 来源头与 third-party/HEROUI-LICENSE。加载顺序按基线把 breadcrumbs 放在 link 之前,使禁用链接透明度生效。 +- `packages/styles/src/components/{typography,breadcrumbs,empty-state}/*.styles.ts`:tv 变体与 slot 类名,合并到本项目的 `packages/styles/src/index.ts`。 +- CN `(typography)/typography.mdx` 与 6 个示例;CN `(navigation)/breadcrumbs.mdx` 与 7 个示例。EmptyState 在固定基线没有独立中文页和示例,Vue 页与 4 个示例明确标注为自编。 +- 默认 Breadcrumbs 分隔符来自基线 `icons.tsx` 的 ChevronRight SVG;自定义分隔符示例把上游手写 SVG 替换为 Tabler `IconCaretRightFilled`,遵守演示图标约定。 +- Typography 的 `render`、Breadcrumbs 的 `render` 与 `onAction`、React 对象子部件访问方式改为 Vue `as`、具名导出、插槽与原生链接事件;差异见各迁移报告。 diff --git a/docs/verification.md b/docs/verification.md index 14be91f..8b64344 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -280,3 +280,57 @@ CheckboxGroup 底座行为临时探针单独验证了禁用值仍提交与 reset 详细架构、差异与证据见 [Checkbox/Radio 报告](./migrations/FORM-03-checkbox-radio.md)。最终 `pnpm test` 16 文件 / 259 项(含 node SSR 5);`pnpm test:unit` 15 文件 / 254 项(不含 node SSR,包含 jsdom 水合);typecheck/build:docs/format/diff-check 通过。37 个预览均可挂载,且顺序与基线清单相同;CSS 规范化比对通过(hv- 与等价 reduced-motion media 差异已记录)。临时 dist Props 正反类型探针通过并移除。 浏览器在 5173 实测 Checkbox Space/默认值/半选、CheckboxGroup required 聚焦/同名多值提交/全选、RadioGroup 方向键与 roving Tab/校验聚焦/实际提交、配送卡片选中边框。三个页面桌面表格 736px、390 窄屏表格 350px,均无横向溢出;浅深主题、定制卡片、代码实际多色高亮已检查。warn/error 为空,恢复浅色与默认视口;截图 `/private/tmp/heroui-vue-form03-radio.png`。没有新增独立安装、自动视觉、完整读屏/触屏/RTL 或 Nuxt 验收。 + +## M15–M17 Typography / EmptyState / Breadcrumbs(2026-10-22) + +起始 HEAD `bcadbea`(feat: add Checkbox and Radio field families),工作区起点干净。上游只读 `../heroui` @ `ce90ea3`。详细范围与差异见 [M15](./migrations/M15-typography.md)、[M16](./migrations/M16-empty-state.md)、[M17](./migrations/M17-breadcrumbs.md)。 + +### 命令(分别记录) + +| 入口 | 文件数 | 通过数 | 含 SSR | +| ----------------- | ------ | ------ | ------------------- | +| `pnpm test` | 17 | 284 | 是(ssr.test.ts 6) | +| `pnpm test:unit` | 16 | 278 | 否 | +| `pnpm test:ssr` | 1 | 6 | 是 | +| `pnpm typecheck` | — | 通过 | — | +| `pnpm build:docs` | — | 通过 | — | +| `pnpm format` | — | 通过 | — | + +`build:docs` 完成 styles/components 构建、VitePress SSR 构建与页面渲染,仅有 VitePress chunk >500 kB 提示。新增测试文件 `tests/typography-empty-breadcrumbs.test.ts` 24 项,并加入 `test:unit`;`ssr.test.ts` 新增 1 项组合 SSR 渲染。 + +### 浏览器(127.0.0.1:5173) + +- 桌面视口 800×655,浅色与深色;另用同源 390×900 iframe 检查窄屏,均在浅色下复测三页。 +- Typography:6 个预览、6 张 API 表;桌面表宽 724px、窄屏 350px,`table-layout:fixed` 且 `scrollWidth == clientWidth`,无横向溢出。浅色计算样式 h1 36/40、h2 30/36、body 16/28、body-sm 14/24、body-xs 12/20、code 14/20;深色对应颜色切到深色变量。组件预览 h1 在窄屏保持 36px,不再被文档全局 `h1` 的 28px 覆盖。 +- EmptyState:4 个自编示例、6 个预览实例(自定义样式在示例与自定义样式区重复)、1 张 API 表;默认回退为 `No results found`,14/20、8px padding、muted 色。实际点击“切换内容”在回退与 `没有找到匹配的结果。` 之间双向切换。桌面 724px、窄屏 350px,无溢出。 +- Breadcrumbs:7 个预览、3 张 API 表;根为 `ol`,`aria-label="Breadcrumbs"`;末项为 `span[role=link]`,带 `aria-current="page"`、`aria-disabled="true"`、`tabindex="-1"`(Vue Link 的禁用策略,RAC 省略 `tabindex`;两者均不可 Tab)、无 `href`/`target`。禁用示例 0 个 `a`、4 个 `span[role=link]`,前三项 opacity 0.5、当前项 1;`render-function` 的无 `href` 项为 `span[role=link][tabindex="0"]`,无 `aria-disabled`;默认分隔符 12×12,`data-slot` 与尺寸类正确。桌面/窄屏均无溢出。 +- 回归 `/components/button`:35 个按钮;页面标题桌面 32px、窄屏 28px;正文内联代码 12px;2 张表桌面 724px、窄屏 350px,无溢出。 + +### 文档隔离与共享修正 + +- `.docs-main > h1` 收回文档标题样式,避免 36px Typography h1 被文档的 32/28px 规则覆盖;窄屏媒体查询同步收窄。 +- 文档正文内联代码样式排除 `.not-prose`,预览内 `Typography code` 保持 14px,不再被文档 12px 覆盖。 +- 共享 `Link` 在无 `href` 时不再输出 `target="_self"`;当前项与禁用 Breadcrumb 不再出现无效 target。 +- 样式入口按基线顺序把 breadcrumbs 放在 link 之前;禁用项透明度恢复 0.5,当前项由更高优先级规则保持 1。 + +### 独立复核返工 + +独立只读复核未发现 P0/P1,指出 3 项 P2:兼容矩阵表格含裸竖线、禁用 span 的 `tabindex` 与 RAC 差异记录不足、内部 `isLast`/`separatorSlot` 进入公开 `BreadcrumbsItemProps`。已分别改写表格单元格、在组件文档/验证/差异表中记录 `tabindex="-1"` 与 RAC 省略的差异、用 `Omit` 收紧公开类型并加入 `@ts-expect-error` 类型回归。另补齐了 RAC 的“无 `href` 非当前项也渲染为 `span[role=link]`、未禁用时 `tabindex="0"`”路径。返工后 `test` / `test:unit` / `test:ssr` / `typecheck` / `build:docs` / `format` 均重新通过,计数不变。 + +### 限制 + +- 浏览器截图接口持续返回 “Screenshot needs a visible tab”,本轮没有位图截图;以上为 DOM 与计算样式记录,不等同于逐像素视觉验收。 +- 隐藏浏览器窗口下发送 Tab 键未移动焦点,未取得真实键盘 Tab 轨迹;改用 DOM 的 `tabindex`/ARIA 与单元测试验证,读屏未验证。 +- 390×900 为桌面浏览器同源 iframe,不是真实手机或触摸设备。 +- 未执行 Nuxt 水合、RTL、完整触屏/读屏、独立安装 dist、`test:browser`/`test:visual`/`test:package`。 +- 未提交、未推送,也未宣布集成验收通过。验证后已移除临时 iframe、恢复浅色主题与桌面视口。 + +## M15–M17 Breadcrumbs 复核返工(2026-10-22) + +两项 P2:Fieldset 禁用被 Breadcrumbs 根 provide 遮蔽;末项变中间项后 asChild 未重建导致只剩裸文本。已合并继承禁用并按结构模式重建 Link。`pnpm test` 290(17 文件,SSR 6)、`test:unit` 284、typecheck、format 通过。详见 `docs/migrations/M15-M17-review.md` 与 `M17-breadcrumbs.md`。 + +## M15–M17 返工后集成人独立复核(2026-10-22) + +[复核报告](./migrations/M15-M17-review.md#返工后独立复核2026-10-22):两项 P2 已关闭。独立验证首个 Legend 的禁用例外、嵌套 disabled=false 不逃逸、稳定 key 的实际重排、真实 a/span/href/aria-current 和事件取消;原文 5 份完整 SFC 提取后通过 vue-tsc 并实际挂载,17 份演示无警告挂载,dist Props 正反类型探针通过。 + +正式 `pnpm test` 为 17 文件 / 290 项(含 node SSR 6);`pnpm test:unit` 为 16 文件 / 284 项(不含 node SSR)。typecheck/build:docs/format/diff-check 通过。临时额外 3 项探针已移除,不计入正式计数。本轮未逐页浏览器复测,也未新增自动视觉、读屏/RTL/触屏、Nuxt 或独立安装验收。 diff --git a/package.json b/package.json index 7111fe9..d07df9b 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/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts", + "test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts", "test:ssr": "vitest run tests/ssr.test.ts", "format": "prettier --check .", "format:fix": "prettier --write .", diff --git a/packages/styles/components/breadcrumbs.css b/packages/styles/components/breadcrumbs.css new file mode 100644 index 0000000..c491169 --- /dev/null +++ b/packages/styles/components/breadcrumbs.css @@ -0,0 +1,31 @@ +/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc. + * See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */ + +/* Base breadcrumbs container */ +.hv-breadcrumbs { + @apply flex items-center gap-1.5; + + /* Breadcrumb link */ + .hv-breadcrumbs__link { + @apply relative text-sm leading-5 font-medium text-muted no-underline opacity-100; + + &:hover, + &[data-hovered="true"] { + @apply underline; + } + + &[data-current="true"] { + @apply text-link opacity-100; + } + } + + /* Breadcrumb item wrapper */ + .hv-breadcrumbs__item { + @apply flex shrink-0 items-center justify-center gap-1; + } + + /* Separator icon */ + .hv-breadcrumbs__separator { + @apply size-3 text-muted rtl:rotate-180; + } +} diff --git a/packages/styles/components/empty-state.css b/packages/styles/components/empty-state.css new file mode 100644 index 0000000..d1cddf1 --- /dev/null +++ b/packages/styles/components/empty-state.css @@ -0,0 +1,7 @@ +/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc. + * See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */ + +/* Base empty-state styles */ +.hv-empty-state { + @apply p-2 text-sm text-muted; +} diff --git a/packages/styles/components/typography.css b/packages/styles/components/typography.css new file mode 100644 index 0000000..937d842 --- /dev/null +++ b/packages/styles/components/typography.css @@ -0,0 +1,166 @@ +/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc. + * See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */ + +.hv-typography { + @apply text-foreground; +} + +.hv-typography-prose { + @apply text-foreground; +} + +.hv-typography-prose h1 { + @apply text-4xl font-semibold tracking-tight; +} + +.hv-typography-prose h2 { + @apply text-3xl font-semibold tracking-tight; +} + +.hv-typography-prose h3 { + @apply text-2xl font-semibold tracking-tight; +} + +.hv-typography-prose h4 { + @apply text-xl font-semibold tracking-tight; +} + +.hv-typography-prose h5 { + @apply text-lg font-semibold tracking-tight; +} + +.hv-typography-prose h6 { + @apply text-base font-semibold tracking-tight; +} + +.hv-typography-prose p { + @apply text-base leading-7; +} + +.hv-typography-prose code { + @apply rounded-md bg-default px-1.5 py-0.5 font-mono text-sm text-foreground; +} + +.hv-typography-prose a { + @apply font-medium text-link underline underline-offset-4; +} + +.hv-typography-prose blockquote { + @apply mt-4 border-s-4 border-border ps-4 text-muted italic; +} + +.hv-typography-prose ul { + @apply my-4 list-disc space-y-2 ps-6; +} + +.hv-typography-prose ol { + @apply my-4 list-decimal space-y-2 ps-6; +} + +.hv-typography-prose li { + @apply text-base leading-7; +} + +.hv-typography-prose hr { + @apply my-8 border-separator; +} + +.hv-typography-prose pre { + @apply my-4 overflow-x-auto rounded-xl bg-default p-4 font-mono text-sm leading-relaxed; +} + +.hv-typography-prose strong { + @apply font-semibold text-foreground; +} + +.hv-typography-prose em { + @apply italic; +} + +.hv-typography-prose img { + @apply my-4 rounded-xl; +} + +.hv-typography--h1 { + @apply text-4xl font-semibold tracking-tight; +} + +.hv-typography--h2 { + @apply text-3xl font-semibold tracking-tight; +} + +.hv-typography--h3 { + @apply text-2xl font-semibold tracking-tight; +} + +.hv-typography--h4 { + @apply text-xl font-semibold tracking-tight; +} + +.hv-typography--h5 { + @apply text-lg font-semibold tracking-tight; +} + +.hv-typography--h6 { + @apply text-base font-semibold tracking-tight; +} + +.hv-typography--body { + @apply text-base leading-7; +} + +.hv-typography--body-sm { + @apply text-sm leading-6; +} + +.hv-typography--body-xs { + @apply text-xs leading-5; +} + +.hv-typography--code { + @apply rounded-md bg-default px-1.5 py-0.5 font-mono text-sm text-foreground; +} + +.hv-typography--align-start { + @apply text-start; +} + +.hv-typography--align-center { + @apply text-center; +} + +.hv-typography--align-end { + @apply text-end; +} + +.hv-typography--align-justify { + @apply text-justify; +} + +.hv-typography--color-default { + @apply text-foreground; +} + +.hv-typography--color-muted { + @apply text-muted; +} + +.hv-typography--truncate { + @apply block truncate; +} + +.hv-typography--weight-normal { + @apply font-normal; +} + +.hv-typography--weight-medium { + @apply font-medium; +} + +.hv-typography--weight-semibold { + @apply font-semibold; +} + +.hv-typography--weight-bold { + @apply font-bold; +} diff --git a/packages/styles/index.css b/packages/styles/index.css index 528630d..92ab70c 100644 --- a/packages/styles/index.css +++ b/packages/styles/index.css @@ -15,6 +15,10 @@ @import "./components/label.css" layer(components); @import "./components/description.css" layer(components); @import "./components/surface.css" layer(components); +/* Keep breadcrumbs before link.css, matching the baseline component order. + * Breadcrumb link rules then override Link defaults, while Link's disabled + * rule still applies to non-current breadcrumb links. */ +@import "./components/breadcrumbs.css" layer(components); @import "./components/link.css" layer(components); @import "./components/spinner.css" layer(components); @import "./components/avatar.css" layer(components); @@ -65,6 +69,10 @@ @import "./components/search-field.css" layer(components); +@import "./components/typography.css" layer(components); + +@import "./components/empty-state.css" layer(components); + /* Vue disabled scopes preserve native first-legend semantics. A label in the * exempt legend must not pick up the baseline blanket ancestor opacity rule. * Local and outer disabled labels still carry hv-label--disabled. */ diff --git a/packages/styles/src/index.ts b/packages/styles/src/index.ts index 206042b..c553ba0 100644 --- a/packages/styles/src/index.ts +++ b/packages/styles/src/index.ts @@ -639,3 +639,67 @@ export const radioGroupVariants = tv({ }); export type RadioGroupVariants = VariantProps; + +export const typographyVariants = tv({ + defaultVariants: { + align: "start", + color: "default", + type: "body", + }, + slots: { + base: "hv-typography", + prose: "hv-typography-prose", + }, + variants: { + align: { + center: "hv-typography--align-center", + end: "hv-typography--align-end", + justify: "hv-typography--align-justify", + start: "hv-typography--align-start", + }, + color: { + default: "hv-typography--color-default", + muted: "hv-typography--color-muted", + }, + truncate: { + true: "hv-typography--truncate", + }, + type: { + body: "hv-typography--body", + "body-sm": "hv-typography--body-sm", + "body-xs": "hv-typography--body-xs", + code: "hv-typography--code", + h1: "hv-typography--h1", + h2: "hv-typography--h2", + h3: "hv-typography--h3", + h4: "hv-typography--h4", + h5: "hv-typography--h5", + h6: "hv-typography--h6", + }, + weight: { + bold: "hv-typography--weight-bold", + medium: "hv-typography--weight-medium", + normal: "hv-typography--weight-normal", + semibold: "hv-typography--weight-semibold", + }, + }, +}); + +export type TypographyVariants = VariantProps; + +export const breadcrumbsVariants = tv({ + slots: { + base: "hv-breadcrumbs", + item: "hv-breadcrumbs__item", + link: "hv-breadcrumbs__link", + separator: "hv-breadcrumbs__separator", + }, +}); + +export type BreadcrumbsVariants = VariantProps; + +export const emptyStateVariants = tv({ + base: "hv-empty-state", +}); + +export type EmptyStateVariants = VariantProps; diff --git a/packages/vue/src/components/breadcrumbs/Breadcrumbs.vue b/packages/vue/src/components/breadcrumbs/Breadcrumbs.vue new file mode 100644 index 0000000..a2c7a56 --- /dev/null +++ b/packages/vue/src/components/breadcrumbs/Breadcrumbs.vue @@ -0,0 +1,95 @@ + diff --git a/packages/vue/src/components/breadcrumbs/BreadcrumbsItem.vue b/packages/vue/src/components/breadcrumbs/BreadcrumbsItem.vue new file mode 100644 index 0000000..a01a248 --- /dev/null +++ b/packages/vue/src/components/breadcrumbs/BreadcrumbsItem.vue @@ -0,0 +1,187 @@ + diff --git a/packages/vue/src/components/breadcrumbs/BreadcrumbsSeparatorIcon.vue b/packages/vue/src/components/breadcrumbs/BreadcrumbsSeparatorIcon.vue new file mode 100644 index 0000000..c34be8d --- /dev/null +++ b/packages/vue/src/components/breadcrumbs/BreadcrumbsSeparatorIcon.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/packages/vue/src/components/empty-state/EmptyState.vue b/packages/vue/src/components/empty-state/EmptyState.vue new file mode 100644 index 0000000..35cd1ba --- /dev/null +++ b/packages/vue/src/components/empty-state/EmptyState.vue @@ -0,0 +1,79 @@ + diff --git a/packages/vue/src/components/link/Link.vue b/packages/vue/src/components/link/Link.vue index 3be7d16..fe8aeb5 100644 --- a/packages/vue/src/components/link/Link.vue +++ b/packages/vue/src/components/link/Link.vue @@ -259,7 +259,7 @@ defineExpose({ :as-child="asChild" v-bind="passthroughAttrs" :href="href" - :target="target" + :target="href ? target : undefined" :rel="rel" :download="downloadAttr" :class="slots.base()" diff --git a/packages/vue/src/components/typography/Typography.vue b/packages/vue/src/components/typography/Typography.vue new file mode 100644 index 0000000..9c5e64c --- /dev/null +++ b/packages/vue/src/components/typography/Typography.vue @@ -0,0 +1,68 @@ + + + + + + + diff --git a/packages/vue/src/components/typography/TypographyCode.vue b/packages/vue/src/components/typography/TypographyCode.vue new file mode 100644 index 0000000..d268a8d --- /dev/null +++ b/packages/vue/src/components/typography/TypographyCode.vue @@ -0,0 +1,35 @@ + + + + + + + diff --git a/packages/vue/src/components/typography/TypographyHeading.vue b/packages/vue/src/components/typography/TypographyHeading.vue new file mode 100644 index 0000000..1becce8 --- /dev/null +++ b/packages/vue/src/components/typography/TypographyHeading.vue @@ -0,0 +1,42 @@ + + + + + + + diff --git a/packages/vue/src/components/typography/TypographyParagraph.vue b/packages/vue/src/components/typography/TypographyParagraph.vue new file mode 100644 index 0000000..357f716 --- /dev/null +++ b/packages/vue/src/components/typography/TypographyParagraph.vue @@ -0,0 +1,47 @@ + + + + + + + diff --git a/packages/vue/src/components/typography/TypographyProse.vue b/packages/vue/src/components/typography/TypographyProse.vue new file mode 100644 index 0000000..d3fdfaf --- /dev/null +++ b/packages/vue/src/components/typography/TypographyProse.vue @@ -0,0 +1,15 @@ + + + + + + + diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 336f68b..731e357 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -262,3 +262,32 @@ export { type RadioVariants, type RadioGroupVariants, } from "@heroui-vue/styles"; + +export { default as Typography } from "./components/typography/Typography.vue"; +export { default as TypographyHeading } from "./components/typography/TypographyHeading.vue"; +export { default as TypographyParagraph } from "./components/typography/TypographyParagraph.vue"; +export { default as TypographyCode } from "./components/typography/TypographyCode.vue"; +export { default as TypographyProse } from "./components/typography/TypographyProse.vue"; +export type { + TypographyProps, + TypographyHeadingProps, + TypographyParagraphProps, + TypographyCodeProps, + TypographyProseProps, +} from "./types"; + +export { default as EmptyState } from "./components/empty-state/EmptyState.vue"; +export type { EmptyStateProps } from "./types"; + +export { default as Breadcrumbs } from "./components/breadcrumbs/Breadcrumbs.vue"; +export { default as BreadcrumbsItem } from "./components/breadcrumbs/BreadcrumbsItem.vue"; +export type { BreadcrumbsProps, BreadcrumbsItemProps } from "./types"; + +export { + typographyVariants, + breadcrumbsVariants, + emptyStateVariants, + type TypographyVariants, + type BreadcrumbsVariants, + type EmptyStateVariants, +} from "@heroui-vue/styles"; diff --git a/packages/vue/src/types.ts b/packages/vue/src/types.ts index b8209fd..d1f9356 100644 --- a/packages/vue/src/types.ts +++ b/packages/vue/src/types.ts @@ -119,6 +119,34 @@ export type FieldsetActionsProps = InstanceType< import type SearchField from "./components/search-field/SearchField.vue"; export type SearchFieldProps = InstanceType["$props"]; +import type Typography from "./components/typography/Typography.vue"; +import type TypographyHeading from "./components/typography/TypographyHeading.vue"; +import type TypographyParagraph from "./components/typography/TypographyParagraph.vue"; +import type TypographyCode from "./components/typography/TypographyCode.vue"; +import type TypographyProse from "./components/typography/TypographyProse.vue"; +import type EmptyState from "./components/empty-state/EmptyState.vue"; +import type Breadcrumbs from "./components/breadcrumbs/Breadcrumbs.vue"; +import type BreadcrumbsItem from "./components/breadcrumbs/BreadcrumbsItem.vue"; + +export type TypographyProps = InstanceType["$props"]; +export type TypographyHeadingProps = InstanceType< + typeof TypographyHeading +>["$props"]; +export type TypographyParagraphProps = InstanceType< + typeof TypographyParagraph +>["$props"]; +export type TypographyCodeProps = InstanceType["$props"]; +export type TypographyProseProps = InstanceType< + typeof TypographyProse +>["$props"]; +export type EmptyStateProps = InstanceType["$props"]; +export type BreadcrumbsProps = InstanceType["$props"]; +/** Public item props; Root injects `isLast` / `separatorSlot` internally. */ +export type BreadcrumbsItemProps = Omit< + InstanceType["$props"], + "isLast" | "separatorSlot" +>; + import type SearchFieldGroup from "./components/search-field/SearchFieldGroup.vue"; export type SearchFieldGroupProps = InstanceType< typeof SearchFieldGroup diff --git a/tests/ssr.test.ts b/tests/ssr.test.ts index c567271..5f1af0f 100644 --- a/tests/ssr.test.ts +++ b/tests/ssr.test.ts @@ -194,3 +194,43 @@ it("renders choice groups and nested content associations without browser global expect(refs.length).toBeGreaterThan(2); for (const id of refs) expect(ids).toContain(id); }); + +it("renders typography, empty state and breadcrumbs without browser globals", async () => { + const { + Typography, + TypographyHeading, + TypographyParagraph, + TypographyCode, + TypographyProse, + EmptyState, + Breadcrumbs, + BreadcrumbsItem, + } = await import("../packages/vue/src"); + const html = await renderToString( + createSSRApp({ + render: () => + h("div", {}, [ + h(Typography, { type: "h2" }, () => "排版标题"), + h(TypographyHeading, { level: 3 }, () => "三级标题"), + h(TypographyParagraph, { size: "sm" }, () => "正文"), + h(TypographyCode, {}, () => "code"), + h(TypographyProse, {}, () => h("p", "富文本段落")), + h(EmptyState), + h(Breadcrumbs, {}, () => [ + h(BreadcrumbsItem, { href: "#home" }, () => "首页"), + h(BreadcrumbsItem, null, () => "当前页"), + ]), + ]), + }), + ); + + expect(html).toContain(" { + document.body.innerHTML = ""; +}); + +describe("Typography", () => { + it("renders body text as a paragraph with baseline classes", () => { + const w = mount(Typography, { slots: { default: "正文" } }); + const root = w.get("[data-slot=typography]"); + expect(root.element.tagName).toBe("P"); + expect(root.classes()).toContain("hv-typography"); + expect(root.classes()).toContain("hv-typography--body"); + expect(root.classes()).toContain("hv-typography--align-start"); + expect(root.classes()).toContain("hv-typography--color-default"); + expect(root.attributes("data-type")).toBe("body"); + }); + + it("maps every type to its default semantic element", () => { + const cases = [ + ["h1", "H1"], + ["h2", "H2"], + ["h3", "H3"], + ["h4", "H4"], + ["h5", "H5"], + ["h6", "H6"], + ["body", "P"], + ["body-sm", "P"], + ["body-xs", "P"], + ["code", "CODE"], + ] as const; + + for (const [type, tag] of cases) { + const w = mount(Typography, { + props: { type }, + slots: { default: type }, + }); + const root = w.get("[data-slot=typography]"); + expect(root.element.tagName).toBe(tag); + expect(root.attributes("data-type")).toBe(type); + expect(root.classes()).toContain(`hv-typography--${type}`); + w.unmount(); + } + }); + + it("renders Heading, Paragraph and Code primitives", () => { + const heading = mount(TypographyHeading, { + props: { level: 3 }, + slots: { default: "标题" }, + }); + expect(heading.element.tagName).toBe("H3"); + expect(heading.attributes("data-type")).toBe("h3"); + expect(heading.classes()).toContain("hv-typography--h3"); + + const paragraph = mount(TypographyParagraph, { + props: { size: "sm" }, + slots: { default: "正文" }, + }); + expect(paragraph.element.tagName).toBe("P"); + expect(paragraph.attributes("data-type")).toBe("body-sm"); + expect(paragraph.classes()).toContain("hv-typography--body-sm"); + + const code = mount(TypographyCode, { slots: { default: "code" } }); + expect(code.element.tagName).toBe("CODE"); + expect(code.attributes("data-type")).toBe("code"); + }); + + it("supports the as override while keeping visual type classes", () => { + const w = mount(Typography, { + props: { type: "h1", as: "h2" }, + slots: { default: "视觉 H1,语义 H2" }, + }); + const root = w.get("[data-slot=typography]"); + expect(root.element.tagName).toBe("H2"); + expect(root.attributes("data-type")).toBe("h1"); + expect(root.classes()).toContain("hv-typography--h1"); + }); + + it("applies align, color, weight and truncate variants", () => { + const w = mount(Typography, { + props: { + align: "center", + color: "muted", + weight: "bold", + truncate: true, + }, + }); + const root = w.get("[data-slot=typography]"); + expect(root.classes()).toContain("hv-typography--align-center"); + expect(root.classes()).toContain("hv-typography--color-muted"); + expect(root.classes()).toContain("hv-typography--weight-bold"); + expect(root.classes()).toContain("hv-typography--truncate"); + }); + + it("renders Prose with its baseline root and class", () => { + const w = mount(TypographyProse, { + slots: { default: () => h("p", "段落") }, + }); + const root = w.get("[data-slot=prose]"); + expect(root.element.tagName).toBe("DIV"); + expect(root.classes()).toContain("hv-typography-prose"); + expect(root.text()).toBe("段落"); + }); + + it("merges dynamic attributes and class values without stale keys", async () => { + const extra = ref>({}); + const classValue = ref("base-extra"); + const w = mount( + defineComponent({ + components: { Typography }, + setup() { + return { extra, classValue }; + }, + template: `文本`, + }), + ); + + let root = w.get("[data-slot=typography]"); + expect(root.attributes("aria-label")).toBeUndefined(); + expect(root.classes()).toContain("base-extra"); + + extra.value = { "aria-label": "说明", "data-testid": "typo" }; + classValue.value = ["array-extra", { "object-extra": true }]; + await nextTick(); + root = w.get("[data-slot=typography]"); + expect(root.attributes("aria-label")).toBe("说明"); + expect(root.attributes("data-testid")).toBe("typo"); + expect(root.classes()).toContain("array-extra"); + expect(root.classes()).toContain("object-extra"); + expect(root.classes()).not.toContain("base-extra"); + + extra.value = {}; + classValue.value = undefined; + await nextTick(); + root = w.get("[data-slot=typography]"); + expect(root.attributes("aria-label")).toBeUndefined(); + expect(root.classes()).toContain("hv-typography"); + + extra.value = { title: "再次出现" }; + await nextTick(); + expect(w.get("[data-slot=typography]").attributes("title")).toBe( + "再次出现", + ); + w.unmount(); + }); + + it("updates type and slot content dynamically", async () => { + const type = ref<"body" | "h2">("body"); + const text = ref("第一版"); + const w = mount( + defineComponent({ + components: { Typography }, + setup() { + return { type, text }; + }, + template: `{{ text }}`, + }), + ); + expect(w.get("[data-slot=typography]").element.tagName).toBe("P"); + type.value = "h2"; + text.value = "第二版"; + await nextTick(); + const root = w.get("[data-slot=typography]"); + expect(root.element.tagName).toBe("H2"); + expect(root.classes()).toContain("hv-typography--h2"); + expect(root.text()).toBe("第二版"); + w.unmount(); + }); + + it("keeps public typography types constrained", () => { + const props: InstanceType["$props"] = { + type: "h1", + align: "center", + color: "muted", + weight: "bold", + truncate: true, + as: "h2", + }; + // @ts-expect-error type must be one of the documented typography types + const badType: InstanceType["$props"]["type"] = "h7"; + // @ts-expect-error align must be start | center | end | justify + const badAlign: InstanceType["$props"]["align"] = "left"; + // @ts-expect-error Heading level must be 1-6 + const badLevel: InstanceType["$props"]["level"] = + 7; + void props; + void badType; + void badAlign; + void badLevel; + expect(props.type).toBe("h1"); + }); +}); + +describe("EmptyState", () => { + it("renders the baseline fallback when no content is provided", () => { + const w = mount(EmptyState); + const root = w.get("[data-slot=empty-state]"); + expect(root.element.tagName).toBe("DIV"); + expect(root.classes()).toContain("hv-empty-state"); + expect(root.text()).toBe("No results found"); + }); + + it("falls back for empty, whitespace and conditional slots", () => { + const empty = mount(EmptyState, { slots: { default: () => "" } }); + expect(empty.text()).toBe("No results found"); + + const whitespace = mount(EmptyState, { + slots: { default: () => " " }, + }); + expect(whitespace.text()).toBe("No results found"); + + const conditional = mount( + defineComponent({ + components: { EmptyState }, + setup() { + return { show: ref(false) }; + }, + template: `内容`, + }), + ); + expect(conditional.text()).toBe("No results found"); + }); + + it("shows conditional content and restores the fallback dynamically", async () => { + const show = ref(false); + const w = mount( + defineComponent({ + components: { EmptyState }, + setup() { + return { show }; + }, + template: `没有结果`, + }), + ); + expect(w.text()).toBe("No results found"); + show.value = true; + await nextTick(); + expect(w.text()).toBe("没有结果"); + show.value = false; + await nextTick(); + expect(w.text()).toBe("No results found"); + }); + + it("merges dynamic attrs, class values and custom root elements", async () => { + const extra = ref>({}); + const w = mount( + defineComponent({ + components: { EmptyState }, + setup() { + return { extra }; + }, + template: `内容`, + }), + ); + let root = w.get("[data-slot=empty-state]"); + expect(root.element.tagName).toBe("SECTION"); + expect(root.classes()).toContain("hv-empty-state"); + expect(root.classes()).toContain("a"); + expect(root.classes()).toContain("b"); + + extra.value = { "aria-label": "空", "data-testid": "empty" }; + await nextTick(); + root = w.get("[data-slot=empty-state]"); + expect(root.attributes("aria-label")).toBe("空"); + expect(root.attributes("data-testid")).toBe("empty"); + + extra.value = {}; + await nextTick(); + expect(w.get("[data-slot=empty-state]").attributes("aria-label")).toBe( + undefined, + ); + w.unmount(); + }); +}); + +describe("Breadcrumbs", () => { + const items = () => + h(Breadcrumbs, null, { + default: () => [ + h(BreadcrumbsItem, { href: "#home" }, () => "首页"), + h(BreadcrumbsItem, { href: "#products" }, () => "产品"), + h(BreadcrumbsItem, null, () => "笔记本电脑"), + ], + }); + + it("renders an ordered list with a default accessible name", () => { + const w = mount(items()); + const root = w.get("[data-slot=breadcrumbs]"); + expect(root.element.tagName).toBe("OL"); + expect(root.attributes("aria-label")).toBe("Breadcrumbs"); + expect(root.classes()).toContain("hv-breadcrumbs"); + expect(w.findAll("[data-slot=breadcrumbs-item]")).toHaveLength(3); + }); + + it("marks the last item current and renders separators only between items", () => { + const w = mount(items()); + const listItems = w.findAll("[data-slot=breadcrumbs-item]"); + const links = w.findAll("a"); + const current = listItems[2]; + + expect(links).toHaveLength(2); + expect(current.attributes("data-current")).toBe("true"); + expect(current.attributes("data-disabled")).toBe("true"); + const currentLink = current.get("[role=link]"); + expect(currentLink.element.tagName).toBe("SPAN"); + expect(currentLink.attributes("aria-current")).toBe("page"); + expect(currentLink.attributes("aria-disabled")).toBe("true"); + expect(currentLink.attributes("tabindex")).toBe("-1"); + expect(currentLink.attributes("data-current")).toBe("true"); + expect(currentLink.attributes("href")).toBeUndefined(); + expect(currentLink.attributes("target")).toBeUndefined(); + + const separators = w.findAll("[data-slot=breadcrumbs-separator]"); + expect(separators).toHaveLength(2); + expect(separators[0].classes()).toContain("hv-breadcrumbs__separator"); + expect(separators[0].attributes("aria-hidden")).toBe("true"); + expect(separators[0].attributes("role")).toBe("presentation"); + }); + + it("supports a custom accessible name and custom root/item elements", () => { + const w = mount(Breadcrumbs, { + props: { "aria-label": "当前位置", as: "nav" }, + slots: { + default: () => h(BreadcrumbsItem, { as: "div" }, () => "当前页面"), + }, + }); + const root = w.get("[data-slot=breadcrumbs]"); + expect(root.element.tagName).toBe("NAV"); + expect(root.attributes("aria-label")).toBe("当前位置"); + expect(w.get("[data-slot=breadcrumbs-item]").element.tagName).toBe("DIV"); + }); + + it("passes link props and item attributes to their documented targets", () => { + const w = mount(Breadcrumbs, { + slots: { + default: () => [ + h( + BreadcrumbsItem, + { + href: "https://example.com", + target: "_blank", + rel: "noreferrer", + download: "report.pdf", + "data-custom": "bar", + }, + () => "文档", + ), + h(BreadcrumbsItem, null, () => "中间"), + h(BreadcrumbsItem, null, () => "当前"), + ], + }, + }); + const link = w.get("a"); + expect(link.attributes("href")).toBe("https://example.com"); + expect(link.attributes("target")).toBe("_blank"); + expect(link.attributes("rel")).toBe("noreferrer"); + expect(link.attributes("download")).toBe("report.pdf"); + expect( + w.get("[data-slot=breadcrumbs-item]").attributes("data-custom"), + ).toBe("bar"); + + const middle = w.findAll("[data-slot=link]")[1]; + expect(middle.element.tagName).toBe("SPAN"); + expect(middle.attributes("role")).toBe("link"); + expect(middle.attributes("tabindex")).toBe("0"); + expect(middle.attributes("href")).toBeUndefined(); + expect(middle.attributes("aria-disabled")).toBeUndefined(); + }); + + it("disables all links at the root and blocks click activation", async () => { + const clicks = vi.fn(); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup() { + return { clicks }; + }, + template: ` + + 首页 + 当前 + + `, + }), + { attachTo: document.body }, + ); + const link = w.get("[data-slot=link]"); + expect(link.element.tagName).toBe("SPAN"); + expect(link.attributes("href")).toBeUndefined(); + expect(link.attributes("target")).toBeUndefined(); + expect(link.attributes("aria-disabled")).toBe("true"); + expect(link.attributes("tabindex")).toBe("-1"); + expect(link.attributes("data-disabled")).toBe("true"); + await link.trigger("click"); + expect(clicks).not.toHaveBeenCalled(); + w.unmount(); + }); + + it("disables a single item without disabling its siblings", async () => { + const clicks = vi.fn(); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup() { + return { clicks }; + }, + template: ` + + 首页 + 产品 + 当前 + + `, + }), + { attachTo: document.body }, + ); + const links = w.findAll("[data-slot=link]"); + expect(links[0].element.tagName).toBe("SPAN"); + expect(links[0].attributes("aria-disabled")).toBe("true"); + expect(links[0].attributes("href")).toBeUndefined(); + expect(links[1].element.tagName).toBe("A"); + expect(links[1].attributes("aria-disabled")).toBeUndefined(); + await links[0].trigger("click"); + expect(clicks).not.toHaveBeenCalled(); + w.unmount(); + }); + + it("clones custom separator content with the baseline class", () => { + const w = mount(Breadcrumbs, { + slots: { + separator: () => h("span", { class: "custom-sep" }, "›"), + default: () => [ + h(BreadcrumbsItem, { href: "#" }, () => "首页"), + h(BreadcrumbsItem, null, () => "当前"), + ], + }, + }); + const separator = w.get("[data-slot=breadcrumbs-separator]"); + expect(separator.element.tagName).toBe("SPAN"); + expect(separator.classes()).toContain("custom-sep"); + expect(separator.classes()).toContain("hv-breadcrumbs__separator"); + expect(separator.text()).toBe("›"); + }); + + it("moves the current state when conditional items change", async () => { + const showLast = ref(false); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup() { + return { showLast }; + }, + template: ` + + 首页 + 产品 + 笔记本电脑 + + `, + }), + ); + let listItems = w.findAll("[data-slot=breadcrumbs-item]"); + expect(listItems).toHaveLength(2); + expect(listItems[1].attributes("data-current")).toBe("true"); + + showLast.value = true; + await nextTick(); + listItems = w.findAll("[data-slot=breadcrumbs-item]"); + expect(listItems).toHaveLength(3); + expect(listItems[1].attributes("data-current")).toBeUndefined(); + expect(listItems[2].attributes("data-current")).toBe("true"); + w.unmount(); + }); + + it("provides scoped item state to the default slot", () => { + const w = mount(Breadcrumbs, { + slots: { + default: () => + h(BreadcrumbsItem, null, { + default: ({ isCurrent, isDisabled }: any) => + `${isCurrent ? "current" : "link"}:${isDisabled ? "disabled" : "enabled"}`, + }), + }, + }); + expect(w.text()).toBe("current:disabled"); + }); + + it("merges class values on both the item and its link", async () => { + const classValue = ref("first"); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup() { + return { classValue }; + }, + template: ` + + 首页 + 当前 + + `, + }), + ); + let item = w.get("[data-slot=breadcrumbs-item]"); + let link = w.get("a"); + expect(item.classes()).toContain("first"); + expect(link.classes()).toContain("first"); + + classValue.value = ["second", { third: true }]; + await nextTick(); + item = w.get("[data-slot=breadcrumbs-item]"); + link = w.get("a"); + expect(item.classes()).toContain("second"); + expect(item.classes()).toContain("third"); + expect(link.classes()).toContain("second"); + expect(link.classes()).not.toContain("first"); + w.unmount(); + }); + + it("keeps public breadcrumbs types constrained", () => { + const props: InstanceType["$props"] = { + ariaLabel: "当前位置", + isDisabled: true, + as: "nav", + }; + const item: BreadcrumbsItemProps = { + href: "#", + target: "_blank", + rel: "noreferrer", + download: true, + isDisabled: false, + as: "li", + }; + const internalItem: BreadcrumbsItemProps = { + // @ts-expect-error separatorSlot is internal Root wiring. + separatorSlot: () => null, + }; + // @ts-expect-error isDisabled must be boolean + const badRootDisabled: InstanceType< + typeof Breadcrumbs + >["$props"]["isDisabled"] = "yes"; + // @ts-expect-error href must be a string + const badHref: BreadcrumbsItemProps["href"] = 42; + void props; + void item; + void internalItem; + void badRootDisabled; + void badHref; + expect(props.isDisabled).toBe(true); + }); + + it("inherits Fieldset disabled and blocks real link activation", async () => { + const clicks = vi.fn(); + const w = mount( + defineComponent({ + components: { Fieldset, Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ clicks }), + template: ` + + + 首页 + 产品 + + + `, + }), + { attachTo: document.body }, + ); + await nextTick(); + const link = w.get("[data-slot=link]"); + expect(link.element.tagName).toBe("SPAN"); + expect(link.attributes("href")).toBeUndefined(); + expect(link.attributes("aria-disabled")).toBe("true"); + expect(link.attributes("tabindex")).toBe("-1"); + await link.trigger("click"); + expect(clicks).not.toHaveBeenCalled(); + // Keyboard activation must also be blocked. + await link.trigger("keydown", { key: "Enter" }); + expect(clicks).not.toHaveBeenCalled(); + w.unmount(); + }); + + it("re-enables and disables again with ancestor Fieldset", async () => { + const disabled = ref(true); + const clicks = vi.fn(); + const w = mount( + defineComponent({ + components: { Fieldset, Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ disabled, clicks }), + template: ` + + + 首页 + 当前 + + + `, + }), + { attachTo: document.body }, + ); + await nextTick(); + expect(w.get("[data-slot=link]").element.tagName).toBe("SPAN"); + + disabled.value = false; + await nextTick(); + await nextTick(); + const enabled = w.get("[data-slot=link]"); + expect(enabled.element.tagName).toBe("A"); + expect(enabled.attributes("href")).toBe("#home"); + expect(enabled.attributes("aria-disabled")).toBeUndefined(); + await enabled.trigger("click"); + expect(clicks).toHaveBeenCalledTimes(1); + + disabled.value = true; + await nextTick(); + await nextTick(); + const again = w.get("[data-slot=link]"); + expect(again.element.tagName).toBe("SPAN"); + expect(again.attributes("href")).toBeUndefined(); + await again.trigger("click"); + expect(clicks).toHaveBeenCalledTimes(1); + w.unmount(); + }); + + it("does not let item isDisabled=false escape ancestor Fieldset disable", async () => { + const clicks = vi.fn(); + const w = mount( + defineComponent({ + components: { Fieldset, Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ clicks }), + template: ` + + + + 首页 + + 当前 + + + `, + }), + { attachTo: document.body }, + ); + await nextTick(); + const link = w.get("[data-slot=link]"); + expect(link.element.tagName).toBe("SPAN"); + expect(link.attributes("href")).toBeUndefined(); + await link.trigger("click"); + expect(clicks).not.toHaveBeenCalled(); + w.unmount(); + }); + + it("restores a real link when the current item becomes a middle item", async () => { + const showDetail = ref(false); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ showDetail }), + template: ` + + Home + Products + Detail + + `, + }), + { attachTo: document.body }, + ); + await nextTick(); + await nextTick(); + let items = w.findAll("[data-slot=breadcrumbs-item]"); + expect(items).toHaveLength(2); + expect(items[1].find("a").exists()).toBe(false); + expect(items[1].get("[data-slot=link]").element.tagName).toBe("SPAN"); + + showDetail.value = true; + await nextTick(); + await nextTick(); + items = w.findAll("[data-slot=breadcrumbs-item]"); + expect(items).toHaveLength(3); + const productLink = items[1].find("a"); + expect(productLink.exists()).toBe(true); + expect(productLink.attributes("href")).toBe("#products"); + expect(items[1].get("[data-slot=link]").element.tagName).toBe("A"); + expect(items[2].get("[data-slot=link]").element.tagName).toBe("SPAN"); + expect(items[2].attributes("data-current")).toBe("true"); + + showDetail.value = false; + await nextTick(); + await nextTick(); + items = w.findAll("[data-slot=breadcrumbs-item]"); + expect(items).toHaveLength(2); + expect(items[1].find("a").exists()).toBe(false); + expect(items[1].get("[data-slot=link]").element.tagName).toBe("SPAN"); + expect(items[1].attributes("data-current")).toBe("true"); + w.unmount(); + }); + + it("restores navigation when href appears on a non-current item", async () => { + const href = ref(undefined); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ href }), + template: ` + + Home + Products + Detail + + `, + }), + { attachTo: document.body }, + ); + await nextTick(); + await nextTick(); + let link = w.findAll("[data-slot=link]")[1]; + expect(link.element.tagName).toBe("SPAN"); + expect(link.attributes("href")).toBeUndefined(); + + href.value = "#products"; + await nextTick(); + await nextTick(); + link = w.findAll("[data-slot=link]")[1]; + expect(link.element.tagName).toBe("A"); + expect(link.attributes("href")).toBe("#products"); + + href.value = undefined; + await nextTick(); + await nextTick(); + link = w.findAll("[data-slot=link]")[1]; + expect(link.element.tagName).toBe("SPAN"); + expect(link.attributes("href")).toBeUndefined(); + w.unmount(); + }); + + it("keeps unique aria-current and working middle links after reorder", async () => { + const showDetail = ref(false); + const w = mount( + defineComponent({ + components: { Breadcrumbs, BreadcrumbsItem }, + setup: () => ({ showDetail }), + template: ` + + A + B + C + + `, + }), + { attachTo: document.body }, + ); + showDetail.value = true; + await nextTick(); + await nextTick(); + const current = w + .findAll("[data-slot=link]") + .filter((el) => el.attributes("aria-current") === "page"); + expect(current).toHaveLength(1); + expect(current[0].element.tagName).toBe("SPAN"); + const anchors = w.findAll("a"); + expect(anchors.map((a) => a.attributes("href"))).toEqual(["#a", "#b"]); + for (const a of anchors) { + expect(a.attributes("aria-current")).toBeUndefined(); + expect(a.attributes("tabindex")).not.toBe("-1"); + } + w.unmount(); + }); +});
Prose 适用于标记已是语义化、由 HeroUI 应用默认排版节奏的写作型内容。
+ 行内代码如 + as + 与 Typography 原语获得相同的代码样式处理。 +
as