UNPKG

@hypernetlabs/web-ui

Version:
70 lines 3.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GovernancePagination = exports.getPageItemIndexList = exports.extractDataByPage = void 0; const react_1 = __importStar(require("react")); const lab_1 = require("@material-ui/lab"); const GovernancePagination_style_1 = require("../../components/GovernancePagination/GovernancePagination.style"); const extractDataByPage = (data, rowsPerPage, page) => { if (!data.length || !rowsPerPage) { return data; } const startIndex = (page - 1) * rowsPerPage; const endIndex = startIndex + rowsPerPage; return data.slice(startIndex, endIndex); }; exports.extractDataByPage = extractDataByPage; const getPageItemIndexList = (totalItems, currentPage, itemsPerPage) => { const proposalNumberArr = []; if (totalItems) { for (let i = 1; i <= Math.min(totalItems, itemsPerPage); i++) { // Get indices from current page backwards. const index = totalItems - (currentPage - 1) * itemsPerPage - i + 1; // Proposals starts with index one. if (index > 0) { proposalNumberArr.push(index); } } } return proposalNumberArr; }; exports.getPageItemIndexList = getPageItemIndexList; const GovernancePagination = (props) => { const { shape = "rounded", customPageOptions, count = 1, defaultPage = 1, className, ...rest } = props; const classes = (0, GovernancePagination_style_1.useStyles)(); const customPageCount = (0, react_1.useMemo)(() => { if (!customPageOptions) { return 0; } return Math.ceil(customPageOptions.totalItems / customPageOptions.itemsPerPage); }, [JSON.stringify(customPageOptions)]); const customDefaultPage = (0, react_1.useMemo)(() => { if (!customPageOptions || !(customPageOptions === null || customPageOptions === void 0 ? void 0 : customPageOptions.currentPageStartIndex)) { return 0; } return Math.ceil(customPageOptions.currentPageStartIndex / customPageOptions.itemsPerPage); }, [JSON.stringify(customPageOptions)]); return (react_1.default.createElement(lab_1.Pagination, { className: `${classes.pagination} ${className}`, shape: shape, count: customPageOptions ? customPageCount : count, ...rest, page: (customPageOptions === null || customPageOptions === void 0 ? void 0 : customPageOptions.currentPage) || defaultPage, defaultPage: (customPageOptions === null || customPageOptions === void 0 ? void 0 : customPageOptions.currentPageStartIndex) ? customDefaultPage : defaultPage })); }; exports.GovernancePagination = GovernancePagination; //# sourceMappingURL=GovernancePagination.js.map