Skip to content
Snippets Groups Projects
FAQ.tsx 1.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo NOUTS's avatar
    Hugo NOUTS committed
    import React, { useState } from 'react'
    import GenericExpansionPanel from 'components/CommonKit/ExpansionPanel/StyledSampleExpansionPanel'
    
    import FAQJSon from 'db/FAQ.json'
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    
    const formatDetails = (details: Array<string>) => {
      const formatedDetails: React.ReactNode[] = []
      details.forEach((detail, index) => {
        formatedDetails.push(
          <div key={index} className="faq-content-detail">
    
            {`${detail}`}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
          </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