diff --git a/src/kit/pagination.tsx b/src/kit/pagination.tsx index 4d620b4..8a4014f 100644 --- a/src/kit/pagination.tsx +++ b/src/kit/pagination.tsx @@ -4,12 +4,16 @@ import { cn } from "../lib/utils" const DEFAULT_SIZES = [15, 30, 50] as const -/** Номера страниц с многоточиями: 1 … 4 5 6 … 12 */ +/** + * Номера страниц с многоточиями: 1 … 4 5 6 … 12. Мест всегда 7 — при переключении стрелки не сдвигаются: + * у начала 1 2 3 4 5 … 12, у конца 1 … 8 9 10 11 12. + */ function pageList(current: number, pages: number): (number | "gap")[] { if (pages <= 7) return Array.from({ length: pages }, (_, i) => i) - const set = new Set([0, pages - 1, current - 1, current, current + 1]) - const sorted = [...set].filter((p) => p >= 0 && p < pages).sort((a, b) => a - b) - return sorted.flatMap((p, i) => (i > 0 && p - sorted[i - 1] > 1 ? ["gap" as const, p] : [p])) + const last = pages - 1 + if (current < 4) return [0, 1, 2, 3, 4, "gap", last] + if (current > last - 4) return [0, "gap", last - 4, last - 3, last - 2, last - 1, last] + return [0, "gap", current - 1, current, current + 1, "gap", last] } /** @@ -38,11 +42,18 @@ export function Pagination({ const from = total ? current * size + 1 : 0 const to = Math.min((current + 1) * size, total) - const pageButton = "grid h-7 min-w-7 place-items-center rounded-md px-1.5 text-xs font-medium tabular transition" + const pageButton = "grid h-8 min-w-8 place-items-center rounded-md px-2 text-ui font-medium tabular transition" return ( -