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
81 changes: 81 additions & 0 deletions components/Table/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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) => {
if (totalPages <= 0) return null;

return (
<Flex
css={{
paddingTop: "$4",
paddingBottom: "$4",
alignItems: "center",
justifyContent: "center",
...css,
}}
>
<Box
aria-label="Previous Page"
as="button"
type="button"
css={{
background: "none",
border: "none",
cursor: "pointer",
color: canPrevious ? "$primary11" : "$hiContrast",
opacity: canPrevious ? 1 : 0.5,
}}
onClick={() => {
if (canPrevious) {
onPrevious();
}
}}
>
<ArrowLeftIcon />
</Box>
<Box css={{ fontSize: "$2", marginLeft: "$3", marginRight: "$3" }}>
Page <Box as="span">{currentPage}</Box> of{" "}
<Box as="span">{totalPages}</Box>
</Box>
<Box
aria-label="Next Page"
as="button"
type="button"
css={{
background: "none",
border: "none",
cursor: "pointer",
color: canNext ? "$primary11" : "$hiContrast",
opacity: canNext ? 1 : 0.5,
}}
onClick={() => {
if (canNext) {
onNext();
}
}}
>
<ArrowRightIcon />
</Box>
</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