# 分隔线

## 使用方法

`Divider` 用一条细线把相关内容分成若干区块，适合在表单、列表或设置项之间做视觉上的划分。需要为分区标注名称时，也可以把简短文字放在线条中间：

```vue
<script setup lang="ts">
import { Divider } from '@astryx-vue/core/Divider'
</script>

<template>
  <Divider label="或" />
</template>
```

### 结构

- **分隔组**: 把一条或两条线排在可选标签周围的分隔组。
- **线**: 画出的线段。有标签时会再画一段。
- **标签**: 显示在两段线之间的可选内容。

## 最佳实践

| 指引 | 实践 |
| --- | --- |
| 推荐 | 相关内容区块之间使用 `subtle` 分隔线；需要更醒目的边界时，改用 `strong`。 |
| 推荐 | 分区需要一个可见的类别标题时，为分隔线添加 `label`，文字会居中显示在线条上。 |
| 避免 | 避免密集使用分隔线：能用留白和排版区分内容时，优先使用间距而不是线条。 |

## 示例

### 通栏

分隔线穿过卡片内边距，从一边拉到另一边，放在明细和合计之间。

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Divider } from '@astryx-vue/core/Divider'
import { Section } from '@astryx-vue/core/Section'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Section variant="transparent" width="100%">
    <Card :width="400">
      <VStack :gap="3">
        <Text type="label">
          Order Summary
        </Text>
        <HStack h-align="between">
          <Text type="body">
            3 items
          </Text>
          <Text type="body">
            $127.00
          </Text>
        </HStack>
        <Divider is-full-bleed />
        <HStack h-align="between">
          <Text type="body">
            Shipping
          </Text>
          <Text type="body">
            $7.99
          </Text>
        </HStack>
        <HStack h-align="between">
          <Text type="body">
            Tax
          </Text>
          <Text type="body">
            $10.16
          </Text>
        </HStack>
        <Divider is-full-bleed />
        <HStack h-align="between">
          <Text type="label">
            Total
          </Text>
          <Text type="label">
            $145.15
          </Text>
        </HStack>
      </VStack>
    </Card>
  </Section>
</template>
```

### 变体

带「or」的分隔线用来表示另一种登录方式，强调线放在说明文字前面。

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Divider } from '@astryx-vue/core/Divider'
import { Section } from '@astryx-vue/core/Section'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Section variant="transparent" width="100%">
    <Card :width="400">
      <VStack :gap="3">
        <VStack :gap="1">
          <Text type="label">
            Sign in with email
          </Text>
          <Text type="body">
            Enter your email and password to access your account.
          </Text>
        </VStack>
        <Divider label="or" />
        <VStack :gap="1">
          <Text type="label">
            Sign in with SSO
          </Text>
          <Text type="body">
            Use your company credentials to sign in automatically.
          </Text>
        </VStack>
        <Divider variant="strong" />
        <Text color="secondary" type="supporting">
          By signing in, you agree to our Terms of Service and Privacy Policy.
        </Text>
      </VStack>
    </Card>
  </Section>
</template>
```

### 垂直

并排的指标之间用垂直分隔线隔开。

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Divider } from '@astryx-vue/core/Divider'
import { Section } from '@astryx-vue/core/Section'
import { HStack, StackItem, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const metrics = [
  { label: 'Revenue', value: '$24,500', delta: '+12% vs last month' },
  { label: 'Users', value: '1,240', delta: '+8% vs last month' },
  { label: 'Conversion', value: '3.2%', delta: '-0.5% vs last month' },
]
</script>

<template>
  <Section variant="transparent" width="100%">
    <Card>
      <HStack align="stretch" :gap="4">
        <template v-for="(metric, index) in metrics" :key="metric.label">
          <Divider v-if="index > 0" orientation="vertical" style="align-self: stretch; height: auto" />
          <StackItem size="fill">
            <VStack :gap="1">
              <Text type="label">
                {{ metric.label }}
              </Text>
              <Text type="label">
                {{ metric.value }}
              </Text>
              <Text color="secondary" type="supporting">
                {{ metric.delta }}
              </Text>
            </VStack>
          </StackItem>
        </template>
      </HStack>
    </Card>
  </Section>
</template>
```

## 属性

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | 分隔线的方向，垂直分隔线适合放在固定高度的行内。 |
| `label` | `string \| number` | — | 显示在分隔线中间的文字，同时作为分隔线的无障碍名称。数字 0 会显示出来，空字符串不显示。 |
| `variant` | `'subtle' \| 'strong'` | `'subtle'` | 线条的视觉强弱，strong 使用强调边框色，适合需要明显边界的场景。 |
| `isFullBleed` | `boolean` | `false` | 为 true 时，分隔线会越过容器内边距，延伸到容器边缘。 |

## 插槽

- `label`：分隔线中间的富文本内容，会替代 `label` 属性的纯文字。

## 主题

```css
.my-divider {
  --astryx-divider-color-subtle: #00000014;
}
```

- `--astryx-divider-color-subtle`：`subtle` 线条颜色。
- `--astryx-divider-color-strong`：`strong` 线条颜色。
- `--astryx-divider-label-color`：文字颜色。
- `--astryx-border-width`：线条粗细。
