Command Palette

Search for a command to run...

Docs
Compact Accordion

Compact Accordion

A clean and minimal accordion component with icons and smooth animations for organizing content in collapsible sections.

Loading...

Installation

Usage

import CompactAccordion, {
  CompactAccordionItem,
} from "@/components/ruixen/compact-accordion";
import { HelpCircle, Settings } from "lucide-react";
 
const items: CompactAccordionItem[] = [
  {
    icon: HelpCircle,
    value: "item-1",
    question: "What is this component?",
    answer:
      "This is a compact accordion component with icons and smooth animations.",
  },
  {
    icon: Settings,
    value: "item-2",
    question: "How do I customize it?",
    answer:
      "You can customize the styling using Tailwind CSS classes and pass different icons.",
  },
];
 
export default function MyAccordion() {
  return <CompactAccordion items={items} />;
}

Props

PropTypeDefaultDescription
itemsCompactAccordionItem[]-Array of accordion items to display
type"single" | "multiple""single"Whether only one or multiple items can be open
collapsiblebooleantrueWhether items can be collapsed
classNamestring"space-y-3"Additional CSS classes for the accordion container

CompactAccordionItem Structure

Each accordion item should have the following structure:

interface CompactAccordionItem {
  icon: ElementType; // Lucide React icon component
  value: string; // Unique identifier for the item
  question: string; // The question/title text
  answer: string; // The answer/content text
}

Features

  • Icon Integration: Each item displays a Lucide React icon for visual context
  • Smooth Animations: Built-in transitions for opening/closing states
  • Accessible: Built on Radix UI Accordion for proper accessibility
  • Dark Mode: Supports both light and dark themes
  • Customizable: Easy to style with Tailwind CSS
  • Responsive: Works well on all screen sizes
  • Visual Indicators: Shows item values and state changes

Examples

Basic Usage

import CompactAccordion from "@/components/ruixen/compact-accordion";
import { HelpCircle } from "lucide-react";
 
const basicItems = [
  {
    icon: HelpCircle,
    value: "faq-1",
    question: "How does this work?",
    answer:
      "This accordion component organizes content in collapsible sections.",
  },
];
 
<CompactAccordion items={basicItems} />;

Multiple Items Open

<CompactAccordion items={items} type="multiple" collapsible={true} />

Custom Styling

<CompactAccordion items={items} className="space-y-4 max-w-2xl" />

FAQ Section

import { HelpCircle, Info, Settings, Shield } from "lucide-react";
 
const faqItems = [
  {
    icon: HelpCircle,
    value: "general",
    question: "What is this service?",
    answer: "We provide a comprehensive solution for managing your workflow.",
  },
  {
    icon: Shield,
    value: "security",
    question: "Is my data secure?",
    answer: "Yes, we use enterprise-grade encryption and security measures.",
  },
  {
    icon: Settings,
    value: "setup",
    question: "How do I get started?",
    answer: "Simply sign up for an account and follow our onboarding guide.",
  },
  {
    icon: Info,
    value: "support",
    question: "How can I get help?",
    answer: "Contact our support team through the help center or live chat.",
  },
];
 
<CompactAccordion items={faqItems} />;

Styling

The component uses Tailwind CSS for styling and includes:

  • Hover Effects: Subtle background changes on hover
  • Focus States: Proper focus indicators for keyboard navigation
  • Active States: Visual feedback when items are expanded
  • Border Accents: Left border accent when items are open
  • Smooth Transitions: All state changes are animated

Accessibility

  • Built on Radix UI Accordion primitive
  • Full keyboard navigation support
  • Proper ARIA attributes for screen readers
  • Focus management and tab order
  • Semantic HTML structure

Dependencies

  • @radix-ui/react-accordion - For accessible accordion functionality
  • lucide-react - For icons
  • react - React framework