Surfacesradix-ui
Collapsible
Show and hide a region from a trigger, with a measured height animation.
Installation
pnpm dlx shadcn@latest add https://glasscn.app/r/collapsible.jsonReact Native (iOS, Android and web through react-native-web) — same parts and props:
pnpm dlx shadcn@latest add https://glasscn.app/r/native-collapsible.jsonOr with the namespace set up: shadcn add @glasscn-app/collapsible
Parts: Collapsible, CollapsibleTrigger (asChild a Button), CollapsibleContent. The content's height animates; reduced motion opens it at once.
Source
components/glass/collapsible.tsx
"use client"
import * as React from "react"
import { cn } from "cn"
import { Collapsible as CollapsiblePrimitive } from "radix-ui"
/**
* shadcn's Collapsible: show and hide a region from a trigger. The content animates its height
* (Radix measures it); reduced motion opens it at once.
*/
function Collapsible({ ...props }: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
}
function CollapsibleTrigger({ ...props }: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
return <CollapsiblePrimitive.CollapsibleTrigger data-slot="collapsible-trigger" {...props} />
}
function CollapsibleContent({ className, ...props }: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
return (
<CollapsiblePrimitive.CollapsibleContent
data-slot="collapsible-content"
className={cn(
"overflow-hidden data-[state=closed]:animate-[glass-collapsible-up_var(--glass-duration)_ease-out] data-[state=open]:animate-[glass-collapsible-down_calc(var(--glass-duration)*1.5)_ease-out] motion-reduce:animate-none!",
className
)}
{...props}
/>
)
}
export { Collapsible, CollapsibleTrigger, CollapsibleContent }