From b960dd334f81013fd6c8b6d13257df2d93133ee9 Mon Sep 17 00:00:00 2001 From: Ilya Mukhortov Date: Wed, 28 Oct 2026 12:00:13 +1000 Subject: [PATCH] Pagination: larger text, pages stay put when switching Three-column grid keeps the page numbers centred whatever the range label width; with many pages there are always 7 slots. Co-Authored-By: Claude Opus 5.5 --- src/kit/pagination.tsx | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) 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 ( -
- + // Три колонки: страницы строго по центру, сколько бы места ни занимали «1 – 15 из 28» и размеры. + // На телефоне не влезает в строку — переносится, как раньше. +
+ {from} – {to} из {total} @@ -58,7 +69,7 @@ export function Pagination({ {pageList(current, pages).map((p, i) => p === "gap" ? ( - + … ) : ( @@ -88,7 +99,7 @@ export function Pagination({
{onSizeChange ? ( -
+
{sizeOptions.map((s) => (