Synertech Web/ui v0.57.5 Site Storybook

Documentation / Display & media

EmptyState

Server-compatible@synertech/uiOpen in Storybook

What a list, a table, a chart or a page shows when there is nothing in it: an icon, a title, a line of explanation and the action that follows. One main action at most, worded as the next step ("Create an invoice"), and a second one when needed ("Import a file").

DataGrid and the charts use it themselves to say "no data" and "could not be loaded", and take one in emptyState to say more: why it is empty, and what to do. Three sizes: sm in a table, a chart or a card, md for a panel, lg for a whole page.

The title is a paragraph; headingLevel makes it a section heading when the state stands for a section of the page. The icon is decorative. No hooks and no text of its own: it renders on the server.

Examples

Basic usage

An icon, a title saying what is missing, a description saying what to do, and the action that follows.

Open in a tab
import { Button, EmptyState } from "@synertech/ui";

const InboxIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} aria-hidden="true">
    <path strokeLinejoin="round" d="M3 13.5 5.5 5h13l2.5 8.5V19H3z" />
    <path strokeLinejoin="round" d="M3 13.5h5l1.5 2.5h5l1.5-2.5h5" />
  </svg>
);

export function Basic() {
  return (
    <EmptyState
      icon={<InboxIcon />}
      title="Aucune facture pour l'instant"
      description="Créez la première, elle apparaîtra ici."
      action={<Button label="Créer une facture" />}
    />
  );
}

Two actions

secondaryAction comes after the main action: another way to start, never a second main action.

Open in a tab
import { Button, EmptyState } from "@synertech/ui";

const InboxIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} aria-hidden="true">
    <path strokeLinejoin="round" d="M3 13.5 5.5 5h13l2.5 8.5V19H3z" />
    <path strokeLinejoin="round" d="M3 13.5h5l1.5 2.5h5l1.5-2.5h5" />
  </svg>
);

const secondary = {
  bgColor: "bg-white hover:bg-gray-50 border border-gray-300",
  textColor: "text-gray-700",
};

export function TwoActions() {
  return (
    <EmptyState
      icon={<InboxIcon />}
      title="Aucune facture pour l'instant"
      description="Créez la première ou importez un fichier CSV."
      action={<Button label="Créer une facture" />}
      secondaryAction={<Button label="Importer un CSV" {...secondary} />}
    />
  );
}

Sizes

sm in a table, a chart or a card, md (the default) for a panel, lg for a whole page.

Open in a tab
import { EmptyState } from "@synertech/ui";

const FolderIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} aria-hidden="true">
    <path
      strokeLinejoin="round"
      d="M3 6.5A1.5 1.5 0 0 1 4.5 5H9l2 2.5h8.5A1.5 1.5 0 0 1 21 9v9.5a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18.5z"
    />
  </svg>
);

export function Sizes() {
  return (
    <div className="grid w-full gap-6 sm:grid-cols-3">
      {(["sm", "md", "lg"] as const).map((size) => (
        <EmptyState
          key={size}
          size={size}
          icon={<FolderIcon />}
          title="Dossier vide"
          description={`Taille ${size}.`}
        />
      ))}
    </div>
  );
}

In a grid

A search with no result is not an empty list: the state says so, and offers to clear it.

Open in a tab
import { useState } from "react";
import { Button, DataGrid, EmptyState, Input, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  amount: number;
}

const invoices: Invoice[] = [
  { id: "F-1042", client: "Atelier Morel", amount: 1280 },
  { id: "F-1043", client: "Boulangerie Gagnon", amount: 342.5 },
  { id: "F-1044", client: "Clinique des Saules", amount: 2310 },
];

const invoiceColumns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Numéro" },
  { key: "client", header: "Client" },
  { key: "amount", header: "Montant", align: "right" },
];

const SearchIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} aria-hidden="true">
    <circle cx="11" cy="11" r="6.5" />
    <path strokeLinecap="round" d="m16 16 4.5 4.5" />
  </svg>
);

