# Collapsible

Unstyled show and hide region with a trigger, opening in one frame.

Source: https://www.ui95.dev/ui/collapsible

## Examples

```tsx
import { Button } from "@/components/ui/button"
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"

import type { ShowcaseDemo } from "../types"

function renderCollapsible(defaultOpen: boolean) {
  return (
    <Collapsible defaultOpen={defaultOpen} className="flex flex-col gap-2">
      <CollapsibleTrigger asChild>
        <Button size="sm">Toggle details</Button>
      </CollapsibleTrigger>
      <CollapsibleContent className="text-lg">
        Hidden until the trigger is pressed.
      </CollapsibleContent>
    </Collapsible>
  )
}

export const demo: ShowcaseDemo = {
  span: "single",
  variants: [
    { label: "closed", render: () => renderCollapsible(false) },
    { label: "open", render: () => renderCollapsible(true) },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/collapsible.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install radix-ui
```

`components/ui/collapsible.tsx`

```tsx
"use client"

import { Collapsible as CollapsiblePrimitive } from "radix-ui"

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({
  ...props
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
  return (
    <CollapsiblePrimitive.CollapsibleContent
      data-slot="collapsible-content"
      {...props}
    />
  )
}

export { Collapsible, CollapsibleContent,CollapsibleTrigger }
```

## API reference

### Collapsible

No props of its own. It forwards the props of the element or primitive it wraps.

### CollapsibleContent

No props of its own. It forwards the props of the element or primitive it wraps.

### CollapsibleTrigger

No props of its own. It forwards the props of the element or primitive it wraps.

## Sounds

- `button.press`
- `button.release`
