-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: storybook emotion 설정 - storybookjs/storybook#7540 * feat: svg wrapper component * feat: arrow icon * feat: typo theme * feat: emotion theme * feat: emotion faq example * feat: emotion theme * feat: emotion faq example * feat: typo theme * chore: vscode typescript 버전 세팅 * chore: rename FAQ -> FAQItem * feat: create FAQList * feat: create FAQList story * feat: li list style none * chore: mock 데이터 위치 수정
- Loading branch information
1 parent
5905a6d
commit 9947e15
Showing
7 changed files
with
189 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { css, Theme } from '@emotion/react'; | ||
import { motion, Variants } from 'framer-motion'; | ||
|
||
import { ArrowIcon } from '~/components/Icons'; | ||
import { theme } from '~/styles/theme'; | ||
|
||
interface FAQItemProps { | ||
isOpen: boolean; | ||
onClickOpenButton: () => void; | ||
title: string; | ||
description: string; | ||
} | ||
|
||
export function FAQItem({ isOpen, onClickOpenButton, title, description }: FAQItemProps) { | ||
return ( | ||
<li onClick={onClickOpenButton}> | ||
<motion.div | ||
css={theme => headerCss(theme, isOpen)} | ||
animate={isOpen ? 'open' : 'closed'} | ||
variants={headerVariants} | ||
transition={{ duration: 0.3, ease: 'easeOut' }} | ||
> | ||
<h3>{title}</h3> | ||
<motion.div variants={arrowIconVariants} transition={{ duration: 0.3, ease: 'easeOut' }}> | ||
<ArrowIcon | ||
direction={isOpen ? 'up' : 'down'} | ||
css={theme => arrowIconCss(theme, isOpen)} | ||
/> | ||
</motion.div> | ||
</motion.div> | ||
|
||
<motion.div | ||
css={bodyCss} | ||
initial={{ opacity: 0, height: 0 }} | ||
animate={isOpen ? 'open' : 'closed'} | ||
variants={bodyVariants} | ||
transition={{ duration: 0.3, height: 0, ease: 'easeOut' }} | ||
> | ||
<p>{description}</p> | ||
</motion.div> | ||
</li> | ||
); | ||
} | ||
|
||
const headerVariants: Variants = { | ||
open: { backgroundColor: theme.colors.blue400 }, | ||
closed: { backgroundColor: theme.colors.black400 }, | ||
}; | ||
|
||
const bodyVariants: Variants = { | ||
open: { opacity: 1, height: 'fit-content' }, | ||
closed: { opacity: 0, height: 0 }, | ||
}; | ||
|
||
const arrowIconVariants: Variants = { | ||
open: { stroke: theme.colors.black800 }, | ||
closed: { stroke: theme.colors.blue400 }, | ||
}; | ||
|
||
const headerCss = (theme: Theme, isOpen: boolean) => css` | ||
background-color: ${isOpen ? theme.colors.blue400 : theme.colors.black400}; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 25px 30px; | ||
> h3 { | ||
color: ${isOpen ? theme.colors.black800 : theme.colors.white}; | ||
text-align: center; | ||
${theme.typos.pretendard.subTitle2} | ||
} | ||
`; | ||
|
||
const arrowIconCss = (theme: Theme, isOpen: boolean) => css` | ||
> path { | ||
stroke: ${isOpen ? theme.colors.black800 : theme.colors.blue400}; | ||
} | ||
`; | ||
|
||
const bodyCss = (theme: Theme) => css` | ||
background-color: ${theme.colors.black800}; | ||
> p { | ||
padding: 40px; | ||
color: ${theme.colors.white}; | ||
${theme.typos.pretendard.body1}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useState } from 'react'; | ||
|
||
import { FAQItem } from '~/components/FAQ/FAQItem'; | ||
|
||
type FAQListType = { title: string; description: string }; | ||
|
||
interface FAQListProps { | ||
FAQList: FAQListType[]; | ||
} | ||
|
||
const DEFAULT_OPEN = 0; | ||
const CLOSE = -1; | ||
|
||
export function FAQList({ FAQList }: FAQListProps) { | ||
const [activeIndex, setActiveIndex] = useState(DEFAULT_OPEN); | ||
|
||
const onClickActiveFaq = (idx: number) => { | ||
/** | ||
* 열려 있는 아이템 다시 클릭하면 닫히게 하기 | ||
*/ | ||
setActiveIndex(prev => (prev === idx ? CLOSE : idx)); | ||
}; | ||
|
||
return ( | ||
<ul> | ||
{FAQList.map((item, index) => ( | ||
<FAQItem | ||
key={item.title} | ||
isOpen={activeIndex === index} | ||
onClickOpenButton={() => onClickActiveFaq(index)} | ||
{...item} | ||
/> | ||
))} | ||
</ul> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
export { FAQ } from './FAQ'; | ||
import { FAQItem } from '~/components/FAQ/FAQItem'; | ||
import { FAQList } from '~/components/FAQ/FAQList'; | ||
|
||
export const FAQ = Object.assign( | ||
{}, | ||
{ | ||
List: FAQList, | ||
Item: FAQItem, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,8 @@ export const resetCss = css` | |
line-height: 1; | ||
} | ||
ol, | ||
ul { | ||
ul, | ||
li { | ||
list-style: none; | ||
} | ||
blockquote, | ||
|