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 不完全一致,本实现以固定提交源码为准。需要独立导航地标时,可由应用在外层使用 `