interface PaginationProps { page: number; totalPages: number; totalElements: number; pageSize: number; onPageChange: (page: number) => void; } /** * 표시할 페이지 번호 목록 생성 (Truncated Page Number) * - 총 7슬롯 이하면 전부 표시 * - 7슬롯 초과면 현재 페이지 기준 양쪽 1개 + 처음/끝 + ellipsis */ function getPageNumbers(current: number, total: number): (number | 'ellipsis')[] { if (total <= 7) { return Array.from({ length: total }, (_, i) => i); } const pages: (number | 'ellipsis')[] = []; const SIBLING = 1; const leftSibling = Math.max(current - SIBLING, 0); const rightSibling = Math.min(current + SIBLING, total - 1); const showLeftEllipsis = leftSibling > 1; const showRightEllipsis = rightSibling < total - 2; pages.push(0); if (showLeftEllipsis) { pages.push('ellipsis'); } else { for (let i = 1; i < leftSibling; i++) { pages.push(i); } } for (let i = leftSibling; i <= rightSibling; i++) { if (i !== 0 && i !== total - 1) { pages.push(i); } } if (showRightEllipsis) { pages.push('ellipsis'); } else { for (let i = rightSibling + 1; i < total - 1; i++) { pages.push(i); } } if (total > 1) { pages.push(total - 1); } return pages; } export default function Pagination({ page, totalPages, totalElements, pageSize, onPageChange, }: PaginationProps) { if (totalPages <= 1) return null; const start = page * pageSize + 1; const end = Math.min((page + 1) * pageSize, totalElements); const pages = getPageNumbers(page, totalPages); const btnBase = 'inline-flex items-center justify-center w-7 h-7 text-xs rounded transition-colors'; const btnEnabled = 'hover:bg-wing-hover text-wing-muted'; const btnDisabled = 'opacity-30 cursor-not-allowed text-wing-muted'; return (
{totalElements.toLocaleString()}건 중 {start.toLocaleString()}~ {end.toLocaleString()}
{/* First */} {/* Prev */} {/* Page Numbers */} {pages.map((p, idx) => p === 'ellipsis' ? ( ) : ( ), )} {/* Next */} {/* Last */}
); }