Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix faq dropdown function #376

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/components/FaqBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const Container = styled.div`
overflow:hidden;

${p => p.expanded
? `
? `
border-color: #C4B2F0;
`
: `
: `
border-color: #C4B2F0;
`}

Expand Down Expand Up @@ -75,15 +75,10 @@ const Arrow = ({ color }) => (
</svg>
)

const FaqBox = ({ question, answer }) => {
const [isExpanded, setIsExpanded] = useState(false)

const FaqBox = ({ question, answer, isExpanded, onExpand }) => {
return (
<Container
expanded={isExpanded}>
<Top
expanded={isExpanded}
onClick={() => setIsExpanded(!isExpanded)}>
<Container expanded={isExpanded}>
<Top expanded={isExpanded} onClick={onExpand}>
{question}
<TopExpand style={isExpanded ? { transform: 'rotate(0)' } : { transform: 'rotate(180deg)' }}>
<Arrow color={isExpanded ? '#2C2543' : '#2C2543'} />
Expand Down
41 changes: 31 additions & 10 deletions src/sections/Faq.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const bobbing = keyframes`
50% {
transform: translateY(-20px);
}
`;
`

const Nugget = styled.div`
background: url('assets/background/faq/nugget.png') no-repeat;
Expand Down Expand Up @@ -211,16 +211,31 @@ display:none;
}
`

const FaqCollection = ({ category, faqs }) => (
const FaqCollection = ({ category, faqs, expandedQuestion, setExpandedQuestion }) => (
<CollectionContainer>
<CollectionName>{category}</CollectionName>

{faqs.map(q => <FaqBox key={q.question} question={q.question} answer={q.answer} />)}
{faqs.map(q =>
<FaqBox
key={q.question}
question={q.question}
answer={q.answer}
isExpanded={expandedQuestion === q.question}
onExpand={() => {
if (expandedQuestion === q.question) {
setExpandedQuestion(null)
} else {
setExpandedQuestion(q.question)
}
}}
/>
)}
</CollectionContainer>
)

const Faq = () => {
const [faqData, setFaqData] = useState(null)
const [expandedQuestion, setExpandedQuestion] = useState(null)

// (@htdf processData)
// (@signature (listof FAQ) -> Object)
Expand Down Expand Up @@ -249,7 +264,7 @@ const Faq = () => {
<Nugget></Nugget>
<BearArm />
<DeerArm></DeerArm>
<BgScroll/>
<BgScroll />
<Wrapper id="faq">
<StyledTitle>
FAQ
Expand All @@ -258,24 +273,30 @@ const Faq = () => {
{faqData
? (
<FaqGrid>

<FaqColumn>
{faqData.General &&
<FaqCollection category="General" faqs={faqData.General} />
<FaqCollection
category="General"
faqs={faqData.General}
expandedQuestion={expandedQuestion}
setExpandedQuestion={setExpandedQuestion}
/>
}
</FaqColumn>

<FaqColumn>
{faqData["Teams & Projects"] &&
<FaqCollection category="Projects" faqs={faqData["Teams & Projects"]} />
{faqData['Teams & Projects'] &&
<FaqCollection category="Projects" faqs={faqData['Teams & Projects']} expandedQuestion={expandedQuestion}
setExpandedQuestion={setExpandedQuestion} />
}
{faqData.Logistics &&
<FaqCollection category="Logistics" faqs={faqData.Logistics} />
<FaqCollection category="Logistics" faqs={faqData.Logistics} expandedQuestion={expandedQuestion}
setExpandedQuestion={setExpandedQuestion} />
}
</FaqColumn>

</FaqGrid>
)
)
: 'loading...'}

</Wrapper>
Expand Down
Loading