@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 2.24 kB
JavaScript
"use client";
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListPaginationContext from"../../context/OrderListPaginationContext";import useCustomContext from"../../utils/hooks/useCustomContext";import omit from"../../utils/omit";export function OrderListPaginationButtons({previousPageButton,nextPageButton,navigationButtons,children,...props}){const{...prevButton}={show:!0,...previousPageButton},{...nextButton}={show:!0,...nextPageButton},{...navButton}={show:!0,...navigationButtons},ctx=useCustomContext({context:OrderListPaginationContext,contextComponentName:"OrderList",currentComponentName:"OrderListPaginationButtons",key:"totalRows"}),PrevButton=prevButton.show?prevButton.hideWhenDisabled===!0&&ctx?.canPreviousPage===!1?null:_jsx("button",{"data-testid":"prev-button",...omit(prevButton,["show","hideWhenDisabled"]),disabled:ctx?.canPreviousPage===!1,onClick:()=>ctx?.previousPage(),children:previousPageButton?.label??"<"}):null,NextButton=nextButton.show?nextButton.hideWhenDisabled===!0&&ctx?.canNextPage===!1?null:_jsx("button",{"data-testid":"next-button",...omit(nextButton,["show","hideWhenDisabled"]),disabled:ctx?.canNextPage===!1,onClick:()=>ctx?.nextPage(),children:nextButton?.label??">"}):null,pagesToShow=ctx?.canPreviousPage===!1?ctx?.pageOptions.slice(0,3).map(v=>v+1):ctx?.canNextPage===!1?ctx?.pageOptions.slice(ctx?.pageOptions.length-3,ctx?.pageOptions.length).map(v=>v+1):ctx?.pageOptions.slice(ctx?.pageIndex-1,ctx?.pageIndex+2).map(v=>v+1),NavButtons=navButton.show?pagesToShow?.map(v=>{const className=(ctx?.pageIndex!=null?ctx?.pageIndex+1:1)===v?`${navButton?.className??""} ${navButton?.activeClassName??""}`:navButton?.className;return _jsx("button",{"data-testid":`page-${v}`,...omit(navButton,["show","activeClassName","className"]),className,onClick:()=>ctx?.gotoPage(v-1),children:v},`page-${v}`)}):null,parentProps={navigationButtons,prevButton,nextButton,...ctx,...props};return children==null?ctx?.totalRows===0?null:_jsxs("div",{...props,children:[PrevButton,NavButtons,NextButton]}):_jsx(Parent,{...parentProps,children})}OrderListPaginationButtons.displayName="OrderListPaginationButtons";export default OrderListPaginationButtons;