Skip to main content
astrocraft-ui/ components · 101

Empty State

Free · MIT

Headless, accessible, and styled entirely through the attribute surface below — bring your own CSS system, or start from the reference theme.

Install

Without a flag you get no styling at all — plain HTML carrying the attribute surface below. --theme copies the same theme in two dialects;--bridge lumos re-points either one onto Lumos for Astro's tokens (it needs a theme to re-point, and Lumos itself, already in your project).

Unstyled — behavior only, you write the CSS

Install command
npx astrocraft-ui add display/empty-state

Plain-CSS theme — no build step

Install command
npx astrocraft-ui add display/empty-state --theme css

Tailwind theme — needs Tailwind v4

Install command
npx astrocraft-ui add display/empty-state --theme tailwind

Plain-CSS theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add display/empty-state --theme css --bridge lumos

Tailwind theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add display/empty-state --theme tailwind --bridge lumos

Live demo

EmptyState

The illustration is wrapped aria-hidden in one place rather than left to whoever pastes the SVG in — it repeats what the heading says. Mark it live when it replaces a list after a filter, and it announces itself; a server-rendered one has no change to report.

No invoices

Nothing matches “draft” in the last 90 days.

Attribute surface

With no class-merging machinery, these attributes are the whole extension point. State is a data-attribute or a native attribute; visibility is the hiddenattribute. Generated from source by pnpm slots.

ComponentSlotsVariantsRuntime stateNative state
`EmptyState.astro``empty-state` `empty-state-media``data-size`: `sm` · `md` · `lg`——
`EmptyStateActions.astro``empty-state-actions`———
`EmptyStateDescription.astro``empty-state-description`———
`EmptyStateTitle.astro``empty-state-title`———

Source

What the command copies — 5 files, alias-free so the copy lands standing alone. This is the whole component; there is nothing else.

src/components/ui/display/empty-state/EmptyState.astro
---
// src/components/ui/display/empty-state/EmptyState.astro — headless primitive (see ../../README.md).
// The "no results", "nothing here yet", "your inbox is empty" block. Compose EmptyStateTitle /
// EmptyStateDescription / EmptyStateActions, and pass the illustration in the `media` slot.
//
// Two things earn it a file, and neither is the box:
//
//   • THE MEDIA IS DECORATION AND IS MARKED SO. An empty state's illustration repeats what the
//     heading below it already says, so it is wrapped `aria-hidden="true"` here — one place, once —
//     rather than left to whoever pastes the SVG in. Get that wrong and every empty state announces
//     a stray "image" or, worse, a filename.
//   • `live` MAKES IT AN ANNOUNCEMENT. An empty state that replaces a list after a filter is a
//     change nothing else reports: focus stays in the search box, the rows vanish, and a screen
//     reader user hears nothing at all. `live` renders `role="status"`, which announces the block
//     when it appears. It is OFF by default because a server-rendered empty state has no change to
//     report, and a live region that is already on screen at load announces nothing anyway.
//
//   <EmptyState live>
//     <svg slot="media" … />
//     <EmptyStateTitle>No invoices</EmptyStateTitle>
//     <EmptyStateDescription>Nothing matches "draft".</EmptyStateDescription>
//     <EmptyStateActions><Button>Clear filters</Button></EmptyStateActions>
//   </EmptyState>
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div"> & {
  /** Announce the block when it appears — for an empty state swapped in after a search or filter. */
  live?: boolean;
  size?: "sm" | "md" | "lg";
};

const { live = false, size = "md", class: className, ...rest } = Astro.props;
---

<div
  role={live ? "status" : undefined}
  class={className}
  data-slot="empty-state"
  data-size={size}
  {...rest}
>
  {
    Astro.slots.has("media") && (
      <div data-slot="empty-state-media" aria-hidden="true">
        <slot name="media" />
      </div>
    )
  }
  <slot />
</div>
src/components/ui/display/empty-state/EmptyStateActions.astro
---
// src/components/ui/display/empty-state/EmptyStateActions.astro — EmptyState compound part
// (see ../../README.md). The row of buttons or links that resolves the empty state. Keep it LAST: it is
// the answer to the title above it, and a screen reader reads the reason before the remedy.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div">;

const { class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="empty-state-actions" {...rest}><slot /></div>
src/components/ui/display/empty-state/EmptyStateDescription.astro
---
// src/components/ui/display/empty-state/EmptyStateDescription.astro — EmptyState compound part
// (see ../../README.md). The sentence under the title. Say what to do next, not just what is missing.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"p">;

const { class: className, ...rest } = Astro.props;
---

<p class={className} data-slot="empty-state-description" {...rest}><slot /></p>
src/components/ui/display/empty-state/EmptyStateTitle.astro
---
// src/components/ui/display/empty-state/EmptyStateTitle.astro — EmptyState compound part (see ../../README.md).
// <h3>, the same level CardTitle takes: an empty state stands in for a section's content, so it sits
// below that section's own heading. Wrap it in your own heading level if the nesting differs.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"h3">;

const { class: className, ...rest } = Astro.props;
---

<h3 class={className} data-slot="empty-state-title" {...rest}><slot /></h3>
src/components/ui/display/empty-state/index.ts
import EmptyState from "./EmptyState.astro";
import EmptyStateActions from "./EmptyStateActions.astro";
import EmptyStateDescription from "./EmptyStateDescription.astro";
import EmptyStateTitle from "./EmptyStateTitle.astro";

export { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateTitle };
export default EmptyState;

What you get

The component source, copied into your project by npx astrocraft-ui add display/empty-state — no package dependency, no CSS to fight. Whatever the paid blocks compose, this is it.