# Empty State

> What a view shows when it's empty, after a failure, or when access is refused, for a whole page or inside a table or list.

Page: https://uicontext.com/docs/components/empty-state

Group: Primitives.

## When to use

What a view shows when it's empty, after a failure, or when access is refused, for a whole page or inside a table or list. Use [Skeleton](https://uicontext.com/docs/components/skeleton.md) instead when the content is on its way, not missing.

## Usage

```ts
import { EmptyState } from "./ui/uicontext/components/States.ts"

export const IssuesBody = <M>(h: Html.H<M>, issues: ReadonlyArray<string>) =>
	issues.length === 0
		? EmptyState(h, { title: "No open issues", hint: "Issues you're assigned show here." })
		: h.ul.children(issues.map((title) => h.li.key(title).children(title)))
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Loading, empty, failed and no access

The example the page opens with: Empty State in “Loading, empty, failed and no access”.

This example also uses Segmented Control and Skeleton. Install them too:

```sh
npx shadcn@latest add checkfu/uicontext/segmented-control checkfu/uicontext/skeleton
```

```ts title="src/demo.ts" source="www/src/examples/empty-state/demo.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { Button } from "./ui/uicontext/components/Button.ts"
import { EmptyState, ErrorBanner } from "./ui/uicontext/components/States.ts"
import { SkeletonList } from "./ui/uicontext/components/Skeleton.ts"
import { SegmentedControl } from "./ui/uicontext/components/SegmentedControl.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	stack: { display: "grid", gap: space.lg, inlineSize: "min(100%, 34rem)" },
	note: { margin: 0, minBlockSize: "1.4em", fontSize: font.sm, color: color.muted },
	panel: {
		minBlockSize: 200,
		padding: space.lg,
		borderRadius: corner.card,
		backgroundColor: color.panel,
		boxShadow: `inset 0 0 0 1px ${color.line}`,
	},
})

const Shown = Schema.Literals(["loading", "empty", "failed", "refused"])

const Message = UiSchema.TaggedEnum({
	PickedState: { state: Shown },
	ClickedRetry: {},
	CompletedRetry: {},
	ClickedCreate: {},
	ClickedRequestAccess: {},
})

// stands in for the app's request: it fails again, so the banner stays to show
const Retry = Command.make("Example.RetryRuns", {}, () => Effect.sleep("900 millis").pipe(Effect.as(Message.CompletedRetry())))

// the app's words for each rejection its services can return
const copy = {
	Unreachable: { sentence: "Couldn't load this workflow's runs.", nextStep: "Check your connection, then try again.", action: "Try again" },
	NotAMember: {
		sentence: "You don't have access to Invoice sync.",
		nextStep: "Ask Maya Chen, its owner, to add you.",
		action: "Request access",
		tone: "neutral" as const,
	},
}

