tailwind-nextjs-blog/components/Pagination.tsx

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-07-17 21:40:41 +08:00
import Link from '@/components/Link'
interface Props {
totalPages: number
currentPage: number
}
export default function Pagination({ totalPages, currentPage }: Props) {
const prevPage = currentPage - 1 > 0
const nextPage = currentPage + 1 <= totalPages
2022-07-17 21:40:41 +08:00
return (
<div className="space-y-2 pt-6 pb-8 md:space-y-5">
<nav className="flex justify-between">
{!prevPage && (
<button className="cursor-auto disabled:opacity-50" disabled={!prevPage}>
2022-07-17 21:40:41 +08:00
Previous
</button>
)}
{prevPage && (
<Link href={currentPage - 1 === 1 ? `/blog/` : `/blog/page/${currentPage - 1}`}>
<button>Previous</button>
2022-07-17 21:40:41 +08:00
</Link>
)}
<span>
{currentPage} of {totalPages}
</span>
{!nextPage && (
<button className="cursor-auto disabled:opacity-50" disabled={!nextPage}>
2022-07-17 21:40:41 +08:00
Next
</button>
)}
{nextPage && (
<Link href={`/blog/page/${currentPage + 1}`}>
<button>Next</button>
2022-07-17 21:40:41 +08:00
</Link>
)}
</nav>
</div>
)
}