Collapsible

An interactive component that expands/collapses a panel.

shadcn/ui docs

@peduarte starred 3 repositories

@radix-ui/primitives

Installation

pnpm dlx shadcn@latest add https://neobrutalism.dev/r/collapsible.json

Usage

import { ChevronsUpDown } from "lucide-react"
 
import * as React from "react"
 
import { Button } from "@/components/ui/button"
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"
const [isOpen, setIsOpen] = React.useState(false)
<Collapsible
  open={isOpen}
  onOpenChange={setIsOpen}
  className="w-[350px] space-y-2"
>
  <div className="rounded-base flex items-center justify-between space-x-4 border-2 border-border text-foreground bg-background px-4 py-2">
    <h4 className="text-sm font-heading">
      @peduarte starred 3 repositories
    </h4>
    <CollapsibleTrigger render={<Button variant="noShadow" size="sm" className="w-9 bg-secondary-background text-foreground p-0" />}>
        <ChevronsUpDown className="size-4" />
        <span className="sr-only">Toggle</span>
      </CollapsibleTrigger>
  </div>
  <div className="rounded-base border-2 border-border bg-background px-4 py-3 font-mono font-base text-foreground text-sm">
    @radix-ui/primitives
  </div>
  <CollapsibleContent className="space-y-2 text-foreground font-base">
    <div className="rounded-base border-2 border-border bg-background px-4 py-3 font-mono text-sm">
      @radix-ui/colors
    </div>
    <div className="rounded-base border-2 border-border bg-background px-4 py-3 font-mono text-sm">
      @stitches/react
    </div>
  </CollapsibleContent>
</Collapsible>

Examples

Default

@peduarte starred 3 repositories

@radix-ui/primitives

Basic

A basic collapsible inside a Card. The trigger is rendered as a Button and the chevron rotates using the data-panel-open attribute.

Settings Panel

Use a trigger button to reveal additional settings.

Radius
Set the corner radius of the element.