UNPKG

simple-react-ui

Version:

a simple react component library written in TypeScript+ React.js

69 lines 2.96 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 pagination_info_1 = require("pagination-info"); /** * 分页组件 */ var Pagination = /** @class */ (function (_super) { __extends(Pagination, _super); function Pagination() { return _super !== null && _super.apply(this, arguments) || this; } /** * 生成onClick事件处理函数的高阶函数 */ Pagination.prototype._genOnClick = function (e, i) { e.preventDefault(); var onChange = this.props.onChange; return function (e) { onChange(i); return false; }; }; ; Pagination.prototype._genFirstDigitLink = function (firstDigit) { var _this = this; return React.createElement("li", null, React.createElement("a", { href: "#", onClick: function (e) { _this._genOnClick(e, firstDigit)(e); } }, "\u00AB")); }; Pagination.prototype._genLastDigitLink = function (lastDigit) { var _this = this; return React.createElement("li", null, React.createElement("a", { href: "#", onClick: function (e) { return _this._genOnClick(e, lastDigit)(e); } }, "\u00BB")); }; Pagination.prototype.render = function () { var _this = this; var _info = pagination_info_1.calculatePaginationInfo(this.props.total, this.props.size, this.props.current, this.props.semiBandWidth); return (React.createElement("nav", null, React.createElement("ul", { className: "pagination" }, _info.shouldDisplay ? this._genFirstDigitLink(_info.firstDigit) : "", _info.shouldDisplay ? _info.array.map(function (i) { return React.createElement("li", { key: i, onClick: function (e) { return _this._genOnClick(e, i)(e); } }, React.createElement("a", { href: i + '', className: _info.current == i ? "active" : "" }, i)); }) : "", _info.shouldDisplay ? this._genLastDigitLink(_info.lastDigit) : ""))); }; Pagination.defaultProps = { total: 50, size: 10, current: 1, semiBandWidth: 5, onChange: function (page) { }, }; return Pagination; }(React.Component)); exports.Pagination = Pagination; ; exports.default = Pagination; //# sourceMappingURL=index.js.map