widenarrow-ui 1.0.48 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,18 @@ import { HierarchyTypes } from 'src/constants';
2
2
  import { SearchResultInterface } from '../../types/common.types';
3
3
  export interface PaginationProps {
4
4
  pagination: SearchResultInterface;
5
- onPaginate: (page: number) => void;
6
- onPageSizeChange?: (pageSize: number) => void;
5
+ onChange: (searchResult: SearchResultInterface) => void;
7
6
  slim?: boolean;
8
- tablePagination?: boolean;
7
+ withPageSizeChange?: boolean;
8
+ withTablePagination?: boolean;
9
+ withFastForwardButtons: boolean;
10
+ pageSizeOptions?: Array<number>;
9
11
  buttonType?: HierarchyTypes.PRIMARY | HierarchyTypes.SECONDARY;
10
12
  className?: string;
11
13
  nextPageTitle?: string;
12
14
  previousPageTitle?: string;
15
+ firstPageTitle?: string;
16
+ lastPageTitle?: string;
13
17
  pageSizeTitleCallback?: (args: {
14
18
  pageSize: number;
15
19
  }) => string;
package/lib/index.d.ts CHANGED
@@ -510,14 +510,18 @@ interface SearchResultInterface {
510
510
 
511
511
  interface PaginationProps {
512
512
  pagination: SearchResultInterface;
513
- onPaginate: (page: number) => void;
514
- onPageSizeChange?: (pageSize: number) => void;
513
+ onChange: (searchResult: SearchResultInterface) => void;
515
514
  slim?: boolean;
516
- tablePagination?: boolean;
515
+ withPageSizeChange?: boolean;
516
+ withTablePagination?: boolean;
517
+ withFastForwardButtons: boolean;
518
+ pageSizeOptions?: Array<number>;
517
519
  buttonType?: HierarchyTypes$1.PRIMARY | HierarchyTypes$1.SECONDARY;
518
520
  className?: string;
519
521
  nextPageTitle?: string;
520
522
  previousPageTitle?: string;
523
+ firstPageTitle?: string;
524
+ lastPageTitle?: string;
521
525
  pageSizeTitleCallback?: (args: {
522
526
  pageSize: number;
523
527
  }) => string;
package/lib/index.esm.js CHANGED
@@ -2608,7 +2608,7 @@ var styles$b = {"body":"Pagination-module_WRLv5h","container":"Pagination-module
2608
2608
  var s$b = classNames.bind(styles$b);
2609
2609
  var Pagination = function (_a) {
2610
2610
  var _b;
2611
- var className = _a.className, pagination = _a.pagination, onPaginate = _a.onPaginate, slim = _a.slim, onPageSizeChange = _a.onPageSizeChange, _c = _a.buttonType, buttonType = _c === void 0 ? HierarchyTypes.SECONDARY : _c, tablePagination = _a.tablePagination, previousPageTitle = _a.previousPageTitle, nextPageTitle = _a.nextPageTitle, pageSizeTitleCallback = _a.pageSizeTitleCallback, tableIntervalTitleCallback = _a.tableIntervalTitleCallback;
2611
+ var className = _a.className, pagination = _a.pagination, slim = _a.slim, onChange = _a.onChange, _c = _a.buttonType, buttonType = _c === void 0 ? HierarchyTypes.SECONDARY : _c, _d = _a.pageSizeOptions, pageSizeOptions = _d === void 0 ? [10, 20, 30, 40, 50, 80, 100] : _d, firstPageTitle = _a.firstPageTitle, previousPageTitle = _a.previousPageTitle, nextPageTitle = _a.nextPageTitle, lastPageTitle = _a.lastPageTitle, pageSizeTitleCallback = _a.pageSizeTitleCallback, tableIntervalTitleCallback = _a.tableIntervalTitleCallback, withTablePagination = _a.withTablePagination, withFastForwardButtons = _a.withFastForwardButtons, withPageSizeChange = _a.withPageSizeChange;
2612
2612
  if (!pagination) {
2613
2613
  return null;
2614
2614
  }
@@ -2624,9 +2624,6 @@ var Pagination = function (_a) {
2624
2624
  var _a;
2625
2625
  return s$b('button', (_a = { button_slim: slim }, _a[additionalClassName] = additionalClassName, _a));
2626
2626
  };
2627
- if (numberOfPages < 2) {
2628
- return null;
2629
- }
2630
2627
  if (pagination.fetching && !numberOfPages) {
2631
2628
  return (jsx("ul", { className: s$b('container', (_b = {}, _b[className] = className, _b)), children: times(function (i) { return (jsx("li", { className: itemClassName, children: jsx("div", { className: buttonClassName() }) }, i)); }, 5) }));
2632
2629
  }
@@ -2637,39 +2634,40 @@ var Pagination = function (_a) {
2637
2634
  ? tableIntervalTitleCallback({ start: start, end: end, total: pagination.numberOfHits })
2638
2635
  : "".concat(start, " - ").concat(end, " of ").concat(pagination.numberOfHits) }) }));
2639
2636
  };
