跳转到内容
Nacre
组件配色
EN

分隔线 Divider

stableDivider在画廊运行
Divider
在浏览器里运行真实组件。

1pt border 色的细线,给同一块内容里的分组;默认横向撑满宽,vertical 竖向撑满高。块与块之间用留白,不用线。

状态:stable · 组件:Divider

import { Divider } from 'nacre'

横向:父容器给宽,线撑满;上下的间距由父容器的 gap 决定。

import { Text, View } from 'nsh'
import { Divider, TEXT_SIZE } from 'nacre'
export function DividerUsage() {
return (
<View class="w-[320px] max-w-full gap-3">
<Text class={`${TEXT_SIZE.small} text-foreground`}>进行中的会话</Text>
<Divider testID="demo-divider-h" />
<Text class={`${TEXT_SIZE.small} text-foreground`}>已结束的会话</Text>
</View>
)
}

vertical:工具条里把两组操作隔开,高度跟随父行(父行要有确定高度)。

import { View } from 'nsh'
import { Divider, IconButton } from 'nacre'
export function DividerVertical() {
return (
<View class="h-7 flex-row items-center gap-2">
<IconButton icon="copy" size="sm" label="复制" />
<IconButton icon="reply" size="sm" label="引用回复" />
<Divider testID="demo-divider-v" vertical />
<IconButton icon="trash" size="sm" label="撤回" />
</View>
)
}

一行里的时间、渠道、坐席用竖线隔开,比「·」更清楚地分成几段。

import { Text, View } from 'nsh'
import { Divider, TEXT_SIZE } from 'nacre'
export function DividerMeta() {
return (
<View class="h-4 flex-row items-center gap-2">
<Text class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>11-22 14:05</Text>
<Divider vertical />
<Text class={`${TEXT_SIZE.caption} text-muted-foreground`}>网页</Text>
<Divider vertical />
<Text class={`${TEXT_SIZE.caption} text-muted-foreground`}>陈智源</Text>
</View>
)
}

同一张卡片里的两组字段用一根线分开;卡片与卡片之间不画线。

import { Text, View } from 'nsh'
import { Button, Card, Divider, SectionHeader, TEXT_SIZE } from 'nacre'
export function DividerInCard() {
return (
<Card size="sm">
<SectionHeader title="客户资料" action={<Button size="sm" variant="ghost">编辑</Button>} />
<View class="gap-1">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>姓名:林嘉怡</Text>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>账户:港股 · 美股</Text>
</View>
<Divider />
<View class="gap-1">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>最近来访:11-22 14:05</Text>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>服务坐席:陈智源</Text>
</View>
</Card>
)
}
  • 纯装饰,不进读屏树;分组的含义要靠标题或文字表达。

该用

  • 同一块内容里分组
  • 横竖两种:列表里横向,工具条里竖向
  • 竖向线的父行给定高(如 h-6)

不该用

  • 每行之间都画线(用行距、ListBox 的间隔)
  • 用线分隔两个卡片或两块区域(用留白)
  • 自己写 h-px bg-border
属性 类型 默认 说明
vertical boolean —
class string —
testID string —

* 必填