45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||
import { Text } from '~/components/ui/text';
|
||
import { PaginationLink } from '~/components/assets/list/pagination-link';
|
||
import { ASSETS_PAGE_SIZE } from '~/data/assets/constants';
|
||
import { getPaginationRange } from '~/lib/pagination';
|
||
|
||
interface AssetPaginationProps {
|
||
page: number;
|
||
totalPages: number;
|
||
totalItems: number;
|
||
}
|
||
|
||
export function AssetPagination({ page, totalPages, totalItems }: AssetPaginationProps) {
|
||
if (totalItems === 0) return null;
|
||
const first = (page - 1) * ASSETS_PAGE_SIZE + 1;
|
||
const last = Math.min(page * ASSETS_PAGE_SIZE, totalItems);
|
||
|
||
return (
|
||
<nav aria-label='Pagination' className='flex flex-col items-center justify-between gap-3 border-t border-border-divider pt-5 sm:flex-row'>
|
||
<Text variant='caption'>
|
||
Showing {first}–{last} of {totalItems}
|
||
</Text>
|
||
{totalPages > 1 && (
|
||
<div className='flex items-center gap-1.5'>
|
||
<PaginationLink page={page - 1} disabled={page === 1} label='Previous page'>
|
||
<ChevronLeft size={13} strokeWidth={2.4} />
|
||
</PaginationLink>
|
||
{getPaginationRange(page, totalPages).map((item, index) =>
|
||
item === 'ellipsis' ? (
|
||
<Text key={`ellipsis-${index}`} as='span' variant='caption' className='px-1.5'>…</Text>
|
||
) : (
|
||
<PaginationLink key={item} page={item} active={item === page}>
|
||
{item}
|
||
</PaginationLink>
|
||
),
|
||
)}
|
||
<PaginationLink page={page + 1} disabled={page === totalPages} label='Next page'>
|
||
<ChevronRight size={13} strokeWidth={2.4} />
|
||
</PaginationLink>
|
||
</div>
|
||
)}
|
||
</nav>
|
||
);
|
||
}
|