2637
+ var firstPageButton = withFastForwardButtons ? (jsx("li", { children: jsx("button", { title: firstPageTitle || 'First page', className: buttonClassName(isFirstPage ? 'button_disabled' : undefined), onClick: function () {
2638
+ onChange(__assign(__assign({}, pagination), { currentPage: 1 }));
2639
+ }, disabled: isFirstPage, children: jsx(Icon, { icon: IconTypes.ARROW_FIRST_PAGE }) }) })) : null;
2640
+ var previousPageButton = (jsx("li", { className: itemClassName, children: jsx("button", { title: previousPageTitle || 'Previous page', className: buttonClassName(isFirstPage ? 'button_disabled' : undefined), onClick: function () {
2641
+ !isFirstPage && onChange(__assign(__assign({}, pagination), { currentPage: pagination.currentPage - 1 }));
2642
+ }, disabled: isFirstPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_LEFT }) }) }));
2643
+ var nextPageButton = (jsx("li", { className: itemClassName, children: jsx("button", { title: nextPageTitle || 'Next page', className: buttonClassName(isLastPage ? 'button_disabled' : undefined), onClick: function () {
2644
+ onChange(__assign(__assign({}, pagination), { currentPage: pagination.currentPage + 1 }));
2645
+ }, disabled: isLastPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_RIGHT }) }) }));
2646
+ var lastPageButton = withFastForwardButtons ? (jsx("li", { children: jsx("button", { title: lastPageTitle || 'Last page', className: buttonClassName(isLastPage ? 'button_disabled' : undefined), onClick: function () {
2647
+ onChange(__assign(__assign({}, pagination), { currentPage: pagination.numberOfPages }));
2648
+ }, disabled: isLastPage, children: jsx(Icon, { icon: IconTypes.ARROW_LAST_PAGE }) }) })) : null;
2640
2649
  /*
2641
2650
  paginationMarkup
2642
2651
  */
2643
2652
  var paginationMarkup = function () {
2644
2653
  var _a, _b;
2645
- if (tablePagination) {
2646
- return (jsxs(Box, { alignItems: 'center', children: [jsxs("ul", { className: s$b('container', (_a = {}, _a[className] = className, _a)), children: [jsx("li", { className: itemClassName, children: jsx("button", { title: previousPageTitle || 'Previous page', className: buttonClassName(isFirstPage ? 'button_disabled' : undefined), onClick: function () {
2647
- !isFirstPage && onPaginate(pagination.currentPage - 1);
2648
- }, disabled: isFirstPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_LEFT }) }) }), jsx("li", { className: itemClassName, children: jsx("button", { title: nextPageTitle || 'Next page', className: buttonClassName(isLastPage ? 'button_disabled' : undefined), onClick: function () {
2649
- onPaginate(pagination.currentPage + 1);
2650
- }, disabled: isLastPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_RIGHT }) }) })] }), getPageInfoText()] }));
2654
+ if (withTablePagination) {
2655
+ return (jsxs(Box, { alignItems: 'center', children: [jsxs("ul", { className: s$b('container', (_a = {}, _a[className] = className, _a)), children: [firstPageButton, previousPageButton, nextPageButton, lastPageButton] }), getPageInfoText()] }));
2651
2656
  }
