feat: add asset pagination
This commit is contained in:
parent
a7194c48fe
commit
d857bc7990
44
app/components/assets/list/asset-pagination.tsx
Normal file
44
app/components/assets/list/asset-pagination.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user