-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'React-정원식-Sprint5' into React-정원식
- Loading branch information
Showing
10 changed files
with
196 additions
and
48 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,33 @@ | ||
.pagination-bar { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.btn-pagination { | ||
border: 1px solid #e5e7eb; | ||
border-radius: 50%; | ||
width: 40px; | ||
height: 40px; | ||
color: #6b7280; | ||
font-weight: 600; | ||
font-size: 16px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-right: 20px; | ||
} | ||
|
||
.btn-pagination:last-child { | ||
margin-right: 0; | ||
} | ||
|
||
.btn-pagination:disabled { | ||
cursor: default; | ||
opacity: 0.5; | ||
} | ||
|
||
.btn-pagination.active { | ||
background-color: var(--blue); | ||
color: #fff; | ||
} |
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,55 @@ | ||
import React from 'react'; | ||
import './PaginatinoBar.css'; | ||
import { ReactComponent as IconArrowLeft } from '../../../assets/images/icons/arrow_left.svg'; | ||
import { ReactComponent as IconArrowRight } from '../../../assets/images/icons/arrow_right.svg'; | ||
|
||
function PaginationBar({ totalPageNum, activePageNum, onPageChange }) { | ||
const maxVisiblePages = 5; | ||
let startPage; | ||
|
||
if (totalPageNum <= maxVisiblePages) { | ||
startPage = 1; | ||
} else { | ||
startPage = Math.max(activePageNum - Math.floor(maxVisiblePages / 2), 1); | ||
startPage = Math.min(startPage, totalPageNum - maxVisiblePages + 1); | ||
} | ||
|
||
const pages = Array.from( | ||
{ length: Math.min(maxVisiblePages, totalPageNum - startPage + 1) }, | ||
(_, i) => startPage + i | ||
); | ||
return ( | ||
<> | ||
<div className="pagination-bar"> | ||
<button | ||
className="btn-pagination" | ||
disabled={activePageNum === 1} | ||
onClick={() => onPageChange(activePageNum - 1)} | ||
> | ||
<IconArrowLeft /> | ||
</button> | ||
{/* 반복 */} | ||
{pages.map((page) => ( | ||
<button | ||
key={page} | ||
className={`btn-pagination ${ | ||
activePageNum === page ? 'active' : '' | ||
}`} | ||
onClick={() => onPageChange(page)} | ||
> | ||
{page} | ||
</button> | ||
))} | ||
<button | ||
className="btn-pagination" | ||
disabled={activePageNum === totalPageNum} | ||
onClick={() => onPageChange(activePageNum + 1)} | ||
> | ||
<IconArrowRight /> | ||
</button> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default PaginationBar; |
File renamed without changes.
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.