UNPKG

react-instantsearch

Version:
120 lines 5.88 kB
var _excluded = ["pages", "currentPage", "nbPages", "isFirstPage", "isLastPage", "showFirst", "showPrevious", "showNext", "showLast", "createURL", "onNavigate", "translations", "classNames"], _excluded2 = ["isDisabled", "className", "classNames", "href", "onClick"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } import { cx } from 'instantsearch-ui-components'; import React from 'react'; import { isModifierClick } from "./lib/isModifierClick.js"; export function Pagination(_ref) { var pages = _ref.pages, currentPage = _ref.currentPage, nbPages = _ref.nbPages, isFirstPage = _ref.isFirstPage, isLastPage = _ref.isLastPage, _ref$showFirst = _ref.showFirst, showFirst = _ref$showFirst === void 0 ? true : _ref$showFirst, _ref$showPrevious = _ref.showPrevious, showPrevious = _ref$showPrevious === void 0 ? true : _ref$showPrevious, _ref$showNext = _ref.showNext, showNext = _ref$showNext === void 0 ? true : _ref$showNext, _ref$showLast = _ref.showLast, showLast = _ref$showLast === void 0 ? true : _ref$showLast, createURL = _ref.createURL, onNavigate = _ref.onNavigate, translations = _ref.translations, _ref$classNames = _ref.classNames, classNames = _ref$classNames === void 0 ? {} : _ref$classNames, props = _objectWithoutProperties(_ref, _excluded); var firstPageIndex = 0; var previousPageIndex = currentPage - 1; var nextPageIndex = currentPage + 1; var lastPageIndex = nbPages - 1; return /*#__PURE__*/React.createElement("div", _extends({}, props, { className: cx('ais-Pagination', classNames.root, nbPages <= 1 && cx('ais-Pagination--noRefinement', classNames.noRefinementRoot), props.className) }), /*#__PURE__*/React.createElement("ul", { className: cx('ais-Pagination-list', classNames.list) }, showFirst && /*#__PURE__*/React.createElement(PaginationItem, { isDisabled: isFirstPage, className: cx('ais-Pagination-item--firstPage', classNames.firstPageItem), classNames: classNames, "aria-label": translations.firstPageItemAriaLabel, href: createURL(firstPageIndex), onClick: function onClick() { return onNavigate(firstPageIndex); } }, translations.firstPageItemText), showPrevious && /*#__PURE__*/React.createElement(PaginationItem, { isDisabled: isFirstPage, className: cx('ais-Pagination-item--previousPage', classNames.previousPageItem), classNames: classNames, "aria-label": translations.previousPageItemAriaLabel, href: createURL(previousPageIndex), onClick: function onClick() { return onNavigate(previousPageIndex); } }, translations.previousPageItemText), pages.map(function (page) { return /*#__PURE__*/React.createElement(PaginationItem, { key: page, isDisabled: false, className: cx('ais-Pagination-item--page', classNames.pageItem, page === currentPage && cx('ais-Pagination-item--selected', classNames.selectedItem)), classNames: classNames, "aria-label": translations.pageItemAriaLabel({ currentPage: page + 1, nbPages: nbPages }), href: createURL(page), onClick: function onClick() { return onNavigate(page); } }, translations.pageItemText({ currentPage: page + 1, nbPages: nbPages })); }), showNext && /*#__PURE__*/React.createElement(PaginationItem, { isDisabled: isLastPage, className: cx('ais-Pagination-item--nextPage', classNames.nextPageItem), classNames: classNames, "aria-label": translations.nextPageItemAriaLabel, href: createURL(nextPageIndex), onClick: function onClick() { return onNavigate(nextPageIndex); } }, translations.nextPageItemText), showLast && /*#__PURE__*/React.createElement(PaginationItem, { isDisabled: isLastPage, className: cx('ais-Pagination-item--lastPage', classNames.lastPageItem), classNames: classNames, "aria-label": translations.lastPageItemAriaLabel, href: createURL(lastPageIndex), onClick: function onClick() { return onNavigate(lastPageIndex); } }, translations.lastPageItemText))); } function PaginationItem(_ref2) { var isDisabled = _ref2.isDisabled, className = _ref2.className, classNames = _ref2.classNames, href = _ref2.href, _onClick = _ref2.onClick, props = _objectWithoutProperties(_ref2, _excluded2); if (isDisabled) { return /*#__PURE__*/React.createElement("li", { className: cx('ais-Pagination-item', classNames.item, 'ais-Pagination-item--disabled', classNames.disabledItem, className) }, /*#__PURE__*/React.createElement("span", _extends({ className: cx('ais-Pagination-link', classNames.link) }, props))); } return /*#__PURE__*/React.createElement("li", { className: cx('ais-Pagination-item', classNames.item, className) }, /*#__PURE__*/React.createElement("a", _extends({ className: cx('ais-Pagination-link', classNames.link), href: href, onClick: function onClick(event) { if (isModifierClick(event)) { return; } event.preventDefault(); _onClick(event); } }, props))); }