All files / src/components/faq/FAQ FAQ.tsx

0% Statements 0/6
0% Branches 0/6
0% Functions 0/4
0% Lines 0/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
import React, { useState } from "react";
import { ChevronDown, ChevronUp } from "lucide-react";
 
type FAQItem = {
  question: React.ReactNode;
  answer: React.ReactNode;
};
 
interface FAQProps {
  items: FAQItem[];
}
 
export default function FAQ({ items }: FAQProps) {
  const [openIndex, setOpenIndex] = useState<number | null>(null);
 
  const toggle = (index: number) => {
    setOpenIndex(openIndex === index ? null : index);
  };
 
  return (
    <div className="max-w-2xl p-4 space-y-4">
      {items.map((item, index) => (
        <div
          key={index}
          className="border rounded-2xl shadow-sm overflow-hidden"
        >
          <button
            className="w-full flex justify-between items-center p-4 bg-gray-50 hover:bg-gray-100 transition-colors"
            onClick={() => toggle(index)}
          >
            <span className="text-left font-medium">{item.question}</span>
            {openIndex === index ? (
              <ChevronUp className="w-5 h-5 text-gray-500" />
            ) : (
              <ChevronDown className="w-5 h-5 text-gray-500" />
            )}
          </button>
          {openIndex === index && (
            <div className="p-4 bg-white text-gray-700 border-t">
              {item.answer}
            </div>
          )}
        </div>
      ))}
    </div>
  );
}