SunUI
Founding$79 lifetime updates till Jan 11Claim a seat
FreeProduct UISection

Empty State

Dashed empty-state card with a 1.5-stroke icon, title, description and a Load example plus outline button pair (or a custom action), centered or start-aligned.

When to use it

  • Lists or tables that have no data yet and need a clear next step
  • First-run screens where loading an example teaches the product faster than an empty form

Watch out

  • Passing action replaces the built-in Load example and secondary buttons
  • Keep the description to one or two short sentences so the card stays scannable

Let your agent add it

One copy holds the install command, when to use it, the props and the design rules. Paste it into Claude Code, Cursor or Codex.

Install with the CLI

Uses the shadcn CLI. The source is copied into your project, so you own every line.

$ npx shadcn@latest add https://sunui.synvize.com/r/empty-state.json

Or install manually

  1. 1. Install the dependencies.
    $ npm install clsx tailwind-merge
  2. 2. Add a cn helper at lib/utils.ts if you do not have one. Not using shadcn/ui? Also add sunui-theme.css for the colour tokens (how). Then copy the component.
    empty-state.tsx
    "use client";
    
    import type { ComponentProps, ReactNode } from "react";
    
    import { cn } from "@/lib/utils";
    
    /* ---------- Buttons (same as shadcn Button default and outline) ---------- */
    
    const buttonBase =
      "inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:translate-y-px disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
    const buttonVariant = {
      default: "bg-primary text-primary-foreground hover:bg-primary/80",
      outline: "border-border bg-background hover:bg-muted hover:text-foreground",
    };
    const buttonSize = {
      default: "h-8 gap-1.5 px-2.5",
      sm: "h-7 gap-1 rounded-md px-2.5 text-[0.8rem] [&_svg:not([class*='size-'])]:size-3.5",
    };
    
    export interface StateButtonProps extends Omit<ComponentProps<"button">, "type"> {
      variant?: keyof typeof buttonVariant;
      size?: keyof typeof buttonSize;
      /** When given, renders as a link */
      href?: string;
    }
    
    export function StateButton({ variant = "default", size = "default", href, className, children, ...props }: StateButtonProps) {
      const cls = cn(buttonBase, buttonVariant[variant], buttonSize[size], className);
      if (href) {
        return (
          <a href={href} className={cls} onClick={props.onClick as ComponentProps<"a">["onClick"]}>
            {children}
          </a>
        );
      }
      return (
        <button type="button" className={cls} {...props}>
          {children}
        </button>
      );
    }
    
    /* ---------- Empty ---------- */
    
    export interface StateLink {
      label: ReactNode;
      href?: string;
      onClick?: () => void;
    }
    
    export interface EmptyStateProps {
      title: ReactNode;
      description?: ReactNode;
      /** Icon drawn with a 1.5 stroke width; defaults to an inbox */
      icon?: ReactNode;
      /** Custom actions; when given, the built-in two buttons are not rendered */
      action?: ReactNode;
      /** Primary button such as "Load sample data", so users first see a filled-in view */
      onLoadExample?: () => void;
      /** Outline button beside it, for example "Add members" */
      secondary?: StateLink;
      /** start: left-aligned variant (title, description and button row aligned left) */
      align?: "center" | "start";
      /** UI language: en, zh-TW, zh-CN, ja. Tags such as zh-Hant-HK or ja-JP are also accepted */
      locale?: string;
      /** Override built-in strings; takes precedence over locale */
      labels?: Partial<EmptyStateLabels>;
      className?: string;
    }
    
    export interface EmptyStateLabels {
      loadExample: ReactNode;
    }
    
    type SunLocale = "en" | "zh-TW" | "zh-CN" | "ja";
    
    /** Map any language tag to one of the four built-in languages; everything else falls back to English */
    function resolveLocale(tag?: string): SunLocale {
      const t = (tag ?? "en").toLowerCase();
      if (t.startsWith("zh")) return /hant|tw|hk|mo/.test(t) ? "zh-TW" : "zh-CN";
      if (t.startsWith("ja")) return "ja";
      return "en";
    }
    
    const MESSAGES: Record<SunLocale, EmptyStateLabels> = {
      en: { loadExample: "Load example" },
      "zh-TW": { loadExample: "載入範例" },
      "zh-CN": { loadExample: "加载示例" },
      ja: { loadExample: "サンプルを読み込む" },
    };
    
    export function EmptyState({ title, description, icon, action, onLoadExample, secondary, align = "center", locale = "en", labels, className }: EmptyStateProps) {
      const t = { ...MESSAGES[resolveLocale(locale)], ...labels };
      const start = align === "start";
      const builtIn =
        onLoadExample || secondary ? (
          <div className={cn("flex flex-wrap gap-2", start ? "justify-start" : "justify-center")}>
            {onLoadExample && (
              <StateButton onClick={onLoadExample}>
                <SparklesIcon />
                {t.loadExample}
              </StateButton>
            )}
            {secondary && (
              <StateButton variant="outline" href={secondary.href} onClick={secondary.onClick}>
                {secondary.label}
              </StateButton>
            )}
          </div>
        ) : null;
    
      return (
        <div className={cn("flex flex-col overflow-hidden rounded-xl border border-dashed border-border bg-transparent text-sm text-card-foreground", className)}>
          <div className={cn("flex flex-col gap-4 px-5 py-16", start ? "items-start text-left" : "items-center text-center")}>
            <span className="text-muted-foreground [&_svg]:size-6">{icon ?? <InboxIcon />}</span>
            <div>
              <p className="text-sm font-medium text-foreground">{title}</p>
              {description ? <p className={cn("mt-1 max-w-sm text-sm text-muted-foreground", !start && "mx-auto")}>{description}</p> : null}
            </div>
            {action ?? builtIn}
          </div>
        </div>
      );
    }
    
    /* ---------- Icons (lucide shapes, 1.5 stroke width) ---------- */
    
    const iconProps = {
      viewBox: "0 0 24 24",
      fill: "none",
      stroke: "currentColor",
      strokeWidth: 1.5,
      strokeLinecap: "round",
      strokeLinejoin: "round",
      "aria-hidden": true,
    } as const;
    
    export function InboxIcon() {
      return (
        <svg {...iconProps}>
          <polyline points="22 12 16 12 14 15 10 15 8 12 2 12" />
          <path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" />
        </svg>
      );
    }
    
    export function UsersIcon() {
      return (
        <svg {...iconProps}>
          <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
          <circle cx="9" cy="7" r="4" />
          <path d="M22 21v-2a4 4 0 0 0-3-3.87" />
          <path d="M16 3.13a4 4 0 0 1 0 7.75" />
        </svg>
      );
    }
    
    // Icons inside buttons keep lucide's default stroke width of 2
    function SparklesIcon() {
      return (
        <svg {...iconProps} strokeWidth={2}>
          <path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" />
          <path d="M20 3v4" />
          <path d="M22 5h-4" />
          <path d="M4 17v2" />
          <path d="M5 18H3" />
        </svg>
      );
    }