Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat : Pagination Module
Browse files Browse the repository at this point in the history
  • Loading branch information
kasterra committed Jul 2, 2024
1 parent 02438a7 commit 61dff92
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 0 deletions.
74 changes: 74 additions & 0 deletions app/components/common/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import styles from "./pagination.module.css";
import LeftBtnSVG from "./left-btn.svg?react";
import RightBtnSVG from "./right-btn.svg?react";

interface Props {
currentPage: number;
lastPage: number;
onChangePage: (page: number) => void;
style: React.CSSProperties;
}

const Pagination = ({ currentPage, lastPage, onChangePage, style }: Props) => {
const startPage = Math.max(1, currentPage - 2);
const endPage = Math.min(lastPage, currentPage + 2);
const pageNumbers = [];

for (let i = startPage; i <= endPage; i++) {
pageNumbers.push(i);
}
return (
<div className={styles.container} style={style}>
<button type="button" className={styles.btn}>
<LeftBtnSVG
style={{ fill: currentPage === 1 ? "#C5C5C5" : "#161616" }}
/>
</button>
{startPage > 1 && (
<>
<button
type="button"
className={styles.btn}
onClick={() => onChangePage(1)}
>
1
</button>
<div className={styles.btn}>...</div>
</>
)}

{pageNumbers.map((pageNumber) => (
<button
type="button"
className={`${styles.btn} ${
pageNumber === currentPage && styles.enabled
}`}
onClick={() => onChangePage(pageNumber)}
>
{pageNumber}
</button>
))}

{endPage < lastPage && (
<>
<div className={styles.btn}>...</div>
<button
type="button"
className={styles.btn}
onClick={() => onChangePage(lastPage)}
>
{lastPage}
</button>
</>
)}

<button type="button" className={styles.btn}>
<RightBtnSVG
style={{ fill: currentPage === lastPage ? "#C5C5C5" : "#161616" }}
/>
</button>
</div>
);
};

export default Pagination;
17 changes: 17 additions & 0 deletions app/components/common/pagination.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.container {
display: flex;
align-items: center;
width: fit-content;
}

.btn {
width: 50px;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
}

.enabled {
border-bottom: 4px solid #0070ff;
}
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/// <reference types="vite/client" />
/// <reference types="@remix-run/node" />
/// <reference types="vite-plugin-svgr/client" />
Loading

0 comments on commit 61dff92

Please sign in to comment.