Empty for Astro
Astro empty-state parts for lists, searches, and unfinished setup.
Installation
bunx --bun shadcn@latest add @gnostic/emptynpx shadcn@latest add @gnostic/emptypnpm dlx shadcn@latest add @gnostic/emptyComponent classes: Default Gnostic.
Complete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/empty/empty-content.astro
---
/**
* Actions under an empty state, such as a button, input, or link.
*/
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div
data-slot="empty-content"
class={cn("flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-sm text-balance", className)}
{...props}
>
<slot />
</div>
src/components/ui/empty/empty-description.astro
---
/**
* Supporting text for an empty state.
* A description that follows the title keeps a small gap above it.
*/
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div
data-slot="empty-description"
class={cn("text-sm text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary [[data-slot=empty-title]+&]:mt-1", className)}
{...props}
>
<slot />
</div>
src/components/ui/empty/empty-header.astro
---
/**
* Groups the media, title, and description of an empty state.
* The group stays narrow and centered.
*/
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div
data-slot="empty-header"
class={cn("flex max-w-sm flex-col items-center text-center", className)}
{...props}
>
<slot />
</div>
src/components/ui/empty/empty-media.astro
---
/**
* Media for an empty state: an icon, an image, or another component.
*
* `variant="icon"` draws two offset cards behind the icon.
* Those cards are decorative. The slot stays on the front card.
* A `class` on this component also reaches each card, so a size or color
* change stays on the whole stack.
*
* @see https://coss.com/ui/docs/components/empty
*/
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const emptyMediaVariants = cva("flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0", {
defaultVariants: {
variant: "default",
},
variants: {
variant: {
default: "bg-transparent",
icon: "relative flex size-9 shrink-0 items-center justify-center rounded-md border bg-card text-foreground shadow-sm/5 not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] [&_svg:not([class*='size-'])]:size-4.5",
},
},
})
type Props = HTMLAttributes<"div"> & VariantProps<typeof emptyMediaVariants>
const { class: className, variant = "default", ...props } = Astro.props
/** Shared face for the front card and the two offset cards. */
const cardClass = cn(emptyMediaVariants({ variant }), className)
---
<div
data-slot="empty-media"
data-variant={variant}
class={cn("relative mb-6", className)}
{...props}
>
{variant === "icon" && (
<>
<div
aria-hidden="true"
data-slot="empty-media-decoration"
class={cn(
cardClass,
"pointer-events-none absolute bottom-px origin-bottom-left -translate-x-0.5 -rotate-10 scale-84 shadow-none",
)}
/>
<div
aria-hidden="true"
data-slot="empty-media-decoration"
class={cn(
cardClass,
"pointer-events-none absolute bottom-px origin-bottom-right translate-x-0.5 rotate-10 scale-84 shadow-none",
)}
/>
</>
)}
<div data-slot="empty-media-content" data-variant={variant} class={cardClass}>
<slot />
</div>
</div>
src/components/ui/empty/empty-title.astro
---
/**
* Title of an empty state.
* `font-heading` follows the sans face until a theme sets another heading font.
*/
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div data-slot="empty-title" class={cn("font-heading text-xl font-semibold", className)} {...props}>
<slot />
</div>
src/components/ui/empty/empty.astro
---
/**
* Root container for an empty state.
* Place `EmptyHeader` and `EmptyContent` inside it.
*
* @see https://coss.com/ui/docs/components/empty
*/
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div data-slot="empty" class={cn("flex min-w-0 flex-1 flex-col items-center justify-center gap-6 px-6 py-12 text-center text-balance md:py-20", className)} {...props}>
<slot />
</div>
src/components/ui/empty/index.ts
/** Empty state parts. Styles follow https://coss.com/ui/docs/components/empty */
export { default as Empty } from "./empty.astro"
export { default as EmptyContent } from "./empty-content.astro"
export { default as EmptyDescription } from "./empty-description.astro"
export { default as EmptyMedia } from "./empty-media.astro"
export { default as EmptyTitle } from "./empty-title.astro"
export { default as EmptyHeader } from "./empty-header.astro"
Usage
import {
Empty,
EmptyContent,
EmptyDescription,
EmptyHeader,
EmptyMedia,
EmptyTitle,
} from "@/components/ui/empty"
---
import Inbox from "@lucide/astro/icons/inbox"
import { Button } from "@/components/ui/button"
import {
Empty,
EmptyContent,
EmptyDescription,
EmptyHeader,
EmptyMedia,
EmptyTitle,
} from "@/components/ui/empty"
---
<Empty>
<EmptyHeader>
<EmptyMedia variant="icon">
<Inbox />
</EmptyMedia>
<EmptyTitle>No data</EmptyTitle>
<EmptyDescription>No data found.</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Button>Add data</Button>
</EmptyContent>
</Empty>
Composition
Arrange the parts as shown for an Empty state:
Empty
├── EmptyHeader
│ ├── EmptyMedia
│ ├── EmptyTitle
│ └── EmptyDescription
└── EmptyContent
Examples
Default
Notes
- Use
EmptyHeaderwhen you want the media, title, and description grouped as one block. EmptyMedia variant="icon"is a good default for simple status states.- Add
EmptyContentonly when the empty state needs an action such as retry, clear filters, or go back.
API Reference
Read the installed source for the complete prop types.
When to use Empty
Use Empty where content will appear after an action or data change. Explain why the area is empty and give one useful next step. Add media only when it helps explain the state.
Keyboard and behavior
Empty is static markup. Actions inside it use normal links or buttons. For search results updated by a script, announce the result count through an appropriate live region in your application.
Theme and layout
Spacing and muted text make the message distinct without a heavy surface. Check the action row at narrow widths and avoid fixed heights that create large blank regions.
