-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pagination.tsx
46 lines (45 loc) · 1.05 KB
/
Pagination.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
import { generatePagination } from "../lib/pagination";
import Link from "next/link";
type Props = {
current: number;
pages: number;
link: {
href: (page: number) => string;
as: (page: number) => string;
};
};
export default function Pagination({ current, pages, link }: Props) {
const pagination = generatePagination(current, pages);
return (
<ul>
{pagination.map((it, i) => (
<li key={i}>
{it.excerpt ? (
"..."
) : (
<Link href={link.href(it.page)} as={link.as(it.page)}>
<a className={it.page === current ? "active" : null}>{it.page}</a>
</Link>
)}
</li>
))}
<style jsx>{`
ul {
list-style: none;
margin: 3rem 0 0 0;
padding: 0;
}
li {
display: inline-block;
margin-right: 1em;
color: #9b9b9b;
font-size: 1.25rem;
}
a.active {
color: #222;
font-weight: bold;
}
`}</style>
</ul>
);
}