-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from choco-team/feat/137-studentInfo
[FE] 가로 스크롤 탭 UI 추가
- Loading branch information
Showing
9 changed files
with
191 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { FaChevronLeft, FaChevronRight } from 'react-icons/fa6'; | ||
|
||
import * as S from './style'; | ||
|
||
const Tab = ({ children }: React.PropsWithChildren) => { | ||
const [hasScroll, setHasScroll] = useState(false); | ||
const scrollRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleScrollTab = (scrollTo: 'left' | 'right') => { | ||
if (!scrollRef.current) return; | ||
const { clientWidth } = scrollRef.current; | ||
|
||
scrollRef.current.scrollBy({ | ||
top: 0, | ||
left: ((scrollTo === 'left' ? -1 : 1) * clientWidth) / 2, | ||
behavior: 'smooth', | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!scrollRef.current) return; | ||
|
||
const observer = new ResizeObserver((entries) => { | ||
const element = entries[0]; | ||
const { | ||
contentRect: { width }, | ||
target: { scrollWidth }, | ||
} = element; | ||
|
||
setHasScroll(width < scrollWidth); | ||
}); | ||
|
||
observer.observe(scrollRef.current); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<S.TabContainer> | ||
{hasScroll && ( | ||
<S.ScrollTabButton | ||
concept="text" | ||
onClick={() => handleScrollTab('left')} | ||
> | ||
<FaChevronLeft /> | ||
</S.ScrollTabButton> | ||
)} | ||
<S.ScrollBox ref={scrollRef}> | ||
<S.ListContainer>{children}</S.ListContainer> | ||
</S.ScrollBox> | ||
{hasScroll && ( | ||
<S.ScrollTabButton | ||
concept="text" | ||
onClick={() => handleScrollTab('right')} | ||
> | ||
<FaChevronRight /> | ||
</S.ScrollTabButton> | ||
)} | ||
</S.TabContainer> | ||
); | ||
}; | ||
|
||
Tab.Button = S.ListButton; | ||
|
||
export default Tab; |
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,66 @@ | ||
import styled from 'styled-components'; | ||
|
||
import Button from '@Components/Button'; | ||
|
||
import { flexCustom } from '@Styles/common'; | ||
|
||
export const TabContainer = styled.div` | ||
${flexCustom('row', 'flex-start', 'center', '8px')} | ||
width: 100%; | ||
`; | ||
|
||
export const ScrollTabButton = styled(Button)` | ||
${flexCustom('row', 'center', 'center')} | ||
margin-top: 0.25rem; | ||
width: 2rem; | ||
min-width: 2rem; | ||
height: 2rem; | ||
padding: 0; | ||
border-radius: 50%; | ||
`; | ||
|
||
export const ScrollBox = styled.div` | ||
width: 100%; | ||
padding-bottom: 5px; | ||
margin-bottom: 8px; | ||
overflow-x: auto; | ||
overflow-y: hidden; | ||
&::-webkit-scrollbar { | ||
height: 3px; | ||
} | ||
&::-webkit-scrollbar-thumb { | ||
background-color: ${({ theme }) => theme.border.gray}; | ||
border-radius: 10px; | ||
} | ||
`; | ||
|
||
export const ListContainer = styled.div` | ||
display: flex; | ||
column-gap: 0.5rem; | ||
width: max-content; | ||
`; | ||
|
||
export const ListButton = styled(Button)<{ | ||
$isSelected: boolean; | ||
}>` | ||
${flexCustom('row', 'center', 'center', '0.25rem')} | ||
border: none; | ||
background-color: ${({ theme, $isSelected }) => | ||
$isSelected ? theme.selectionBackground.primary : 'transparent'}; | ||
color: ${({ theme, $isSelected }) => | ||
$isSelected ? theme.accentText : theme.subText}; | ||
font-weight: ${({ $isSelected }) => ($isSelected ? 600 : 400)}; | ||
line-height: var(--title-button-line-height); | ||
transition: background-color 0.2s ease; | ||
&:hover { | ||
background-color: ${({ theme }) => theme.selectionBackground.primary}; | ||
} | ||
svg { | ||
color: ${({ theme }) => theme.color.warning[400]}; | ||
} | ||
`; |
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