Skip to content

Commit 49013ae

Browse files
committed
feat: improve pagination button functionality and styling
- Add disabled prop to PaginationButton component - Modify pagination button rendering to always show first/previous/next/last buttons to prevent components jumping across pages - Disable navigation buttons when at page boundaries - Update button styling for active and disabled states
1 parent 9a9be8b commit 49013ae

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

components/global/pagination/pagination-button.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface PaginationButtonProps {
99
children: React.ReactNode;
1010
active?: boolean;
1111
onClick?: () => void;
12+
disabled?: boolean;
1213
}
1314

1415
export default function PaginationButton({
@@ -17,16 +18,18 @@ export default function PaginationButton({
1718
children,
1819
active,
1920
onClick,
21+
disabled,
2022
}: PaginationButtonProps) {
2123
const buttonContent = (
2224
<Button
2325
aria-label={typeof children === "string" ? children : undefined}
2426
className={cn(
25-
"flex items-center gap-2 border-black border-",
26-
active && "bg-white text-black ",
27+
"flex items-center gap-2 border-black border-2",
28+
active && "bg-white text-black cursor-default hover:bg-white",
2729
)}
2830
size="sm"
2931
onClick={onClick}
32+
disabled={disabled}
3033
>
3134
{arrow === "left" && (
3235
<ChevronLeft style={{ width: "10px", height: "10px" }} />
@@ -38,7 +41,7 @@ export default function PaginationButton({
3841
</Button>
3942
);
4043

41-
if (href) {
44+
if (href && !active && !disabled) {
4245
return (
4346
<Link href={href} prefetch={true}>
4447
{buttonContent}

components/global/pagination/pagination.tsx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,45 @@ export default function Pagination({
6969
return (
7070
<div className="flex flex-col sm:flex-row gap-4 items-center justify-between w-full mt-4">
7171
<div className="flex items-center justify-start gap-2">
72-
{pageNumber > 1 && (
73-
<>
74-
<PaginationButton href={getPageHref(1)} arrow="left">
75-
First
76-
</PaginationButton>
77-
<PaginationButton href={getPageHref(pageNumber - 1)} arrow="left">
78-
Previous
79-
</PaginationButton>
80-
</>
81-
)}
72+
<>
73+
<PaginationButton
74+
disabled={pageNumber === 1}
75+
href={getPageHref(1)}
76+
arrow="left"
77+
>
78+
First
79+
</PaginationButton>
80+
<PaginationButton
81+
disabled={pageNumber === 1}
82+
href={getPageHref(pageNumber - 1)}
83+
arrow="left"
84+
>
85+
Previous
86+
</PaginationButton>
87+
</>
8288
</div>
8389

8490
<div className="flex items-center justify-center gap-2">
8591
{renderPageNumbers()}
8692
</div>
8793

8894
<div className="flex items-center justify-end gap-2">
89-
{pageNumber < totalPages && (
90-
<>
91-
<PaginationButton href={getPageHref(pageNumber + 1)} arrow="right">
92-
Next
93-
</PaginationButton>
94-
<PaginationButton href={getPageHref(totalPages)} arrow="right">
95-
Last
96-
</PaginationButton>
97-
</>
98-
)}
95+
<>
96+
<PaginationButton
97+
disabled={pageNumber === totalPages}
98+
href={getPageHref(pageNumber + 1)}
99+
arrow="right"
100+
>
101+
Next
102+
</PaginationButton>
103+
<PaginationButton
104+
disabled={pageNumber === totalPages}
105+
href={getPageHref(totalPages)}
106+
arrow="right"
107+
>
108+
Last
109+
</PaginationButton>
110+
</>
99111
</div>
100112
</div>
101113
);

0 commit comments

Comments
 (0)