type PaginationProps = { currentPage: number; totalPages: number; onPageChange: (page: number) => void; }; const Pagination: React.FC = ({ currentPage, totalPages, onPageChange, }) => { const getPaginationItems = () => { const delta = 1; const range = []; for (let i = 1; i <= totalPages; i++) { if (i === 1 || i === totalPages || (i >= currentPage - delta && i <= currentPage + delta)) { range.push(i); } } const rangeWithDots: (number | string)[] = []; let l: number | undefined; for (const i of range) { if (l !== undefined) { if (i - l === 2) { rangeWithDots.push(l + 1); } else if (i - l > 2) { rangeWithDots.push('...'); } } rangeWithDots.push(i); l = i; } return rangeWithDots; }; const pages = getPaginationItems(); return (
{pages.map((page, index) => page === '...' ? ( ... ) : ( ), )}
); }; export default Pagination;