generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathpagination-controls.server.tsx
63 lines (61 loc) · 1.63 KB
/
pagination-controls.server.tsx
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
58
59
60
61
62
63
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNextLink,
PaginationPreviousLink
} from '@/src/components/ui/pagination'
import { cn } from '@/src/lib/utils'
import { searchParamsCache, serialize } from './searchParams'
type PaginationControlsProps = {
numPages: number
}
// Use <Link> components to navigate between pages
export function ServerPaginationControls({
numPages
}: PaginationControlsProps) {
const { page, delay, renderOn } = searchParamsCache.all()
function pageURL(page: number) {
return serialize('/playground/pagination', {
page,
delay,
renderOn
})
}
return (
<Pagination className="not-prose items-center gap-2">
<PaginationContent>
<PaginationItem>
<PaginationPreviousLink
href={pageURL(page - 1)}
disabled={page === 1}
scroll={false}
/>
</PaginationItem>
{Array.from({ length: numPages }, (_, i) => (
<PaginationItem key={i}>
<PaginationLink
href={pageURL(i + 1)}
isActive={page === i + 1}
scroll={false}
>
{i + 1}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationNextLink
disabled={page === numPages}
href={pageURL(page + 1)}
scroll={false}
/>
</PaginationItem>
</PaginationContent>
<div
aria-label={'Loading status unavailable on the server'}
className={cn('h-2 w-2 rounded-full bg-zinc-500')}
/>
</Pagination>
)
}