export function InADataGrid() {
  const [query, setQuery] = useState("Tremblay");
  const rows = invoices.filter((invoice) =>
    invoice.client.toLowerCase().includes(query.trim().toLowerCase())
  );

  return (
    <div className="flex w-full flex-col gap-3">
      <Input
        type="search"
        size="sm"
        label="Rechercher un client"
        hideLabel
        placeholder="Client"
        value={query}
        onChange={(event) => setQuery(event.target.value)}
        className="w-64"
      />
      <DataGrid
        columns={invoiceColumns}
        data={rows}
        rowKey="id"
        emptyState={
          <EmptyState
            size="sm"
            icon={<SearchIcon />}
            title={`Aucun client ne correspond à « ${query} »`}
            description="Vérifiez l'orthographe, ou cherchez un autre nom."
            action={<Button size="sm" label="Effacer la recherche" onClick={() => setQuery("")} />}
          />
        }
      />
    </div>
  );
}

The face of the charts

Without emptyState, a chart says "No data" with this component, and "Chart could not be loaded" the same way, with the button of onRetry.

Open in a tab
import { LineChart } from "@synertech/ui";

export function InCharts() {
  return (
    <div className="grid w-full gap-6 md:grid-cols-2">
      <LineChart
        title="Visites"
        data={[]}
        x={{ key: "day" }}
        series={[{ key: "visits", label: "Visites" }]}
        height={180}
      />
      <LineChart
        title="Inscriptions"
        data={[]}
        x={{ key: "day" }}
        series={[{ key: "signups", label: "Inscriptions" }]}
        height={180}
        error
        onRetry={() => {}}
      />
    </div>
  );
}

A whole page

size="lg" and headingLevel when the state stands for a section: the title takes its place in the outline of the page.

Open in a tab
import { Button, EmptyState } from "@synertech/ui";

const FolderIcon = () => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.6} aria-hidden="true">
    <path
      strokeLinejoin="round"
      d="M3 6.5A1.5 1.5 0 0 1 4.5 5H9l2 2.5h8.5A1.5 1.5 0 0 1 21 9v9.5a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18.5z"
    />
  </svg>
);

const secondary = {
  bgColor: "bg-white hover:bg-gray-50 border border-gray-300",
  textColor: "text-gray-700",
};

export function WholePage() {
  return (
    <section className="w-full rounded-xl border border-dashed border-gray-300 dark:border-gray-600">
      <EmptyState
        size="lg"
        headingLevel={2}
        icon={<FolderIcon />}
        title="Aucun projet"
        description="Un projet réunit les factures, les clients et les documents d'un mandat."
        action={<Button size="lg" label="Créer un projet" />}
        secondaryAction={<Button size="lg" label="Lire le guide" {...secondary} />}
      />
    </section>
  );
}

API reference

Components

EmptyState

ComponentServer-compatible

What a list, a table, a chart or a page shows when there is nothing in it: an icon, a title, a line of explanation and the action that follows.

DataGrid and every chart take one in emptyState, and draw their own "no data" and "could not be loaded" with it, so that the three look alike.

No hooks and no handlers of its own: it renders on the server. It writes no text of its own either, so UILabelsProvider has nothing to give it.

import { EmptyState } from "@synertech/ui";

Props — EmptyStateProps

PropTypeDefaultDescription
title• ReactNode —

What there is not, in one line: "No invoices yet".

action ReactNode —

The one action that follows: create the first, clear the filters, retry. Usually a Button.

children ReactNode —

Drawn under the description, before the actions: a hint, a list of suggestions.

description ReactNode —

Why there is nothing, or what to do about it.

headingLevel 1 | 2 | 3 | 4 | 5 | 6 —

Makes the title a heading of this level, for a state that stands for a section of the page. Left out, the title is a paragraph: in a table, a chart or a card, a heading would cut the outline of the page.

icon ReactNode —

A picture of what is missing, drawn in a disc above the title. It is decorative and hidden from assistive technologies: the title says it. An <svg> is sized by size, whatever its own width and height.

secondaryAction ReactNode —

A second way out, drawn after the first: import a file, read the guide.

size EmptyStateSize "md"

sm in a table, a chart or a card, md for a panel, lg for a whole page.

+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

type EmptyStateSize = "sm" | "md" | "lg"