forked from rajun/ar-test
feat: add pagination link
This commit is contained in:
parent
f3f09d9c05
commit
1a7385f6f3
33
app/components/assets/list/pagination-link.tsx
Normal file
33
app/components/assets/list/pagination-link.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import { Link, useLocation } from 'react-router';
|
||||||
|
import { Button } from '~/components/ui/button';
|
||||||
|
import { cn } from '~/lib/utils';
|
||||||
|
|
||||||
|
interface PaginationLinkProps {
|
||||||
|
page: number;
|
||||||
|
active?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
label?: string;
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Links to another page of the current list, keeping its other search params (e.g. the filter)
|
||||||
|
export function PaginationLink({ page, active, disabled, label, children }: PaginationLinkProps) {
|
||||||
|
const { search } = useLocation();
|
||||||
|
const params = new URLSearchParams(search);
|
||||||
|
params.set('page', String(page));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
asChild
|
||||||
|
size='icon'
|
||||||
|
variant={active ? 'default' : 'secondary'}
|
||||||
|
aria-label={label}
|
||||||
|
aria-current={active ? 'page' : undefined}
|
||||||
|
aria-disabled={disabled}
|
||||||
|
className={cn('shadow-none', disabled && 'pointer-events-none opacity-40')}
|
||||||
|
>
|
||||||
|
<Link to={`?${params}`}>{children}</Link>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user