import React from 'react'; import { clsx } from 'clsx'; import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react'; import Button from './Button'; export interface PaginationProps { currentPage: number; totalPages: number; onPageChange: (page: number) => void; pageSize?: number; totalItems?: number; showPageNumbers?: boolean; showFirstLast?: boolean; className?: string; } /** * Pagination component */ export const Pagination = ({ currentPage, totalPages, onPageChange, pageSize, totalItems, showPageNumbers = true, showFirstLast = true, className, }: PaginationProps) => { const getPageNumbers = () => { const delta = 2; const range = []; const rangeWithDots = []; for ( let i = Math.max(2, currentPage - delta); i <= Math.min(totalPages - 1, currentPage + delta); i++ ) { range.push(i); } if (currentPage - delta > 2) { rangeWithDots.push(1, '...'); } else { rangeWithDots.push(1); } rangeWithDots.push(...range); if (currentPage + delta < totalPages - 1) { rangeWithDots.push('...', totalPages); } else { rangeWithDots.push(totalPages); } return rangeWithDots; }; const pageNumbers = getPageNumbers(); if (totalPages <= 1) return null; return (
{/* Info */} {totalItems !== undefined && pageSize && (
Showing {(currentPage - 1) * pageSize + 1} to{' '} {Math.min(currentPage * pageSize, totalItems)} of {totalItems} results
)} {/* Pagination Controls */}
{showFirstLast && ( )} {showPageNumbers && (
{pageNumbers.map((page, index) => { if (page === '...') { return ( ... ); } const pageNum = page as number; const isActive = pageNum === currentPage; return ( ); })}
)} {showFirstLast && ( )}
); };