|Kit

EmptyState

The block a list shows in place of its rows — an icon, a title, a muted description and the actions. DataTable's empty and error views are drawn with it.

EmptyState is what a list shows when it has no rows to draw: an icon in a ThemeIcon, a title, a muted description and the actions, centred at a minimum height. DataTable draws its empty and error views with it, so a card grid, a timeline or a grouped list that comes up empty (or fails to load) looks the same as a table that does.

import { EmptyState } from "@42-central/ui-react/empty-state";
import { FolderPlus } from "lucide-react";

<EmptyState
  icon={<FolderPlus />}
  title="No projects yet"
  description="Projects you create or join show up here."
>
  <Button size="sm">New project</Button>
</EmptyState>;

Basic

Only title is required. icon and description each appear when given, and children (the actions) go in a row under the text.

Your inbox is empty

Code

<EmptyState icon={<Inbox />} title="Your inbox is empty" />

Description and actions

The description is muted, so the title stays the headline. The children are the actions: they sit below the text and wrap on a narrow container.

No students match your filters

Try a broader search, or clear the filters.

Code

<EmptyState
  icon={<SearchX />}
  title="No students match your filters"
  description="Try a broader search, or clear the filters."
>
  <Button variant="light" color="neutral" size="sm">Clear filters</Button>
  <Button size="sm" startSlot={<Plus />}>Invite a student</Button>
</EmptyState>

Error

A list that failed to load must not read like a list with nothing in it. Give it color="red", which tints the icon and the title (the description stays muted), and role="alert" so a screen reader announces it. The role is left to you because only you know whether the block appeared in response to something.

Code

<EmptyState
  color="red"
  role="alert"
  icon={<ServerCrash />}
  title="Couldn't load the projects"
  description="The server didn't answer. Check your connection and try again."
>
  <Button variant="light" color="neutral" size="sm" startSlot={<RefreshCw />} onClick={refetch}>
    Retry
  </Button>
</EmptyState>

Colors

color takes any palette color. Without one, the icon is the muted default tile and the title the primary text color. With one, the icon is that color's light tile and the title takes the color's text shade.

Start your first project

Submissions are paused

Code

<EmptyState color="brand" icon={<FolderPlus />} title="Start your first project" />
<EmptyState color="orange" icon={<Inbox />} title="Submissions are paused" />

In a list that isn't a table

The block fills whatever replaces the rows. Here a card grid with no cards shows it inside the grid's frame.

No projects yet

Projects you create or join show up here.

Code

{projects.length === 0 ? (
  <Card>
    <EmptyState
      icon={<FolderPlus />}
      title="No projects yet"
      description="Projects you create or join show up here."
    >
      <Button size="sm" startSlot={<Plus />}>New project</Button>
    </EmptyState>
  </Card>
) : (
  <div className="grid grid-cols-3 gap-4">{projects.map(…)}</div>
)}

Font size

EmptyState sets no font size: it uses the size of wherever it sits. A table's density therefore carries into its placeholder. In body text, set one with className (the demos on this page use text-sm).

Composition

For a layout the props don't cover, compose the parts: EmptyState.Root, .Icon, .Title, .Description and .Actions. The root is a column with a gap between its children, so wrap the title and description in one element to keep them together, as the ready-made form does. A composed .Title follows the root's color without being told. Pass the same color to .Icon.

Submissions are paused

They reopen on Monday at 9:00.

Code

<EmptyState.Root color="orange">
  <EmptyState.Icon color="orange" size="lg" radius="full">
    <Inbox />
  </EmptyState.Icon>
  <div>
    <EmptyState.Title className="font-semibold">Submissions are paused</EmptyState.Title>
    <EmptyState.Description>They reopen on Monday at 9:00.</EmptyState.Description>
  </div>
</EmptyState.Root>

In DataTable

DataTable renders its empty and error props as an EmptyState. The error view is red and the empty view neutral. Pass { title, description, actions, color } to set the parts (actions becomes the children), and color to override a view's palette. See DataTable's states.

API

EmptyState accepts every div prop (role, id, style, …) plus:

Prop

Type

The parts:

  • EmptyState.Root: the centred column, which takes color and testId.
  • EmptyState.Icon: a ThemeIcon that takes every one of its props. Its variant is default without a color and light with one.
  • EmptyState.Title and EmptyState.Description: paragraphs.
  • EmptyState.Actions: a centred row that wraps.

Accessibility

  • The icon is decorative (aria-hidden). The title carries the meaning.
  • Give an error role="alert", so it is announced when it replaces the rows. An empty list that was empty from the start needs no role.
  • The title is a paragraph, not a heading, so it doesn't add to the page outline. If the page's outline should list it, compose with your own heading inside EmptyState.Root.

Changelog

v0.30.0
  • New EmptyState: the icon, title, description and actions a list shows when it has no rows, with a color prop and composable parts

    #474

On this page