-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 우선순위 결과에서 해당 시간대에 불가능한 사람 수 표시 (#133)
* fix: update font weight * feat: add accordion component
- Loading branch information
1 parent
b1b3ee1
commit 2e328ed
Showing
14 changed files
with
277 additions
and
89 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,82 @@ | ||
import theme from '@/styles/theme'; | ||
import styled from '@emotion/styled'; | ||
|
||
export const Wrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
`; | ||
|
||
export const Group = styled.section` | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
cursor: pointer; | ||
`; | ||
|
||
export const GroupInfo = styled.div` | ||
display: flex; | ||
${theme.colors.gray07}; | ||
${theme.typography.medium01}; | ||
`; | ||
|
||
export const ListWrapper = styled.div` | ||
width: 100%; | ||
height: 0px; | ||
overflow: hidden; | ||
transition: height 0.35s ease, background 0.35s ease; | ||
`; | ||
|
||
export const AccordionIcon = styled.img<{ isCollapsed: boolean }>` | ||
transition: transform 0.3s ease; | ||
transform: ${({ isCollapsed }) => | ||
isCollapsed ? 'rotate(0deg)' : 'rotate(180deg)'}; | ||
`; | ||
|
||
export const ItemWrapper = styled.div` | ||
padding: 16px 0 0 0; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
`; | ||
|
||
export const Item = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
`; | ||
|
||
export const InfoText = styled.div` | ||
color: #979797; | ||
${theme.typography.medium05}; | ||
.available { | ||
color: ${theme.colors.purple06}; | ||
} | ||
.unavailable { | ||
color: ${theme.colors.orange02}; | ||
} | ||
`; | ||
|
||
export const NameList = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 4px; | ||
`; | ||
|
||
export const NameBlock = styled.div` | ||
width: 46.5px; | ||
height: 24px; | ||
background: #ffffff; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border-radius: 2.8px; | ||
${theme.typography.medium05}; | ||
color: ${theme.colors.gray05}; | ||
`; |
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,106 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { | ||
AccordionIcon, | ||
Group, | ||
GroupInfo, | ||
InfoText, | ||
Item, | ||
ItemWrapper, | ||
ListWrapper, | ||
NameBlock, | ||
NameList, | ||
Wrapper, | ||
} from './index.styles'; | ||
import accordionUnfold from '@/assets/icons/accordionUnfold.svg'; | ||
|
||
interface Props { | ||
title: string; | ||
defaultOpen?: boolean; | ||
totalCount: number; | ||
availableParticipantNames: string[]; | ||
unavailableParticipantNames: string[]; | ||
} | ||
|
||
const Accordion = ({ | ||
title, | ||
defaultOpen = false, | ||
totalCount, | ||
availableParticipantNames, | ||
unavailableParticipantNames, | ||
}: Props) => { | ||
const parentRef = useRef<HTMLDivElement>(null); | ||
const childRef = useRef<HTMLDivElement>(null); | ||
|
||
const [isCollapsed, setIsCollapsed] = useState<boolean>(defaultOpen); | ||
|
||
useEffect(() => { | ||
if (defaultOpen && parentRef.current && childRef.current) { | ||
parentRef.current.style.height = `${childRef.current.clientHeight}px`; | ||
} | ||
}, [defaultOpen]); | ||
|
||
const handleClickAccordion = () => { | ||
if ( | ||
totalCount === 0 || | ||
parentRef.current === null || | ||
childRef.current === null | ||
) { | ||
return; | ||
} | ||
|
||
if (parentRef.current.clientHeight > 0) { | ||
parentRef.current.style.height = '0px'; | ||
} else if (parentRef.current.clientHeight === 0) { | ||
parentRef.current.style.height = `${childRef.current.clientHeight}px`; | ||
} | ||
|
||
setIsCollapsed(!isCollapsed); | ||
}; | ||
|
||
return ( | ||
<Wrapper> | ||
<Group onClick={handleClickAccordion}> | ||
<GroupInfo>{title}</GroupInfo> | ||
{!!totalCount && ( | ||
<AccordionIcon | ||
src={accordionUnfold} | ||
alt={isCollapsed ? '펼치기' : '접기'} | ||
isCollapsed={isCollapsed} | ||
/> | ||
)} | ||
</Group> | ||
|
||
<ListWrapper ref={parentRef}> | ||
<ItemWrapper ref={childRef}> | ||
<Item> | ||
<InfoText> | ||
<span>{`${totalCount}명 중 `}</span> | ||
<span className="available">{`${availableParticipantNames.length}명 가능`}</span> | ||
</InfoText> | ||
<NameList> | ||
{!!availableParticipantNames.length && | ||
availableParticipantNames.map((name) => ( | ||
<NameBlock key={name}>{name.slice(0, 4)}</NameBlock> | ||
))} | ||
</NameList> | ||
</Item> | ||
|
||
<Item> | ||
<InfoText> | ||
<span>{`${totalCount}명 중 `}</span> | ||
<span className="unavailable">{`${unavailableParticipantNames.length}명 불가능`}</span> | ||
</InfoText> | ||
<NameList> | ||
{!!unavailableParticipantNames.length && | ||
unavailableParticipantNames.map((name) => ( | ||
<NameBlock key={name}>{name.slice(0, 4)}</NameBlock> | ||
))} | ||
</NameList> | ||
</Item> | ||
</ItemWrapper> | ||
</ListWrapper> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default Accordion; |
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 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 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 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
Oops, something went wrong.