Skip to content

Commit

Permalink
feat: arrow enabled in last page in case closeonlastpage function was…
Browse files Browse the repository at this point in the history
… passed
  • Loading branch information
kemuru committed Jul 2, 2024
1 parent e5fd320 commit 70f4635
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/hooks/pagination/use-pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
9 changes: 7 additions & 2 deletions src/lib/pagination/compact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface CompactPaginationProps {
numPages: number;
//eslint-disable-next-line @typescript-eslint/ban-types
callback: Function;
closeOnLastPage?: () => void;
label?: ReactNode;
className?: string;
}
Expand All @@ -70,19 +71,23 @@ const CompactPagination: React.FC<CompactPaginationProps> = ({
currentPage,
numPages,
callback,
closeOnLastPage,
label,
className,
}) => {
const [{ incrementPage, decrementPage, minPageReached, maxPageReached }] =
usePagination(currentPage, numPages, callback);
usePagination(currentPage, numPages, callback, closeOnLastPage);

return (
<Wrapper {...{ className }}>
<StyledLabel>{label}</StyledLabel>
<LeftArrow disabled={minPageReached} onClick={decrementPage}>
<Arrow className={StyledSVG.styledComponentId} />
</LeftArrow>
<RightArrow disabled={maxPageReached} onClick={incrementPage}>
<RightArrow
disabled={maxPageReached && !closeOnLastPage}
onClick={incrementPage}
>
<Arrow className={StyledSVG.styledComponentId} />
</RightArrow>
</Wrapper>
Expand Down

0 comments on commit 70f4635

Please sign in to comment.