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

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.
@@ -62,7 +62,8 @@ const childrenArray = props => {
62
62
  return Array.isArray(children) ? children : [children];
63
63
  };
64
64
  function propsHaveCompactView(props) {
65
- return props.variant === 'compact' && childrenArray(props).length > 5;
65
+ if (props.children) return props.variant === 'compact' && childrenArray(props).length > 5;
66
+ return props.variant === 'compact' && props.totalPageNumber > 5;
66
67
  }
67
68
  /**
68
69
  ---
@@ -78,6 +79,7 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
78
79
  this._nextButton = null;
79
80
  this._lastButton = null;
80
81
  this.ref = null;
82
+ this.currentPageRef = null;
81
83
  this.handleElementRef = el => {
82
84
  this.ref = el;
83
85
  if (el && typeof this.props.elementRef === 'function') {
@@ -89,6 +91,114 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
89
91
  this.props.inputRef(el);
90
92
  }
91
93
  };
94
+ this.renderDefaultPageInput = () => {
95
+ const _this$props = this.props,
96
+ currentPage = _this$props.currentPage,
97
+ totalPageNumber = _this$props.totalPageNumber;
98
+ return (0, _emotion.jsx)(_PaginationPageInput.PaginationPageInput, {
99
+ numberOfPages: totalPageNumber,
100
+ currentPageIndex: currentPage - 1,
101
+ onChange: (_e, nextPageIndex) => {
102
+ var _this$props$onPageCha, _this$props2;
103
+ 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);
104
+ },
105
+ screenReaderLabel: this.props.screenReaderLabelNumberInput,
106
+ label: this.props.labelNumberInput,
107
+ disabled: this.props.disabled,
108
+ inputRef: this.handleInputRef
109
+ });
110
+ };
111
+ this.handleNavigation = (nextIndex, previousIndex) => {
112
+ const onPageChange = this.props.onPageChange;
113
+ if (typeof onPageChange === 'function') {
114
+ onPageChange(nextIndex, previousIndex);
115
+ }
116
+ };
117
+ this.renderPagesInInterval = (from, to, currentPage) => {
118
+ if (to - from > 1000) throw new Error('Pagination: too many pages (more than 1000)');
119
+ const pages = [];
120
+ for (let i = from; i <= to; i++) {
121
+ var _this$props$renderPag, _this$props3;
122
+ pages.push((0, _emotion.jsx)(Pagination.Page, {
123
+ ref: e => i === currentPage ? this.currentPageRef = e : null,
124
+ key: i,
125
+ onClick: () => this.handleNavigation(i, currentPage),
126
+ current: i === currentPage
127
+ }, (_this$props$renderPag = (_this$props3 = this.props).renderPageIndicator) === null || _this$props$renderPag === void 0 ? void 0 : _this$props$renderPag.call(_this$props3, i, currentPage)));
128
+ }
129
+ return pages;
130
+ };
131
+ this.renderDefaultPages = () => {
132
+ const _this$props4 = this.props,
133
+ ellipsis = _this$props4.ellipsis,
134
+ currentPage = _this$props4.currentPage,
135
+ totalPageNumber = _this$props4.totalPageNumber,
136
+ siblingCount = _this$props4.siblingCount,
137
+ boundaryCount = _this$props4.boundaryCount,
138
+ variant = _this$props4.variant;
139
+ const pages = [];
140
+ if (totalPageNumber <= 2 * boundaryCount || totalPageNumber <= 1 + siblingCount + boundaryCount || variant === 'full') {
141
+ return this.renderPagesInInterval(1, totalPageNumber, currentPage);
142
+ }
143
+ if (currentPage > boundaryCount + siblingCount + 1) {
144
+ pages.push(this.renderPagesInInterval(1, boundaryCount, currentPage));
145
+ pages.push(ellipsis);
146
+ if (currentPage - siblingCount > totalPageNumber - boundaryCount + 1) {
147
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
148
+ return pages;
149
+ }
150
+ pages.push(this.renderPagesInInterval(currentPage - siblingCount, currentPage, currentPage));
151
+ } else {
152
+ pages.push(this.renderPagesInInterval(1, Math.max(currentPage, boundaryCount), currentPage));
153
+ }
154
+ if (currentPage < totalPageNumber - (siblingCount + boundaryCount)) {
155
+ pages.push(this.renderPagesInInterval(Math.max(currentPage, boundaryCount) + 1, currentPage + siblingCount, currentPage));
156
+ pages.push(ellipsis);
157
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
158
+ } else {
159
+ pages.push(this.renderPagesInInterval(currentPage + 1, totalPageNumber, currentPage));
160
+ }
161
+ return pages;
162
+ };
163
+ this.renderDefaultArrowButton = direction => {
164
+ if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
165
+ return null;
166
+ }
167
+ // We don't display the arrows in "compact" variant under 6 items
168
+ if (!(propsHaveCompactView(this.props) || this.inputMode)) {
169
+ return null;
170
+ }
171
+ const _this$props5 = this.props,
172
+ totalPageNumber = _this$props5.totalPageNumber,
173
+ currentPage = _this$props5.currentPage;
174
+ const _this$getArrowVariant = this.getArrowVariant(direction, currentPage - 1, totalPageNumber),
175
+ label = _this$getArrowVariant.label,
176
+ shouldEnableIcon = _this$getArrowVariant.shouldEnableIcon,
177
+ handleButtonRef = _this$getArrowVariant.handleButtonRef;
178
+ const disabled = this.props.disabled || !shouldEnableIcon;
179
+ const onClick = () => {
180
+ if (direction === 'first') {
181
+ this.handleNavigation(1, currentPage);
182
+ }
183
+ if (direction === 'prev') {
184
+ this.handleNavigation(Math.max(currentPage - 1, 1), currentPage);
185
+ }
186
+ if (direction === 'next') {
187
+ this.handleNavigation(Math.min(currentPage + 1, totalPageNumber), currentPage);
188
+ }
189
+ if (direction === 'last') {
190
+ this.handleNavigation(totalPageNumber, currentPage);
191
+ }
192
+ };
193
+ return shouldEnableIcon || this.showDisabledButtons ? (0, _emotion.jsx)(_PaginationArrowButton.PaginationArrowButton, {
194
+ direction: direction,
195
+ "data-direction": direction,
196
+ label: label,
197
+ onClick: onClick,
198
+ disabled: disabled,
199
+ buttonRef: handleButtonRef
200
+ }) : null;
201
+ };
92
202
  this._labelId = props.deterministicId();
93
203
  }
94
204
  get _root() {
@@ -119,12 +229,19 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
119
229
  }
120
230
  }
121
231
  componentDidMount() {
122
- var _this$props$makeStyle, _this$props;
123
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
232
+ var _this$props$makeStyle, _this$props6;
233
+ (_this$props$makeStyle = (_this$props6 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props6);
124
234
  }
125
235
  componentDidUpdate(prevProps, _prevState, snapshot) {
126
- var _this$props$makeStyle2, _this$props2;
127
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
236
+ var _this$props$makeStyle2, _this$props7;
237
+ (_this$props$makeStyle2 = (_this$props7 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props7);
238
+
239
+ // set focus on the currently active page
240
+ if (this.props.currentPage !== prevProps.currentPage && document.activeElement !== this._firstButton && document.activeElement !== this._prevButton && document.activeElement !== this._nextButton && document.activeElement !== this._lastButton) {
241
+ var _this$currentPageRef, _this$currentPageRef$, _this$currentPageRef$2;
242
+ // @ts-expect-error fix typing
243
+ (_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$);
244
+ }
128
245
  if (!this.props.shouldHandleFocus || !propsHaveCompactView(prevProps) && !propsHaveCompactView(this.props)) {
129
246
  return;
130
247
  } else {
@@ -174,6 +291,7 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
174
291
  }, this.props.label);
175
292
  }
176
293
  renderPageInput(currentPageIndex) {
294
+ if (!this.props.children) return this.renderDefaultPageInput();
177
295
  return (0, _emotion.jsx)(_PaginationPageInput.PaginationPageInput, {
178
296
  numberOfPages: this.childPages.length,
179
297
  currentPageIndex: currentPageIndex,
@@ -189,6 +307,7 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
189
307
  (_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);
190
308
  }
191
309
  renderPages(currentPageIndex) {
310
+ if (!this.props.children) return this.renderDefaultPages();
192
311
  const allPages = this.childPages;
193
312
  let visiblePages = allPages;
194
313
  if (this.compactView) {
@@ -256,8 +375,8 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
256
375
  }
257
376
  renderArrowButton(direction, currentPageIndex) {
258
377
  var _page$props, _page$props2;
378
+ if (!this.props.children) return this.renderDefaultArrowButton(direction);
259
379
  const childPages = this.childPages;
260
-
261
380
  // We don't display the arrows in "compact" variant under 6 items
262
381
  if (!(propsHaveCompactView(this.props) || this.inputMode)) {
263
382
  return null;
@@ -265,11 +384,11 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
265
384
  if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
266
385
  return null;
267
386
  }
268
- const _this$getArrowVariant = this.getArrowVariant(direction, currentPageIndex, childPages.length),
269
- pageIndex = _this$getArrowVariant.pageIndex,
270
- label = _this$getArrowVariant.label,
271
- shouldEnableIcon = _this$getArrowVariant.shouldEnableIcon,
272
- handleButtonRef = _this$getArrowVariant.handleButtonRef;
387
+ const _this$getArrowVariant2 = this.getArrowVariant(direction, currentPageIndex, childPages.length),
388
+ pageIndex = _this$getArrowVariant2.pageIndex,
389
+ label = _this$getArrowVariant2.label,
390
+ shouldEnableIcon = _this$getArrowVariant2.shouldEnableIcon,
391
+ handleButtonRef = _this$getArrowVariant2.handleButtonRef;
273
392
  const page = childPages[pageIndex];
274
393
  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;
275
394
  const onClick = page === null || page === void 0 ? void 0 : (_page$props2 = page.props) === null || _page$props2 === void 0 ? void 0 : _page$props2.onClick;
@@ -284,7 +403,6 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
284
403
  }
285
404
  render() {
286
405
  var _this$props$styles, _this$props$styles2;
287
- if (!this.props.children) return null;
288
406
  const currentPageIndex = fastFindIndex(this.childPages, p => p && p.props && p.props.current);
289
407
  const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Pagination.allowedProps), Pagination);
290
408
  return (0, _emotion.jsx)(_View.View, Object.assign({}, passthroughProps, {
@@ -307,6 +425,12 @@ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeter
307
425
  as: 'div',
308
426
  labelNumberInput: numberOfPages => `of ${numberOfPages}`,
309
427
  screenReaderLabelNumberInput: (currentPage, numberOfPages) => `Select page (${currentPage} of ${numberOfPages})`,
310
- shouldHandleFocus: true
428
+ shouldHandleFocus: true,
429
+ totalPageNumber: 0,
430
+ currentPage: 1,
431
+ siblingCount: 1,
432
+ boundaryCount: 1,
433
+ ellipsis: '...',
434
+ renderPageIndicator: page => page
311
435
  }, _class2.Page = _PaginationButton.PaginationButton, _class2.Navigation = _PaginationArrowButton.PaginationArrowButton, _class2)) || _class) || _class) || _class);
312
436
  var _default = exports.default = Pagination;
@@ -50,6 +50,13 @@ const propTypes = exports.propTypes = {
50
50
  as: _propTypes.default.elementType,
51
51
  elementRef: _propTypes.default.func,
52
52
  inputRef: _propTypes.default.func,
53
- shouldHandleFocus: _propTypes.default.bool
53
+ shouldHandleFocus: _propTypes.default.bool,
54
+ totalPageNumber: _propTypes.default.number,
55
+ currentPage: _propTypes.default.number,
56
+ siblingCount: _propTypes.default.number,
57
+ boundaryCount: _propTypes.default.number,
58
+ onPageChange: _propTypes.default.func,
59
+ renderPageIndicator: _propTypes.default.func,
60
+ ellipsis: _propTypes.default.node
54
61
  };
55
- const allowedProps = exports.allowedProps = ['children', 'disabled', 'withFirstAndLastButton', 'showDisabledButtons', 'label', 'labelNext', 'labelPrev', 'labelFirst', 'labelLast', 'labelNumberInput', 'screenReaderLabelNumberInput', 'variant', 'margin', 'as', 'elementRef', 'inputRef', 'shouldHandleFocus'];
62
+ const allowedProps = exports.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'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-pagination",
3
- "version": "8.51.0",
3
+ "version": "8.51.1-snapshot-6",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,29 +23,31 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.51.0",
27
- "@instructure/ui-test-locator": "8.51.0",
28
- "@instructure/ui-test-queries": "8.51.0",
29
- "@instructure/ui-test-utils": "8.51.0"
26
+ "@instructure/ui-babel-preset": "8.51.1-snapshot-6",
27
+ "@instructure/ui-test-locator": "8.51.1-snapshot-6",
28
+ "@instructure/ui-test-queries": "8.51.1-snapshot-6",
29
+ "@instructure/ui-test-utils": "8.51.1-snapshot-6",
30
+ "@testing-library/jest-dom": "^6.1.4",
31
+ "@testing-library/react": "^14.0.0"
30
32
  },
31
33
  "dependencies": {
32
34
  "@babel/runtime": "^7.23.2",
33
- "@instructure/emotion": "8.51.0",
34
- "@instructure/shared-types": "8.51.0",
35
- "@instructure/ui-a11y-content": "8.51.0",
36
- "@instructure/ui-a11y-utils": "8.51.0",
37
- "@instructure/ui-buttons": "8.51.0",
38
- "@instructure/ui-dom-utils": "8.51.0",
39
- "@instructure/ui-icons": "8.51.0",
40
- "@instructure/ui-number-input": "8.51.0",
41
- "@instructure/ui-portal": "8.51.0",
42
- "@instructure/ui-prop-types": "8.51.0",
43
- "@instructure/ui-react-utils": "8.51.0",
44
- "@instructure/ui-testable": "8.51.0",
45
- "@instructure/ui-tooltip": "8.51.0",
46
- "@instructure/ui-utils": "8.51.0",
47
- "@instructure/ui-view": "8.51.0",
48
- "@instructure/uid": "8.51.0",
35
+ "@instructure/emotion": "8.51.1-snapshot-6",
36
+ "@instructure/shared-types": "8.51.1-snapshot-6",
37
+ "@instructure/ui-a11y-content": "8.51.1-snapshot-6",
38
+ "@instructure/ui-a11y-utils": "8.51.1-snapshot-6",
39
+ "@instructure/ui-buttons": "8.51.1-snapshot-6",
40
+ "@instructure/ui-dom-utils": "8.51.1-snapshot-6",
41
+ "@instructure/ui-icons": "8.51.1-snapshot-6",
42
+ "@instructure/ui-number-input": "8.51.1-snapshot-6",
43
+ "@instructure/ui-portal": "8.51.1-snapshot-6",
44
+ "@instructure/ui-prop-types": "8.51.1-snapshot-6",
45
+ "@instructure/ui-react-utils": "8.51.1-snapshot-6",
46
+ "@instructure/ui-testable": "8.51.1-snapshot-6",
47
+ "@instructure/ui-tooltip": "8.51.1-snapshot-6",
48
+ "@instructure/ui-utils": "8.51.1-snapshot-6",
49
+ "@instructure/ui-view": "8.51.1-snapshot-6",
50
+ "@instructure/uid": "8.51.1-snapshot-6",
49
51
  "keycode": "^2.2.1",
50
52
  "prop-types": "^15.8.1"
51
53
  },
@@ -2,6 +2,285 @@
2
2
  describes: Pagination
3
3
  ---
4
4
 
5
+ ### NOTE
6
+
7
+ Pagination is in a state of transition. Its API has been expanded to allow
8
+ as close to zero config usage as possible, without introducing breaking changes to the previous methods.
9
+
10
+ The component is under review by the design team and it's possible we'll deprecate te "old" API in a
11
+ following version. If you're able to, please use the "new" API. Its documentation is on the top of this page.
12
+
13
+ One of the biggest improvement is that pagination now can handle large page numbers as well.
14
+
15
+ ### Pagination
16
+
17
+ The pagination component provides props to handle most of the pagination use-cases. These following examples are the same as the "old" examples in behaviour, but with the "new" API
18
+
19
+ - ```js
20
+ class Example extends React.Component {
21
+ constructor(props) {
22
+ super(props)
23
+ this.state = { currentPage: 1 }
24
+ }
25
+
26
+ render() {
27
+ return (
28
+ <Pagination
29
+ as="nav"
30
+ margin="small"
31
+ variant="compact"
32
+ labelNext="Next Page"
33
+ labelPrev="Previous Page"
34
+ currentPage={this.state.currentPage}
35
+ totalPageNumber={9}
36
+ onPageChange={(nextPage) => this.setState({ currentPage: nextPage })}
37
+ />
38
+ )
39
+ }
40
+ }
41
+
42
+ render(<Example />)
43
+ ```
44
+
45
+ - ```js
46
+ const Example = () => {
47
+ const [currentPage, setCurrentPage] = useState(1)
48
+
49
+ return (
50
+ <Pagination
51
+ as="nav"
52
+ margin="small"
53
+ variant="compact"
54
+ labelNext="Next Page"
55
+ labelPrev="Previous Page"
56
+ currentPage={currentPage}
57
+ totalPageNumber={9}
58
+ onPageChange={(nextPage) => setCurrentPage(nextPage)}
59
+ />
60
+ )
61
+ }
62
+
63
+ render(<Example />)
64
+ ```
65
+
66
+ You can set any `totalPageNumber`, the component can handle it easily. Furthermore, you can set
67
+ `siblingCount`, which indicates how many pages are visible on either side of the `currentPage` and the
68
+ `boundaryCount`, which indicates how many pages are visible in the beginning and end.
69
+
70
+ - ```js
71
+ class Example extends React.Component {
72
+ constructor(props) {
73
+ super(props)
74
+ this.state = { currentPage: 1 }
75
+ }
76
+
77
+ render() {
78
+ return (
79
+ <Pagination
80
+ as="nav"
81
+ margin="small"
82
+ variant="compact"
83
+ labelNext="Next Page"
84
+ labelPrev="Previous Page"
85
+ currentPage={this.state.currentPage}
86
+ totalPageNumber={100000}
87
+ onPageChange={(nextPage) => this.setState({ currentPage: nextPage })}
88
+ siblingCount={3}
89
+ boundaryCount={2}
90
+ />
91
+ )
92
+ }
93
+ }
94
+
95
+ render(<Example />)
96
+ ```
97
+
98
+ - ```js
99
+ const Example = () => {
100
+ const [currentPage, setCurrentPage] = useState(1)
101
+ return (
102
+ <Pagination
103
+ as="nav"
104
+ margin="small"
105
+ variant="compact"
106
+ labelNext="Next Page"
107
+ labelPrev="Previous Page"
108
+ currentPage={currentPage}
109
+ totalPageNumber={100000}
110
+ onPageChange={(nextPage) => setCurrentPage(nextPage)}
111
+ siblingCount={3}
112
+ boundaryCount={2}
113
+ />
114
+ )
115
+ }
116
+
117
+ render(<Example />)
118
+ ```
119
+
120
+ You can only display 1000 pages at once.
121
+
122
+ - ```js
123
+ class Example extends React.Component {
124
+ constructor(props) {
125
+ super(props)
126
+ this.state = { currentPage: 1 }
127
+ }
128
+
129
+ render() {
130
+ return (
131
+ <Pagination
132
+ as="nav"
133
+ margin="small"
134
+ variant="full"
135
+ labelNext="Next Page"
136
+ labelPrev="Previous Page"
137
+ currentPage={this.state.currentPage}
138
+ totalPageNumber={100000}
139
+ onPageChange={(nextPage) => this.setState({ currentPage: nextPage })}
140
+ siblingCount={3}
141
+ boundaryCount={2}
142
+ />
143
+ )
144
+ }
145
+ }
146
+
147
+ render(<Example />)
148
+ ```
149
+
150
+ - ```js
151
+ const Example = () => {
152
+ const [currentPage, setCurrentPage] = useState(1)
153
+ return (
154
+ <Pagination
155
+ as="nav"
156
+ margin="small"
157
+ variant="full"
158
+ labelNext="Next Page"
159
+ labelPrev="Previous Page"
160
+ currentPage={currentPage}
161
+ totalPageNumber={100000}
162
+ onPageChange={(nextPage) => setCurrentPage(nextPage)}
163
+ siblingCount={3}
164
+ boundaryCount={2}
165
+ />
166
+ )
167
+ }
168
+
169
+ render(<Example />)
170
+ ```
171
+
172
+ You can override the default page rendering with `renderPageIndicator`.
173
+
174
+ - ```js
175
+ class Example extends React.Component {
176
+ constructor(props) {
177
+ super(props)
178
+ this.state = { currentPage: 1 }
179
+ }
180
+
181
+ pageMap = ['A-G', 'H-J', 'K-M', 'N-Q', 'R-Z']
182
+
183
+ render() {
184
+ return (
185
+ <Pagination
186
+ as="nav"
187
+ margin="small"
188
+ variant="full"
189
+ labelNext="Next Page"
190
+ labelPrev="Previous Page"
191
+ currentPage={this.state.currentPage}
192
+ totalPageNumber={5}
193
+ onPageChange={(nextPage) => this.setState({ currentPage: nextPage })}
194
+ siblingCount={5}
195
+ boundaryCount={0}
196
+ renderPageIndicator={(page) => this.pageMap[page - 1]}
197
+ />
198
+ )
199
+ }
200
+ }
201
+
202
+ render(<Example />)
203
+ ```
204
+
205
+ - ```js
206
+ const Example = () => {
207
+ const [currentPage, setCurrentPage] = useState(1)
208
+
209
+ const pageMap = ['A-G', 'H-J', 'K-M', 'N-Q', 'R-Z']
210
+
211
+ return (
212
+ <Pagination
213
+ as="nav"
214
+ margin="small"
215
+ variant="full"
216
+ labelNext="Next Page"
217
+ labelPrev="Previous Page"
218
+ currentPage={currentPage}
219
+ totalPageNumber={5}
220
+ onPageChange={(nextPage) => setCurrentPage(nextPage)}
221
+ siblingCount={5}
222
+ boundaryCount={0}
223
+ renderPageIndicator={(page) => pageMap[page - 1]}
224
+ />
225
+ )
226
+ }
227
+
228
+ render(<Example />)
229
+ ```
230
+
231
+ The `variant="input"` prop will render Pagination with a NumberInput and all the arrow buttons.
232
+
233
+ - ```js
234
+ class Example extends React.Component {
235
+ constructor(props) {
236
+ super(props)
237
+ this.state = { currentPage: 1 }
238
+ }
239
+
240
+ render() {
241
+ return (
242
+ <Pagination
243
+ as="nav"
244
+ margin="small"
245
+ variant="input"
246
+ labelNext="Next Page"
247
+ labelPrev="Previous Page"
248
+ currentPage={this.state.currentPage}
249
+ totalPageNumber={9}
250
+ onPageChange={(nextPage) => this.setState({ currentPage: nextPage })}
251
+ />
252
+ )
253
+ }
254
+ }
255
+
256
+ render(<Example />)
257
+ ```
258
+
259
+ - ```js
260
+ const Example = () => {
261
+ const [currentPage, setCurrentPage] = useState(1)
262
+
263
+ return (
264
+ <Pagination
265
+ as="nav"
266
+ margin="small"
267
+ variant="input"
268
+ labelNext="Next Page"
269
+ labelPrev="Previous Page"
270
+ currentPage={currentPage}
271
+ totalPageNumber={9}
272
+ onPageChange={(nextPage) => setCurrentPage(nextPage)}
273
+ />
274
+ )
275
+ }
276
+
277
+ render(<Example />)
278
+ ```
279
+
280
+ ### Legacy examples
281
+
282
+ These provide possibly finer, but much more complicated control over the pagination component. They are still supported, but we recommend using the new API.
283
+
5
284
  Renders available pages of content, and reacts to selection of another page.
6
285
  Expects array of `Pagination.Page` children. Focus and announcement of page change is
7
286
  the responsibility of your app.