import * as React from "react"; import type { LucideIcon } from "lucide-react"; import { Button } from "./button"; import { hasSlot, renderActions, type ActionData } from "./data-slots"; import { Skeleton } from "./skeleton"; import { cn } from "../lib/cn"; type LegacyCta = { label: string; onClick: () => void; disabled?: boolean; }; export interface EmptyStateProps { /** One of the brand's illustrations: the path of an image under `public/` * (`/img/illustrations/welcome.svg`; shown at 180px with empty alt text, * the title says it all), or an element for anything else. */ illustration?: string | React.ReactNode; title: React.ReactNode; text?: React.ReactNode; /** Buttons, main one first, as elements or `ActionData`. Children go * there too. */ actions?: React.ReactNode | ActionData | ActionData[]; children?: React.ReactNode; /** 2 by default. */ headingLevel?: 1 | 2 | 3; className?: string; // What the component took before the design system's names. The pages not // yet restyled still pass these; a restyled page uses the ones above. /** @deprecated Pass `illustration`. */ icon?: LucideIcon; /** @deprecated Pass `text`. */ description?: React.ReactNode; /** @deprecated Pass `actions`. */ cta?: LegacyCta; /** @deprecated Pass `actions`. Only shown when `cta` is too. */ secondaryCta?: LegacyCta; } export function EmptyStateSkeleton() { return (
); } // The design system's EmptyState: an illustration, what is missing in a // title, what it is for in a sentence, and one or two buttons that say what // to do next, centred in the card that will hold the content. Not for an // error: a failure is a `Notice` with the reason and a way out. // // Without an illustration the earlier `icon` on its tinted tile stands in. export function EmptyState({ illustration, title, text, actions, children, headingLevel = 2, className, icon: Icon, description, cta, secondaryCta, }: EmptyStateProps) { const Heading = `h${headingLevel}` as "h1" | "h2" | "h3"; const sentence = text ?? description; const hasActions = hasSlot(actions) || hasSlot(children) || Boolean(cta); return (
{typeof illustration === "string" ? ( // A local SVG, which next/image would not optimise either. ) : ( illustration )} {!illustration && Icon && (
)}
{title} {sentence && (

{sentence}

)}
{hasActions && (
{renderActions(actions)} {children} {cta && ( )} {cta && secondaryCta && ( )}
)}
); }