Docs
Collapse

Collapse

A vertically stacked set of interactive headings that each reveal a section of content.

Defualt

Installation

Install the following dependencies:

npm install @radix-ui/react-accordion

Copy and paste the following code into your project.

Update the import paths to match your project setup.

Update tailwind.config.js

Add the following animations to your tailwind.config.js file:

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      keyframes: {
        "accordion-down": {
          from: { height: "0" },
          to: { height: "var(--radix-accordion-content-height)" },
        },
        "accordion-up": {
          from: { height: "var(--radix-accordion-content-height)" },
          to: { height: "0" },
        },
      },
      animation: {
        "accordion-down": "accordion-down 0.2s ease-out",
        "accordion-up": "accordion-up 0.2s ease-out",
      },
    },
  },
}

Usage

import { Collapse, CollapseGroup } from "@/components/ui/accordion"
<CollapseGroup>
  <Collapse title="Question A">
    <Text className="mb-4" size={16}>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
      veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
      commodo consequat.
    </Text>
  </Collapse>
  <Collapse defaultExpanded title="Question B">
    <Text className="mb-4" size={16}>
      Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
      dolore eu fugiat nulla pariatur.
    </Text>
  </Collapse>
</CollapseGroup>