Files
ims/components/incidents/pagination.tsx
T

33 lines
903 B
TypeScript

import Link from 'next/link'
interface Props {
page: number
pageSize: number
total: number
href: string
}
export function Pagination({ page, pageSize, total, href }: Props) {
const totalPages = Math.max(1, Math.ceil(total / pageSize))
if (totalPages <= 1) return null
const link = (p: number, label: string, disabled: boolean) =>
disabled ? (
<span className="px-3 py-1.5 text-sm text-gray-300">{label}</span>
) : (
<Link href={`${href}?page=${p}`} className="px-3 py-1.5 text-sm text-accent-700 hover:underline">
{label}
</Link>
)
return (
<nav className="flex items-center justify-between mt-4" aria-label="Pagination">
{link(page - 1, '← Previous', page <= 1)}
<span className="text-sm text-gray-500">
Page {page} of {totalPages}
</span>
{link(page + 1, 'Next →', page >= totalPages)}
</nav>
)
}