react ~4 KB 0 deps v0.1.0 ↗ GitHub ↗

@mshafiqyajid/react-empty-state

Headless empty state hook and styled component. Five presets, custom icon/image, size and orientation variants, action slots, fully accessible.

Playground #

Start your first project

Create a project to organize your work and collaborate with your team.

No data yet

Start adding items to see them here.

Props
TSX
import { EmptyStateStyled } from "@mshafiqyajid/react-empty-state/styled";
import "@mshafiqyajid/react-empty-state/styles.css";

<EmptyStateStyled />

Install #

npm install @mshafiqyajid/react-empty-state

Quick start #

import { EmptyStateStyled } from "@mshafiqyajid/react-empty-state/styled";
import "@mshafiqyajid/react-empty-state/styles.css";

<EmptyStateStyled
  preset="no-data"
  action={<button>Add item</button>}
/>

// Custom content
<EmptyStateStyled
  title="Nothing here yet"
  description="Create your first item to get started."
  action={<button>Create item</button>}
  size="lg"
/>

Headless #

import { useEmptyState } from "@mshafiqyajid/react-empty-state";

function MyEmptyState({ title }: { title: string }) {
  const { rootProps } = useEmptyState({ title });
  return (
    <div {...rootProps} className="my-empty-state">
      <p>{title}</p>
    </div>
  );
}

Presets #

PresetTitleDescription
no-dataNo data yetStart adding items to see them here.
no-resultsNo results foundTry adjusting your search or filters.
errorSomething went wrongPlease try again later.
offlineYou're offlineCheck your internet connection.
empty-searchNo matchesWe couldn't find anything matching your search.

Preset values for title, description, and icon are overridden when you supply those props directly.

API #

PropTypeDefaultDescription
preset"no-data" | "no-results" | "error" | "offline" | "empty-search"Built-in preset with icon, title, and description
iconReactNodeCustom icon element (overrides preset icon)
imagestring | ReactNodeImage URL or element shown in place of the icon
titleReactNodeHeading text (overrides preset title)
descriptionReactNodeBody text (overrides preset description)
actionReactNodePrimary action slot
secondaryActionReactNodeSecondary action slot
size"sm" | "md" | "lg""md"Controls icon and font size
orientation"vertical" | "horizontal""vertical"Stack direction — vertical centers content, horizontal aligns left
childrenReactNodeCustom content rendered inside the body after description and before actions
classNamestringExtra class on the root element
styleCSSPropertiesInline style override

Headless API — useEmptyState #

OptionTypeDescription
titlestringUsed as aria-label on the root element

The hook returns rootProps with role="status" and aria-label set to the title string.

Edit this page on GitHub