Skip to content

Commit

Permalink
Merge pull request #317 from GDSC-PKNU-Official/feat/#316
Browse files Browse the repository at this point in the history
Reafactor(FAQBox): 재사용 컴포넌트 ToggleInfo 적용
  • Loading branch information
hwinkr authored Feb 5, 2024
2 parents 97ba73b + 0d5f08f commit 012bd3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 52 deletions.
79 changes: 28 additions & 51 deletions src/components/FAQBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Icon from '@components/Common/Icon';
import ToggleInfo from '@components/Common/ToggleInfo';
import { FAQ_CONSTANTS } from '@constants/FAQ';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { THEME } from '@styles/ThemeProvider/theme';
import openLink from '@utils/router/openLink';
import React, { useState } from 'react';
import React from 'react';

interface FAQBoxProps {
readonly question: string;
Expand All @@ -15,80 +15,57 @@ interface FAQBoxProps {
}

const FAQBox = ({ question, answer }: FAQBoxProps) => {
const [showAnswer, setShowAnswer] = useState<boolean>(false);
const toggleAnswer = () => setShowAnswer((prevState) => !prevState);

const seperatedAnswerText = answer.text.split(FAQ_CONSTANTS.LINE_SEPERATOR);
const moveToLink = () => {
if (!answer.link) return;

openLink(answer.link);
};
const hasAnswerLink = () => !!answer.link;

const hasLink = !!answer.link;

return (
<>
<QuestionContainer onClick={toggleAnswer} showAnswer={showAnswer}>
<QuestionMark>{FAQ_CONSTANTS.QUESTION_MARK}</QuestionMark>
<QuestionText>{question}</QuestionText>
<IconContainer>
<Icon kind="arrowDown" size="24" />
</IconContainer>
</QuestionContainer>
{showAnswer && (
<AnswerContainer>
{seperatedAnswerText.map((line, index) => (
<p key={index}>{line}</p>
))}
{hasAnswerLink() && (
<StyledLink onClick={moveToLink}>{FAQ_CONSTANTS.LINK}</StyledLink>
)}
</AnswerContainer>
)}
<ToggleInfo
infoTitle={() => (
<>
<span
css={css`
font-weight: bold;
`}
>
{FAQ_CONSTANTS.QUESTION_MARK}
</span>
<QuestionText>{question}</QuestionText>
</>
)}
infoDesc={() => (
<AnswerContainer>
{answer.text}
{hasLink && (
<StyledLink onClick={moveToLink}>{FAQ_CONSTANTS.LINK}</StyledLink>
)}
</AnswerContainer>
)}
/>
<BoundaryLine />
</>
);
};

export default FAQBox;

const QuestionContainer = styled.div<{ showAnswer: boolean }>`
position: relative;
padding: 10px 0px 10px 0px;
display: flex;
align-items: center;
${({ showAnswer }) => css`
& > span {
color: ${showAnswer && THEME.PRIMARY};
}
& > div > svg {
transform: ${showAnswer ? 'rotate(-180deg)' : 'rotate(0deg)'};
transition: all ease 0.3s;
}
`}
`;

const QuestionMark = styled.span`
font-weight: bold;
`;

const QuestionText = styled.span`
text-indent: 1rem;
`;

const IconContainer = styled.div`
position: absolute;
right: 0;
display: flex;
`;

const AnswerContainer = styled.div`
background-color: #7a9dd31a;
color: ${THEME.TEXT.BLACK};
line-height: 1.8;
padding: 10px 20px 10px 20px;
border-radius: 10px;
margin-bottom: 10px;
white-space: pre-line;
`;

const StyledLink = styled.span`
Expand Down
2 changes: 1 addition & 1 deletion src/constants/FAQ/faq-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const FAQ_DATA: FAQ[] = [
{
question: '이미 앱스토어로 다운 받았어요.(IOS)',
answer: {
text: '이미 앱스토어로 다운 받으셨다면 기존의 앱을 지운 후 아래의 링크로 이동해 방법을 따라해주세요 :)',
text: '이미 앱스토어로 다운 받으셨다면 기존의 앱을 지운 후 아래의 링크로 이동해 방법을 따라해주세요 :)\n',
link: 'https://burimi.notion.site/IOS-71bbd68542f24b8db00718367d327597',
},
},
Expand Down

0 comments on commit 012bd3f

Please sign in to comment.