Newer
Older
import React, { useState } from 'react'
import GenericExpansionPanel from 'components/CommonKit/ExpansionPanel/StyledSampleExpansionPanel'
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
const decoreText = (line: string) => {
if (line === ' ') {
return <span className="spaceline">{line}</span>
} else if (line.includes('<b>')) {
const indexStart = line.indexOf('<b>')
const indexEnd = line.indexOf('</b>')
return (
<>
{line.substring(0, indexStart)}
<span className="text-bold">
{line.substring(indexStart + 3, indexEnd)}
</span>
{line.substring(indexEnd + 4, line.length)}
</>
)
} else if (line.includes('<u>')) {
const indexStart = line.indexOf('<u>')
const indexEnd = line.indexOf('</u>')
return (
<>
{line.substring(0, indexStart)}
<span className="text-underline">
{line.substring(indexStart + 3, indexEnd)}
</span>
{line.substring(indexEnd + 4, line.length)}
</>
)
} else if (line.includes('<a>')) {
const indexStart = line.indexOf('<a>')
const indexEnd = line.indexOf('</a>')
return (
<>
{line.substring(0, indexStart)}
<a
href={line.substring(indexStart + 3, indexEnd)}
target="_blank"
rel="noopener noreferrer"
>
{line.substring(indexStart + 3, indexEnd)}
</a>
{line.substring(indexEnd + 4, line.length)}
</>
)
} else {
return line
}
}
const formatDetails = (details: Array<string>) => {
const formatedDetails: React.ReactNode[] = []
details.forEach((detail, index) => {
formatedDetails.push(
<div key={index} className="faq-content-detail">
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</div>
)
})
return formatedDetails
}
const FAQ = () => {
const [expandedPanel, setExpandedPanel] = useState<string | false>(false)
const handleChange = (panel: string) => (
event: React.ChangeEvent<{}>,
isExpanded: boolean
) => {
setExpandedPanel(isExpanded ? panel : false)
}
return (
<div className="faq-view-root">
<div className="faq-view-content">
{FAQJSon.map((question, index) => {
return (
<GenericExpansionPanel
key={index}
summary={question.summary}
details={formatDetails(question.details)}
expanded={expandedPanel === `panel${index}`}
onChange={handleChange(`panel${index}`)}
/>
)
})}
</div>
</div>
)
}
export default FAQ