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

46 lines
1018 B
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 ? (
<div className={"prev mx-3"}></div>
) : (
<Link className={"next block mx-3"} href={`./${page - 1}`}>
</Link>
)}
{[...Array(pageCount)].map((el, index) => (
<div
key={index}
className={`page-item mx-3 ${
page === index + 1 ? "text-[#009fe9]" : "text-[#666666]"
}`}
>
{index + 1}
</div>
))}
{page >= pageCount ? (
<div className={"next mx-3"}></div>
) : (
<Link className={"next block mx-3"} href={`./${page + 1}`}>
</Link>
)}
</div>
);
};
export default Pagination;