From 70f4635da8f367c45b1985d9bb640f9bb2f24ed5 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:49:41 +0200 Subject: [PATCH] feat: arrow enabled in last page in case closeonlastpage function was passed --- src/hooks/pagination/use-pagination.tsx | 9 +++++++-- src/lib/pagination/compact.tsx | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hooks/pagination/use-pagination.tsx b/src/hooks/pagination/use-pagination.tsx index 4adce79..183d890 100644 --- a/src/hooks/pagination/use-pagination.tsx +++ b/src/hooks/pagination/use-pagination.tsx @@ -3,11 +3,16 @@ const usePagination = ( numPages: number, //eslint-disable-next-line @typescript-eslint/ban-types callback: Function, + closeOnLastPage?: () => void, numNeighbors = 2 ) => { const incrementPage = () => { - const newPage = Math.min(numPages, currentPage + 1); - callback(newPage); + if (currentPage === numPages && closeOnLastPage) { + closeOnLastPage(); + } else { + const newPage = Math.min(numPages, currentPage + 1); + callback(newPage); + } }; const decrementPage = () => { diff --git a/src/lib/pagination/compact.tsx b/src/lib/pagination/compact.tsx index f080381..c4887e7 100644 --- a/src/lib/pagination/compact.tsx +++ b/src/lib/pagination/compact.tsx @@ -62,6 +62,7 @@ interface CompactPaginationProps { numPages: number; //eslint-disable-next-line @typescript-eslint/ban-types callback: Function; + closeOnLastPage?: () => void; label?: ReactNode; className?: string; } @@ -70,11 +71,12 @@ const CompactPagination: React.FC = ({ currentPage, numPages, callback, + closeOnLastPage, label, className, }) => { const [{ incrementPage, decrementPage, minPageReached, maxPageReached }] = - usePagination(currentPage, numPages, callback); + usePagination(currentPage, numPages, callback, closeOnLastPage); return ( @@ -82,7 +84,10 @@ const CompactPagination: React.FC = ({ - +