Patterns
Empty and loading states
What a screen shows before it has anything to show: the shape of the content while it loads, a first step when there is nothing yet, and a way back when a search finds nothing.
Show the shape while loading
Draw the real frame (header, columns, card outlines) and put soft bones where text will land, each about as wide as what it stands for. When the data arrives it fills the same boxes, so nothing jumps.
Bones breathe on opacity only. With reduced motion or the Motion switch off they stay still. The region carries aria-busy, and one status line tells screen readers what is loading.
- Under 300 ms, show nothing: a flash of bones is worse than a short wait.
- Over 10 seconds, replace the bones with words and a way to cancel or retry.
- Never use a spinner for a whole page of content; keep spinners for buttons that are working.
| Task | Owner | Priority | Due |
|---|---|---|---|
| Write the November release notes | Farah Haddad | High | Tue 17 Nov |
| Review the pricing page copy | Ana Ribeiro | Medium | Wed 18 Nov |
| Fix the invite link expiry | Dara Novak | High | Thu 19 Nov |
| Record the onboarding walkthrough | Ben Okafor | Low | Fri 20 Nov |
4 tasks due this week
'use client'
import { useState } from 'react'
import { CalendarDays } from 'lucide-react'
import { Badge } from '@/nacre/components/Badge'
import { SegmentedControl } from '@/nacre/components/SegmentedControl'
import { Table } from '@/nacre/components/Table'
// One table, three states. Loading keeps the real header and draws bones the size of real cells, so nothing jumps
// when the rows arrive. aria-busy marks the region and one polite status line says what is happening.
type State = 'loading' | 'loaded' | 'empty'
const COLUMNS = [
{ key: 'task', header: 'Task' },
{ key: 'owner', header: 'Owner' },
{ key: 'priority', header: 'Priority' },
{ key: 'due', header: 'Due', align: 'end' as const },
]
const TASKS = [
{ id: 'q4-21', task: 'Write the November release notes', owner: 'Farah Haddad', priority: 'High', due: 'Tue 17 Nov' },
{ id: 'q4-24', task: 'Review the pricing page copy', owner: 'Ana Ribeiro', priority: 'Medium', due: 'Wed 18 Nov' },
{ id: 'q4-27', task: 'Fix the invite link expiry', owner: 'Dara Novak', priority: 'High', due: 'Thu 19 Nov' },
{ id: 'q4-30', task: 'Record the onboarding walkthrough', owner: 'Ben Okafor', priority: 'Low', due: 'Fri 20 Nov' },
]
// Each bone is as wide and tall as the content it stands for.
const BONES = {
task: 'h-3 w-[12rem]',
owner: 'h-3 w-[6rem]',
priority: 'h-5 w-[3.5rem]',
due: 'ms-auto h-3 w-[5rem]',
} as const
const TONES = { High: 'warning', Medium: 'neutral', Low: 'neutral' } as const
const STATUS: Record<State, string> = { loading: 'Loading tasks', loaded: '4 tasks due this week', empty: 'No tasks due this week' }
export function LoadingStates() {
const [state, setState] = useState<State>('loaded')
const rows =
state === 'empty' ? []
: state === 'loading' ? [0, 1, 2, 3].map((n) => ({
id: `bone-${n}`,
cells: {
task: <span aria-hidden="true" className={`nx-skeleton max-w-full ${BONES.task}`} />,
owner: <span aria-hidden="true" className={`nx-skeleton max-w-full ${BONES.owner}`} />,
priority: <span aria-hidden="true" className={`nx-skeleton max-w-full ${BONES.priority}`} />,
due: <span aria-hidden="true" className={`nx-skeleton max-w-full ${BONES.due}`} />,
},
}))
: TASKS.map((t) => ({
id: t.id,
cells: { task: t.task, owner: t.owner, priority: <Badge tone={TONES[t.priority as keyof typeof TONES]} size="sm">{t.priority}</Badge>, due: t.due },
}))
return (
<div className="flex w-full max-w-[44rem] flex-col gap-4">
<SegmentedControl
label="Data state"
value={state}
onValueChange={(v) => setState(v as State)}
options={[{ value: 'loading', label: 'Loading' }, { value: 'loaded', label: 'Loaded' }, { value: 'empty', label: 'Empty' }]}
/>
<div data-testid="loading-demo" aria-busy={state === 'loading'} className="rounded-lg bg-surface p-2 shadow-1">
<Table
caption="Due this week"
columns={COLUMNS}
rows={rows}
empty={
<span className="flex flex-col items-center gap-2 text-center">
<CalendarDays size={20} strokeWidth={1.5} aria-hidden="true" className="text-icon-muted" />
<span className="text-label text-fg-strong">Nothing due this week</span>
<span className="text-caption text-fg-muted">Tasks due before Sunday 22 November show here.</span>
</span>
}
/>
</div>
<p role="status" className="sr-only">{STATUS[state]}</p>
</div>
)
}
Empty is a starting point
A new project has no tasks yet. Say what will live here and offer the first action as the primary button. A small illustration may use the iris colours, since illustrations are one of the two places they belong.
A search with no results is different: repeat the query so people can spot a typo, and offer the way back.
- DoName the thing: Add the first task to Mobile onboarding.
- AvoidWrite a generic line such as No data.
- DoOffer one primary action and at most one secondary.
- AvoidFill the empty state with every action the screen has.
Add the first task to Mobile onboarding
Tasks you add here show on the board and in everyone's week.
No tasks match “invoice export”
Check the spelling, or clear the search to see all 19 tasks in Q4 launch.
'use client'
import { useEffect, useRef, useState } from 'react'
import { Plus, Search, Upload } from 'lucide-react'
import { Button } from '@/nacre/components/Button'
// Two kinds of empty. A new project is a starting point: say what goes here and offer the first action. A search
// with no results is a dead end to back out of: repeat the query and offer the way back. When the button that was
// pressed goes away, focus moves to the heading of what replaced it, which shows the usual focus-visible ring.
function Illustration() {
// Iris colours are allowed here: this is an illustration.
return (
<svg viewBox="0 0 120 80" aria-hidden="true" className="h-20 w-[7.5rem]">
<rect x="14" y="14" width="92" height="56" rx="10" fill="var(--nx-surface)" stroke="var(--nx-line)" />
<rect x="26" y="28" width="40" height="6" rx="3" fill="var(--nx-iris-lilac)" />
<rect x="26" y="42" width="60" height="6" rx="3" fill="var(--nx-iris-sky)" />
<rect x="26" y="56" width="28" height="6" rx="3" fill="var(--nx-iris-peach)" />
<circle cx="96" cy="16" r="10" fill="var(--nx-iris-rose)" />
</svg>
)
}
const IMPORTED = ['Draft the welcome screen copy', 'Pick the onboarding illustrations', 'Write the permission prompts']
export function EmptyStates() {
const [added, setAdded] = useState<'' | 'new' | 'csv'>('')
const [query, setQuery] = useState('invoice export')
const newHeading = useRef<HTMLHeadingElement>(null)
const searchHeading = useRef<HTMLHeadingElement>(null)
const touched = useRef<'new' | 'search' | null>(null)
useEffect(() => {
if (touched.current === 'new') newHeading.current?.focus()
if (touched.current === 'search') searchHeading.current?.focus()
touched.current = null
}, [added, query])
const add = (how: '' | 'new' | 'csv') => {
touched.current = 'new'
setAdded(how)
}
return (
<div className="grid w-full max-w-[44rem] gap-4 md:grid-cols-2">
<div className="flex flex-col items-center gap-4 rounded-lg bg-surface p-6 text-center shadow-1">
{added ? (
<>
<h3 ref={newHeading} tabIndex={-1} className="rounded-xs text-heading-3 text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus">Mobile onboarding</h3>
{added === 'csv' && <p className="text-body text-fg-muted">3 tasks imported from onboarding.csv.</p>}
<ul className="m-0 flex w-full flex-col gap-2 p-0 text-start">
{(added === 'csv' ? IMPORTED : IMPORTED.slice(0, 1)).map((t) => (
<li key={t} className="list-none rounded-sm bg-sunken px-3 py-2 text-body text-fg-strong">{t}</li>
))}
</ul>
<Button variant="ghost" size="sm" onClick={() => add('')}>Reset the demo</Button>
</>
) : (
<>
<Illustration />
<h3 ref={newHeading} tabIndex={-1} className="rounded-xs text-heading-3 text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus">Add the first task to Mobile onboarding</h3>
<p className="text-body text-fg-muted">Tasks you add here show on the board and in everyone's week.</p>
<div className="flex flex-wrap justify-center gap-2">
<Button leading={<Plus size={16} aria-hidden="true" />} onClick={() => add('new')}>New task</Button>
<Button variant="secondary" leading={<Upload size={16} aria-hidden="true" />} onClick={() => add('csv')}>Import from CSV</Button>
</div>
</>
)}
</div>
<div className="flex flex-col items-center gap-4 rounded-lg bg-surface p-6 text-center shadow-1">
<span className="inline-grid size-10 place-items-center rounded-full bg-sunken text-icon-muted"><Search size={18} aria-hidden="true" /></span>
{query ? (
<>
<h3 ref={searchHeading} tabIndex={-1} className="rounded-xs text-heading-3 text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus">No tasks match “{query}”</h3>
<p className="text-body text-fg-muted">Check the spelling, or clear the search to see all 19 tasks in Q4 launch.</p>
<Button variant="secondary" onClick={() => { touched.current = 'search'; setQuery('') }}>Clear search</Button>
</>
) : (
<>
<h3 ref={searchHeading} tabIndex={-1} className="rounded-xs text-heading-3 text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus">Search cleared</h3>
<p className="text-body text-fg-muted">All 19 tasks in Q4 launch are showing again.</p>
<Button variant="ghost" size="sm" onClick={() => { touched.current = 'search'; setQuery('invoice export') }}>Reset the demo</Button>
</>
)}
</div>
</div>
)
}
First run
A workspace on its first day is a short checklist. Progress shows how far along it is, Steps shows what comes next, and one button does the next step. Done steps stay visible so the list reads as progress, not as chores.
2 steps left, about 3 minutes.
- Create the workspace, doneNacre, for six people.
- Invite your team, doneFive invites sent, four accepted.
- Connect your calendarMeetings show next to tasks.
- Create your first projectStart from a template or a blank board.
'use client'
import { useState } from 'react'
import { Button } from '@/nacre/components/Button'
import { Progress } from '@/nacre/components/Progress'
import { Steps } from '@/nacre/components/Steps'
// First run: the empty workspace is a checklist, not a blank page. Progress says how far, Steps says what is next,
// and one primary button does the next thing.
const STEPS = [
{ label: 'Create the workspace', description: 'Nacre, for six people.' },
{ label: 'Invite your team', description: 'Five invites sent, four accepted.' },
{ label: 'Connect your calendar', description: 'Meetings show next to tasks.' },
{ label: 'Create your first project', description: 'Start from a template or a blank board.' },
]
const NEXT = ['Create the workspace', 'Invite your team', 'Connect Google Calendar', 'Create a project']
export function FirstRun() {
const [done, setDone] = useState(2)
const finished = done >= STEPS.length
return (
<div className="flex w-full max-w-[26rem] flex-col gap-5 rounded-lg bg-surface p-6 shadow-1">
<Progress label="Workspace setup" value={done} max={STEPS.length} showValue hint={finished ? 'All set. Welcome to Nacre.' : `${STEPS.length - done} steps left, about 3 minutes.`} tone={finished ? 'success' : 'neutral'} />
<Steps label="Setup steps" steps={STEPS} current={done} orientation="vertical" />
{finished ? (
<Button variant="secondary" onClick={() => setDone(2)}>Reset the demo</Button>
) : (
<Button onClick={() => setDone((d) => d + 1)}>{NEXT[done]}</Button>
)}
</div>
)
}