2652
- return (jsxs("ul", { className: s$b('container', (_b = {}, _b[className] = className, _b)), children: [jsx("li", { className: itemClassName, children: jsx("button", { title: previousPageTitle || 'Previous page', className: buttonClassName(isFirstPage ? 'button_disabled' : undefined), onClick: function () {
2653
- !isFirstPage && onPaginate(pagination.currentPage - 1);
2654
- }, disabled: isFirstPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_LEFT }) }) }), getPaginationArray(pagination).map(function (pageObject, index) {
2657
+ return (jsxs("ul", { className: s$b('container', (_b = {}, _b[className] = className, _b)), children: [firstPageButton, previousPageButton, getPaginationArray(pagination).map(function (pageObject, index) {
2655
2658
  if (pageObject.type === 'dots') {
2656
2659
  return (jsx("li", { className: itemClassName, children: jsx("div", { className: s$b('dots', { dots_slim: slim }), children: "..." }) }, "".concat(pageObject.type, "-").concat(index)));
2657
2660
  }
2658
2661
  return (jsx("li", { className: itemClassName, children: jsx("button", { title: "Go to page ".concat(pageObject.page), className: buttonClassName(pageObject.page === pagination.currentPage ? 'button_isActive' : undefined), onClick: function () {
2659
- onPaginate(pageObject.page);
2662
+ onChange(__assign(__assign({}, pagination), { currentPage: pageObject.page }));
2660
2663
  }, children: pageObject.page }) }, "".concat(pageObject.type, "-").concat(index)));
2661
- }), jsx("li", { className: itemClassName, children: jsx("button", { title: nextPageTitle || 'Next page', className: buttonClassName(isLastPage ? 'button_disabled' : undefined), onClick: function () {
2662
- onPaginate(pagination.currentPage + 1);
2663
- }, disabled: isLastPage, children: jsx(Icon, { icon: IconTypes.CHEVRON_RIGHT }) }) })] }));
2664
+ }), nextPageButton, lastPageButton] }));
2664
2665
  };
2665
- /*
2666
- pageSizeMarkup
2667
- */
2668
2666
  var sizeTitle = pageSizeTitleCallback ? pageSizeTitleCallback({ pageSize: pagination.pageSize }) : "Page size: ".concat(pagination.pageSize);
2669
2667
  var pageSizeMarkup = function () {
2670
- return onPageSizeChange ? (jsxs(Fragment, { children: [jsx(Separator, { marginX: '15' }), jsx(DropDown, { buttonComponent: jsx(InlineButton, { type: buttonType, text: sizeTitle }), title: sizeTitle, children: [10, 20, 30, 40, 50, 80, 100]
2668
+ return withPageSizeChange ? (jsxs(Fragment, { children: [jsx(Separator, { marginX: '15' }), jsx(DropDown, { buttonComponent: jsx(InlineButton, { type: buttonType, text: sizeTitle }), title: sizeTitle, children: pageSizeOptions
2671
2669
  .filter(function (pageSize) { return pageSize < pagination.numberOfHits; })
2672
- .map(function (pageSize) { return (jsx(DropDownItem, { text: pageSize.toString(), onClickCallback: function () { return onPageSizeChange(pageSize); }, active: pagination.pageSize === pageSize, closeDropDownOnClick: true, withEllipsis: true })); }) })] })) : null;
2670
+ .map(function (pageSize) { return (jsx(DropDownItem, { text: pageSize.toString(), onClickCallback: function () { return onChange(__assign(__assign({}, pagination), { pageSize: pageSize })); }, active: pagination.pageSize === pageSize, closeDropDownOnClick: true, withEllipsis: true })); }) })] })) : null;
2673
2671
  };
2674
2672
  return (jsxs(Box, { alignItems: 'center', children: [paginationMarkup(), pageSizeMarkup()] }));
2675
2673
  };