30 lines
851 B
TypeScript
30 lines
851 B
TypeScript
import Link from 'next/link';
|
|
|
|
/** Pagination controls for a list route that reads `?page=`. */
|
|
export function PagePagination({ page, pages, basePath }: { page: number; pages: number; basePath: string }) {
|
|
if (pages <= 1) return null;
|
|
const prev = page > 1 ? `${basePath}?page=${page - 1}` : null;
|
|
const next = page < pages ? `${basePath}?page=${page + 1}` : null;
|
|
return (
|
|
<nav className="mt-10 flex items-center justify-between text-sm" aria-label="Pagination">
|
|
{prev ? (
|
|
<Link href={prev} className="btn-secondary">
|
|
Previous
|
|
</Link>
|
|
) : (
|
|
<span />
|
|
)}
|
|
<span className="muted">
|
|
Page {page} of {pages}
|
|
</span>
|
|
{next ? (
|
|
<Link href={next} className="btn-secondary">
|
|
Next
|
|
</Link>
|
|
) : (
|
|
<span />
|
|
)}
|
|
</nav>
|
|
);
|
|
}
|