-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPagination.js
38 lines (35 loc) · 1.54 KB
/
Pagination.js
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
import React from "react"
import Link from "next/link"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
import {faChevronLeft, faChevronRight} from "@fortawesome/free-solid-svg-icons";
const Pagination = (props) => {
const links = [];
for (let i = 1; i <= props.totalPages; i++) {
links.push(<li key={`page-${i}`}>
{i === props.currentPage ?
<span className="inline-block bg-gray-500 py-1 px-3">{i}</span> :
<Link href={`${props.path}/[page]`} as={`${props.path}/${i}`}>
<a className="inline-block py-1 px-3 hover:bg-gray-400">{i}</a>
</Link>
}
</li>)
}
return (<ul className="flex justify-center space-x-2 font-bold">
{props.currentPage > 1 && <li>
<Link href={`${props.path}/[page]`} as={`${props.path}/${props.currentPage - 1}`}>
<a className="inline-block py-1 px-3 hover:bg-gray-400" title="previous page">
<FontAwesomeIcon icon={faChevronLeft}/>
</a>
</Link>
</li>}
{props.totalPages > 1 && links}
{props.currentPage < props.totalPages && <li>
<Link href={`${props.path}/[page]`} as={`${props.path}/${props.currentPage + 1}`}>
<a className="inline-block py-1 px-3 hover:bg-gray-400" title="next page">
<FontAwesomeIcon icon={faChevronRight}/>
</a>
</Link>
</li>}
</ul>)
}
export default Pagination