Skip to main content
Decoderen
Browse documentation

EmptyState

Explain an empty collection honestly on a Material 3 outlined card, optionally with a useful next step.

Title only

No entries

Show code
Example.astroAstro
---
import EmptyState from '@dhekode/ui/patterns/EmptyState.tsx';
---

<EmptyState title="No entries" />

With description

No entries

New entries will appear here.

Show code
Example.astroAstro
---
import EmptyState from '@dhekode/ui/patterns/EmptyState.tsx';
---

<EmptyState title="No entries" description="New entries will appear here." />

With action

No entries

New entries will appear here.

Show code
Example.astroAstro
---
import EmptyState from '@dhekode/ui/patterns/EmptyState.tsx';
import Button from '@dhekode/ui/primitives/Button.tsx';
---

<EmptyState title="No entries" description="New entries will appear here.">
  <Button href="/decoderen/button/" variant="secondary">View Button</Button>
</EmptyState>
API reference
title

Type: string

Default: required

Empty-state heading.

description

Type: string

Default: unset

Helpful context.

level

Type: 2 | 3

Default: 2

Choose the level from document hierarchy, not desired size.

className

Type: string | undefined

Default: unset

Adds classes to the React component root, after its own utilities. React components take className, not class.

Slots: Default: optional action content.

No loading, error or illustration variant exists. Do not invent entries or business claims to fill the space.

Original component source
packages/ui/src/patterns/EmptyState.tsxAstro
import type { ReactNode } from 'react';
import { classNames } from '@dhekode/utils/class-names';

export interface EmptyStateProps {
  title: string;
  description?: string | undefined;
  /** Heading level, chosen from the page's outline; the look stays the same. */
  level?: 2 | 3 | undefined;
  className?: string | undefined;
  /** Optional next actions, such as a Button. */
  children?: ReactNode;
}

/**
 * Shown when a collection has no published entries, on a Material 3 outlined card. Never fill
 * gaps with fake items.
 */
export default function EmptyState({
  title,
  description,
  level = 2,
  className,
  children,
}: EmptyStateProps) {
  const Heading = level === 3 ? 'h3' : 'h2';
  return (
    <div
      className={classNames(
        'dk-empty grid justify-items-start gap-md rounded-card border-(length:--dk-border-width-hairline) border-solid border-surface-border px-xl py-2xl',
        className,
      )}
    >
      <Heading className="dk-empty__title text-h4">{title}</Heading>
      {description && (
        <p className="dk-empty__description max-w-measure-lead text-surface-muted">{description}</p>
      )}
      {children && <div className="dk-empty__actions flex flex-wrap gap-sm">{children}</div>}
    </div>
  );
}

Best practices

  • Explain the empty state and provide a relevant next action when one exists.