From 69000ee25ce48c769bd8dcc6dbd14fa91f97b3d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Demey Date: Fri, 5 Jul 2019 16:53:59 +0200 Subject: [PATCH 1/3] fix(pagination): Disable buttons if they cannot be used --- src/js/components/shared/pagination/index.js | 54 ++++++++++--------- .../shared/pagination/pagination.scss | 4 ++ .../shared/pagination/pagination.spec.js | 16 ++++++ 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/js/components/shared/pagination/index.js b/src/js/components/shared/pagination/index.js index 3700521dd..dad0cf49d 100644 --- a/src/js/components/shared/pagination/index.js +++ b/src/js/components/shared/pagination/index.js @@ -12,8 +12,20 @@ function checkInvalidPage(targetPage, listSize) { * context: The context of the page. Used for theming */ class Pagination extends Component { - constructor() { - super(); + static propTypes = { + itemEls: PropTypes.arrayOf(PropTypes.element).isRequired, + itemsPerPage: PropTypes.string.isRequired, + context: PropTypes.oneOf([ + '', + 'concepts', + 'collections', + 'classifications', + 'operations', + ]), + }; + + constructor(props) { + super(props); this.state = { currentPage: 1, }; @@ -46,20 +58,18 @@ class Pagination extends Component { pageNumbers.push(i); } - function activePage(page) { - return page === currentPage ? 'page-item active' : 'page-item'; + function isActivePage(page) { + return page === currentPage; } function isDisabled(targetPage) { - return checkInvalidPage(targetPage, pageNumbers.length) - ? 'page-item disabled' - : 'page-item'; + return checkInvalidPage(targetPage, pageNumbers.length); } const renderPageNumbers = pageNumbers .filter(number => number - 3 < currentPage && number + 3 > currentPage) .map(number => { return ( -
  • +
  • -
  • +
  • {renderPageNumbers} -
  • +
  • -
  • +