@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.11 kB
JavaScript
"use client";
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListPaginationContext from"../../context/OrderListPaginationContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderListPaginationInfo({as="span",children,...props}){const ctx=useCustomContext({context:OrderListPaginationContext,contextComponentName:"OrderList",currentComponentName:"OrderListPaginationInfo",key:"totalRows"}),TagElement=as,totRows=ctx?.totalRows??0,pageIndex=ctx?.pageIndex??0,pageSize=ctx?.pageSize??10;let firstRow=pageIndex===0?pageIndex+1:pageIndex,lastRow=firstRow*pageSize;ctx?.canPreviousPage===!0&&(firstRow=Math.floor(firstRow*pageSize)+1,lastRow=Math.floor(firstRow+pageSize-1)),ctx?.canNextPage===!1&&(lastRow=totRows);const parentProps={...props,as,firstRow,lastRow,totRows};return children==null?totRows===0?null:_jsx(TagElement,{...props,children:`${firstRow} - ${lastRow} of ${totRows}`}):_jsx(Parent,{...parentProps,children})}OrderListPaginationInfo.displayName="OrderListPaginationInfo";export default OrderListPaginationInfo;