Skip to content
Nacre
Color palette
中文

EmptyState

stableEmptyStateOpen in playground
EmptyState
Runs the real component in your browser.

Explains why something is empty and what to do next: an icon on a light tile, a title, one line of guidance and an optional action. md fills the whole area, sitting slightly above center; sm goes in right-panel sections, popovers and lists.

Phone: Explains why it’s empty and what to do next: one secondary-colored icon, a title, a line of guidance and an optional action, with no icon tile. md fills the area, sitting slightly above center; sm goes in sections, sheets and lists.

Status: stable · Components: EmptyState

import { EmptyState } from 'nacre'

Full-page empty state (md, the default): fills its parent, which needs a height; put the action in 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="No chats"
description={refreshed() ? 'Up to date. No new chats.' : 'New chats will appear here'}
action={<Button size="sm" onPress={() => refreshed.set(true)}>Refresh</Button>}
/>
</View>
)
}

Use inline for a single line within a list section. size=“sm”: in right-panel sections and popovers; it does not fill the area and the icon tile is one step smaller. Usually no action.

Phone: size=“sm”: for sections, sheets and lists; it does not fill the area and its icon is 28; usually no action. inline marks an empty list inside a section with one line of text.

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="No cases"
description="Cases submitted by customers will appear here"
/>
</View>
)
}

Empty because of filters: the title says “No … match the filters”, and the action is “Clear filters”.

import { View, signal } from 'nsh'
import { Button, EmptyState, TOUCH } from 'nacre'
export function EmptyStateFiltered() {
const filters = signal(['Channel: Web', 'Status: Unresolved'])
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
? 'No chat records match the filters'
: 'No chat records'
}
description={
filters().length > 0
? `$Current filters: ${filters().join(', ')}`
: 'Ended chats will appear here'
}
action={
filters().length > 0 ? (
<Button size="sm" variant="outline" onPress={() => filters.set([])}>
Clear filters
</Button>
) : undefined
}
/>
</View>
)
}

Empty because of an error: say what went wrong and offer “Retry”; don’t write “No data”.

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`}>Customer profile loaded</Text>}>
<EmptyState
icon="warning"
title="Failed to load"
description="Network error: the customer profile didn’t load"
action={
<Button size="sm" variant="outline" icon="refresh" onPress={() => loaded.set(true)}>
Retry
</Button>
}
/>
</If>
</View>
)
}

illustration replaces the icon tile above the title (the welcome sketch shown when no chat is selected). The illustration is decorative, drawn in the app with semantic tokens only; the library handles only its position and spacing (24 below at md, 16 at sm). With an illustration, icon is not drawn.

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="Pick a chat to start"
description="3 chats in progress on the left"
/>
</View>
)
}
  • The title and description are plain text, read in order; the action is a regular button, reachable with Tab.
  • The icon is decorative; put its meaning in the title.

Do

  • Use illustration for the app’s own artwork on a full-area welcome screen
  • Offer “Clear filters” when filters are applied
  • Say what is empty in the title (“No chats”)
  • Use the description for the next step or when content will appear

Don’t

  • Put text inside the illustration (screen readers can’t read it and it doesn’t change with the language)
  • Write only “No data”
  • Use the same empty state for errors and for truly having no data
  • Put more than one primary button in an empty state

Property descriptions follow the Chinese source comments.

Prop Type Default Description
icon IconName —
illustration JSX.Element — 插画:代替图标徽记放在标题上方(会话区欢迎页那种整块示意图)。插画是装饰,留在应用里画,库只管位置与间距; 给了就不画 icon
title * string —
description string —
action JSX.Element —
testID string —
size 'inline' | 'sm' | 'md' — md 整页(默认,撑满、上下等距居中);sm 放在右栏分区、浮层、列表里——不撑满、边距小一档,图标块小一档。inline 只显示一行标题,放在还有其它内容的列表分区
class string —

* required