Expandable card
A native details card with a compact summary, animated disclosure and a slot for additional content.
pnpm dlx shadcn@latest add @haze/expandable-card---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id: string;
title?: string;
description?: string;
headingLevel?: 2 | 3 | 4;
open?: boolean;
class?: string;
}
const { id, title = "Workspace retention", description = "Keep the details close without crowding the page.", headingLevel = 3, open = false, class: className } = Astro.props;
const Heading = ({ 2: "h2", 3: "h3", 4: "h4" } as const)[headingLevel];
const slide = "supports-[interpolate-size:allow-keywords]:[interpolate-size:allow-keywords] supports-[interpolate-size:allow-keywords]:details-content:h-0 supports-[interpolate-size:allow-keywords]:details-content:overflow-clip supports-[interpolate-size:allow-keywords]:details-content:transition-[height,content-visibility] supports-[interpolate-size:allow-keywords]:details-content:transition-discrete supports-[interpolate-size:allow-keywords]:details-content:duration-300 supports-[interpolate-size:allow-keywords]:details-content:ease-snappy supports-[interpolate-size:allow-keywords]:open:details-content:h-auto";
---
<details id={id} open={open} class={cn("w-full min-w-0 overflow-hidden rounded-xl border border-border bg-card text-card-foreground transition-[border-color,box-shadow] duration-200 ease-snappy hover:border-border-strong open:border-border-strong", slide, className)}>
<summary class="flex min-h-16 cursor-pointer list-none items-start justify-between gap-4 p-4.5 transition-colors duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
<span class="grid min-w-0 gap-1"><Heading class="text-[1.0625rem]/6 font-medium tracking-[-0.01em]">{title}</Heading><span class="text-[0.8125rem]/5 text-muted-foreground">{description}</span></span>
<ChevronDown aria-hidden="true" class="mt-0.5 size-4 shrink-0 text-muted-foreground transition-[rotate] duration-200 ease-spring motion-reduce:transition-none [[open]>summary_&]:rotate-180" />
</summary>
<div class="border-t border-border bg-muted p-4.5 text-[0.8125rem]/5 text-muted-foreground not-supports-[interpolate-size:allow-keywords]:animate-rise">
<slot><p>Archived projects stay available for 90 days. Workspace owners can export a copy before the retention period ends.</p></slot>
</div>
</details>When to use
- A card needs to keep its main information readable while making secondary details available on demand.
- Expanded content belongs in the current document flow and should work without client code.
When not to use
- Use accordion for a coordinated set of repeated question and answer rows.
- Use dialog when opening the details must move focus into a modal task.
Installation
Add the Haze registry to components.json once, then install Expandable card with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/expandable-cardnpx shadcn@latest add @haze/expandable-cardyarn dlx shadcn@latest add @haze/expandable-cardbunx --bun shadcn@latest add @haze/expandable-cardFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique caller supplied prefix for the control and its associated content. |
| title | string | Workspace retention | Heading in the disclosure summary. |
| description | string | Keep the details close without crowding the page. | Short secondary description beside the disclosure chevron. |
| headingLevel | 2 | 3 | 4 | 3 | Heading level appropriate to the containing page. |
| open | boolean | false | Whether the native disclosure starts expanded. |
| class | string | – | Additional classes on this component's outer wrapper. |
Keyboard interactions
- EnterSpace
- Expand or collapse the focused card summary.
- Tab
- Reach expanded links and controls after the summary.
Accessibility
- The summary is the native disclosure control, so the browser exposes expanded state and manages the closed content.
- The summary target spans the full card header and its focus outline stays inside the card's clipped edge.
- Supported browsers interpolate the details panel height; other browsers animate only the appearing content and the theme disables both paths for reduced motion.
- The caller selects the summary heading level and can put normal links or form controls inside the default content slot.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Expandable card" with `npx shadcn@latest add @haze/expandable-card`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ExpandableCard from "@/components/haze/ui/expandable-card.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/expandable-card.md
Customize with real content
Adapt the Haze expandable-card ui for our product. Replace the demo values of these props with our real content: id, title, description, headingLevel, open, class. Keep the layout, the heading level rules and these accessibility details: The summary is the native disclosure control, so the browser exposes expanded state and manages the closed content. The summary target spans the full card header and its focus outline stays inside the card's clipped edge. Supported browsers interpolate the details panel height; other browsers animate only the appearing content and the theme disables both paths for reduced motion. The caller selects the summary heading level and can put normal links or form controls inside the default content slot. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using expandable-card, check it fits: use it when a card needs to keep its main information readable while making secondary details available on demand.; expanded content belongs in the current document flow and should work without client code.. Avoid it when use accordion for a coordinated set of repeated question and answer rows.; use dialog when opening the details must move focus into a modal task.. Alternatives: @haze/accordion, @haze/card, @haze/dialog.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.