106 lines
3.3 KiB
Markdown
106 lines
3.3 KiB
Markdown
---
|
||
title: Separator 分隔符
|
||
description: 在内容区块之间进行视觉分隔。
|
||
component: separator
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { Separator } from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="separator-basic" />
|
||
|
||
## 示例
|
||
|
||
### 变体
|
||
|
||
<ComponentPreview name="separator-variants" />
|
||
|
||
### 与 Surface 组合
|
||
|
||
Separator 组件会根据不同的表面背景自动适配,以获得更好的可见性。
|
||
|
||
<ComponentPreview name="separator-with-surface" />
|
||
|
||
### 垂直方向
|
||
|
||
<ComponentPreview name="separator-vertical" />
|
||
|
||
### 带内容
|
||
|
||
<ComponentPreview name="separator-with-content" />
|
||
|
||
### 渲染函数
|
||
|
||
Vue 使用 `as-child` 将分隔符属性合并到默认插槽中唯一的自定义根元素,对应上游 `render` 函数示例,不将 render prop 原样搬入 Vue。
|
||
|
||
<ComponentPreview name="separator-render-function" />
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="separator-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
若要自定义组件类,可使用 `@layer components` 指令。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-separator {
|
||
@apply bg-accent h-[2px];
|
||
}
|
||
|
||
.hv-separator--vertical {
|
||
@apply bg-accent w-[2px];
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||
|
||
### CSS 类
|
||
|
||
Separator 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/separator.css)):
|
||
|
||
#### 基础类与方向类 [!toc]
|
||
|
||
- `.hv-separator` - 基础 Separator 样式,默认水平方向
|
||
- `.hv-separator--horizontal` - 水平方向(全宽,高度 1px)
|
||
- `.hv-separator--vertical` - 垂直方向(全高,宽度 1px)
|
||
|
||
#### 变体类 [!toc]
|
||
|
||
- `.hv-separator--default` - 默认变体,标准对比度
|
||
- `.hv-separator--secondary` - 次要变体,中等对比度
|
||
- `.hv-separator--tertiary` - 第三级变体,较弱对比度
|
||
|
||
## API 参考
|
||
|
||
### Separator
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| ------------- | ---------------------------------------- | -------------- | -------------------------------- |
|
||
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Separator 的方向 |
|
||
| `variant` | `'default' \| 'secondary' \| 'tertiary'` | `'default'` | Separator 的视觉变体 |
|
||
| `decorative` | `boolean` | `false` | 装饰性分隔线,使用 `role="none"` |
|
||
| `as` | `string` | `'hr'` | 自定义根元素标签 |
|
||
| `asChild` | `boolean` | `false` | 将属性合并到默认插槽唯一根元素 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件基础类合并;不要使用 React 的 `className`。
|
||
|
||
默认渲染为 `hr`,带 `role="separator"` 与 `data-orientation`。`orientation` 为 `vertical` 时附加 `aria-orientation="vertical"`。上游 `render` 由 `as-child` 适配。
|
||
|
||
## 相关组件
|
||
|
||
[Surface 表面](./surface) · [Card 卡片](./card)
|