-
Notifications
You must be signed in to change notification settings - Fork 0
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
[TASK-46, 47] style: Pagination, FilterDropdown 구현 #10
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ddb2e2
style: 초기 테마(dark)를 명시적으로 설정
dahyeo-n 0ff8c28
style: Pagination 구현
dahyeo-n 47c2254
style: Pagination의 페이지 범위 제한 (5페이지까지 보이게)
dahyeo-n 1053492
refactor: 명확한 변수명으로 변경
dahyeo-n 6d772d9
style: Pagination 폰트 스타일 추가
dahyeo-n 1f04619
style: FilterDropdown UI 구축
dahyeo-n faefae1
style: 토글 아이콘 추가
dahyeo-n a135af1
chore: 접근성 고려를 위한 aria-label 추가
dahyeo-n 4ba46ae
feat: 드롭다운 클릭 외부 감지 기능 추가
dahyeo-n 5a0a531
feat: 드롭다운 접근성 개선을 위한 aria-expanded 및 role 속성 추가
dahyeo-n 0ea5c0b
refactor: 명확한 변수명으로 변경
dahyeo-n f18e373
refactor: children 강제성 제외를 위해 React.FC 타입 제거
dahyeo-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,83 @@ | ||
'use client'; | ||
|
||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import Icon from '../Icon/Icon'; | ||
|
||
interface FilterDropdownProps { | ||
options: string[]; | ||
selected: string; | ||
onChange: (value: string) => void; | ||
} | ||
|
||
const FilterDropdown = ({ | ||
options, | ||
selected, | ||
onChange, | ||
}: FilterDropdownProps) => { | ||
const [isDropdownOpen, setIsDropdownOpen] = useState(false); | ||
const dropdownRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const handleClickOutside = (event: MouseEvent) => { | ||
if ( | ||
dropdownRef.current && | ||
!dropdownRef.current.contains(event.target as Node) | ||
) { | ||
setIsDropdownOpen(false); | ||
} | ||
}; | ||
|
||
document.addEventListener('mousedown', handleClickOutside); | ||
return () => document.removeEventListener('mousedown', handleClickOutside); | ||
}, []); | ||
|
||
const handleOptionSelect = (option: string) => { | ||
onChange(option); | ||
setIsDropdownOpen(false); | ||
}; | ||
|
||
return ( | ||
<div className='body2 relative inline-block text-left' ref={dropdownRef}> | ||
<button | ||
onClick={() => setIsDropdownOpen(!isDropdownOpen)} | ||
aria-label={`Currently selected filter: ${selected}`} | ||
aria-expanded={isDropdownOpen} | ||
className='flex items-center justify-between w-[149px] h-[44px] px-[23px] py-[10px] | ||
text-white bg-gray-900 rounded-[5px] gap-[36px] shadow-sm | ||
hover:bg-gray-800 focus:outline-none' | ||
> | ||
{selected} | ||
<span className='text-gray-300'> | ||
{isDropdownOpen ? ( | ||
<Icon name='ChevronUp' size='m' /> | ||
) : ( | ||
<Icon name='ChevronDown' size='m' /> | ||
)} | ||
</span> | ||
</button> | ||
|
||
{isDropdownOpen && ( | ||
<div | ||
className='w-full mt-3 bg-gray-900 rounded-[5px] shadow-lg' | ||
role='menu' | ||
> | ||
<ul className='py-1'> | ||
{options.map((option, index) => ( | ||
<li | ||
key={index} | ||
onClick={() => handleOptionSelect(option)} | ||
aria-current={option === selected ? 'true' : undefined} | ||
className={`block w-[149px] h-[44px] px-[23px] py-[10px] text-gray-400 cursor-pointer hover:bg-gray-800`} | ||
> | ||
{option} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FilterDropdown; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import Icon from '../Icon/Icon'; | ||
|
||
interface PaginationProps { | ||
currentPage: number; | ||
totalPages: number; | ||
onPageChange: (page: number) => void; | ||
} | ||
|
||
const Pagination = ({ | ||
currentPage, | ||
totalPages, | ||
onPageChange, | ||
}: PaginationProps) => { | ||
const isFirstPage = currentPage === 1; | ||
const isLastPage = currentPage === totalPages; | ||
|
||
const calculateVisiblePages = ( | ||
currentPage: number, | ||
totalPages: number, | ||
maxVisiblePages: number, | ||
): number[] => { | ||
const startPage = Math.max( | ||
1, | ||
currentPage - Math.floor(maxVisiblePages / 2), | ||
); | ||
const endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); | ||
const adjustedStartPage = Math.max(1, endPage - maxVisiblePages + 1); | ||
|
||
return Array.from( | ||
{ length: endPage - adjustedStartPage + 1 }, | ||
(_, i) => adjustedStartPage + i, | ||
); | ||
}; | ||
|
||
const visiblePages = calculateVisiblePages(currentPage, totalPages, 5); | ||
|
||
return ( | ||
<div className='flex items-center justify-center gap-6'> | ||
<div className='flex gap-1' id='first-previous-buttons'> | ||
<button | ||
onClick={() => onPageChange(1)} | ||
disabled={isFirstPage} | ||
aria-label='Go to first page' | ||
className={`p-2 rounded ${ | ||
isFirstPage ? 'text-gray-600 cursor-not-allowed' : 'text-gray-300' | ||
}`} | ||
> | ||
<Icon name='ChevronDoubleLeft' size='s' /> | ||
</button> | ||
|
||
<button | ||
onClick={() => onPageChange(currentPage - 1)} | ||
disabled={isFirstPage} | ||
aria-label='Go to previous page' | ||
className={`p-2 rounded ${ | ||
isFirstPage ? 'text-gray-600 cursor-not-allowed' : 'text-gray-300' | ||
}`} | ||
> | ||
<Icon name='ChevronLeft' size='s' /> | ||
</button> | ||
</div> | ||
|
||
<div className='flex gap-1' id='number-buttons'> | ||
{visiblePages.map((page) => ( | ||
<button | ||
key={page} | ||
onClick={() => onPageChange(page)} | ||
aria-current={page === currentPage ? 'page' : undefined} | ||
className={`button-s p-3 w-[46px] rounded-full transition-colors ${ | ||
page === currentPage | ||
? 'bg-main text-white' | ||
: 'text-gray-600 hover:bg-gray-900' | ||
}`} | ||
> | ||
{page} | ||
</button> | ||
))} | ||
</div> | ||
|
||
<div className='flex gap-1' id='next-last-buttons'> | ||
<button | ||
onClick={() => onPageChange(currentPage + 1)} | ||
disabled={isLastPage} | ||
aria-label='Go to next page' | ||
className={`p-2 rounded ${ | ||
isLastPage ? 'text-gray-600 cursor-not-allowed' : 'text-gray-300' | ||
}`} | ||
> | ||
<Icon name='ChevronRight' size='s' /> | ||
</button> | ||
|
||
<button | ||
onClick={() => onPageChange(totalPages)} | ||
disabled={isLastPage} | ||
aria-label='Go to last page' | ||
className={`p-2 rounded ${ | ||
isLastPage ? 'text-gray-600 cursor-not-allowed' : 'text-gray-300' | ||
}`} | ||
> | ||
<Icon name='ChevronDoubleRight' size='s' /> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Pagination; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에서 직접 이벤트를 할당해주신 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event
를 직접 할당한 이유는mousedown
이벤트 객체를 활용하기 위해서예요!더 자세히 설명하면,
event.target
을 확인하기 위해서:
event.target
은 사용자가 클릭한 HTML 요소를 참조해요.타입 안정성을 위해서
event
에MouseEvent
타입을 명시했어요.따라서,
event
를 명시적으로 사용하지 않으면 클릭된 요소를 알 수 없어서 외부 클릭 감지 기능이 제대로 작동되지 않을 수도 있어요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설명 감사합니다! 코드를 리뷰하면서 onBlur를 활용할 수 있지 않을까 생각도 해봤는데 onBlur를 포커싱이 불가능한 요소에 적용했을 때는 별도로 추가 처리가 필요해져서 onBlur의 의도와는 다르게 억지로 활용하는 느낌이라 다현님께서 구현한 방식이 더 괜찮겠다는 생각을 했습니다! 👍👍👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오옹 감사합니다! 답변드리며 저도 더 공부되는 느낌이라 너무 좋습니다 👍🏻✨