-
Notifications
You must be signed in to change notification settings - Fork 0
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 #14 from codestates-seb/dev
Upstream Pull
- Loading branch information
Showing
26 changed files
with
1,209 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,106 @@ | ||
import styled, { css } from 'styled-components'; | ||
|
||
const Nav = styled.nav` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 0.25rem; | ||
`; | ||
|
||
const Button = styled.button` | ||
display: flex; | ||
border: none; | ||
padding: 0.5rem; | ||
border-radius: 0.188rem; | ||
background: hsl(210, 8%, 85%); | ||
color: black; | ||
width: 1.563rem; | ||
height: 1.563rem; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 0.8rem; | ||
${(props) => | ||
props.active && | ||
css` | ||
background: #f48225; | ||
`} | ||
`; | ||
const PageBtn = styled.button` | ||
display: flex; | ||
border: none; | ||
padding: 0.5rem; | ||
border-radius: 0.188rem; | ||
background: ${(props) => (props.active ? '#f48225' : 'hsl(210, 8%, 85%)')}; | ||
color: black; | ||
width: 1.563rem; | ||
height: 1.563rem; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 0.8rem; | ||
`; | ||
const LeftButtons = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 0.25rem; | ||
`; | ||
|
||
const RightButtons = styled.div` | ||
display: flex; | ||
align-items: center; | ||
gap: 0.25rem; | ||
`; | ||
// total : 전체 질문의 갯수 | ||
// limit : 페이지 당 게시물 수 | ||
// setPage : 현재 페이지의 번호 상태 | ||
|
||
function Pagination({ total, limit, setPage, page, setLimit }) { | ||
// Pagenation 알고리즘 -> 전체 질문의 갯수/ 페이지 당 게시물 수 | ||
const numPages = Math.ceil(total / limit); | ||
const handleLimitChange = (value) => { | ||
setLimit(value); | ||
}; | ||
return ( | ||
<> | ||
<Nav> | ||
<LeftButtons> | ||
<Button onClick={() => setPage(page - 1)} disabled={page === 1}> | ||
Pre | ||
</Button> | ||
{Array(numPages) | ||
.fill() | ||
.map((_, i) => ( | ||
<Button | ||
key={i + 1} | ||
active={i + 1 === page} | ||
onClick={() => setPage(i + 1)} | ||
> | ||
{i + 1} | ||
</Button> | ||
))} | ||
<Button | ||
onClick={() => setPage(page + 1)} | ||
disabled={page === numPages} | ||
> | ||
Next | ||
</Button> | ||
</LeftButtons> | ||
|
||
<RightButtons> | ||
<PageBtn onClick={() => handleLimitChange(5)} active={limit === 5}> | ||
5 | ||
</PageBtn> | ||
<PageBtn onClick={() => handleLimitChange(30)} active={limit === 30}> | ||
30 | ||
</PageBtn> | ||
<PageBtn onClick={() => handleLimitChange(30)} active={limit === 50}> | ||
50 | ||
</PageBtn> | ||
</RightButtons> | ||
</Nav> | ||
</> | ||
); | ||
} | ||
|
||
export default Pagination; |
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.