saleor-dashboard/src/components/TablePagination/TablePaginationWithContext.tsx
Michał Droń d5c9a3dae8
Add trailing commas (#2062)
* Require trailing commas

* Add trailing commas

* Add trailing commas in testUtils dir

* Add trailing commas
2022-06-21 11:36:55 +02:00

50 lines
1.1 KiB
TypeScript

import { usePaginatorContext } from "@saleor/hooks/usePaginator";
import React from "react";
import TablePagination, { PaginationProps } from "./TablePagination";
export type TablePaginationWithContextProps = Omit<
PaginationProps,
| "nextHref"
| "prevHref"
| "hasNextPage"
| "hasPreviousPage"
| "onNextPage"
| "onPreviousPage"
>;
export const TablePaginationWithContext = (
props: TablePaginationWithContextProps,
) => {
const {
hasNextPage,
hasPreviousPage,
paginatorType,
...paginationProps
} = usePaginatorContext();
if (paginatorType === "click") {
const { loadNextPage, loadPreviousPage } = paginationProps;
return (
<TablePagination
{...props}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
/>
);
}
const { prevPageHref, nextPageHref } = paginationProps;
return (
<TablePagination
{...props}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
prevHref={prevPageHref}
nextHref={nextPageHref}
/>
);
};