Skip to content

Commit 63deadd

Browse files
Hardik500roboquat
authored andcommitted
Improve pagination usability
1 parent 9e6f2f6 commit 63deadd

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

components/dashboard/src/Pagination/Pagination.tsx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { getPaginationNumbers } from "./getPagination";
8-
import Arrow from "../components/Arrow";
8+
import PaginationNavigationButton from "./PaginationNavigationButton";
99

1010
interface PaginationProps {
1111
totalNumberOfPages: number;
@@ -29,23 +29,23 @@ function Pagination(props: PaginationProps) {
2929
};
3030
const getClassnames = (pageNumber: string | number) => {
3131
if (pageNumber === currentPage) {
32-
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 bg-gray-100 disabled pointer-events-none";
32+
return "font-semibold text-gray-500 dark:text-gray-400 max-h-9 max-w-8 flex items-center justify-center rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 dark:bg-gray-700 bg-gray-100 disabled pointer-events-none px-3 py-2";
3333
}
3434
if (pageNumber === "...") {
35-
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 disabled pointer-events-none";
35+
return "font-semibold text-gray-500 dark:text-gray-400 max-h-9 max-w-8 flex items-center justify-center rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 disabled pointer-events-none px-3 py-2";
3636
}
37-
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 cursor-pointer";
37+
return "font-semibold text-gray-500 dark:text-gray-400 max-h-9 max-w-8 flex items-center justify-center rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 cursor-pointer px-3 py-2";
3838
};
3939

4040
return (
4141
<nav className="mt-16 mb-16">
42-
<ul className="flex justify-center space-x-4">
43-
<li className={`text-gray-400 ${currentPage === 1 ? "disabled" : "cursor-pointer text-gray-500"}`}>
44-
<span onClick={prevPage}>
45-
<Arrow direction={"left"} />
46-
Previous
47-
</span>
48-
</li>
42+
<ul className="flex justify-center items-center space-x-4">
43+
<PaginationNavigationButton
44+
isDisabled={currentPage === 1}
45+
onClick={prevPage}
46+
label={"Previous"}
47+
arrowDirection={"left"}
48+
/>
4949
{calculatedPagination.map((pn, i) => {
5050
if (pn === "...") {
5151
return <li className={getClassnames(pn)}>&#8230;</li>;
@@ -56,16 +56,12 @@ function Pagination(props: PaginationProps) {
5656
</li>
5757
);
5858
})}
59-
<li
60-
className={`text-gray-400 ${
61-
currentPage === totalNumberOfPages ? "disabled" : "cursor-pointer text-gray-500"
62-
}`}
63-
>
64-
<span onClick={nextPage}>
65-
Next
66-
<Arrow direction={"right"} />
67-
</span>
68-
</li>
59+
<PaginationNavigationButton
60+
isDisabled={currentPage === totalNumberOfPages}
61+
onClick={nextPage}
62+
label={"Next"}
63+
arrowDirection={"right"}
64+
/>
6965
</ul>
7066
</nav>
7167
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import Arrow from "../components/Arrow";
8+
9+
interface PaginationNavigationButtonProps {
10+
isDisabled: boolean;
11+
label: string;
12+
arrowDirection: string;
13+
onClick: () => void;
14+
}
15+
16+
function PaginationNavigationButton(props: PaginationNavigationButtonProps) {
17+
const activeArrowClass = props.isDisabled
18+
? "border-gray-300 dark:border-gray-500"
19+
: "border-gray-500 dark:border-gray-400 group-hover:border-gray-600 dark:group-hover:border-gray-400";
20+
21+
return (
22+
<li
23+
className={`font-semibold text-gray-300 ${
24+
props.isDisabled ? "disabled dark:text-gray-500" : "cursor-pointer dark:text-gray-400 text-gray-500"
25+
}`}
26+
>
27+
<span onClick={props.onClick}>
28+
{props.arrowDirection === "right" && props.label}
29+
<Arrow direction={props.arrowDirection} customBorderClasses={activeArrowClass} />
30+
{props.arrowDirection === "left" && props.label}
31+
</span>
32+
</li>
33+
);
34+
}
35+
36+
export default PaginationNavigationButton;

0 commit comments

Comments
 (0)