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
API
定位到「API」Divider
定位到「Divider」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
vertical |
boolean |
— | |
class |
string |
— | |
testID |
string |
— |
* 必填