Empty State
Base empty state with an icon in a muted tile, a heading, a short description and a slot for one action. The heading level is a prop so it fits the surrounding outline.
How it differs. The neutral baseline with slots only (icon, title, description, actions) inside a dashed frame, and no structure tied to a cause.
Install
pnpm dlx shadcn@latest add @hazine/empty-stateAdds 1 file and 1 Hazine item (@hazine/heading).
First time? Add the registry to components.json
{
"registries": {
"@hazine": "https://api.hazine.dev/r/{name}.json"
}
}Needed once per project. Items resolve each other through the @hazine namespace.
components/hazine/empty-state.tsx, 54 lines
import * as React from "react"
import { cn } from "@/lib/utils"
import { Heading, type HeadingLevel } from "@/components/hazine/heading"
export interface EmptyStateProps extends React.ComponentProps<"div"> {
/** Decorative icon shown in a muted tile above the title. */
icon?: React.ReactNode
/** Says what will appear here. */
title: string
description?: string
/** One action that fills the empty space. */
actions?: React.ReactNode
headingLevel?: HeadingLevel
}
export function EmptyState({
icon,
title,
description,
actions,
headingLevel = 3,
className,
...props
}: EmptyStateProps) {
return (
<div
data-slot="empty-state"
className={cn(
"flex flex-col items-center gap-2 rounded-lg border border-dashed border-border px-6 py-12 text-center",
className
)}
{...props}
>
{icon && (
<span
aria-hidden="true"
className="mb-2 flex size-12 items-center justify-center rounded-md bg-muted text-foreground"
>
{icon}
</span>
)}
<Heading level={headingLevel} className="text-base font-semibold">
{title}
</Heading>
{description && (
<p className="max-w-[40ch] text-sm text-muted-foreground">
{description}
</p>
)}
{actions && <div className="mt-4">{actions}</div>}
</div>
)
}
The demo in the preview, 33 lines
import { Inbox, Plus } from "lucide-react"
import { Button } from "@/components/ui/button"
import { EmptyState } from "@/components/hazine/empty-state"
export default function EmptyStateDemo() {
return (
<EmptyState
icon={<Inbox className="size-6" strokeWidth={1.5} />}
title="No invoices yet"
description="Invoices you send to clients appear here with their payment status."
actions={
<Button size="sm">
<Plus aria-hidden="true" />
Create invoice
</Button>
}
/>
)
}
function EmptyStateTextOnly() {
return (
<EmptyState
title="No matching clients"
description="Clear the filters to see all 48 clients again."
/>
)
}
export const scenarios = {
"text-only": EmptyStateTextOnly,
}
Props5
- icon
- React.ReactNode
- Decorative icon shown in a muted tile above the title.
- titlerequired
- string
- Says what will appear here.
- description
- string
- actions
- React.ReactNode
- One action that fills the empty space.
- headingLevel
- HeadingLevel = 3
Also accepts every prop of React.ComponentProps<"div">.
Accessibility
- Pattern
- Landmarks and headings
- Keyboard
- Nothing to operate. The item has no focusable parts.
- Screen reader
A heading at the level given by headingLevel followed by a paragraph. The icon is decorative and hidden from assistive technology.
- Reduced motion
- No motion.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies1
- @hazine/heading
Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.
Tokens shipped0
None. The item is styled by the tokens your theme already has.