-
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 #10 from JECT-Study/feature/design-system
[TASK-46, 47] style: Pagination, FilterDropdown 구현
- Loading branch information
Showing
10 changed files
with
218 additions
and
26 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 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; |