Files
no-copy-frontend/src/app/components/Pagination.tsx
T

69 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-02-10 15:40:18 +07:00
'use client'
export function Pagination({ totalPages, currentPage, fileId, callBack }: any) {
2026-02-10 17:29:36 +07:00
if (totalPages === 0) {
return null;
}
2026-02-10 15:40:18 +07:00
const getVisiblePages = () => {
const pages = [];
const maxVisible = 7;
let start = Math.max(1, currentPage - 3);
let end = Math.min(totalPages, currentPage + 3);
if (end - start + 1 < maxVisible) {
if (start === 1) {
end = Math.min(totalPages, start + maxVisible - 1);
} else if (end === totalPages) {
start = Math.max(1, end - maxVisible + 1);
}
}
for (let i = start; i <= end; i++) {
pages.push(i);
}
return pages;
};
const visiblePages = getVisiblePages();
return (
2026-02-10 17:29:36 +07:00
<div className="pagination-wrapper">
{visiblePages[0] > 1 && (
<>
2026-02-10 15:40:18 +07:00
<button
2026-02-10 17:29:36 +07:00
className={`pagination-button`}
onClick={() => callBack(fileId, 1, true)}
2026-02-10 15:40:18 +07:00
>
2026-02-10 17:29:36 +07:00
1
2026-02-10 15:40:18 +07:00
</button>
2026-02-10 17:29:36 +07:00
{visiblePages[0] > 2 && <span>...</span>}
</>
)}
2026-02-10 15:40:18 +07:00
2026-02-10 17:29:36 +07:00
{visiblePages.map(page => (
<button
key={page}
onClick={() => callBack(fileId, page, true)}
className={`pagination-button ${page === currentPage ? 'current-page' : ''}`}
>
{page}
</button>
))}
{visiblePages[visiblePages.length - 1] < totalPages && (
<>
{visiblePages[visiblePages.length - 1] < totalPages - 1 && <span>...</span>}
<button
className={`pagination-button`}
onClick={() => callBack(fileId, totalPages, true)}
>
{totalPages}
</button>
</>
)}
2026-02-10 15:40:18 +07:00
</div>
);
}