Skip to content
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

πŸ”€ Refactor/PaginationStyle#321 [νŽ˜μ΄μ§€λ„€μ΄μ…˜ μƒˆ λ””μžμΈ 적용] #322

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 58 additions & 39 deletions gongjakso/src/components/Pagination/Pagination.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import React, { useState } from 'react';
import styled from 'styled-components';

const Nav = styled.nav`
display: flex;
justify-content: center;
align-items: center;
gap: 0.25rem;
margin: 8.125rem 0;
`;

const Button = styled.button`
border: none;
border-radius: 50%;
width: 2rem;
height: 2rem;
padding: 0.5rem;
margin: 0;
color: ${props => (props['aria-current'] ? 'white' : 'black')};
background: ${props => (props['aria-current'] ? 'black' : 'transparent')};
font-size: 0.875rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;

&:hover {
cursor: pointer;
background: ${props => (props['aria-current'] ? 'black' : '#f0f0f0')};
}

&[disabled] {
color: #999;
cursor: not-allowed;
background: transparent;
}

&[aria-current] {
font-weight: bold;
transform: none;
}
`;

const ArrowButton = styled(Button)`
background: transparent;
color: black;

&:hover {
background: #f0f0f0;
}

&[disabled] {
color: #999;
background: transparent;
}
`;

function Pagination({ total, page, setPage, loadPosts }) {
const numPages = total;
const [currentPageRange, setCurrentPageRange] = useState([1, 10]);
Expand Down Expand Up @@ -29,9 +83,9 @@ function Pagination({ total, page, setPage, loadPosts }) {

return (
<Nav>
<Button onClick={handlePrevPage} disabled={page === 1}>
<ArrowButton onClick={handlePrevPage} disabled={page === 1}>
{'<'}
</Button>
</ArrowButton>
{Array(numPages)
.fill()
.map((_, i) => {
Expand All @@ -54,46 +108,11 @@ function Pagination({ total, page, setPage, loadPosts }) {
}
return null;
})}
<Button onClick={handleNextPage} disabled={page === numPages}>
<ArrowButton onClick={handleNextPage} disabled={page === numPages}>
{'>'}
</Button>
</ArrowButton>
</Nav>
);
}

const Nav = styled.nav`
display: flex;
justify-content: center;
align-items: center;
gap: 4px;
margin: 130px 0;
`;

const Button = styled.button`
border: none;
border-radius: 8px;
padding: 8px;
margin: 0;
color: black;
font-size: 1rem;

&:hover {
cursor: pointer;
transform: translateY(-2px);
}

&[disabled] {
color: white;
cursor: revert;
transform: revert;
}

&[aria-current] {
font-weight: 700;
font-size: 1.5rem;
cursor: revert;
transform: revert;
}
`;

export default Pagination;