UNPKG

solrkit

Version:

![Build Status](https://travis-ci.org/garysieling/solrkit.svg?branch=master) ![Dependencies](https://david-dm.org/garysieling/solrkit/status.svg)

67 lines 2.76 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_1 = require("react"); var semantic_ui_react_1 = require("semantic-ui-react"); var _ = require("lodash"); var Pagination = (function (_super) { __extends(Pagination, _super); function Pagination() { return _super.call(this) || this; } Pagination.prototype.handlePaging = function (idx) { var _this = this; return function () { _this.context.transition({ start: (idx - 1) * _this.props.pageSize }); }; }; Pagination.prototype.render = function () { var _this = this; var self = this; var pageSize = self.props.pageSize || 10; var numRows = self.props.numRows || 0; var activePage = 1 + self.context.searchState.start / pageSize; if (numRows < pageSize) { return null; } var maxPage = Math.ceil(numRows / pageSize); if (maxPage < activePage) { activePage = maxPage; } var pages = maxPage > 0 ? _.takeRight(_.takeWhile(_.range(1, Math.max(maxPage, 1)), function (value, index, array) { return index < activePage + 2; }), 5) : [1]; if (pages[0] !== 1) { pages.unshift(-1); pages.unshift(1); } if (pages[pages.length - 1] < maxPage) { pages.push(-1); pages.push(maxPage); } var menuItems = (pages.map(function (idx, row) { return idx === -1 ? (React.createElement(semantic_ui_react_1.Menu.Item, { key: row, disabled: true }, "...")) : (React.createElement(semantic_ui_react_1.Menu.Item, { key: row, name: idx + '', active: activePage === idx, onClick: _this.handlePaging(idx) })); })); return (React.createElement(semantic_ui_react_1.Menu, { pagination: true }, menuItems)); }; Pagination.contextTypes = { searchState: react_1.PropTypes.object, transition: react_1.PropTypes.func }; return Pagination; }(React.Component)); exports.Pagination = Pagination; //# sourceMappingURL=Pagination.js.map