Collapsible
An expandable content region using the shadcn Collapsible primitive.
Collapsible is a low-level primitive for revealing and hiding related content. Use it when a component needs custom trigger or content composition.
Use Collapsible for generic disclosure behaviour: rows, sections, menus, tool details, and custom layouts. Use Collapsible Alert instead when the disclosure is an alert-styled callout that should keep standard alert padding, variants, trigger styling, and toggle treatment.
Loading...
'use client'
import { ChevronsUpDown } from 'lucide-react'
import * as React from 'react'
import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
export function CollapsibleDemo() {
const [isOpen, setIsOpen] = React.useState(false)
return (
<Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-[350px] space-y-2">
<div className="flex items-center justify-between space-x-4 px-4">
<h4 className="text-sm font-semibold">@peduarte starred 3 repositories</h4>
<CollapsibleTrigger asChild>
<Button type="outline" size="medium" className="w-9 p-0">
<ChevronsUpDown className="h-4 w-4" />
<span className="sr-only">Toggle</span>
</Button>
</CollapsibleTrigger>
</div>
<div className="rounded-md border px-4 py-3 font-mono text-sm">@radix-ui/primitives</div>
<CollapsibleContent className="space-y-2">
<div className="rounded-md border px-4 py-3 font-mono text-sm">@radix-ui/colors</div>
<div className="rounded-md border px-4 py-3 font-mono text-sm">@stitches/react</div>
</CollapsibleContent>
</Collapsible>
)
}Usage
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from 'ui/src/components/shadcn/ui/collapsible'<Collapsible>
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
<CollapsibleContent>
<p>Content revealed when expanded.</p>
</CollapsibleContent>
</Collapsible>Default open
<Collapsible defaultOpen>
<CollapsibleTrigger>Details</CollapsibleTrigger>
<CollapsibleContent>
<p>This section is expanded by default.</p>
</CollapsibleContent>
</Collapsible>Animation
Add animation classes to CollapsibleContent when animated open and close transitions are needed.
<CollapsibleContent className="data-closed:animate-collapsible-up data-open:animate-collapsible-down">
<p>Content revealed when expanded.</p>
</CollapsibleContent>