说明为什么空、接下来能做什么:浅底图标块 + 标题 + 一句引导 + 可选动作。md 撑满整块、略高于正中;sm 用在右栏分区、浮层、列表里。
手机:说明为什么空、接下来能做什么:一个次要色图标 + 标题 + 一句引导 + 可选动作,不套图标块。md 撑满整块、略高于正中;sm 用在分区、面板、列表里。
状态:stable · 组件:EmptyState
引入
定位到「引入」import { EmptyState } from 'nacre'用法
定位到「用法」整页空态(md,默认):撑满父容器,父容器要有高度;动作放 action。
import { View, signal } from 'nsh'import { Button, EmptyState, TOUCH } from 'nacre'
export function EmptyStateUsage() { const refreshed = signal(false) return ( <View class={`${TOUCH ? 'w-full' : 'w-[320px] max-w-full rounded-lg border border-border'} min-h-[200px]`}> <EmptyState icon="chat" title="暂无会话" description={refreshed() ? '已刷新,暂无新会话' : '新的会话接入后会出现在这里'} action={<Button size="sm" onPress={() => refreshed.set(true)}>刷新</Button>} /> </View> )}示例
定位到「示例」小号
定位到「小号」size=“sm”:右栏分区、浮层里,不撑满、图标块小一档;一般不放动作。inline 用一行文字标记分区内的空列表。
手机:size=“sm”:放在分区、面板、列表里,不撑满,图标 28;一般不放动作。inline 用一行文字标记分区内的空列表。
import { View } from 'nsh'import { EmptyState, TOUCH } from 'nacre'
export function EmptyStateSmall() { return ( <View class={`${TOUCH ? 'w-full' : 'w-[260px] max-w-full rounded-lg border border-border'}`}> <EmptyState size="sm" icon="clipboard-list" title="暂无客诉记录" description="客户提交的客诉会出现在这里" /> </View> )}筛选无结果
定位到「筛选无结果」空是因为筛选:标题说「没有符合条件的…」,动作给「清空筛选」。
import { View, signal } from 'nsh'import { Button, EmptyState, TOUCH } from 'nacre'
export function EmptyStateFiltered() { const filters = signal(['渠道:网页', '状态:未解决']) return ( <View class={`${TOUCH ? 'w-full' : 'w-[320px] max-w-full rounded-lg border border-border'} min-h-[200px]`}> <EmptyState icon="filter" title={ filters().length > 0 ? '没有符合条件的会话记录' : '暂无会话记录' } description={ filters().length > 0 ? `$当前筛选:${filters().join('、')}` : '结束的会话会出现在这里' } action={ filters().length > 0 ? ( <Button size="sm" variant="outline" onPress={() => filters.set([])}> 清空筛选 </Button> ) : undefined } /> </View> )}加载失败
定位到「加载失败」空是因为出错:说清原因,动作给「重试」,不要写成「暂无数据」。
import { Text, View, signal } from 'nsh'import { Button, EmptyState, TEXT_SIZE, TOUCH } from 'nacre'
export function EmptyStateError() { const loaded = signal(false) return ( <View class={`${TOUCH ? 'w-full' : 'w-[320px] max-w-full rounded-lg border border-border'} min-h-[200px]`}> <If when={!loaded()} else={<Text class={`${TEXT_SIZE.body} text-foreground`}>客户资料已载入</Text>}> <EmptyState icon="warning" title="加载失败" description="网络异常,客户资料没有加载出来" action={ <Button size="sm" variant="outline" icon="refresh" onPress={() => loaded.set(true)}> 重试 </Button> } /> </If> </View> )}插画
定位到「插画」illustration 代替图标徽记放在标题上方(会话区没选会话时的欢迎示意图)。插画是装饰,在应用里画,只用语义 token;库只管位置和间距(md 下方 24、sm 下方 16)。给了插画就不画 icon。
import { View } from 'nsh'import { EmptyState, TOUCH } from 'nacre'
function Sketch() { return ( <View class="flex-row items-end gap-2"> <View class="gap-1.5 px-3 py-2 rounded-xl rounded-bl-sm bg-card border border-border"> <View class="h-1.5 w-[46px] rounded-full bg-border" /> <View class="h-1.5 w-[30px] rounded-full bg-border" /> </View> <View class="flex-row items-center gap-1 px-3 py-3 rounded-xl rounded-br-sm bg-bubble-self"> <View class="w-1.5 h-1.5 rounded-full bg-primary" /> <View class="w-1.5 h-1.5 rounded-full bg-primary" /> <View class="w-1.5 h-1.5 rounded-full bg-primary" /> </View> </View> )}
export function EmptyStateIllustration() { return ( <View class={`${TOUCH ? 'w-full' : 'w-[320px] max-w-full rounded-lg border border-border'} min-h-[220px]`}> <EmptyState testID="empty-illustration" illustration={<Sketch />} icon="chat" title="选择一个会话开始" description="左侧有 3 个进行中的会话" /> </View> )}无障碍
定位到「无障碍」- 标题与说明是普通文字,读屏按顺序读;动作是普通按钮,Tab 可达。
- 图标只是装饰,含义要写在标题里。
该用 / 不该用
定位到「该用 / 不该用」该用
- 整块区域的欢迎页用 illustration 放应用自己的插画
- 有筛选时给「清空筛选」
- 标题说清楚是什么空了(「暂无会话」)
- 说明写下一步或什么时候会有内容
不该用
- 插画里放文字(读屏读不到,换语言也不变)
- 只写「暂无数据」
- 出错和真的没有数据用同一个空态
- 在空态里放多个主按钮
API
定位到「API」EmptyState
定位到「EmptyState」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
icon |
IconName |
— | |
illustration |
JSX.Element |
— | 插画:代替图标徽记放在标题上方(会话区欢迎页那种整块示意图)。插画是装饰,留在应用里画,库只管位置与间距; 给了就不画 icon |
title * |
string |
— | |
description |
string |
— | |
action |
JSX.Element |
— | |
testID |
string |
— | |
size |
'inline' | 'sm' | 'md' |
— | md 整页(默认,撑满、上下等距居中);sm 放在右栏分区、浮层、列表里——不撑满、边距小一档,图标块小一档。inline 只显示一行标题,放在还有其它内容的列表分区 |
class |
string |
— |
* 必填