# Empty state

Explains why a view has no content or failed to load, and offers the action that changes that.

- Family: feedback
- Import: `import { EmptyState } from "@senvenli/react/feedback";`
- Page: https://design.senvenli.com/docs/components/empty-state
- JSON: https://design.senvenli.com/docs/components/empty-state.json

## Example: First use

Says what will appear here and offers the action that fills the view.

```tsx
import { Button } from "@senvenli/react/action";
import { EmptyState } from "@senvenli/react/feedback";

export default function Example() {
  return (
    <EmptyState
      icon="file-text"
      title="No invoices yet"
      description="Invoices you send to customers appear here with their status."
      primaryAction={<Button variant="primary" iconBefore="plus">Create invoice</Button>}
      secondaryAction={<Button variant="subtle">Import from CSV</Button>}
    />
  );
}
```

## Examples

### No results

Repeats the query and offers the way back.

```tsx
import { Button } from "@senvenli/react/action";
import { EmptyState } from "@senvenli/react/feedback";

export default function Example() {
  return (
    <EmptyState
      icon="search-x"
      title="No customers match “lovelace ltd”"
      description="Check the spelling, or clear the filters to see every customer."
      primaryAction={<Button>Clear filters</Button>}
    />
  );
}
```

### Compact

The smaller size, for a card or a table.

```tsx
import { EmptyState } from "@senvenli/react/feedback";
import { Box } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Box radius="large" border>
      <EmptyState
        size="small"
        icon="message-square"
        title="No comments yet"
        description="Comments from your team appear here."
      />
    </Box>
  );
}
```

### Check your inbox

A confirmation with a resend that waits between sends (`useCooldownAction`).

```tsx
import { Button } from "@senvenli/react/action";
import { EmptyState } from "@senvenli/react/feedback";
import { useCooldownAction } from "../otp-field/use-cooldown-action";

// After "Forgot your password?": the same message whether or not the account exists, and a resend that waits.
export default function Example() {
  // The first link was just sent, so the wait is already running (pass 0 when the screen shows later).
  const resend = useCooldownAction(() => new Promise((done) => setTimeout(done, 600)), 60, 60);
  return (
    <EmptyState
      icon="mail-check"
      title="Check your inbox"
      description="If an account exists for that email, we sent a link to reset the password."
      primaryAction={
        <Button isDisabled={resend.remaining > 0} isPending={resend.isPending} onPress={() => void resend.run()}>
          {resend.remaining > 0 ? `Resend in ${resend.remaining}s` : "Resend link"}
        </Button>
      }
      secondaryAction={<Button variant="subtle">Back to sign in</Button>}
    />
  );
}
```

### A failed load

`tone="danger"` replaces the region that failed, announces it and offers a retry.

```tsx
import { Button } from "@senvenli/react/action";
import { EmptyState } from "@senvenli/react/feedback";
import { useState } from "react";

// A failed load: the danger tone, the message announced, the code for support, and a retry that shows it is busy.
export default function Example() {
  const [retrying, setRetrying] = useState(false);
  const retry = async () => {
    setRetrying(true);
    try {
      await new Promise((resolve) => setTimeout(resolve, 800));
    } finally {
      setRetrying(false);
    }
  };
  return (
    <EmptyState
      tone="danger"
      icon="cloud-off"
      announce
      title="Orders could not be loaded"
      description="Check your connection and try again. Your filters are kept."
      details={
        <span className="font-ds-mono text-body-small text-ds-text-subtlest">
          Error code: <bdi>ORD-504</bdi>
        </span>
      }
      primaryAction={
        <Button iconBefore="rotate-cw" isPending={retrying} onPress={() => void retry()}>
          Retry
        </Button>
      }
    />
  );
}
```

## Guidelines

### When to use it

- A list or view has nothing to show yet, no results, or failed to load (tone="danger").

### Use something else when

- [banner](https://design.senvenli.com/docs/components/banner.md): Content is present and a message about it is needed.
- [skeleton](https://design.senvenli.com/docs/components/skeleton.md): The content is still loading.

### Do and avoid

- Never blame the user; say what will appear and how to get it.

## Accessibility

Built in:

- With announce, the message (title, description, details) is an alert; the actions stay outside it.

You provide:

- A heading level when the state is the page's main content.
- For a failed load, a retry Button that shows its pending state (see the example).

## API reference

### EmptyState

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| icon | `IconName` |  | yes | One Lucide icon; no illustrations. |
| title | `React.ReactNode` |  | yes | First use: what will appear here. No results: repeat the query. Cleared: the calm confirmation. |
| headingLevel | `StateHeadingLevel` |  | no | Renders the title as a heading where the state is the page's main content; a plain line by default. |
| description | `React.ReactNode` |  | no | How the content gets here, or the fix; one or two sentences. Never blame the user. |
| primaryAction | `React.ReactNode` |  | no | The action that fills the view (`Button variant="primary"`), or "Clear filters" for no results. |
| secondaryAction | `React.ReactNode` |  | no |  |
| size | `StateSize` | `"medium"` | no | `compact` inside tables and cards. |
| tone | `"neutral" \| "danger"` | `"neutral"` | no | `danger` for a load that failed or a page that is not allowed: the icon in the danger tone. |
| details | `React.ReactNode` |  | no | Extra lines inside the message, under the description: an error code and when it happened, for support. |
| announce | `boolean` |  | no | Announce the message (title, description, details) as an alert; the actions stay outside it. For a state that replaces content the user was waiting for (a failed load); not for a first-use or no-results state. |

### Tokens it reads

`--ds-background-danger`, `--ds-radius-xlarge`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-space-600`, `--ds-surface-sunken`, `--ds-text`, `--ds-text-subtle`

## Related

- [banner](https://design.senvenli.com/docs/components/banner.md)
