Collapsible
Collapsible
"Show 4 more" that opens in place: the hidden part eases open through a blur while the button's words morph to "Show less".
Dependencies
React
Interaction states
- open — Height eases (420ms); the label morphs; the chevron turns.
- close — The reverse.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/collapsibleFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
components.json
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Long lists
The first five, then "Show 12 more".
Descriptions
A clamp that opens to the full text.
Advanced settings
Rarely used fields folded away.
Changelogs
Older entries under one button.
What it handles
- Morphing label — TextMorph between your closed and open words.
- Same fold as the accordion — Height by grid rows, content through a blur.
- Either side — placement="top" or "bottom".
- Accessible — aria-expanded, aria-controls, folded content inert.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { Collapsible } from "@/components/collapsible";
<Collapsible labels={{ closed: "Show 4 more", open: "Show less" }}>
{rest.map((row) => <Row key={row.id} {...row} />)}
</Collapsible>Props
| Prop | Type | Description |
|---|---|---|
| children | ReactNode | – · The hidden part. |
| labels | { closed, open } | { "Show more", "Show less" } · Button words. |
| open / defaultOpen / onOpenChange | boolean / (open) => void | – · State. |
| placement | "top" | "bottom" | "bottom" · Button above or below. |
Accessibility & motion
- Installs accordion for the shared fold and chevron. - Reduced motion: opens in place.
pnpm dlx shadcn@4.21.5 add @cavemio/collapsible