# Separator

用一条水平或垂直线分隔各组内容。

在读者应当视为彼此独立的内容组之间使用分隔线，比如个人资料的标题和下方的简介。

```vue title="basic.vue"
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <div data-slot="stack">
    <div data-slot="stack">
      <h3>Hollis Grant</h3>
      <p data-slot="hint">hollis@example.com</p>
    </div>
    <Separator />
    <p>
      Designs the billing and onboarding flows, and reviews every new pricing
      page.
    </p>
  </div>
</template>
```

用屏幕阅读器阅读这份个人资料。它会在 Hollis Grant 的姓名和邮箱，与下方的简介之间播报一条分隔线。

## 安装
```bash
npm install @ui-sdk/vue @ui-sdk/core
```

## 用法
导入分隔线，把它放在两组内容之间：

```vue
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <section>
    <h2>Hollis Grant</h2>
    <Separator />
    <p>Designs the billing and onboarding flows.</p>
  </section>
</template>
```

## 自己构建
`@ui-sdk/vue/separator` 自带一个现成的 Separator。如果你想用自己的名字构建自己的版本，从 `@ui-sdk/core` 里的 `separator` 原语（primitive）开始：

```ts title="divider.ts"
import { separator } from "@ui-sdk/core/separator"
import { createParts } from "@ui-sdk/vue/primitive"

const { Root: Divider } = createParts(separator, { root: "div" })

export { Divider }
```

```vue
<template>
  <Divider orientation="vertical" />
</template>
```

`Divider` 保留现成 Separator 的行为、状态和数据属性：`separator` 角色、`aria-orientation` 和 `data-orientation`。更多内容见[渲染](/docs/vue/rendering)和[自定义部件](/docs/vue/custom-parts)。

## 垂直
要在一行中的各项之间画线，设置 `orientation="vertical"`。它会占满这一行的高度。

```vue title="vertical.vue"
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <nav aria-label="Legal" data-slot="row">
    <a href="#">Privacy</a>
    <Separator orientation="vertical" />
    <a href="#">Terms</a>
    <Separator orientation="vertical" />
    <a href="#">Cookies</a>
  </nav>
</template>
```

横向阅读 Privacy、Terms 和 Cookies。屏幕阅读器会在每个链接之间播报一条垂直分隔线。

## 堆叠内容
垂直分隔线会拉伸到这一行中最高的项，因此能跨越一个数字和它的标签。

```vue title="menu.vue"
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <div data-slot="row">
    <div data-slot="stack">
      <span>24</span>
      <span data-slot="hint">Projects</span>
    </div>
    <Separator orientation="vertical" />
    <div data-slot="stack">
      <span>1,280</span>
      <span data-slot="hint">Followers</span>
    </div>
    <Separator orientation="vertical" />
    <div data-slot="stack">
      <span>312</span>
      <span data-slot="hint">Following</span>
    </div>
  </div>
</template>
```

比较这些线与统计数据。每条线都贯穿 Projects、Followers 和 Following 的整个高度。

## 列表行
在每两行之间放一条分隔线，把明细列表分隔开。

```vue title="list.vue"
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <div data-slot="stack">
    <dl>
      <dt>Plan</dt>
      <dd>Pro</dd>
    </dl>
    <Separator />
    <dl>
      <dt>Seats</dt>
      <dd>8 of 10</dd>
    </dl>
    <Separator />
    <dl>
      <dt>Renews</dt>
      <dd>December 1, 2026</dd>
    </dl>
  </div>
</template>
```

用屏幕阅读器阅读套餐详情。它会在 Plan、Seats 和 Renews 之间播报一条分隔线。

## 装饰性
当线条不增加信息时，设置 `decorative`。这里的“or”一词已经说明两种登录方式是分开的，所以屏幕阅读器会跳过这些线条。

```vue title="decorative.vue"
<script setup lang="ts">
import { Separator } from "@ui-sdk/vue/separator"
</script>

<template>
  <div data-slot="stack">
    <button type="button" data-variant="solid">Sign In with Passkey</button>
    <div data-slot="row">
      <Separator decorative />
      <span>or</span>
      <Separator decorative />
    </div>
    <button type="button">Email Me a Link</button>
  </div>
</template>
```

用屏幕阅读器从 Sign In with Passkey 读到 Email Me a Link。它会读出“or”，并跳过这些线条。

装饰性分隔线会得到 `role="none"`，没有 `aria-orientation`。它保留 `data-orientation` 用于设置样式。

## 自定义渲染
使用 `#render` 插槽换成不同的元素，比如 `<hr>`，并把提供的 `props` 绑定到它上面。读取分隔线状态的方法见[部件与组合](/docs/vue/parts-and-composition)。

## 样式
分隔线不带样式。给它一个背景，水平时给它高度，垂直时给它宽度，并用 `data-orientation` 区分两者。垂直的线用 `align-self: stretch` 占满所在行的高度。

分隔线的 `data-slot` 是 `separator`，它的 `data-orientation` 列在[数据属性](https://ui-sdk.cn/docs/vue/components/separator#data-attributes)下。

## 数据属性
### Separator
`[data-slot="separator"]`

- `data-orientation` (`horizontal`, `vertical`): Which way the line runs.

## API 参考
props 与下面相同。

### Separator
- `orientation?` (`SeparatorOrientation`): Which way the line runs. A vertical separator divides items in a row.
- `decorative?` (`boolean`): Hides the separator from assistive technology with `role="none"`, for a line that's only visual. Leave it off when the separator divides content a screen reader should hear as separate, like groups of menu items.
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.

### 状态
渲染函数和基于状态的类名会收到什么。

- `orientation` (`SeparatorOrientation`): Which way the line runs.

## 无障碍
组件遵循 [WAI-ARIA separator 角色](https://www.w3.org/TR/wai-aria-1.2/#separator)。分隔线用来分开屏幕阅读器应当分别读出的内容，它通过 `role="separator"` 和对应的 `aria-orientation` 播报。装饰性分隔线只是视觉元素：它得到 `role="none"`，所以屏幕阅读器会跳过它。只有周围内容已经表达了这种分隔时，才使用 `decorative`。无论哪种情况，分隔线都不会获得焦点，所以 Tab 会越过它。

### 经过测试的行为
下面每一行都是一项自动化测试。

- A separator is announced with its orientation.
- A separator can't be focused.
- A separator carries its orientation for styling.

Runs in React、Vue 和 web components.
