Collapsible

A React collapsible on Base UI for expand and collapse sections, sidebar groups, and show more previews that fade long content until opened.

Loading preview

Examples

Practical examples and common states for the same installable component.

Card

Collapsible content inside bordered cards.

examples/collapsible-card.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/wensity/collapsible";
export default function Example() {
return (
<Collapsible variant="card" defaultOpen>
<CollapsibleTrigger>
<div className="flex flex-1 items-center justify-between">
<span>Order #1842</span>
<span className="text-xs font-normal text-[var(--muted-foreground)]">Shipped</span>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="flex items-center justify-between text-sm text-[var(--muted-foreground)]">
<span>2× Wireless Keyboard</span>
<span className="text-[var(--foreground)]">$158.00</span>
</div>
</CollapsibleContent>
</Collapsible>
);
}

Section

Expandable page sections and settings groups.

examples/collapsible-section.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/wensity/collapsible";
export default function Example() {
return (
<Collapsible variant="section" defaultOpen>
<CollapsibleTrigger>
<div className="flex flex-col gap-0.5">
<span className="text-[15px] font-medium">Notifications</span>
<span className="text-xs font-normal text-[var(--muted-foreground)]">
Choose what you get notified about
</span>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<p className="text-sm text-[var(--muted-foreground)]">Product updates: On</p>
</CollapsibleContent>
</Collapsible>
);
}

Sidebar

Collapsible navigation or filter areas.

examples/collapsible-sidebar.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/wensity/collapsible";
import { IconFile, IconFolder } from "@tabler/icons-react";
export default function Example() {
return (
<Collapsible variant="sidebar" defaultOpen>
<CollapsibleTrigger>
<div className="flex items-center gap-2">
<IconFolder className="size-4 text-[var(--muted-foreground)]" stroke={1.75} />
<span>lib</span>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="flex items-center gap-2.5 rounded-full px-3 py-2 text-[14px] text-[var(--muted-foreground)]">
<IconFile className="size-4" stroke={1.75} />
<span>utils.ts</span>
</div>
</CollapsibleContent>
</Collapsible>
);
}

Preview

Shows summary first, then full content.

examples/collapsible-preview.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/wensity/collapsible";
export default function Example() {
return (
<div className="flex h-[240px] w-full max-w-md items-end">
<Collapsible variant="preview" previewHeight={96} className="w-full">
<CollapsibleContent className="rounded-2xl border border-zinc-200/80 bg-white p-5 dark:border-white/[0.06] dark:bg-[#0c0c0e]">
<p className="text-sm leading-relaxed text-[var(--muted-foreground)]">
Our platform gives teams a single source of truth for design and code...
</p>
</CollapsibleContent>
<CollapsibleTrigger
hideIcon
className="w-auto rounded-md px-0 py-1 text-sm font-semibold underline-offset-4 hover:underline focus-visible:underline"
>
{({ open }) => (
<span>{open ? "Show less" : "Show more"}</span>
)}
</CollapsibleTrigger>
</Collapsible>
</div>
);
}

Overview

Collapsible is a React and Tailwind CSS collapsible on Base UI, in Next.js or any React app, for one section that opens and closes. Inline, card, section, and sidebar variants change the trigger and chevron, and the preview variant shows the first 96 pixels of content under a fade, then expands to the measured height when you click Show more. CollapsibleTrigger accepts a function child, so its label can switch between Show more and Show less from the open state. The panel stays mounted while closed, which keeps its text in the page.

Installation

Run the following command

~/your-project
pnpm dlx wensity@latest add collapsible

Usage

Import Collapsible from @/components/wensity/collapsible and render it anywhere in your React or Next.js app. The source lands in your own repo, so every prop, class and animation below is yours to edit.

app/example.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/wensity/collapsible";
export default function Example() {
return (
<Collapsible variant="inline">
<CollapsibleTrigger>Show shipping details</CollapsibleTrigger>
<CollapsibleContent>
<p>Delivered via FedEx Ground, arriving in 3–5 business days.</p>
</CollapsibleContent>
</Collapsible>
);
}

Props

PropTypeDefaultDescription
variant"inline" | "card" | "section" | "sidebar" | "preview""inline"Surface treatment. preview clips content to a fixed height instead of hiding it.
openboolean-Controlled open state.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the panel opens or closes.
previewHeightnumber96Visible height in pixels while collapsed, for the preview variant.
disabledbooleanfalsePrevents the panel from being toggled.
  • Expanding Cards component preview

    Expanding Cards

    Hover a tall editorial strip and it opens wide, the rest of the row holding as tight vertical slivers of the same image.

  • Animated 3D Folder component preview

    Animated 3D Folder

    A real CSS 3D folder that tilts toward your cursor, drops its cover open, and lifts its files into a stepped index.

  • Gooey Navigation Menu component preview

    Gooey Navigation Menu

    A liquid FAB whose child actions stretch out of the trigger like molten metal.

  • Interactive 3D Book component preview

    Interactive 3D Book

    A tactile 3D book cover that opens on click with real matte depth, then turns each page on a weighted hinged flip.