|
1 |
| -import { FaChevronRight } from "react-icons/fa"; |
| 1 | +import { useState } from "react"; |
| 2 | +import { FaChevronRight, FaChevronDown } from "react-icons/fa"; |
| 3 | + |
| 4 | +interface Faq { |
| 5 | + question: string; |
| 6 | + answer: string; |
| 7 | +} |
| 8 | + |
| 9 | +const Faqs: React.FC = () => { |
| 10 | + const [activeIndex, setActiveIndex] = useState<number | null>(null); |
| 11 | + |
| 12 | + const faqs: Faq[] = [ |
| 13 | + { |
| 14 | + question: "What does Renergy Hub offer?", |
| 15 | + answer: "Renergy Hub offers innovative and sustainable energy solutions for homes, businesses, and communities.", |
| 16 | + }, |
| 17 | + { |
| 18 | + question: "What are the benefits of Renergy Hub products?", |
| 19 | + answer: "They provide reliable, eco-friendly energy, reduce utility costs, and support a sustainable future.", |
| 20 | + }, |
| 21 | + { |
| 22 | + question: "How do I install Renergy Hub products?", |
| 23 | + answer: "Installation is simple and handled by certified professionals or guided by clear user instructions.", |
| 24 | + }, |
| 25 | + { |
| 26 | + question: "How often should I inspect Renergy Hub products?", |
| 27 | + answer: "Regular inspections every 6–12 months are recommended to ensure optimal performance.", |
| 28 | + }, |
| 29 | + { |
| 30 | + question: "How can I purchase the Renergy Hub products?", |
| 31 | + answer: "Products can be purchased directly from our website or through authorized distributors.", |
| 32 | + }, |
| 33 | + ]; |
| 34 | + |
| 35 | + const toggleAnswer = (index: number): void => { |
| 36 | + setActiveIndex(activeIndex === index ? null : index); |
| 37 | + }; |
2 | 38 |
|
3 |
| -const Faqs = () => { |
4 | 39 | return (
|
5 | 40 | <div className="flex flex-col px-4 py-8 md:px-8 lg:px-32">
|
6 | 41 | <h2 className="text-2xl font-bold mb-6">FAQs</h2>
|
7 | 42 | <div className="w-full space-y-4">
|
8 |
| - {[ |
9 |
| - "What does Renergy Hub offer?", |
10 |
| - "What are the benefits of Renergy Hub products?", |
11 |
| - "How do I install Renergy Hub products?", |
12 |
| - "How often should I inspect Renergy Hub products?", |
13 |
| - "How can I purchase the Renergy Hub products?", |
14 |
| - ].map((question, index) => ( |
| 43 | + {faqs.map((faq, index) => ( |
15 | 44 | <div
|
16 | 45 | key={index}
|
17 |
| - className="flex items-center justify-between p-4 border border-gray-300 rounded-lg hover:shadow-md transition-shadow cursor-pointer" |
| 46 | + className="border border-gray-300 rounded-lg hover:shadow-md transition-shadow" |
18 | 47 | >
|
19 |
| - <p className="text-gray-700 cursor-pointer">{question}</p> |
20 |
| - <FaChevronRight className="text-gray-500" /> |
| 48 | + <div |
| 49 | + className="flex items-center justify-between p-4 cursor-pointer" |
| 50 | + onClick={() => toggleAnswer(index)} |
| 51 | + > |
| 52 | + <p className="text-gray-700">{faq.question}</p> |
| 53 | + {activeIndex === index ? ( |
| 54 | + <FaChevronDown className="text-gray-500" /> |
| 55 | + ) : ( |
| 56 | + <FaChevronRight className="text-gray-500" /> |
| 57 | + )} |
| 58 | + </div> |
| 59 | + {activeIndex === index && ( |
| 60 | + <div className="p-4 text-gray-600 bg-green-50"> |
| 61 | + {faq.answer} |
| 62 | + </div> |
| 63 | + )} |
21 | 64 | </div>
|
22 | 65 | ))}
|
23 | 66 | </div>
|
|
0 commit comments