Files
caszl-next/app/components/Pagination.tsx

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-10-30 17:29:35 +08:00
import Link from "next/link";
const Pagination = ({
page,
total,
perPage,
}: {
page: number;
total: number;
perPage: number;
}) => {
const pageCount = Math.ceil(total / perPage);
return (
<div
className={"w-full flex justify-center mt-2.5 h-10 items-center text-sm"}
>
{page <= 1 ? (
2023-11-01 17:27:06 +08:00
<div className={"prev mx-3 text-gray-500 cursor-not-allowed"}>
</div>
2023-10-30 17:29:35 +08:00
) : (
<Link className={"next block mx-3"} href={`./${page - 1}`}>
</Link>
)}
2023-11-01 17:27:06 +08:00
{[...Array(pageCount)].map((el, index) =>
page === index + 1 ? (
<div key={index} className={`page-item mx-3 text-[#009fe9]`}>
{index + 1}
</div>
) : (
<Link
className={"page-item mx-3 text-[#666666]"}
key={index}
href={`./${index + 1}`}
>
{index + 1}
</Link>
),
)}
2023-10-30 17:29:35 +08:00
{page >= pageCount ? (
2023-11-01 17:27:06 +08:00
<div className={"next mx-3 text-gray-500 cursor-not-allowed"}>
</div>
2023-10-30 17:29:35 +08:00
) : (
<Link className={"next block mx-3"} href={`./${page + 1}`}>
</Link>
)}
</div>
);
};
export default Pagination;