export const RunStates = Html.component({
	name: "RunStates",
	model: Schema.Struct({ state: Shown, retrying: Schema.Boolean, note: Schema.String }),
	message: Message,
}).make({
	init: () => ({ state: "empty", retrying: false, note: "" }),
	update: {
		PickedState: ($, { state }) => $.evolve({ state, retrying: false, note: "" }),
		ClickedRetry: ($) => ($.model.retrying ? $.model : $.evolve({ state: "loading", retrying: true }).run(Retry.make())),
		CompletedRetry: ($) => ($.model.retrying ? $.evolve({ state: "failed", retrying: false }) : $.model),
		ClickedCreate: ($) => $.evolve({ note: "The app would start a run." }),
		ClickedRequestAccess: ($) => $.evolve({ note: "Request sent. Maya Chen will get an email." }),
	},
	view: (h, { state, note }) =>
		h.div.attrs(sx(styles.stack)).children(
			SegmentedControl(h, {
				label: "State",
				size: "sm",
				value: state,
				options: [
					{ value: "loading", label: "Loading" },
					{ value: "empty", label: "Empty" },
					{ value: "failed", label: "Failed" },
					{ value: "refused", label: "No access" },
				],
				onChange: (value) => Message.PickedState({ state: value === "loading" || value === "failed" || value === "refused" ? value : "empty" }),
			}),
			h.div.attrs({ "aria-live": "polite", ...sx(styles.panel) }).children(
				state === "loading"
					? SkeletonList(h, { label: "Loading runs", shape: "rows", count: 4 })
					: state === "empty"
						? EmptyState(h, {
								icon: "↻",
								title: "No runs yet",
								hint: "Runs show here once Invoice sync is triggered. Run it now to see one.",
								actions: [Button(h, { tone: "primary" }).on("click", Message.ClickedCreate()).children("Run now")],
							})
						: ErrorBanner(h, {
								props: { agentId: "runs-error", rejection: state === "failed" ? "Unreachable" : "NotAMember", copy, urgent: state === "failed" },
								onEmit: {
									RequestedAction: ({ rejection }) => (rejection === "Unreachable" ? Message.ClickedRetry() : Message.ClickedRequestAccess()),
									RequestedDismiss: () => undefined,
								},
							}),
			),
			h.p.attrs({ role: "status", ...sx(styles.note) }).children(note),
		),
})
```

## API reference

### ErrorBanner (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `agentId` | `string` | This banner's id for agents, unique on the page: "spend-limit-error" |
| `rejection` (required) | `string \| null` | The rejection's `_tag`, or null for no banner |
| `copy` (required) | `Record<string, RejectionCopy>` | The app's table: one entry per rejection tag |
| `fallback` | `RejectionCopy` | For a tag the table lacks; a generic "That didn't work" by default |
| `dismissible` | `boolean` | Shows a dismiss button that emits RequestedDismiss |
| `urgent` | `boolean` | Announce at once (a failed action) or politely (a state the page is in) |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedAction` | `{ rejection: string }` | The person asked for the next step of this rejection |
| `RequestedDismiss` | `{ rejection: string }` | The person dismissed the banner; stop passing this rejection |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedAction` | Take the banner's next step (its `action`) |
| `ClickedDismiss` | Dismiss the banner |

### EmptyState (view function)

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `title` (required) | `string` | — | What isn't here, plainly: "No connectors yet" |
| `hint` | `string` | — | Why, or what will appear here: "Connected apps show here. Agents use only the ones you connect." |
| `icon` | `string` | — | One character or symbol, decorative |
| `actions` | `View.Children` | — | The one thing to do about it: usually a single Button |
| `heading` | `"h2" \| "h3" \| "p"` | — | A heading level for the title when the empty state stands for a whole page |
| `variant` | `"page" \| "compact"` | `page` | `page` for a whole page or section; `compact` inside a table, a list or a panel; `page` by default |
| `style` | `Style` | — | StyleX styles applied after the empty state's own. |

## Keyboard and accessibility

- An empty state's title can be an `h2` or `h3` when it stands for a whole page.
- An error banner is an `alert`, or a polite `status` with `urgent: false`; its next step is a real button or link and its dismiss button is labelled.
- Agents read the banner's sentence, next step and action, and can take the next step or dismiss it, as a person would.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/empty-state
```

With npm: `npx shadcn@latest add checkfu/uicontext/empty-state`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/empty-state`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/empty-state`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/States.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/States.ts](https://github.com/checkfu/uicontext/blob/main/src/States.ts)

## Used in

- [SaaS dashboard](https://uicontext.com/blocks/saas-dashboard.md)
- [Chat](https://uicontext.com/blocks/ai-chat.md)
- [Task manager](https://uicontext.com/blocks/issue-tracker.md)
- [Company brain](https://uicontext.com/blocks/doc-workspace.md)
- [Workflow builder](https://uicontext.com/blocks/automation-builder.md)
- [Database](https://uicontext.com/blocks/tables.md)
- [CRM](https://uicontext.com/blocks/crm.md)
- [Analytics dashboard](https://uicontext.com/blocks/analytics.md)
- [Email](https://uicontext.com/blocks/email.md)
- [Scheduling](https://uicontext.com/blocks/scheduling.md)
- [Storefront](https://uicontext.com/blocks/storefront.md)
- [Helpdesk](https://uicontext.com/blocks/helpdesk.md)
- [Agent studio](https://uicontext.com/blocks/agent-studio.md)
- [Work](https://uicontext.com/blocks/work.md)
- [Team assistant](https://uicontext.com/blocks/team-assistant.md)
- [Team chat](https://uicontext.com/blocks/team-chat.md)
- [Bots](https://uicontext.com/blocks/bot-console.md)
- [Design](https://uicontext.com/blocks/design-tool.md)
- [Whiteboard](https://uicontext.com/blocks/whiteboard.md)
- [Empty states](https://uicontext.com/blocks/empty-states.md)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
