@instructure/ui-pagination 8.51.0 → 8.51.1-snapshot-5

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.51.1-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.51.0...v8.51.1-snapshot-5) (2024-01-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * **ui-pagination:** refactor Pagination and expand its API for easy config-based usage ([19b928b](https://github.com/instructure/instructure-ui/commit/19b928bd58212dfd2c9cc8b2a550d504bb3df0bc))
12
+
13
+
14
+
15
+
16
+
6
17
  # [8.51.0](https://github.com/instructure/instructure-ui/compare/v8.50.0...v8.51.0) (2023-12-14)
7
18
 
8
19
  **Note:** Version bump only for package @instructure/ui-pagination
@@ -0,0 +1,182 @@
1
+ var _Pagination, _Pagination2, _Pagination3, _Pagination4, _Pagination5, _Pagination6, _Pagination7, _Pagination8, _Pagination9, _Pagination10, _Pagination11;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { Pagination } from '../index';
30
+ describe('<Pagination />', () => {
31
+ describe('with minimal config', () => {
32
+ it('should render the correct pages - 1', () => {
33
+ const _render = render(_Pagination || (_Pagination = /*#__PURE__*/React.createElement(Pagination, {
34
+ variant: "compact",
35
+ labelNext: "Next Page",
36
+ labelPrev: "Previous Page",
37
+ totalPageNumber: 9
38
+ }))),
39
+ container = _render.container;
40
+ expect(container.firstChild).toHaveTextContent('12...9Next Page');
41
+ });
42
+ it('should render the correct pages - 2', () => {
43
+ const _render2 = render(_Pagination2 || (_Pagination2 = /*#__PURE__*/React.createElement(Pagination, {
44
+ variant: "compact",
45
+ labelNext: "Next Page",
46
+ labelPrev: "Previous Page",
47
+ totalPageNumber: 9,
48
+ currentPage: 5
49
+ }))),
50
+ container = _render2.container;
51
+ expect(container.firstChild).toHaveTextContent('Previous Page1...456...9Next Page');
52
+ });
53
+ it('should render the correct pages - 3', () => {
54
+ const _render3 = render(_Pagination3 || (_Pagination3 = /*#__PURE__*/React.createElement(Pagination, {
55
+ variant: "compact",
56
+ labelNext: "Next Page",
57
+ labelPrev: "Previous Page",
58
+ totalPageNumber: 9,
59
+ currentPage: 5,
60
+ siblingCount: 1,
61
+ boundaryCount: 3
62
+ }))),
63
+ container = _render3.container;
64
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
65
+ });
66
+ it('should render the correct pages - 4', () => {
67
+ const _render4 = render(_Pagination4 || (_Pagination4 = /*#__PURE__*/React.createElement(Pagination, {
68
+ variant: "compact",
69
+ labelNext: "Next Page",
70
+ labelPrev: "Previous Page",
71
+ totalPageNumber: 9,
72
+ currentPage: 5,
73
+ siblingCount: 1,
74
+ boundaryCount: 2
75
+ }))),
76
+ container = _render4.container;
77
+ expect(container.firstChild).toHaveTextContent('Previous Page12...456...89Next Page');
78
+ });
79
+ it('should render the correct pages - 5', () => {
80
+ const _render5 = render(_Pagination5 || (_Pagination5 = /*#__PURE__*/React.createElement(Pagination, {
81
+ variant: "compact",
82
+ labelNext: "Next Page",
83
+ labelPrev: "Previous Page",
84
+ totalPageNumber: 9,
85
+ currentPage: 5,
86
+ siblingCount: 100
87
+ }))),
88
+ container = _render5.container;
89
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
90
+ });
91
+ it('should render the correct pages - 6', () => {
92
+ const _render6 = render(_Pagination6 || (_Pagination6 = /*#__PURE__*/React.createElement(Pagination, {
93
+ variant: "compact",
94
+ labelNext: "Next Page",
95
+ labelPrev: "Previous Page",
96
+ totalPageNumber: 9,
97
+ currentPage: 5,
98
+ boundaryCount: 100
99
+ }))),
100
+ container = _render6.container;
101
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
102
+ });
103
+ it('should render the correct pages - 7', () => {
104
+ const _render7 = render(_Pagination7 || (_Pagination7 = /*#__PURE__*/React.createElement(Pagination, {
105
+ variant: "compact",
106
+ labelNext: "Next Page",
107
+ labelPrev: "Previous Page",
108
+ totalPageNumber: 9,
109
+ currentPage: 1,
110
+ boundaryCount: 3,
111
+ siblingCount: 1
112
+ }))),
113
+ container = _render7.container;
114
+ expect(container.firstChild).toHaveTextContent('123...789Next Page');
115
+ });
116
+ it('should render the correct ellipsis', () => {
117
+ const _render8 = render(_Pagination8 || (_Pagination8 = /*#__PURE__*/React.createElement(Pagination, {
118
+ variant: "compact",
119
+ labelNext: "Next Page",
120
+ labelPrev: "Previous Page",
121
+ totalPageNumber: 9,
122
+ currentPage: 1,
123
+ boundaryCount: 3,
124
+ siblingCount: 1,
125
+ ellipsis: "<->"
126
+ }))),
127
+ container = _render8.container;
128
+ expect(container.firstChild).toHaveTextContent('123<->789Next Page');
129
+ });
130
+ it('should render custom buttons', () => {
131
+ const pageMap = ['A-G', 'H-J', 'K-M', 'N-Q', 'R-Z'];
132
+ const _render9 = render( /*#__PURE__*/React.createElement(Pagination, {
133
+ variant: "full",
134
+ labelNext: "Next Page",
135
+ labelPrev: "Previous Page",
136
+ totalPageNumber: 5,
137
+ currentPage: 1,
138
+ renderPageIndicator: page => pageMap[page - 1]
139
+ })),
140
+ container = _render9.container;
141
+ expect(container.firstChild).toHaveTextContent('A-GH-JK-MN-QR-Z');
142
+ });
143
+ it('should render huge "totalPageNumber"s properly', () => {
144
+ const _render10 = render(_Pagination9 || (_Pagination9 = /*#__PURE__*/React.createElement(Pagination, {
145
+ variant: "compact",
146
+ labelNext: "Next Page",
147
+ labelPrev: "Previous Page",
148
+ totalPageNumber: 1000000000000000,
149
+ currentPage: 5678
150
+ }))),
151
+ container = _render10.container;
152
+ expect(container.firstChild).toHaveTextContent('Previous Page1...567756785679...1000000000000000Next Page');
153
+ });
154
+ it('should render first and last buttons', () => {
155
+ const _render11 = render(_Pagination10 || (_Pagination10 = /*#__PURE__*/React.createElement(Pagination, {
156
+ variant: "compact",
157
+ labelNext: "Next Page",
158
+ labelPrev: "Previous Page",
159
+ labelFirst: "First Page",
160
+ labelLast: "Last Page",
161
+ totalPageNumber: 100,
162
+ currentPage: 5,
163
+ withFirstAndLastButton: true
164
+ }))),
165
+ container = _render11.container;
166
+ expect(container.firstChild).toHaveTextContent('First PagePrevious Page1...456...100Next PageLast Page');
167
+ });
168
+ it('should render every page if boundary and sibling counts are big enough', () => {
169
+ const _render12 = render(_Pagination11 || (_Pagination11 = /*#__PURE__*/React.createElement(Pagination, {
170
+ variant: "compact",
171
+ labelNext: "Next Page",
172
+ labelPrev: "Previous Page",
173
+ totalPageNumber: 10,
174
+ currentPage: 1,
175
+ siblingCount: 5,
176
+ boundaryCount: 4
177
+ }))),
178
+ container = _render12.container;
179
+ expect(container.firstChild).toHaveTextContent('12345678910Next Page');
180
+ });
181
+ });
182
+ });
@@ -45,7 +45,8 @@ const childrenArray = props => {
45
45
  return Array.isArray(children) ? children : [children];
46
46
  };
47
47
  function propsHaveCompactView(props) {
48
- return props.variant === 'compact' && childrenArray(props).length > 5;
48
+ if (props.children) return props.variant === 'compact' && childrenArray(props).length > 5;
49
+ return props.variant === 'compact' && props.totalPageNumber > 5;
49
50
  }
50
51
  /**
51
52
  ---
@@ -61,6 +62,7 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
61
62
  this._nextButton = null;
62
63
  this._lastButton = null;
63
64
  this.ref = null;
65
+ this.currentPageRef = null;
64
66
  this.handleElementRef = el => {
65
67
  this.ref = el;
66
68
  if (el && typeof this.props.elementRef === 'function') {
@@ -72,6 +74,114 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
72
74
  this.props.inputRef(el);
73
75
  }
74
76
  };
77
+ this.renderDefaultPageInput = () => {
78
+ const _this$props = this.props,
79
+ currentPage = _this$props.currentPage,
80
+ totalPageNumber = _this$props.totalPageNumber;
81
+ return jsx(PaginationPageInput, {
82
+ numberOfPages: totalPageNumber,
83
+ currentPageIndex: currentPage - 1,
84
+ onChange: (_e, nextPageIndex) => {
85
+ var _this$props$onPageCha, _this$props2;
86
+ return (_this$props$onPageCha = (_this$props2 = this.props).onPageChange) === null || _this$props$onPageCha === void 0 ? void 0 : _this$props$onPageCha.call(_this$props2, nextPageIndex + 1, currentPage);
87
+ },
88
+ screenReaderLabel: this.props.screenReaderLabelNumberInput,
89
+ label: this.props.labelNumberInput,
90
+ disabled: this.props.disabled,
91
+ inputRef: this.handleInputRef
92
+ });
93
+ };
94
+ this.handleNavigation = (nextIndex, previousIndex) => {
95
+ const onPageChange = this.props.onPageChange;
96
+ if (typeof onPageChange === 'function') {
97
+ onPageChange(nextIndex, previousIndex);
98
+ }
99
+ };
100
+ this.renderPagesInInterval = (from, to, currentPage) => {
101
+ if (to - from > 1000) throw new Error('Pagination: too many pages (more than 1000)');
102
+ const pages = [];
103
+ for (let i = from; i <= to; i++) {
104
+ var _this$props$renderPag, _this$props3;
105
+ pages.push(jsx(Pagination.Page, {
106
+ ref: e => i === currentPage ? this.currentPageRef = e : null,
107
+ key: i,
108
+ onClick: () => this.handleNavigation(i, currentPage),
109
+ current: i === currentPage
110
+ }, (_this$props$renderPag = (_this$props3 = this.props).renderPageIndicator) === null || _this$props$renderPag === void 0 ? void 0 : _this$props$renderPag.call(_this$props3, i, currentPage)));
111
+ }
112
+ return pages;
113
+ };
114
+ this.renderDefaultPages = () => {
115
+ const _this$props4 = this.props,
116
+ ellipsis = _this$props4.ellipsis,
117
+ currentPage = _this$props4.currentPage,
118
+ totalPageNumber = _this$props4.totalPageNumber,
119
+ siblingCount = _this$props4.siblingCount,
120
+ boundaryCount = _this$props4.boundaryCount,
121
+ variant = _this$props4.variant;
122
+ const pages = [];
123
+ if (totalPageNumber <= 2 * boundaryCount || totalPageNumber <= 1 + siblingCount + boundaryCount || variant === 'full') {
124
+ return this.renderPagesInInterval(1, totalPageNumber, currentPage);
125
+ }
126
+ if (currentPage > boundaryCount + siblingCount + 1) {
127
+ pages.push(this.renderPagesInInterval(1, boundaryCount, currentPage));
128
+ pages.push(ellipsis);
129
+ if (currentPage - siblingCount > totalPageNumber - boundaryCount + 1) {
130
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
131
+ return pages;
132
+ }
133
+ pages.push(this.renderPagesInInterval(currentPage - siblingCount, currentPage, currentPage));
134
+ } else {
135
+ pages.push(this.renderPagesInInterval(1, Math.max(currentPage, boundaryCount), currentPage));
136
+ }
137
+ if (currentPage < totalPageNumber - (siblingCount + boundaryCount)) {
138
+ pages.push(this.renderPagesInInterval(Math.max(currentPage, boundaryCount) + 1, currentPage + siblingCount, currentPage));
139
+ pages.push(ellipsis);
140
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
141
+ } else {
142
+ pages.push(this.renderPagesInInterval(currentPage + 1, totalPageNumber, currentPage));
143
+ }
144
+ return pages;
145
+ };
146
+ this.renderDefaultArrowButton = direction => {
147
+ if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
148
+ return null;
149
+ }
150
+ // We don't display the arrows in "compact" variant under 6 items
151
+ if (!(propsHaveCompactView(this.props) || this.inputMode)) {
152
+ return null;
153
+ }
154
+ const _this$props5 = this.props,
155
+ totalPageNumber = _this$props5.totalPageNumber,
156
+ currentPage = _this$props5.currentPage;
157
+ const _this$getArrowVariant = this.getArrowVariant(direction, currentPage - 1, totalPageNumber),
158
+ label = _this$getArrowVariant.label,
159
+ shouldEnableIcon = _this$getArrowVariant.shouldEnableIcon,
160
+ handleButtonRef = _this$getArrowVariant.handleButtonRef;
161
+ const disabled = this.props.disabled || !shouldEnableIcon;
162
+ const onClick = () => {
163
+ if (direction === 'first') {
164
+ this.handleNavigation(1, currentPage);
165
+ }
166
+ if (direction === 'prev') {
167
+ this.handleNavigation(Math.max(currentPage - 1, 1), currentPage);
168
+ }
169
+ if (direction === 'next') {
170
+ this.handleNavigation(Math.min(currentPage + 1, totalPageNumber), currentPage);
171
+ }
172
+ if (direction === 'last') {
173
+ this.handleNavigation(totalPageNumber, currentPage);
174
+ }
175
+ };
176
+ return shouldEnableIcon || this.showDisabledButtons ? jsx(PaginationArrowButton, {
177
+ direction: direction,
178
+ "data-direction": direction,
179
+ label: label,
180
+ onClick: onClick,
181
+ disabled: disabled,
182
+ buttonRef: handleButtonRef
183
+ }) : null;
184
+ };
75
185
  this._labelId = props.deterministicId();
76
186
  }
77
187
  get _root() {
@@ -102,12 +212,19 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
102
212
  }
103
213
  }
104
214
  componentDidMount() {
105
- var _this$props$makeStyle, _this$props;
106
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
215
+ var _this$props$makeStyle, _this$props6;
216
+ (_this$props$makeStyle = (_this$props6 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props6);
107
217
  }
108
218
  componentDidUpdate(prevProps, _prevState, snapshot) {
109
- var _this$props$makeStyle2, _this$props2;
110
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
219
+ var _this$props$makeStyle2, _this$props7;
220
+ (_this$props$makeStyle2 = (_this$props7 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props7);
221
+
222
+ // set focus on the currently active page
223
+ if (this.props.currentPage !== prevProps.currentPage && document.activeElement !== this._firstButton && document.activeElement !== this._prevButton && document.activeElement !== this._nextButton && document.activeElement !== this._lastButton) {
224
+ var _this$currentPageRef, _this$currentPageRef$, _this$currentPageRef$2;
225
+ // @ts-expect-error fix typing
226
+ (_this$currentPageRef = this.currentPageRef) === null || _this$currentPageRef === void 0 ? void 0 : (_this$currentPageRef$ = _this$currentPageRef.ref) === null || _this$currentPageRef$ === void 0 ? void 0 : (_this$currentPageRef$2 = _this$currentPageRef$.focus) === null || _this$currentPageRef$2 === void 0 ? void 0 : _this$currentPageRef$2.call(_this$currentPageRef$);
227
+ }
111
228
  if (!this.props.shouldHandleFocus || !propsHaveCompactView(prevProps) && !propsHaveCompactView(this.props)) {
112
229
  return;
113
230
  } else {
@@ -157,6 +274,7 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
157
274
  }, this.props.label);
158
275
  }
159
276
  renderPageInput(currentPageIndex) {
277
+ if (!this.props.children) return this.renderDefaultPageInput();
160
278
  return jsx(PaginationPageInput, {
161
279
  numberOfPages: this.childPages.length,
162
280
  currentPageIndex: currentPageIndex,
@@ -172,6 +290,7 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
172
290
  (_this$childPages$page = (_this$childPages$page2 = this.childPages[pageIndex].props).onClick) === null || _this$childPages$page === void 0 ? void 0 : _this$childPages$page.call(_this$childPages$page2, event);
173
291
  }
174
292
  renderPages(currentPageIndex) {
293
+ if (!this.props.children) return this.renderDefaultPages();
175
294
  const allPages = this.childPages;
176
295
  let visiblePages = allPages;
177
296
  if (this.compactView) {
@@ -239,8 +358,8 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
239
358
  }
240
359
  renderArrowButton(direction, currentPageIndex) {
241
360
  var _page$props, _page$props2;
361
+ if (!this.props.children) return this.renderDefaultArrowButton(direction);
242
362
  const childPages = this.childPages;
243
-
244
363
  // We don't display the arrows in "compact" variant under 6 items
245
364
  if (!(propsHaveCompactView(this.props) || this.inputMode)) {
246
365
  return null;
@@ -248,11 +367,11 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
248
367
  if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
249
368
  return null;
250
369
  }
251
- const _this$getArrowVariant = this.getArrowVariant(direction, currentPageIndex, childPages.length),
252
- pageIndex = _this$getArrowVariant.pageIndex,
253
- label = _this$getArrowVariant.label,
254
- shouldEnableIcon = _this$getArrowVariant.shouldEnableIcon,
255
- handleButtonRef = _this$getArrowVariant.handleButtonRef;
370
+ const _this$getArrowVariant2 = this.getArrowVariant(direction, currentPageIndex, childPages.length),
371
+ pageIndex = _this$getArrowVariant2.pageIndex,
372
+ label = _this$getArrowVariant2.label,
373
+ shouldEnableIcon = _this$getArrowVariant2.shouldEnableIcon,
374
+ handleButtonRef = _this$getArrowVariant2.handleButtonRef;
256
375
  const page = childPages[pageIndex];
257
376
  const disabled = (page === null || page === void 0 ? void 0 : (_page$props = page.props) === null || _page$props === void 0 ? void 0 : _page$props.disabled) || this.props.disabled || !shouldEnableIcon;
258
377
  const onClick = page === null || page === void 0 ? void 0 : (_page$props2 = page.props) === null || _page$props2 === void 0 ? void 0 : _page$props2.onClick;
@@ -267,7 +386,6 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
267
386
  }
268
387
  render() {
269
388
  var _this$props$styles, _this$props$styles2;
270
- if (!this.props.children) return null;
271
389
  const currentPageIndex = fastFindIndex(this.childPages, p => p && p.props && p.props.current);
272
390
  const passthroughProps = View.omitViewProps(omitProps(this.props, Pagination.allowedProps), Pagination);
273
391
  return jsx(View, Object.assign({}, passthroughProps, {
@@ -290,7 +408,13 @@ let Pagination = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
290
408
  as: 'div',
291
409
  labelNumberInput: numberOfPages => `of ${numberOfPages}`,
292
410
  screenReaderLabelNumberInput: (currentPage, numberOfPages) => `Select page (${currentPage} of ${numberOfPages})`,
293
- shouldHandleFocus: true
411
+ shouldHandleFocus: true,
412
+ totalPageNumber: 0,
413
+ currentPage: 1,
414
+ siblingCount: 1,
415
+ boundaryCount: 1,
416
+ ellipsis: '...',
417
+ renderPageIndicator: page => page
294
418
  }, _class2.Page = PaginationButton, _class2.Navigation = PaginationArrowButton, _class2)) || _class) || _class) || _class);
295
419
  export default Pagination;
296
420
  export { Pagination, PaginationButton };
@@ -43,7 +43,14 @@ const propTypes = {
43
43
  as: PropTypes.elementType,
44
44
  elementRef: PropTypes.func,
45
45
  inputRef: PropTypes.func,
46
- shouldHandleFocus: PropTypes.bool
46
+ shouldHandleFocus: PropTypes.bool,
47
+ totalPageNumber: PropTypes.number,
48
+ currentPage: PropTypes.number,
49
+ siblingCount: PropTypes.number,
50
+ boundaryCount: PropTypes.number,
51
+ onPageChange: PropTypes.func,
52
+ renderPageIndicator: PropTypes.func,
53
+ ellipsis: PropTypes.node
47
54
  };
48
- const allowedProps = ['children', 'disabled', 'withFirstAndLastButton', 'showDisabledButtons', 'label', 'labelNext', 'labelPrev', 'labelFirst', 'labelLast', 'labelNumberInput', 'screenReaderLabelNumberInput', 'variant', 'margin', 'as', 'elementRef', 'inputRef', 'shouldHandleFocus'];
55
+ const allowedProps = ['children', 'disabled', 'withFirstAndLastButton', 'showDisabledButtons', 'label', 'labelNext', 'labelPrev', 'labelFirst', 'labelLast', 'labelNumberInput', 'screenReaderLabelNumberInput', 'variant', 'margin', 'as', 'elementRef', 'inputRef', 'shouldHandleFocus', 'totalPageNumber', 'currentPage', 'onPageChange', 'siblingCount', 'boundaryCount', 'renderPageIndicator', 'ellipsis'];
49
56
  export { propTypes, allowedProps };
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ require("@testing-library/jest-dom");
7
+ var _index = require("../index");
8
+ var _Pagination, _Pagination2, _Pagination3, _Pagination4, _Pagination5, _Pagination6, _Pagination7, _Pagination8, _Pagination9, _Pagination10, _Pagination11;
9
+ /*
10
+ * The MIT License (MIT)
11
+ *
12
+ * Copyright (c) 2015 - present Instructure, Inc.
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included in all
22
+ * copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ * SOFTWARE.
31
+ */
32
+ describe('<Pagination />', () => {
33
+ describe('with minimal config', () => {
34
+ it('should render the correct pages - 1', () => {
35
+ const _render = (0, _react2.render)(_Pagination || (_Pagination = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
36
+ variant: "compact",
37
+ labelNext: "Next Page",
38
+ labelPrev: "Previous Page",
39
+ totalPageNumber: 9
40
+ }))),
41
+ container = _render.container;
42
+ expect(container.firstChild).toHaveTextContent('12...9Next Page');
43
+ });
44
+ it('should render the correct pages - 2', () => {
45
+ const _render2 = (0, _react2.render)(_Pagination2 || (_Pagination2 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
46
+ variant: "compact",
47
+ labelNext: "Next Page",
48
+ labelPrev: "Previous Page",
49
+ totalPageNumber: 9,
50
+ currentPage: 5
51
+ }))),
52
+ container = _render2.container;
53
+ expect(container.firstChild).toHaveTextContent('Previous Page1...456...9Next Page');
54
+ });
55
+ it('should render the correct pages - 3', () => {
56
+ const _render3 = (0, _react2.render)(_Pagination3 || (_Pagination3 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
57
+ variant: "compact",
58
+ labelNext: "Next Page",
59
+ labelPrev: "Previous Page",
60
+ totalPageNumber: 9,
61
+ currentPage: 5,
62
+ siblingCount: 1,
63
+ boundaryCount: 3
64
+ }))),
65
+ container = _render3.container;
66
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
67
+ });
68
+ it('should render the correct pages - 4', () => {
69
+ const _render4 = (0, _react2.render)(_Pagination4 || (_Pagination4 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
70
+ variant: "compact",
71
+ labelNext: "Next Page",
72
+ labelPrev: "Previous Page",
73
+ totalPageNumber: 9,
74
+ currentPage: 5,
75
+ siblingCount: 1,
76
+ boundaryCount: 2
77
+ }))),
78
+ container = _render4.container;
79
+ expect(container.firstChild).toHaveTextContent('Previous Page12...456...89Next Page');
80
+ });
81
+ it('should render the correct pages - 5', () => {
82
+ const _render5 = (0, _react2.render)(_Pagination5 || (_Pagination5 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
83
+ variant: "compact",
84
+ labelNext: "Next Page",
85
+ labelPrev: "Previous Page",
86
+ totalPageNumber: 9,
87
+ currentPage: 5,
88
+ siblingCount: 100
89
+ }))),
90
+ container = _render5.container;
91
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
92
+ });
93
+ it('should render the correct pages - 6', () => {
94
+ const _render6 = (0, _react2.render)(_Pagination6 || (_Pagination6 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
95
+ variant: "compact",
96
+ labelNext: "Next Page",
97
+ labelPrev: "Previous Page",
98
+ totalPageNumber: 9,
99
+ currentPage: 5,
100
+ boundaryCount: 100
101
+ }))),
102
+ container = _render6.container;
103
+ expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
104
+ });
105
+ it('should render the correct pages - 7', () => {
106
+ const _render7 = (0, _react2.render)(_Pagination7 || (_Pagination7 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
107
+ variant: "compact",
108
+ labelNext: "Next Page",
109
+ labelPrev: "Previous Page",
110
+ totalPageNumber: 9,
111
+ currentPage: 1,
112
+ boundaryCount: 3,
113
+ siblingCount: 1
114
+ }))),
115
+ container = _render7.container;
116
+ expect(container.firstChild).toHaveTextContent('123...789Next Page');
117
+ });
118
+ it('should render the correct ellipsis', () => {
119
+ const _render8 = (0, _react2.render)(_Pagination8 || (_Pagination8 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
120
+ variant: "compact",
121
+ labelNext: "Next Page",
122
+ labelPrev: "Previous Page",
123
+ totalPageNumber: 9,
124
+ currentPage: 1,
125
+ boundaryCount: 3,
126
+ siblingCount: 1,
127
+ ellipsis: "<->"
128
+ }))),
129
+ container = _render8.container;
130
+ expect(container.firstChild).toHaveTextContent('123<->789Next Page');
131
+ });
132
+ it('should render custom buttons', () => {
133
+ const pageMap = ['A-G', 'H-J', 'K-M', 'N-Q', 'R-Z'];
134
+ const _render9 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
135
+ variant: "full",
136
+ labelNext: "Next Page",
137
+ labelPrev: "Previous Page",
138
+ totalPageNumber: 5,
139
+ currentPage: 1,
140
+ renderPageIndicator: page => pageMap[page - 1]
141
+ })),
142
+ container = _render9.container;
143
+ expect(container.firstChild).toHaveTextContent('A-GH-JK-MN-QR-Z');
144
+ });
145
+ it('should render huge "totalPageNumber"s properly', () => {
146
+ const _render10 = (0, _react2.render)(_Pagination9 || (_Pagination9 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
147
+ variant: "compact",
148
+ labelNext: "Next Page",
149
+ labelPrev: "Previous Page",
150
+ totalPageNumber: 1000000000000000,
151
+ currentPage: 5678
152
+ }))),
153
+ container = _render10.container;
154
+ expect(container.firstChild).toHaveTextContent('Previous Page1...567756785679...1000000000000000Next Page');
155
+ });
156
+ it('should render first and last buttons', () => {
157
+ const _render11 = (0, _react2.render)(_Pagination10 || (_Pagination10 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
158
+ variant: "compact",
159
+ labelNext: "Next Page",
160
+ labelPrev: "Previous Page",
161
+ labelFirst: "First Page",
162
+ labelLast: "Last Page",
163
+ totalPageNumber: 100,
164
+ currentPage: 5,
165
+ withFirstAndLastButton: true
166
+ }))),
167
+ container = _render11.container;
168
+ expect(container.firstChild).toHaveTextContent('First PagePrevious Page1...456...100Next PageLast Page');
169
+ });
170
+ it('should render every page if boundary and sibling counts are big enough', () => {
171
+ const _render12 = (0, _react2.render)(_Pagination11 || (_Pagination11 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
172
+ variant: "compact",
173
+ labelNext: "Next Page",
174
+ labelPrev: "Previous Page",
175
+ totalPageNumber: 10,
176
+ currentPage: 1,
177
+ siblingCount: 5,
178
+ boundaryCount: 4
179
+ }))),
180
+ container = _render12.container;
181
+ expect(container.firstChild).toHaveTextContent('12345678910Next Page');
182
+ });
183
+ });
184
+ });