-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFAQs.js
More file actions
77 lines (70 loc) · 2.6 KB
/
FAQs.js
File metadata and controls
77 lines (70 loc) · 2.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useState, useRef, useEffect } from "react";
import { FiPlus, FiMinus } from "react-icons/fi";
const FAQs = ({ metainfo }) => {
const [active, setActive] = useState("false");
const contentRef = useRef(null);
useEffect(() => {
contentRef.current.style.maxHeight = active
? `${contentRef.current.scrollHeight}px`
: "0px";
}, [contentRef, active]);
const toggleAnswer = (index) => {
if (active === index) {
return setActive("0");
}
setActive(index);
};
return (
<div
id="faqs"
className="relative mt-16 flex flex-col justify-center items-center py-24 md:px-16 px-0"
>
<h1 className="font-primary text-white text-5xl tracking-wider relative before:content[''] before:absolute before:w-3/4 before:h-1 before:-bottom-2 before:border-b-[3px] before:rounded-sm before:left-2 before:border-[#32F9E5]">
FAQs
</h1>
<div className="container max-w-screen-xl px-2.5 mt-9">
{metainfo.faqs.map((faq, index) => (
<div
key={index}
className="w-full flex-col justify-center items-start my-2 py-3 border-b-2 border-gray-800"
>
<div
onClick={() => toggleAnswer(index)}
className="inline-flex justify-between items-center w-full cursor-pointer"
>
<h2 className="font-body text-left font-bold text-white md:text-xl text-lg md:mr-40">
{faq.question}
</h2>
{active === index ? (
<button
className={`font-primary md:text-2xl text-xl text-brand-primary-highlight md:p-2 p-2 bg-brand-highlight border-2 border-brand-primary-highlight rounded-full inline-flex justify-center items-center`}
onClick={() => toggleAnswer(index)}
>
<FiMinus />
</button>
) : (
<button
className={`font-primary text-2xl text-brand-highlight md:p-2 p-2 border-2 border-brand-primary-highlight rounded-full inline-flex justify-center items-center`}
onClick={() => toggleAnswer(index)}
>
<FiPlus />
</button>
)}
</div>
<p
ref={contentRef}
className={
active === index
? `block mt-2 max-w-3xl font-body font-semibold text-sm text-gray-300`
: `hidden`
}
>
{faq.answer}
</p>
</div>
))}
</div>
</div>
);
};
export default FAQs;