UNPKG

solrkit

Version:

![Build Status](https://travis-ci.org/garysieling/solrkit.svg?branch=master) ![Dependencies](https://david-dm.org/garysieling/solrkit/status.svg) UI Components for Solr, using TypeScript + React

77 lines 2.85 kB
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 __()); }; })(); import * as React from 'react'; import { PropTypes } from 'react'; import { Menu } from 'semantic-ui-react'; import * as _ from 'lodash'; import 'semantic-ui-css/semantic.min.css'; // TODO split into it's own file var PaginationProperties = [ { name: 'data', display: 'Data', type: 'object[]' }, { name: 'pageSize', display: 'Page Size', type: 'number', default: 10 } ]; 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; 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) { return idx === -1 ? (React.createElement(Menu.Item, { key: idx, disabled: true }, "...")) : (React.createElement(Menu.Item, { key: idx, name: idx + '', active: activePage === idx, onClick: _this.handlePaging(idx) })); })); return (React.createElement(Menu, { pagination: true }, menuItems)); }; Pagination.contextTypes = { searchState: PropTypes.object, transition: PropTypes.func }; return Pagination; }(React.Component)); export { Pagination, PaginationProperties }; //# sourceMappingURL=Pagination.js.map