2022-05-31 12:53:16 +00:00
|
|
|
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 = (
|
2022-06-21 09:36:55 +00:00
|
|
|
props: TablePaginationWithContextProps,
|
2022-05-31 12:53:16 +00:00
|
|
|
) => {
|
|
|
|
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}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|