@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.59 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(_a){var _b,_c,_d,{as="span",children}=_a,props=tslib_1.__rest(_a,["as","children"]);const ctx=(0,useCustomContext_1.default)({context:OrderListPaginationContext_1.default,contextComponentName:"OrderList",currentComponentName:"OrderListPaginationInfo",key:"totalRows"}),TagElement=as,totRows=(_b=ctx?.totalRows)!==null&&_b!==void 0?_b:0,pageIndex=(_c=ctx?.pageIndex)!==null&&_c!==void 0?_c:0,pageSize=(_d=ctx?.pageSize)!==null&&_d!==void 0?_d: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=Object.assign(Object.assign({},props),{as,firstRow,lastRow,totRows});return children==null?totRows===0?null:(0,jsx_runtime_1.jsx)(TagElement,Object.assign({},props,{children:`${firstRow} - ${lastRow} of ${totRows}`})):(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children}))}OrderListPaginationInfo.displayName="OrderListPaginationInfo",exports.default=OrderListPaginationInfo;