Skip to content

Commit e650269

Browse files
committed
refactor: reuse data table pagination on mobile voting table
Ensure we use the data table pagination on the mobile voting widget to ensure we have a consistent UI.
1 parent 4a4309a commit e650269

3 files changed

Lines changed: 92 additions & 85 deletions

File tree

components/Table/Pagination.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Box, Flex, Text } from "@livepeer/design-system";
2+
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons";
3+
4+
type PaginationProps = {
5+
currentPage: number;
6+
totalPages: number;
7+
canPrevious: boolean;
8+
canNext: boolean;
9+
onPrevious: () => void;
10+
onNext: () => void;
11+
textSize?: "1" | "2" | "3";
12+
css?: object;
13+
};
14+
15+
const Pagination = ({
16+
currentPage,
17+
totalPages,
18+
canPrevious,
19+
canNext,
20+
onPrevious,
21+
onNext,
22+
textSize = "2",
23+
css,
24+
}: PaginationProps) => {
25+
return (
26+
<Flex
27+
css={{
28+
paddingTop: "$4",
29+
paddingBottom: "$4",
30+
alignItems: "center",
31+
justifyContent: "center",
32+
...css,
33+
}}
34+
>
35+
<Box
36+
as={ArrowLeftIcon}
37+
css={{
38+
cursor: "pointer",
39+
color: canPrevious ? "$primary11" : "$hiContrast",
40+
opacity: canPrevious ? 1 : 0.5,
41+
}}
42+
onClick={() => {
43+
if (canPrevious) {
44+
onPrevious();
45+
}
46+
}}
47+
/>
48+
<Text size={textSize} css={{ marginLeft: "$3", marginRight: "$3" }}>
49+
Page <Box as="span">{currentPage}</Box> of{" "}
50+
<Box as="span">{totalPages}</Box>
51+
</Text>
52+
<Box
53+
as={ArrowRightIcon}
54+
css={{
55+
cursor: "pointer",
56+
color: canNext ? "$primary11" : "$hiContrast",
57+
opacity: canNext ? 1 : 0.5,
58+
}}
59+
onClick={() => {
60+
if (canNext) {
61+
onNext();
62+
}
63+
}}
64+
/>
65+
</Flex>
66+
);
67+
};
68+
69+
export default Pagination;

components/Table/index.tsx

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import {
88
Thead,
99
Tr,
1010
} from "@livepeer/design-system";
11-
import {
12-
ArrowLeftIcon,
13-
ArrowRightIcon,
14-
ChevronDownIcon,
15-
ChevronUpIcon,
16-
} from "@radix-ui/react-icons";
11+
import { ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons";
1712
import { ReactNode } from "react";
1813
import {
1914
Column,
@@ -26,6 +21,7 @@ import {
2621
useTable,
2722
} from "react-table";
2823

24+
import Pagination from "./Pagination";
2925
function DataTable<T extends object>({
3026
heading = null,
3127
input = null,
@@ -243,45 +239,15 @@ function DataTable<T extends object>({
243239
</Tbody>
244240
</Table>
245241
</Box>
246-
<Flex
247-
css={{
248-
paddingTop: "$4",
249-
paddingBottom: "$4",
250-
alignItems: "center",
251-
justifyContent: "center",
252-
}}
253-
>
254-
<Box
255-
as={ArrowLeftIcon}
256-
css={{
257-
cursor: "pointer",
258-
color: canPreviousPage ? "$primary11" : "$hiContrast",
259-
opacity: canPreviousPage ? 1 : 0.5,
260-
}}
261-
onClick={() => {
262-
if (canPreviousPage) {
263-
previousPage();
264-
}
265-
}}
266-
/>
267-
<Box css={{ fontSize: "$2", marginLeft: "$3", marginRight: "$3" }}>
268-
Page <Box as="span">{pageIndex + 1}</Box> of{" "}
269-
<Box as="span">{pageCount}</Box>
270-
</Box>
271-
<Box
272-
as={ArrowRightIcon}
273-
css={{
274-
cursor: "pointer",
275-
color: canNextPage ? "$primary11" : "$hiContrast",
276-
opacity: canNextPage ? 1 : 0.5,
277-
}}
278-
onClick={() => {
279-
if (canNextPage) {
280-
nextPage();
281-
}
282-
}}
283-
/>
284-
</Flex>
242+
<Pagination
243+
currentPage={pageIndex + 1}
244+
totalPages={pageCount}
245+
canPrevious={canPreviousPage}
246+
canNext={canNextPage}
247+
onPrevious={previousPage}
248+
onNext={nextPage}
249+
textSize="2"
250+
/>
285251
</>
286252
</Box>
287253
</>

components/Votes/VoteTable/Views/MobileVoteTable.tsx

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Box, Button, Flex, Text } from "@livepeer/design-system";
2-
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons";
1+
import Pagination from "@components/Table/Pagination";
2+
import { Box, Text } from "@livepeer/design-system";
33
import React from "react";
44

55
import { VoteTableProps } from "./DesktopVoteTable";
@@ -44,44 +44,16 @@ export const MobileVoteCards: React.FC<VoteTableProps> = (props) => {
4444

4545
{/* Pagination */}
4646
{totalPages > 1 && (
47-
<Flex
48-
css={{
49-
marginTop: "$4",
50-
justifyContent: "center",
51-
alignItems: "center",
52-
gap: "$4",
53-
}}
54-
>
55-
<Button
56-
size="1"
57-
disabled={currentPage === 1}
58-
onClick={() => onPageChange?.(currentPage - 1)}
59-
css={{
60-
display: "flex",
61-
alignItems: "center",
62-
gap: "$1",
63-
color: currentPage === 1 ? "$neutral8" : "$white",
64-
}}
65-
>
66-
<ArrowLeftIcon /> Previous
67-
</Button>
68-
<Text css={{ fontSize: "$1", color: "$neutral11" }}>
69-
Page {currentPage} of {totalPages}
70-
</Text>
71-
<Button
72-
size="1"
73-
disabled={currentPage === totalPages}
74-
onClick={() => onPageChange?.(currentPage + 1)}
75-
css={{
76-
display: "flex",
77-
alignItems: "center",
78-
gap: "$1",
79-
color: currentPage === totalPages ? "$neutral8" : "$white",
80-
}}
81-
>
82-
Next <ArrowRightIcon />
83-
</Button>
84-
</Flex>
47+
<Pagination
48+
currentPage={currentPage}
49+
totalPages={totalPages}
50+
canPrevious={currentPage > 1}
51+
canNext={currentPage < totalPages}
52+
onPrevious={() => onPageChange?.(currentPage - 1)}
53+
onNext={() => onPageChange?.(currentPage + 1)}
54+
textSize="1"
55+
css={{ marginTop: "$4", paddingTop: 0, paddingBottom: 0 }}
56+
/>
8557
)}
8658
</Box>
8759
);

0 commit comments

Comments
 (0)