@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.4 kB
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.OrderListPaginationInfo=OrderListPaginationInfo;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),OrderListPaginationContext_1=tslib_1.__importDefault(require("../../context/OrderListPaginationContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function OrderListPaginationInfo({as="span",children,...props}){const ctx=(0,useCustomContext_1.default)({context:OrderListPaginationContext_1.default,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:(0,jsx_runtime_1.jsx)(TagElement,{...props,children:`${firstRow} - ${lastRow} of ${totRows}`}):(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children})}OrderListPaginationInfo.displayName="OrderListPaginationInfo",exports.default=OrderListPaginationInfo;