/* eslint-disable max-len */ import React, { useState, useEffect } from "react"; import { ChevronLeftIcon, ChevronRightIcon } from "../../svg"; interface IProps { total: number; pageSize: number; onChange: (page: number) => void; changePage?: number; } export const Pagination = (props: IProps) => { const { total, pageSize, onChange, changePage } = props; const [currectPage, setCurrectPage] = useState(1); useEffect(() => { if (changePage !== undefined) { setCurrectPage(changePage); } }, [changePage]); const calculateCount = () => { let count = 1; if (total > pageSize && !!(total % pageSize)) { count = Math.floor(total / pageSize) + 1; } else if (total > pageSize && !(total % pageSize)) { count = Math.floor(total / pageSize); } return count; }; const pageCount = calculateCount(); const handleNext = () => { onChange(currectPage + 1); setCurrectPage(currectPage + 1); }; const handlePrev = () => { onChange(currectPage - 1); setCurrectPage(currectPage - 1); }; const keys = Array.from(Array(pageCount).keys()); const pageList = [...keys]; return (
); }; export default Pagination;