Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwaiser committed Oct 1, 2015
2 parents 145dfc0 + df8d2cf commit 81a0278
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ React.render(<App />, document.getElementById("root"));

Check [Live example](http://vayser.github.io/react-js-pagination)

![Example](https://i.gyazo.com/ab4bd1df5a60b7e45f87d8a50472ebba.png)
![Example](https://i.gyazo.com/9af4c2b9e20aa95a67597d3ca64efde3.png)

## Params

Expand Down
76 changes: 76 additions & 0 deletions dist/Page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _classnames = require("classnames");

var _classnames2 = _interopRequireDefault(_classnames);

var Page = (function (_Component) {
_inherits(Page, _Component);

function Page() {
_classCallCheck(this, Page);

_get(Object.getPrototypeOf(Page.prototype), "constructor", this).apply(this, arguments);
}

_createClass(Page, [{
key: "render",
value: function render() {
var el = undefined;

var className = (0, _classnames2["default"])({
"active": this.props.isActive
});

var text = this.props.pageText || this.props.pageNumber;

if (_react2["default"].isValidElement(text)) {
el = text;
} else {
el = _react2["default"].createElement(
"li",
{ className: className },
_react2["default"].createElement(
"a",
{ onClick: this.props.onClick.bind(this, this.props.pageNumber), href: "#" },
text
)
);
}

return el;
}
}], [{
key: "propTypes",
value: {
pageText: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.element]),
pageNumber: _react.PropTypes.number.isRequired,
onClick: _react.PropTypes.func.isRequired,
isActive: _react.PropTypes.bool.isRequired
},
enumerable: true
}]);

return Page;
})(_react.Component);

exports["default"] = Page;
module.exports = exports["default"];
159 changes: 159 additions & 0 deletions dist/Pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _paginator = require("paginator");

var _paginator2 = _interopRequireDefault(_paginator);

var _classnames = require("classnames");

var _classnames2 = _interopRequireDefault(_classnames);

var _Page = require("./Page");

var _Page2 = _interopRequireDefault(_Page);

var lt = "⟨";
var Lt = "«";
var gt = "⟩";
var Gt = "»";

var prevPageText = lt;
var firstPageText = Lt;

var nextPageText = gt;
var lastPageText = Gt;

var Pagination = (function (_React$Component) {
_inherits(Pagination, _React$Component);

function Pagination(props) {
_classCallCheck(this, Pagination);

_get(Object.getPrototypeOf(Pagination.prototype), "constructor", this).call(this);
}

_createClass(Pagination, [{
key: "onClick",
value: function onClick(page, e) {
e.preventDefault();
this.props.onChange(page);
}
}, {
key: "buildPages",
value: function buildPages() {
var pages = [];

var _props = this.props;
var _props$itemsCountPerPage = _props.itemsCountPerPage;
var itemsCountPerPage = _props$itemsCountPerPage === undefined ? 10 : _props$itemsCountPerPage;
var _props$pageRangeDisplayed = _props.pageRangeDisplayed;
var pageRangeDisplayed = _props$pageRangeDisplayed === undefined ? 5 : _props$pageRangeDisplayed;
var _props$activePage = _props.activePage;
var activePage = _props$activePage === undefined ? 1 : _props$activePage;
var _props$prevPageText = _props.prevPageText;
var prevPageText = _props$prevPageText === undefined ? lt : _props$prevPageText;
var _props$nextPageText = _props.nextPageText;
var nextPageText = _props$nextPageText === undefined ? gt : _props$nextPageText;
var _props$firstPageText = _props.firstPageText;
var firstPageText = _props$firstPageText === undefined ? Lt : _props$firstPageText;
var _props$lastPageText = _props.lastPageText;
var lastPageText = _props$lastPageText === undefined ? Gt : _props$lastPageText;
var totalItemsCount = _props.totalItemsCount;

var paginationInfo = new _paginator2["default"](itemsCountPerPage, pageRangeDisplayed).build(totalItemsCount, activePage);

if (paginationInfo.first_page !== paginationInfo.last_page) {
for (var i = paginationInfo.first_page; i <= paginationInfo.last_page; i++) {
pages.push(_react2["default"].createElement(_Page2["default"], {
isActive: i === activePage,
key: i,
pageNumber: i,
onClick: this.onClick.bind(this)
}));
}
}

paginationInfo.has_previous_page && pages.unshift(_react2["default"].createElement(_Page2["default"], {
isActive: false,
key: "prev" + paginationInfo.previous_page,
pageNumber: paginationInfo.previous_page,
onClick: this.onClick.bind(this),
pageText: prevPageText
}));

paginationInfo.first_page > 1 && pages.unshift(_react2["default"].createElement(_Page2["default"], {
isActive: false,
key: 1,
pageNumber: 1,
onClick: this.onClick.bind(this),
pageText: firstPageText
}));

paginationInfo.has_next_page && pages.push(_react2["default"].createElement(_Page2["default"], {
isActive: false,
key: "next" + paginationInfo.next_page,
pageNumber: paginationInfo.next_page,
onClick: this.onClick.bind(this),
pageText: nextPageText
}));

paginationInfo.last_page !== paginationInfo.total_pages && pages.push(_react2["default"].createElement(_Page2["default"], {
isActive: false,
key: paginationInfo.total_pages,
pageNumber: paginationInfo.total_pages,
onClick: this.onClick.bind(this),
pageText: lastPageText
}));

return pages;
}
}, {
key: "render",
value: function render() {
var pages = this.buildPages();

return _react2["default"].createElement(
"ul",
{ className: "pagination" },
pages
);
}
}], [{
key: "propTypes",
value: {
totalItemsCount: _react.PropTypes.number.isRequired,
onChange: _react.PropTypes.func.isRequired,
activePage: _react.PropTypes.number,
pageRangeDisplayed: _react.PropTypes.number,
itemsCountPerPage: _react.PropTypes.number,
prevPageText: _react.PropTypes.string,
nextPageText: _react.PropTypes.string,
firstPageText: _react.PropTypes.string,
lastPageText: _react.PropTypes.string
},
enumerable: true
}]);

return Pagination;
})(_react2["default"].Component);

exports["default"] = Pagination;
module.exports = exports["default"];
2 changes: 1 addition & 1 deletion src/example/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/example/dist/bundle.js.map

Large diffs are not rendered by default.

0 comments on commit 81a0278

Please sign in to comment.