描述列表 DescriptionList
只读的 label / value 行:右栏客户资料、工单详情、通话信息、合并预览。标签列定宽灰字,值 12pt 可折行,可带复制钮;空值显示占位。不是表单字段,可编辑的用 Field。
状态:experimental · 组件:DescriptionList、DescriptionItem、CopyButton、RevealableValue、CopyText
引入
定位到「引入」import { DescriptionList, DescriptionItem, CopyButton, RevealableValue, CopyText } from 'nacre'用法
定位到「用法」纯文字的值给 value(空串显示 emptyText,默认 --);给 copyValue 后点整段值就复制:悬停淡底并露出复制图标,复制后换成对勾 1.5 秒。标签宽与行距在 DescriptionList 上定一次。
import { View } from 'nsh'import { DescriptionItem, DescriptionList } from 'nacre'
export function DescriptionListUsage() { return ( <View class="w-[320px] max-w-full"> <DescriptionList testID="desc-usage"> <DescriptionItem label="会话编号" value="C202611050001" copyValue="C202611050001" testID="desc-usage-id" copyTestID="desc-usage-copy" /> <DescriptionItem label="接入渠道" value="长桥 App" /> <DescriptionItem label="开始时间" value="2026-11-05 09:12:30" /> <DescriptionItem label="结束时间" value={undefined} testID="desc-usage-empty" /> </DescriptionList> </View> )}示例
定位到「示例」查看、收起与复制脱敏字段
定位到「查看、收起与复制脱敏字段」传入当前可显示的 value 和 masked。请求中 loading 禁用查看按钮,收起时复制入口随明文撤下。行菜单负责切换时,用 indicator 显示状态。权限、请求与客户切换由应用管理。
import { signal } from 'nsh'import { RevealableValue } from 'nacre'
export function RevealableContact() { const masked = signal(true) return ( <RevealableValue testID="demo-secret" copyTestID="demo-secret-copy" copyable value={masked() ? '+852 6****42' : '+852 61234542'} masked={masked()} toggleLabel={masked() ? '查看号码' : '隐藏号码'} onToggle={() => masked.set(!masked())} /> )}自定义值、长文与脱敏
定位到「自定义值、长文与脱敏」标签、链接这类值放 children,横排可折行;长文直接折行,标签停在首行。masked 的值不出复制钮(复制脱敏值没意义),读屏名补「已脱敏」;查看明文、拨号这类动作由应用放在 children 里。
import { View } from 'nsh'import { Button, DescriptionItem, DescriptionList, Tag } from 'nacre'
export function DescriptionListRich() { return ( <View class="w-[320px] max-w-full"> <DescriptionList testID="desc-rich"> <DescriptionItem label="状态" testID="desc-rich-status"> <Tag variant="dot" size="md" label="处理中" tone="info" /> <Tag label="重大" tone="destructive" /> </DescriptionItem> <DescriptionItem label="合并的工单"> <Button variant="link" size="inline" onPress={() => {}}> T20261101002 </Button> <Button variant="link" size="inline" onPress={() => {}}> T20261101007 </Button> </DescriptionItem> <DescriptionItem label="客户诉求" value="客户反馈港股打新中签后资金未按时到账,要求说明原因并补偿利息损失。" testID="desc-rich-long" /> <DescriptionItem label="手机号" value="138****5678" copyValue="138****5678" masked testID="desc-rich-masked" copyTestID="desc-rich-masked-copy" /> </DescriptionList> </View> )}紧凑与单行截断
定位到「紧凑与单行截断」density=“compact” 行高 18、行间 2(默认 comfortable 行高 20、行间 6,文字行与带标签的行一样高),放进预览块、卡片里的几行纯文字;有 Tag 的行用默认;英文长标签要么放宽 labelWidth,要么 truncateLabel(单行截断、悬停看全文)。编号、号码这类不该折行的值用 truncate。
import { View } from 'nsh'import { DescriptionItem, DescriptionList } from 'nacre'
export function DescriptionListDensity() { return ( <View class="flex-row flex-wrap gap-8"> <View class="w-[300px] max-w-full rounded-lg bg-secondary px-3 py-2.5"> <DescriptionList testID="desc-compact" density="compact" labelWidth={92}> <DescriptionItem label="主工单" value="T20261101002" /> <DescriptionItem label="处理人" value="林嘉怡" /> <DescriptionItem label="关联记录数" value="12" /> </DescriptionList> </View> <View class="w-[260px] max-w-full"> <DescriptionList testID="desc-truncate" labelWidth={96} truncateLabel> <DescriptionItem label="呼叫中心通话编号" value="a1b2c3d4-e5f6-7890-abcd-ef1234567890" copyValue="a1b2c3d4-e5f6-7890-abcd-ef1234567890" truncate testID="desc-truncate-value" /> <DescriptionItem label="客户号码" value="+852 9123 4567" copyValue="+852 9123 4567" truncate /> </DescriptionList> </View> </View> )}点文字复制 CopyText
定位到「点文字复制 CopyText」编号、ID、单元格里的值:整段是按钮,点文字或复制图标都能复制。悬停淡底、按下深一档,复制后图标换成对勾 1.5 秒。内容里还有别的按钮(显示明文的眼睛)时放在 CopyText 外面。
import { Text, View } from 'nsh'import { CopyText, TEXT_SIZE } from 'nacre'
export function CopyTextUsage() { return ( <View class="flex-row items-center gap-4"> <CopyText value="1006664209" label="复制客户 ID" testID="copy-text-usage"> <Text class={`${TEXT_SIZE.body} tabular-nums text-foreground`}>1006664209</Text> </CopyText> <CopyText value="H17225823" testID="copy-text-account"> <Text class={`${TEXT_SIZE.small} tabular-nums text-muted-foreground`}>H17225823</Text> </CopyText> </View> )}单独的复制钮 CopyButton
定位到「单独的复制钮 CopyButton」编号、表格单元格旁的复制:默认常显;reveal 在桌面悬停或聚焦时显示,手机保持可见。需要记录失败原因时传 onError。
手机:编号、单元格旁的复制钮在手机上常显,点按复制并提示。
import { View, signal } from 'nsh'import { Button, CopyButton, Tag } from 'nacre'
export function CopyButtonUsage() { const chatId = signal('C202611050001') return ( <View class="group flex-row items-center gap-1"> <Tag label={chatId()} /> <CopyButton value={chatId()} testID="copy-button-usage" /> <CopyButton value={chatId()} label="复制会话编号" reveal testID="copy-button-reveal" /> <Button size="sm" variant="ghost" testID="copy-next-chat" onPress={() => chatId.set(chatId().endsWith('1') ? 'C202611050002' : 'C202611050001')}> 切换会话 </Button> </View> )}键盘
定位到「键盘」| 键 | 行为 |
|---|---|
| Tab | 聚焦到复制钮(reveal 的钮聚焦时显示) |
| Space / Return | 复制,读屏名换成「已复制」 |
无障碍
定位到「无障碍」- 标签与值都是文字,读屏按顺序读;值为空时读占位(
--)。 - 复制钮的读屏名默认「复制」,同一屏有多个时传 copyLabel 写清复制什么(「复制会话编号」)。
- masked 的值读屏名后补「已脱敏」,不靠星号让人猜。
该用 / 不该用
定位到「该用 / 不该用」该用
- 右栏、详情、预览里的只读字段用它排
- 同一组行用一个 DescriptionList 定标签宽
- 英文长标签放宽 labelWidth 或 truncateLabel,并在英文 / 日文下看一眼
不该用
- 当表单用(可编辑的用 Field)
- 自己写剪贴板与对勾(用 copyValue 或 CopyButton)
- 给脱敏值放复制钮
API
定位到「API」DescriptionList
定位到「DescriptionList」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
labelWidth |
number |
— | 标签列宽(pt),默认 72;中文四字标签 64–72,英文长标签放宽到 96 或用 truncateLabel |
density |
'compact' | 'comfortable' |
'comfortable' |
comfortable(默认)行高 20(文字行与带标签的行一样高)、行间 6,右栏与详情;compact 行高 18、行间 2,预览块、卡片里的几行纯文字(有 Tag 的行用默认) |
truncateLabel |
boolean |
— | 标签单行截断、悬停看全文;默认放不下时折行(英文长标签不被截掉) |
testID |
string |
— | |
class |
string |
— | |
children |
JSX.Element |
— |
* 必填
DescriptionItem
定位到「DescriptionItem」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
label * |
string |
— | |
value |
string |
— | 纯文字的值:12pt、数字等宽,可折行;空串 / undefined 显示 emptyText(写了这个属性就按文字值排,哪怕值是 undefined)。和 children 二选一 |
children |
JSX.Element |
— | 自定义的值(标签、链接、多段),横排可折行;给了 value 时不渲染 |
copyValue |
string |
— | 值后跟一个小复制钮(悬停整行或键盘聚焦才出现,复制后打勾 1.5 秒),复制的是这个值;空串不出 |
copyLabel |
string |
— | 复制钮的读屏名,默认「复制 + 标签」(「复制客户 ID」):同一列表里多个复制钮读屏分得开 |
emptyText |
string |
'--' |
空值占位,默认 --(弱化灰) |
masked |
boolean |
— | 值已脱敏(含 *):不出复制钮,读屏名补「已脱敏」 |
truncate |
boolean |
— | value 单行截断、悬停看全文(编号、号码这类不该折行的值) |
labelWidth |
number |
— | 只这一行改标签宽(一般在 DescriptionList 上统一给) |
testID |
string |
— | 值的 testID:value 时在文字上,children 时在值容器上 |
copyTestID |
string |
— |
* 必填
CopyButton
定位到「CopyButton」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
value * |
string |
— | 写进剪贴板的值;空串不复制 |
label |
string |
— | 读屏名与悬停提示,默认「复制」 |
copiedLabel |
string |
— | 复制成功后 1.5 秒内的读屏名,默认「已复制」 |
onError |
(error: unknown) => void |
— | 复制失败时通知调用方;不会显示成功对勾 |
testID |
string |
— | |
reveal |
boolean |
— | 桌面端所在 group 悬停或自己聚焦时出现;复制后的对勾保持可见。手机一直显示 |
* 必填
RevealableValue
定位到「RevealableValue」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
value * |
string |
— | 当前允许显示的内容。请求与权限由调用方管理。 |
masked * |
boolean |
— | |
toggleLabel |
string |
— | |
onToggle |
() => void |
— | |
indicator |
boolean |
— | 由行菜单负责切换时,用非交互图标显示当前状态。 |
loading |
boolean |
— | |
copyable |
boolean |
— | |
hoverCopy |
boolean |
— | |
truncate |
boolean |
— | |
textClass |
string |
— | |
testID |
string |
— | |
copyTestID |
string |
— |
* 必填
CopyText
定位到「CopyText」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
value * |
string |
— | 写进剪贴板的值;空串时只显示内容、不可点 |
children * |
JSX.Element |
— | 显示的内容(通常是一段 Text);字号、颜色、截断由调用方给 |
label |
string |
— | 读屏名:「复制 客户 ID」;默认「复制」 |
copiedLabel |
string |
— | 复制成功后 1.5 秒内的读屏名与提示,默认「已复制」 |
testID |
string |
— | |
class |
string |
— | 根节点的布局逃生口(flex、宽、外边距),不改颜色 |
* 必填