Accordion
NewInstallation
npx shadcn@latest add https://uibrik.com/r/accordion.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/accordion/accordion.tsx"use client"; // Sections that open and close in place. The panel eases to its height while // its content fades up a few pixels behind it, and the icon turns as it goes. // One open at a time, or several. Headers are real buttons inside headings; // Up/Down, Home and End move between them. import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useId, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; export type AccordionItem = { title: ReactNode; content: ReactNode }; export type AccordionProps = { items: readonly AccordionItem[]; /** One section open at a time, or any number. */ type?: "single" | "multiple"; /** Indexes open at first. */ defaultOpen?: readonly number[]; /** Open indexes, controlled. Pair with `onOpenChange`. */ open?: readonly number[]; onOpenChange?: (open: number[]) => void;
Adds the files to
components/uibrik/accordion and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/accordion.Props
Accordion- type
- Type "single" | "multiple"
- "single"
- How many sections can be open at once.
- variant
- Type "divided" | "separated"
- "divided"
- Hairlines between sections, or each section as its own card.
- icon
- Type "chevron" | "plus"
- "chevron"
- Chevron that turns, or plus that becomes minus.
- itemsrequired
- Type { title: ReactNode; content: ReactNode }[]
- –
- The sections.
- defaultOpen
- Type number[]
- –
- Indexes open at first.
- open / onOpenChange
- Type number[] / (open) => void
- –
- Open indexes, controlled.
- className
- Type string
- –
- Classes for the list.