Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions components/Table/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Box, Flex } from "@livepeer/design-system";
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons";

type PaginationProps = {
currentPage: number;
totalPages: number;
canPrevious: boolean;
canNext: boolean;
onPrevious: () => void;
onNext: () => void;
css?: object;
};

const Pagination = ({
currentPage,
totalPages,
canPrevious,
canNext,
onPrevious,
onNext,
css,
}: PaginationProps) => {
return (
<Flex
css={{
paddingTop: "$4",
paddingBottom: "$4",
alignItems: "center",
justifyContent: "center",
...css,
}}
>
<Box
as={ArrowLeftIcon}
css={{
cursor: "pointer",
color: canPrevious ? "$primary11" : "$hiContrast",
opacity: canPrevious ? 1 : 0.5,
}}
onClick={() => {
if (canPrevious) {
onPrevious();
}
}}
/>
<Box css={{ fontSize: "$2", marginLeft: "$3", marginRight: "$3" }}>
Page <Box as="span">{currentPage}</Box> of{" "}
<Box as="span">{totalPages}</Box>
</Box>
<Box
as={ArrowRightIcon}
css={{
cursor: "pointer",
color: canNext ? "$primary11" : "$hiContrast",
opacity: canNext ? 1 : 0.5,
}}
onClick={() => {
if (canNext) {
onNext();
}
}}
/>
</Flex>
);
};

export default Pagination;
56 changes: 11 additions & 45 deletions components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import {
Thead,
Tr,
} from "@livepeer/design-system";
import {
ArrowLeftIcon,
ArrowRightIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@radix-ui/react-icons";
import { ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons";
import { ReactNode } from "react";
import {
Column,
Expand All @@ -26,6 +21,8 @@ import {
useTable,
} from "react-table";

import Pagination from "./Pagination";

function DataTable<T extends object>({
heading = null,
input = null,
Expand Down Expand Up @@ -243,45 +240,14 @@ function DataTable<T extends object>({
</Tbody>
</Table>
</Box>
<Flex
css={{
paddingTop: "$4",
paddingBottom: "$4",
alignItems: "center",
justifyContent: "center",
}}
>
<Box
as={ArrowLeftIcon}
css={{
cursor: "pointer",
color: canPreviousPage ? "$primary11" : "$hiContrast",
opacity: canPreviousPage ? 1 : 0.5,
}}
onClick={() => {
if (canPreviousPage) {
previousPage();
}
}}
/>
<Box css={{ fontSize: "$2", marginLeft: "$3", marginRight: "$3" }}>
Page <Box as="span">{pageIndex + 1}</Box> of{" "}
<Box as="span">{pageCount}</Box>
</Box>
<Box
as={ArrowRightIcon}
css={{
cursor: "pointer",
color: canNextPage ? "$primary11" : "$hiContrast",
opacity: canNextPage ? 1 : 0.5,
}}
onClick={() => {
if (canNextPage) {
nextPage();
}
}}
/>
</Flex>
<Pagination
currentPage={pageIndex + 1}
totalPages={pageCount}
canPrevious={canPreviousPage}
canNext={canNextPage}
onPrevious={previousPage}
onNext={nextPage}
/>
</>
</Box>
</>
Expand Down
50 changes: 10 additions & 40 deletions components/Votes/VoteTable/Views/MobileVoteTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, Flex, Text } from "@livepeer/design-system";
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons";
import Pagination from "@components/Table/Pagination";
import { Box, Text } from "@livepeer/design-system";
import React from "react";

import { VoteTableProps } from "./DesktopVoteTable";
Expand Down Expand Up @@ -44,44 +44,14 @@ export const MobileVoteCards: React.FC<VoteTableProps> = (props) => {

{/* Pagination */}
{totalPages > 1 && (
<Flex
css={{
marginTop: "$4",
justifyContent: "center",
alignItems: "center",
gap: "$4",
}}
>
<Button
size="1"
disabled={currentPage === 1}
onClick={() => onPageChange?.(currentPage - 1)}
css={{
display: "flex",
alignItems: "center",
gap: "$1",
color: currentPage === 1 ? "$neutral8" : "$white",
}}
>
<ArrowLeftIcon /> Previous
</Button>
<Text css={{ fontSize: "$1", color: "$neutral11" }}>
Page {currentPage} of {totalPages}
</Text>
<Button
size="1"
disabled={currentPage === totalPages}
onClick={() => onPageChange?.(currentPage + 1)}
css={{
display: "flex",
alignItems: "center",
gap: "$1",
color: currentPage === totalPages ? "$neutral8" : "$white",
}}
>
Next <ArrowRightIcon />
</Button>
</Flex>
<Pagination
currentPage={currentPage}
totalPages={totalPages}
canPrevious={currentPage > 1}
canNext={currentPage < totalPages}
onPrevious={() => onPageChange?.(currentPage - 1)}
onNext={() => onPageChange?.(currentPage + 1)}
/>
)}
</Box>
);
Expand Down
16 changes: 1 addition & 15 deletions components/Votes/VoteTable/Views/VoteItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ function MobileVoteView({ vote, onSelect, formatWeight }: VoteViewProps) {
padding: "2px 8px",
margin: "-2px -8px",
borderRadius: "6px",
transition: "all 0.2s ease",
"&:hover": {
backgroundColor: "$neutral4",
textDecoration: "underline",
textUnderlineOffset: "4px",
},
cursor: "pointer",
"&:focus-visible": {
outline: "2px solid $primary11",
outlineOffset: "2px",
Expand Down Expand Up @@ -183,18 +178,9 @@ function MobileVoteView({ vote, onSelect, formatWeight }: VoteViewProps) {
backgroundColor: "transparent",
padding: "$2",
margin: "-$2",
borderRadius: "$1",
minHeight: "44px",
fontSize: "$1",
fontWeight: 600,
transition: "background-color 0.2s ease",
"&:hover": {
backgroundColor: "$neutral3",
},
"&:focus-visible": {
outline: "2px solid $primary11",
outlineOffset: "2px",
},
}}
>
<Box
Expand Down