Files
alpenwerk-hr/components/ui/Pagination.tsx
Raphael Müllner b47dec6387 Übergabestand 2026-10-14
Alpenwerk HR — HR-Stammdatenverwaltung

Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt,
Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte,
Massenimport und ein lückenloser Nachweis jeder Änderung.

Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung
ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der
Datenbank, die Zugriffsschranke ist Row Level Security.

Betrieb auf Windows Server: siehe deploy/windows/README.md.
Sicherheitskonzept: docs/sicherheitskonzept.md.
2026-10-14 10:12:22 +02:00

58 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Link from "next/link";
// Shared by the employee list and the audit log. One link per page would
// mean 54 of them for ~800 employees, and an unbounded number for the audit
// log, all in a single overflowing row. This shows the first and last page
// plus a window around the current one, with the gaps elided.
const WINDOW = 2;
function pageItems(current: number, total: number): number[] {
const pages = new Set<number>([1, total]);
for (let p = current - WINDOW; p <= current + WINDOW; p++) {
if (p >= 1 && p <= total) pages.add(p);
}
return [...pages].sort((a, b) => a - b);
}
type PaginationProps = {
page: number;
totalPages: number;
hrefFor: (page: number) => string;
/** Screen-reader name, e.g. "Mitarbeiter:innen" — several lists per app. */
label: string;
};
export function Pagination({ page, totalPages, hrefFor, label }: PaginationProps) {
if (totalPages <= 1) return null;
const current = Math.min(Math.max(1, page), totalPages);
const items = pageItems(current, totalPages);
return (
<nav aria-label={`Seiten – ${label}`} className="flex flex-wrap items-center justify-center gap-1 text-sm">
{current > 1 && (
<Link href={hrefFor(current - 1)} rel="prev" className="rounded px-3 py-1 font-semibold text-ink-body hover:bg-surface">
Zurück
</Link>
)}
{items.map((p, i) => (
<span key={p} className="flex items-center gap-1">
{i > 0 && p - items[i - 1] > 1 && <span className="px-1 text-ink-muted">…</span>}
<Link
href={hrefFor(p)}
aria-current={p === current ? "page" : undefined}
className={`rounded px-3 py-1 ${p === current ? "bg-brand-500 font-semibold text-white" : "text-ink-body hover:bg-surface"}`}
>
{p}
</Link>
</span>
))}
{current < totalPages && (
<Link href={hrefFor(current + 1)} rel="next" className="rounded px-3 py-1 font-semibold text-ink-body hover:bg-surface">
Weiter
</Link>
)}
</nav>
);
}