Spaces:
Running
Running
File size: 1,406 Bytes
3a12290 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | "use client"
import { Button } from "@/components/ui/button"
interface ListPaginationProps {
page: number
pageSize: number
totalItems: number
itemLabel: string
onPageChange: (page: number) => void
}
export function ListPagination({
page,
pageSize,
totalItems,
itemLabel,
onPageChange,
}: ListPaginationProps) {
const totalPages = Math.max(1, Math.ceil(totalItems / pageSize))
const start = totalItems === 0 ? 0 : (page - 1) * pageSize + 1
const end = Math.min(page * pageSize, totalItems)
if (totalItems <= pageSize) {
return null
}
return (
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<p className="text-sm text-muted-foreground">
Showing {start}-{end} of {totalItems} {itemLabel}
</p>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(Math.max(1, page - 1))}
disabled={page === 1}
>
Previous
</Button>
<span className="text-sm text-muted-foreground">
Page {page} of {totalPages}
</span>
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(Math.min(totalPages, page + 1))}
disabled={page === totalPages}
>
Next
</Button>
</div>
</div>
)
}
|