Pagination.tsx
| 1 | export interface PaginationInfo { |
| 2 | page: number; |
| 3 | totalPages: number; |
| 4 | /** URL template — use `{page}` as placeholder, e.g. "/repo/issues?status=open&page={page}" */ |
| 5 | pageUrlTemplate: string; |
| 6 | } |
| 7 | |
| 8 | interface PaginationProps extends PaginationInfo {} |
| 9 | |
| 10 | export function Pagination({ |
| 11 | page, |
| 12 | totalPages, |
| 13 | pageUrlTemplate, |
| 14 | }: PaginationProps) { |
| 15 | if (totalPages <= 1) return null; |
| 16 | |
| 17 | const url = (p: number) => pageUrlTemplate.replace("{page}", String(p)); |
| 18 | |
| 19 | return ( |
| 20 | <nav class="pagination" aria-label="Pagination"> |
| 21 | <div class="pagination-prev"> |
| 22 | {page > 1 && ( |
| 23 | <a href={url(page - 1)} class="pagination-btn"> |
| 24 | ← Previous |
| 25 | </a> |
| 26 | )} |
| 27 | </div> |
| 28 | <span class="pagination-info"> |
| 29 | Page {page} of {totalPages} |
| 30 | </span> |
| 31 | <div class="pagination-next"> |
| 32 | {page < totalPages && ( |
| 33 | <a href={url(page + 1)} class="pagination-btn"> |
| 34 | Next → |
| 35 | </a> |
| 36 | )} |
| 37 | </div> |
| 38 | </nav> |
| 39 | ); |
| 40 | } |
| 41 |