Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Ability to disable/enable first/last | previous/next navigations #33

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ PaginationComponent.propTypes = {
// Number of pages being displayed, by default 5
maxPaginationNumbers: PropTypes.number,
// Page where the pagination starts, by default 1
defaultActivePage: PropTypes.number
defaultActivePage: PropTypes.number,
// Change text of "First" button
firstPageText: PropTypes.string
firstPageText: PropTypes.string,
// Change text of "Previous" button
previousPageText: PropTypes.string
previousPageText: PropTypes.string,
// Change text of "Next" button
nextPageText: PropTypes.string
nextPageText: PropTypes.string,
// Change text of "Last" button
lastPageText: PropTypes.string
lastPageText: PropTypes.string,
// Disable/enable first/last navigation
hasFirstLastNavigation: PropTypes.bool,
// Disable enable previous/next navigation
hasNextPreviousNavigation: PropTypes.bool,
// Changes the size of the component. Values: "sm" and "lg". Without the prop the size is normal.
size: PropTypes.string
}
Expand All @@ -50,6 +54,7 @@ PaginationComponent.propTypes = {
- It was added on 1.0.8 but it's worth to mention, the size prop with the values "sm" or "lg" will make smaller or bigger the component. It was an option from the actual Reactstrap PaginationItem component.


## Update 2.0.5



- Added ability to disable/enable first/last navigations
- Added ability to disable/enable previous/next navigations
5 changes: 4 additions & 1 deletion dev/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PaginationComponent from '../src/PaginationComponent';
//import PaginationComponent from '../dist/react-reactstrap-pagination.min.js';
import 'bootstrap/dist/css/bootstrap.min.css';
import {Button} from 'reactstrap';

class App extends React.Component {
state = {
Expand All @@ -27,10 +28,12 @@ class App extends React.Component {
onSelect={this.handleSelected}
maxPaginationNumbers={this.state.maxPaginationNumbers}
defaultActivePage={this.state.defaultActivePage}
hasFirstLastNavigation={false}
hasNextPreviousNavigation={false}
/>
</div>
<div>
<button onClick={()=>{this.setState({defaultActivePage:11, maxPaginationNumbers: 5})}}>Change default active page</button>
<Button color="primary" onClick={()=>{this.setState({defaultActivePage:11, maxPaginationNumbers: 5})}}>Change default active page</Button>
</div>
</>
);
Expand Down
68 changes: 39 additions & 29 deletions dist/react-reactstrap-pagination.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('reactstrap'), require('prop-types'), require('memoize-one')) :
typeof define === 'function' && define.amd ? define(['react', 'reactstrap', 'prop-types', 'memoize-one'], factory) :
(global = global || self, global['react-reactstrap-pagination'] = factory(global.React, global.reactstrap, global.PropTypes, global.memoize));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['react-reactstrap-pagination'] = factory(global.React, global.reactstrap, global.PropTypes, global.memoize));
}(this, (function (React, reactstrap, PropTypes, memoize) { 'use strict';

var React__default = 'default' in React ? React['default'] : React;
PropTypes = PropTypes && Object.prototype.hasOwnProperty.call(PropTypes, 'default') ? PropTypes['default'] : PropTypes;
memoize = memoize && Object.prototype.hasOwnProperty.call(memoize, 'default') ? memoize['default'] : memoize;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
Expand Down Expand Up @@ -82,7 +84,7 @@
if (typeof Proxy === "function") return true;

try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
Expand All @@ -100,6 +102,8 @@
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return _assertThisInitialized(self);
Expand Down Expand Up @@ -136,7 +140,7 @@

_this = _super.call(this, _props);

_defineProperty(_assertThisInitialized(_this), "getNumberOfPages", memoize(function (props) {
_defineProperty(_assertThisInitialized(_this), "getNumberOfPages", memoize__default['default'](function (props) {
var auxPages = props.totalItems / props.pageSize;
var pages = parseInt(auxPages, 10);
pages += pages !== auxPages ? 1 : 0;
Expand All @@ -160,24 +164,26 @@
firstPageText = _this$props.firstPageText,
previousPageText = _this$props.previousPageText,
nextPageText = _this$props.nextPageText,
lastPageText = _this$props.lastPageText; // Since first and last PaginationNumber depend on activepage there's no reason to have them on the state
lastPageText = _this$props.lastPageText,
hasFirstLastNavigation = _this$props.hasFirstLastNavigation,
hasNextPreviousNavigation = _this$props.hasNextPreviousNavigation; // Since first and last PaginationNumber depend on activepage there's no reason to have them on the state
// So we just make the calculations when we need them

var firstPaginationNumber = _this.getFirstPaginationNumber(activePage, pages);

var lastPaginationNumber = _this.getLastPaginationNumber(firstPaginationNumber, pages); // Elements first and previous


items.push(_this.firstOrLastPagItem(firstPageText, 1));
items.push(_this.nextOrPreviousPagItem(previousPageText, 1, "l")); // Page numbers
hasFirstLastNavigation && items.push(_this.firstOrLastPagItem(firstPageText, 1));
hasNextPreviousNavigation && items.push(_this.nextOrPreviousPagItem(previousPageText, 1, "l")); // Page numbers

for (var i = firstPaginationNumber; i <= lastPaginationNumber; i++) {
items.push(_this.numberedPagItem(i, activePage));
} // Elements next and last


items.push(_this.nextOrPreviousPagItem(nextPageText, pages, "r"));
items.push(_this.firstOrLastPagItem(lastPageText, pages));
hasNextPreviousNavigation && items.push(_this.nextOrPreviousPagItem(nextPageText, pages, "r"));
hasFirstLastNavigation && items.push(_this.firstOrLastPagItem(lastPageText, pages));
return items;
});

Expand Down Expand Up @@ -212,26 +218,26 @@
minWidth = "33px";
}

return /*#__PURE__*/React__default.createElement(reactstrap.PaginationItem, {
return /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationItem, {
key: i,
id: "pagebutton".concat(i),
active: activePage === i,
onClick: _this.handleClick
}, /*#__PURE__*/React__default.createElement(reactstrap.PaginationLink, {
}, /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationLink, {
style: {
minWidth: minWidth
}
}, i));
});

_defineProperty(_assertThisInitialized(_this), "nextOrPreviousPagItem", function (name, page, direction) {
return /*#__PURE__*/React__default.createElement(reactstrap.PaginationItem, {
return /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationItem, {
key: name,
disabled: _this.activePage === page,
onClick: function onClick(e) {
return _this.handleSelectNextOrPrevious(direction);
}
}, /*#__PURE__*/React__default.createElement(reactstrap.PaginationLink, null, name));
}, /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationLink, null, name));
});

_defineProperty(_assertThisInitialized(_this), "firstOrLastPagItem", function (name, page) {
Expand All @@ -242,13 +248,13 @@
}
}
};
return /*#__PURE__*/React__default.createElement(reactstrap.PaginationItem, {
return /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationItem, {
key: name,
disabled: _this.activePage === page,
onClick: function onClick() {
return _this.handleClick(event);
}
}, /*#__PURE__*/React__default.createElement(reactstrap.PaginationLink, null, name));
}, /*#__PURE__*/React__default['default'].createElement(reactstrap.PaginationLink, null, name));
});

_defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
Expand Down Expand Up @@ -291,7 +297,7 @@
_createClass(PaginationComponent, [{
key: "render",
value: function render() {
return /*#__PURE__*/React__default.createElement(reactstrap.Pagination, {
return /*#__PURE__*/React__default['default'].createElement(reactstrap.Pagination, {
size: this.props.size
}, this.paginationItems());
}
Expand All @@ -301,24 +307,28 @@
}(React.PureComponent);

PaginationComponent.propTypes = {
totalItems: PropTypes.number.isRequired,
pageSize: PropTypes.number.isRequired,
onSelect: PropTypes.func.isRequired,
maxPaginationNumbers: PropTypes.number,
defaultActivePage: PropTypes.number,
firstPageText: PropTypes.string,
previousPageText: PropTypes.string,
nextPageText: PropTypes.string,
lastPageText: PropTypes.string,
size: PropTypes.string
totalItems: PropTypes__default['default'].number.isRequired,
pageSize: PropTypes__default['default'].number.isRequired,
onSelect: PropTypes__default['default'].func.isRequired,
maxPaginationNumbers: PropTypes__default['default'].number,
defaultActivePage: PropTypes__default['default'].number,
firstPageText: PropTypes__default['default'].string,
previousPageText: PropTypes__default['default'].string,
nextPageText: PropTypes__default['default'].string,
lastPageText: PropTypes__default['default'].string,
size: PropTypes__default['default'].string,
hasNextPreviousNavigation: PropTypes__default['default'].bool,
hasFirstLastNavigation: PropTypes__default['default'].bool
};
PaginationComponent.defaultProps = {
maxPaginationNumbers: 5,
defaultActivePage: 1,
firstPageText: "First",
previousPageText: "Previous",
nextPageText: "Next",
lastPageText: "Last"
lastPageText: "Last",
hasNextPreviousNavigation: true,
hasFirstLastNavigation: true
};

return PaginationComponent;
Expand Down
Loading