@instructure/ui-pagination 11.6.0 → 11.6.1-snapshot-129

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.
Files changed (141) hide show
  1. package/CHANGELOG.md +42 -296
  2. package/es/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.js +2 -2
  3. package/es/Pagination/{PaginationButton → v1/PaginationButton}/index.js +1 -1
  4. package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.js +1 -1
  5. package/es/Pagination/{index.js → v1/index.js} +1 -1
  6. package/es/Pagination/v2/PaginationArrowButton/index.js +109 -0
  7. package/es/Pagination/v2/PaginationArrowButton/props.js +30 -0
  8. package/es/Pagination/v2/PaginationButton/index.js +77 -0
  9. package/es/Pagination/v2/PaginationButton/props.js +29 -0
  10. package/es/Pagination/v2/PaginationPageInput/index.js +189 -0
  11. package/es/Pagination/v2/PaginationPageInput/props.js +26 -0
  12. package/es/Pagination/v2/PaginationPageInput/styles.js +56 -0
  13. package/es/Pagination/v2/index.js +481 -0
  14. package/es/Pagination/v2/props.js +26 -0
  15. package/es/Pagination/v2/styles.js +58 -0
  16. package/es/{index.js → exports/a.js} +1 -1
  17. package/es/exports/b.js +24 -0
  18. package/lib/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.js +8 -8
  19. package/lib/Pagination/{PaginationButton → v1/PaginationButton}/index.js +2 -2
  20. package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.js +2 -2
  21. package/lib/Pagination/{index.js → v1/index.js} +6 -6
  22. package/lib/Pagination/v2/PaginationArrowButton/index.js +115 -0
  23. package/lib/Pagination/v2/PaginationArrowButton/props.js +35 -0
  24. package/lib/Pagination/v2/PaginationButton/index.js +83 -0
  25. package/lib/Pagination/v2/PaginationButton/props.js +34 -0
  26. package/lib/Pagination/v2/PaginationPageInput/index.js +194 -0
  27. package/lib/Pagination/v2/PaginationPageInput/props.js +31 -0
  28. package/lib/Pagination/v2/PaginationPageInput/styles.js +62 -0
  29. package/lib/Pagination/v2/index.js +496 -0
  30. package/lib/Pagination/v2/props.js +31 -0
  31. package/lib/Pagination/v2/styles.js +64 -0
  32. package/lib/{index.js → exports/a.js} +3 -3
  33. package/lib/exports/b.js +18 -0
  34. package/package.json +48 -25
  35. package/src/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.tsx +2 -2
  36. package/src/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.ts +1 -1
  37. package/src/Pagination/{PaginationButton → v1/PaginationButton}/index.tsx +1 -1
  38. package/src/Pagination/{PaginationButton → v1/PaginationButton}/props.ts +1 -1
  39. package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.tsx +1 -1
  40. package/src/Pagination/{index.tsx → v1/index.tsx} +1 -1
  41. package/src/Pagination/v2/PaginationArrowButton/index.tsx +120 -0
  42. package/src/Pagination/v2/PaginationArrowButton/props.ts +74 -0
  43. package/src/Pagination/v2/PaginationButton/index.tsx +82 -0
  44. package/src/Pagination/v2/PaginationButton/props.ts +77 -0
  45. package/src/Pagination/v2/PaginationPageInput/index.tsx +242 -0
  46. package/src/Pagination/v2/PaginationPageInput/props.ts +95 -0
  47. package/src/Pagination/v2/PaginationPageInput/styles.ts +62 -0
  48. package/src/Pagination/v2/README.md +417 -0
  49. package/src/Pagination/v2/index.tsx +665 -0
  50. package/src/Pagination/v2/props.ts +245 -0
  51. package/src/Pagination/v2/styles.ts +64 -0
  52. package/src/exports/a.ts +29 -0
  53. package/src/exports/b.ts +29 -0
  54. package/tsconfig.build.json +1 -0
  55. package/tsconfig.build.tsbuildinfo +1 -1
  56. package/types/Pagination/v1/PaginationArrowButton/index.d.ts.map +1 -0
  57. package/types/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.d.ts +1 -1
  58. package/types/Pagination/v1/PaginationArrowButton/props.d.ts.map +1 -0
  59. package/types/Pagination/v1/PaginationButton/index.d.ts.map +1 -0
  60. package/types/Pagination/{PaginationButton → v1/PaginationButton}/props.d.ts +1 -1
  61. package/types/Pagination/v1/PaginationButton/props.d.ts.map +1 -0
  62. package/types/Pagination/v1/PaginationPageInput/index.d.ts.map +1 -0
  63. package/types/Pagination/v1/PaginationPageInput/props.d.ts.map +1 -0
  64. package/types/Pagination/v1/PaginationPageInput/styles.d.ts.map +1 -0
  65. package/types/Pagination/v1/PaginationPageInput/theme.d.ts.map +1 -0
  66. package/types/Pagination/v1/index.d.ts.map +1 -0
  67. package/types/Pagination/v1/props.d.ts.map +1 -0
  68. package/types/Pagination/v1/styles.d.ts.map +1 -0
  69. package/types/Pagination/v1/theme.d.ts.map +1 -0
  70. package/types/Pagination/v2/PaginationArrowButton/index.d.ts +27 -0
  71. package/types/Pagination/v2/PaginationArrowButton/index.d.ts.map +1 -0
  72. package/types/Pagination/v2/PaginationArrowButton/props.d.ts +17 -0
  73. package/types/Pagination/v2/PaginationArrowButton/props.d.ts.map +1 -0
  74. package/types/Pagination/v2/PaginationButton/index.d.ts +26 -0
  75. package/types/Pagination/v2/PaginationButton/index.d.ts.map +1 -0
  76. package/types/Pagination/v2/PaginationButton/props.d.ts +30 -0
  77. package/types/Pagination/v2/PaginationButton/props.d.ts.map +1 -0
  78. package/types/Pagination/v2/PaginationPageInput/index.d.ts +50 -0
  79. package/types/Pagination/v2/PaginationPageInput/index.d.ts.map +1 -0
  80. package/types/Pagination/v2/PaginationPageInput/props.d.ts +45 -0
  81. package/types/Pagination/v2/PaginationPageInput/props.d.ts.map +1 -0
  82. package/types/Pagination/v2/PaginationPageInput/styles.d.ts +16 -0
  83. package/types/Pagination/v2/PaginationPageInput/styles.d.ts.map +1 -0
  84. package/types/Pagination/v2/index.d.ts +106 -0
  85. package/types/Pagination/v2/index.d.ts.map +1 -0
  86. package/types/Pagination/v2/props.d.ts +138 -0
  87. package/types/Pagination/v2/props.d.ts.map +1 -0
  88. package/types/Pagination/v2/styles.d.ts +16 -0
  89. package/types/Pagination/v2/styles.d.ts.map +1 -0
  90. package/types/exports/a.d.ts +5 -0
  91. package/types/exports/a.d.ts.map +1 -0
  92. package/types/exports/b.d.ts +5 -0
  93. package/types/exports/b.d.ts.map +1 -0
  94. package/src/index.ts +0 -29
  95. package/types/Pagination/PaginationArrowButton/index.d.ts.map +0 -1
  96. package/types/Pagination/PaginationArrowButton/props.d.ts.map +0 -1
  97. package/types/Pagination/PaginationButton/index.d.ts.map +0 -1
  98. package/types/Pagination/PaginationButton/props.d.ts.map +0 -1
  99. package/types/Pagination/PaginationPageInput/index.d.ts.map +0 -1
  100. package/types/Pagination/PaginationPageInput/props.d.ts.map +0 -1
  101. package/types/Pagination/PaginationPageInput/styles.d.ts.map +0 -1
  102. package/types/Pagination/PaginationPageInput/theme.d.ts.map +0 -1
  103. package/types/Pagination/index.d.ts.map +0 -1
  104. package/types/Pagination/props.d.ts.map +0 -1
  105. package/types/Pagination/styles.d.ts.map +0 -1
  106. package/types/Pagination/theme.d.ts.map +0 -1
  107. package/types/index.d.ts +0 -5
  108. package/types/index.d.ts.map +0 -1
  109. /package/es/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.js +0 -0
  110. /package/es/Pagination/{PaginationButton → v1/PaginationButton}/props.js +0 -0
  111. /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.js +0 -0
  112. /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.js +0 -0
  113. /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.js +0 -0
  114. /package/es/Pagination/{props.js → v1/props.js} +0 -0
  115. /package/es/Pagination/{styles.js → v1/styles.js} +0 -0
  116. /package/es/Pagination/{theme.js → v1/theme.js} +0 -0
  117. /package/lib/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.js +0 -0
  118. /package/lib/Pagination/{PaginationButton → v1/PaginationButton}/props.js +0 -0
  119. /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.js +0 -0
  120. /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.js +0 -0
  121. /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.js +0 -0
  122. /package/lib/Pagination/{props.js → v1/props.js} +0 -0
  123. /package/lib/Pagination/{styles.js → v1/styles.js} +0 -0
  124. /package/lib/Pagination/{theme.js → v1/theme.js} +0 -0
  125. /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.ts +0 -0
  126. /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.ts +0 -0
  127. /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.ts +0 -0
  128. /package/src/Pagination/{README.md → v1/README.md} +0 -0
  129. /package/src/Pagination/{props.ts → v1/props.ts} +0 -0
  130. /package/src/Pagination/{styles.ts → v1/styles.ts} +0 -0
  131. /package/src/Pagination/{theme.ts → v1/theme.ts} +0 -0
  132. /package/types/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.d.ts +0 -0
  133. /package/types/Pagination/{PaginationButton → v1/PaginationButton}/index.d.ts +0 -0
  134. /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.d.ts +0 -0
  135. /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.d.ts +0 -0
  136. /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.d.ts +0 -0
  137. /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.d.ts +0 -0
  138. /package/types/Pagination/{index.d.ts → v1/index.d.ts} +0 -0
  139. /package/types/Pagination/{props.d.ts → v1/props.d.ts} +0 -0
  140. /package/types/Pagination/{styles.d.ts → v1/styles.d.ts} +0 -0
  141. /package/types/Pagination/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,496 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Pagination = void 0;
8
+ Object.defineProperty(exports, "PaginationButton", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _PaginationButton.PaginationButton;
12
+ }
13
+ });
14
+ exports.default = void 0;
15
+ var _react = require("react");
16
+ var _latest = require("@instructure/ui-text/latest");
17
+ var _latest2 = require("@instructure/ui-view/latest");
18
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
19
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
20
+ var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
21
+ var _findTabbable = require("@instructure/ui-dom-utils/lib/findTabbable.js");
22
+ var _getActiveElement = require("@instructure/ui-dom-utils/lib/getActiveElement.js");
23
+ var _emotion = require("@instructure/emotion");
24
+ var _PaginationButton = require("./PaginationButton");
25
+ var _PaginationArrowButton = require("./PaginationArrowButton");
26
+ var _PaginationPageInput = require("./PaginationPageInput");
27
+ var _styles = _interopRequireDefault(require("./styles"));
28
+ var _props = require("./props");
29
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
30
+ var _dec, _dec2, _class, _Pagination;
31
+ /*
32
+ * The MIT License (MIT)
33
+ *
34
+ * Copyright (c) 2015 - present Instructure, Inc.
35
+ *
36
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
37
+ * of this software and associated documentation files (the "Software"), to deal
38
+ * in the Software without restriction, including without limitation the rights
39
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
+ * copies of the Software, and to permit persons to whom the Software is
41
+ * furnished to do so, subject to the following conditions:
42
+ *
43
+ * The above copyright notice and this permission notice shall be included in all
44
+ * copies or substantial portions of the Software.
45
+ *
46
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52
+ * SOFTWARE.
53
+ */
54
+ /** This is an [].findIndex optimized to work on really big, but sparse, arrays */
55
+ const fastFindIndex = (arr, fn) => Number(Object.keys(arr).find(k => fn(arr[Number(k)])));
56
+ const childrenArray = props => {
57
+ const children = props.children;
58
+ if (!children) {
59
+ return [];
60
+ }
61
+ return Array.isArray(children) ? children : [children];
62
+ };
63
+ function propsHaveCompactView(props) {
64
+ if (props.children) return props.variant === 'compact' && childrenArray(props).length > 5;
65
+ return props.variant === 'compact' && props.totalPageNumber > 5;
66
+ }
67
+ /**
68
+ ---
69
+ category: components
70
+ ---
71
+ **/
72
+ let Pagination = exports.Pagination = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Pagination = class Pagination extends _react.Component {
73
+ constructor(props) {
74
+ super(props);
75
+ this._labelId = void 0;
76
+ this._firstButton = null;
77
+ this._prevButton = null;
78
+ this._nextButton = null;
79
+ this._lastButton = null;
80
+ this.ref = null;
81
+ this.currentPageRef = null;
82
+ this.handleElementRef = el => {
83
+ this.ref = el;
84
+ if (el && typeof this.props.elementRef === 'function') {
85
+ this.props.elementRef(el);
86
+ }
87
+ };
88
+ this.handleInputRef = el => {
89
+ if (typeof this.props.inputRef === 'function') {
90
+ this.props.inputRef(el);
91
+ }
92
+ };
93
+ this.renderDefaultPageInput = () => {
94
+ const _this$props = this.props,
95
+ currentPage = _this$props.currentPage,
96
+ totalPageNumber = _this$props.totalPageNumber;
97
+ return (0, _jsxRuntime.jsx)(_PaginationPageInput.PaginationPageInput, {
98
+ numberOfPages: totalPageNumber,
99
+ currentPageIndex: currentPage - 1,
100
+ onChange: (_e, nextPageIndex) => {
101
+ var _this$props$onPageCha, _this$props2;
102
+ 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);
103
+ },
104
+ screenReaderLabel: this.props.screenReaderLabelNumberInput,
105
+ label: this.props.labelNumberInput,
106
+ disabled: this.props.disabled,
107
+ inputRef: this.handleInputRef
108
+ });
109
+ };
110
+ this.handleNavigation = (nextIndex, previousIndex) => {
111
+ const onPageChange = this.props.onPageChange;
112
+ if (typeof onPageChange === 'function') {
113
+ onPageChange(nextIndex, previousIndex);
114
+ }
115
+ };
116
+ this.renderPagesInInterval = (from, to, currentPage) => {
117
+ if (to - from > 1000) throw new Error('Pagination: too many pages (more than 1000)');
118
+ const pages = [];
119
+ for (let i = from; i <= to; i++) {
120
+ var _this$props$renderPag, _this$props3;
121
+ pages.push((0, _jsxRuntime.jsx)(Pagination.Page, {
122
+ ref: e => {
123
+ if (i === currentPage) {
124
+ this.currentPageRef = e;
125
+ }
126
+ },
127
+ onClick: () => this.handleNavigation(i, currentPage),
128
+ onMouseEnter: () => this.handleOnMouseEnter(i),
129
+ current: i === currentPage,
130
+ ...(this.props.screenReaderLabelPageButton ? {
131
+ screenReaderLabel: this.props.screenReaderLabelPageButton(i, this.props.totalPageNumber)
132
+ } : {}),
133
+ children: (_this$props$renderPag = (_this$props3 = this.props).renderPageIndicator) === null || _this$props$renderPag === void 0 ? void 0 : _this$props$renderPag.call(_this$props3, i, currentPage)
134
+ }, i));
135
+ }
136
+ return pages;
137
+ };
138
+ this.renderDefaultPages = () => {
139
+ var _this$props$styles3;
140
+ const _this$props4 = this.props,
141
+ ellipsis = _this$props4.ellipsis,
142
+ currentPage = _this$props4.currentPage,
143
+ totalPageNumber = _this$props4.totalPageNumber,
144
+ siblingCount = _this$props4.siblingCount,
145
+ boundaryCount = _this$props4.boundaryCount,
146
+ variant = _this$props4.variant;
147
+ const pages = [];
148
+ if (totalPageNumber <= 2 * boundaryCount || totalPageNumber <= 1 + siblingCount + boundaryCount || variant === 'full') {
149
+ var _this$props$styles;
150
+ return (0, _jsxRuntime.jsx)("ul", {
151
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.pageIndicatorList,
152
+ children: this.renderPagesInInterval(1, totalPageNumber, currentPage)
153
+ });
154
+ }
155
+ if (currentPage > boundaryCount + siblingCount + 1) {
156
+ pages.push(this.renderPagesInInterval(1, boundaryCount, currentPage));
157
+ pages.push((0, _jsxRuntime.jsx)("li", {
158
+ style: {
159
+ all: 'unset'
160
+ },
161
+ children: (0, _jsxRuntime.jsx)(_latest.Text, {
162
+ children: ellipsis
163
+ })
164
+ }, "ellipsis1"));
165
+ if (currentPage - siblingCount > totalPageNumber - boundaryCount + 1) {
166
+ var _this$props$styles2;
167
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
168
+ return (0, _jsxRuntime.jsx)("ul", {
169
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.pageIndicatorList,
170
+ children: pages
171
+ });
172
+ }
173
+ pages.push(this.renderPagesInInterval(currentPage - siblingCount, currentPage, currentPage));
174
+ } else {
175
+ pages.push(this.renderPagesInInterval(1, Math.max(currentPage, boundaryCount), currentPage));
176
+ }
177
+ if (currentPage < totalPageNumber - (siblingCount + boundaryCount)) {
178
+ pages.push(this.renderPagesInInterval(Math.max(currentPage, boundaryCount) + 1, currentPage + siblingCount, currentPage));
179
+ pages.push((0, _jsxRuntime.jsx)("li", {
180
+ style: {
181
+ all: 'unset'
182
+ },
183
+ children: (0, _jsxRuntime.jsx)(_latest.Text, {
184
+ children: ellipsis
185
+ })
186
+ }, "ellipsis2"));
187
+ pages.push(this.renderPagesInInterval(totalPageNumber - boundaryCount + 1, totalPageNumber, currentPage));
188
+ } else {
189
+ pages.push(this.renderPagesInInterval(currentPage + 1, totalPageNumber, currentPage));
190
+ }
191
+ return (0, _jsxRuntime.jsx)("ul", {
192
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.pageIndicatorList,
193
+ children: pages
194
+ });
195
+ };
196
+ this.renderDefaultArrowButton = direction => {
197
+ if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
198
+ return null;
199
+ }
200
+ // We don't display the arrows in "compact" variant under 6 items
201
+ if (!(propsHaveCompactView(this.props) || this.inputMode)) {
202
+ return null;
203
+ }
204
+ const _this$props5 = this.props,
205
+ totalPageNumber = _this$props5.totalPageNumber,
206
+ currentPage = _this$props5.currentPage;
207
+ const _this$getArrowVariant = this.getArrowVariant(direction, currentPage - 1, totalPageNumber),
208
+ label = _this$getArrowVariant.label,
209
+ shouldEnableIcon = _this$getArrowVariant.shouldEnableIcon,
210
+ handleButtonRef = _this$getArrowVariant.handleButtonRef;
211
+ const disabled = this.props.disabled || !shouldEnableIcon;
212
+ const onClick = () => {
213
+ if (direction === 'first') {
214
+ this.handleNavigation(1, currentPage);
215
+ }
216
+ if (direction === 'prev') {
217
+ this.handleNavigation(Math.max(currentPage - 1, 1), currentPage);
218
+ }
219
+ if (direction === 'next') {
220
+ this.handleNavigation(Math.min(currentPage + 1, totalPageNumber), currentPage);
221
+ }
222
+ if (direction === 'last') {
223
+ this.handleNavigation(totalPageNumber, currentPage);
224
+ }
225
+ };
226
+ return shouldEnableIcon || this.showDisabledButtons ? (0, _jsxRuntime.jsx)(_PaginationArrowButton.PaginationArrowButton, {
227
+ direction: direction,
228
+ "data-direction": direction,
229
+ label: label,
230
+ onClick: onClick,
231
+ disabled: disabled,
232
+ buttonRef: handleButtonRef
233
+ }) : null;
234
+ };
235
+ this.handleOnMouseEnter = page => {
236
+ if (typeof this.props.onMouseEnter === 'function') {
237
+ this.props.onMouseEnter(page);
238
+ }
239
+ };
240
+ this._labelId = props.deterministicId();
241
+ }
242
+ get _root() {
243
+ return this.ref;
244
+ }
245
+ get inputMode() {
246
+ return this.props.variant === 'input';
247
+ }
248
+ get childPages() {
249
+ return childrenArray(this.props);
250
+ }
251
+ get withFirstAndLastButton() {
252
+ return this.inputMode || this.props.withFirstAndLastButton;
253
+ }
254
+ get showDisabledButtons() {
255
+ return this.inputMode || this.props.showDisabledButtons;
256
+ }
257
+ getSnapshotBeforeUpdate() {
258
+ const activeElement = (0, _getActiveElement.getActiveElement)();
259
+ if (activeElement === this._firstButton || activeElement === this._prevButton || activeElement === this._nextButton || activeElement === this._lastButton) {
260
+ return {
261
+ lastFocusedButton: activeElement
262
+ };
263
+ } else {
264
+ return {
265
+ lastFocusedButton: void 0
266
+ };
267
+ }
268
+ }
269
+ componentDidMount() {
270
+ var _this$props$makeStyle, _this$props6;
271
+ (_this$props$makeStyle = (_this$props6 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props6);
272
+ }
273
+ componentDidUpdate(prevProps, _prevState, snapshot) {
274
+ var _this$props$makeStyle2, _this$props7;
275
+ (_this$props$makeStyle2 = (_this$props7 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props7);
276
+
277
+ // set focus on the currently active page
278
+ if (this.props.currentPage !== prevProps.currentPage && document.activeElement !== this._firstButton && document.activeElement !== this._prevButton && document.activeElement !== this._nextButton && document.activeElement !== this._lastButton) {
279
+ var _this$currentPageRef, _this$currentPageRef$, _this$currentPageRef$2;
280
+ // @ts-expect-error fix typing
281
+ (_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$);
282
+ }
283
+ if (!this.props.shouldHandleFocus || !propsHaveCompactView(prevProps) && !propsHaveCompactView(this.props)) {
284
+ return;
285
+ } else {
286
+ this.focusElementAfterUpdate(snapshot);
287
+ }
288
+ }
289
+ focusElementAfterUpdate(snapshot) {
290
+ const lastFocusedButton = snapshot.lastFocusedButton;
291
+ if (lastFocusedButton) {
292
+ var _nextFocusElement;
293
+ const focusable = (0, _findTabbable.findTabbable)(this.ref);
294
+ const direction = lastFocusedButton.dataset.direction;
295
+
296
+ // By default we want to focus the previously focused button
297
+ let nextFocusElement = lastFocusedButton;
298
+
299
+ // In case the button is not focusable anymore
300
+ // (disabled or not in the DOM), we focus to the next available page
301
+ if (!focusable.includes(nextFocusElement)) {
302
+ if (direction === 'first' || direction === 'prev') {
303
+ nextFocusElement = focusable[0];
304
+ }
305
+ if (direction === 'next' || direction === 'last') {
306
+ nextFocusElement = focusable[focusable.length - 1];
307
+ }
308
+ }
309
+ ;
310
+ (_nextFocusElement = nextFocusElement) === null || _nextFocusElement === void 0 ? void 0 : _nextFocusElement.focus();
311
+ }
312
+ }
313
+ get compactView() {
314
+ return propsHaveCompactView(this.props);
315
+ }
316
+ transferDisabledPropToChildren(children) {
317
+ return children && this.props.disabled ? _react.Children.map(children, page => /*#__PURE__*/(0, _react.cloneElement)(page, {
318
+ disabled: this.props.disabled
319
+ })) : children;
320
+ }
321
+ renderLabel() {
322
+ const display = this.props.variant === 'full' ? 'inline-block' : 'block';
323
+ const visibleLabel = (0, _hasVisibleChildren.hasVisibleChildren)(this.props.label);
324
+ return (0, _jsxRuntime.jsx)(_latest2.View, {
325
+ padding: visibleLabel ? 'small' : '0',
326
+ display: visibleLabel ? display : 'auto',
327
+ id: this._labelId,
328
+ children: (0, _jsxRuntime.jsx)(_latest.Text, {
329
+ variant: "content",
330
+ children: this.props.label
331
+ })
332
+ });
333
+ }
334
+ renderPageInput(currentPageIndex) {
335
+ if (!this.props.children) return this.renderDefaultPageInput();
336
+ return (0, _jsxRuntime.jsx)(_PaginationPageInput.PaginationPageInput, {
337
+ numberOfPages: this.childPages.length,
338
+ currentPageIndex: currentPageIndex,
339
+ onChange: this.handleInputChange.bind(this),
340
+ screenReaderLabel: this.props.screenReaderLabelNumberInput,
341
+ label: this.props.labelNumberInput,
342
+ disabled: this.props.disabled,
343
+ inputRef: this.handleInputRef
344
+ });
345
+ }
346
+ handleInputChange(event, pageIndex) {
347
+ var _this$childPages$page, _this$childPages$page2;
348
+ (_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);
349
+ }
350
+ renderPages(currentPageIndex) {
351
+ if (!this.props.children) return this.renderDefaultPages();
352
+ const allPages = this.childPages;
353
+ let visiblePages = allPages;
354
+ if (this.compactView) {
355
+ const firstIndex = 0;
356
+ const lastIndex = allPages.length - 1;
357
+ const sliceStart = Math.min(lastIndex - 3, Math.max(currentPageIndex - 1, firstIndex));
358
+ const sliceEnd = Math.min(currentPageIndex + 4, lastIndex);
359
+ visiblePages = allPages.slice(sliceStart, sliceEnd);
360
+ const firstPage = allPages[firstIndex];
361
+ const lastPage = allPages[lastIndex];
362
+ if (sliceStart - firstIndex > 1) visiblePages.unshift((0, _jsxRuntime.jsx)("li", {
363
+ style: {
364
+ all: 'unset'
365
+ },
366
+ "aria-hidden": "true",
367
+ children: (0, _jsxRuntime.jsx)(_latest.Text, {
368
+ children: this.props.ellipsis
369
+ })
370
+ }, "first"));
371
+ if (sliceStart - firstIndex > 0) visiblePages.unshift(firstPage);
372
+ if (lastIndex - sliceEnd + 1 > 1) visiblePages.push((0, _jsxRuntime.jsx)("li", {
373
+ style: {
374
+ all: 'unset'
375
+ },
376
+ "aria-hidden": "true",
377
+ children: (0, _jsxRuntime.jsx)(_latest.Text, {
378
+ children: this.props.ellipsis
379
+ })
380
+ }, "last"));
381
+ if (lastIndex - sliceEnd + 1 > 0) visiblePages.push(lastPage);
382
+ }
383
+ return (0, _jsxRuntime.jsx)(_latest2.View, {
384
+ display: "inline-block",
385
+ as: "ul",
386
+ margin: "0",
387
+ padding: "0",
388
+ children: this.transferDisabledPropToChildren(visiblePages)
389
+ });
390
+ }
391
+ getArrowVariant(direction, currentPageIndex, pagesCount) {
392
+ switch (direction) {
393
+ case 'first':
394
+ return {
395
+ pageIndex: 0,
396
+ label: this.props.labelFirst || 'First Page',
397
+ shouldEnableIcon: currentPageIndex > 1,
398
+ handleButtonRef: el => {
399
+ this._firstButton = el;
400
+ }
401
+ };
402
+ case 'prev':
403
+ return {
404
+ pageIndex: currentPageIndex - 1,
405
+ label: this.props.labelPrev || 'Previous Page',
406
+ shouldEnableIcon: currentPageIndex > 0,
407
+ handleButtonRef: el => {
408
+ this._prevButton = el;
409
+ }
410
+ };
411
+ case 'next':
412
+ return {
413
+ pageIndex: currentPageIndex + 1,
414
+ label: this.props.labelNext || 'Next Page',
415
+ shouldEnableIcon: currentPageIndex < pagesCount - 1,
416
+ handleButtonRef: el => {
417
+ this._nextButton = el;
418
+ }
419
+ };
420
+ case 'last':
421
+ return {
422
+ pageIndex: pagesCount - 1,
423
+ label: this.props.labelLast || 'Last Page',
424
+ shouldEnableIcon: currentPageIndex < pagesCount - 2,
425
+ handleButtonRef: el => {
426
+ this._lastButton = el;
427
+ }
428
+ };
429
+ }
430
+ }
431
+ renderArrowButton(direction, currentPageIndex) {
432
+ var _page$props, _page$props2;
433
+ if (!this.props.children) return this.renderDefaultArrowButton(direction);
434
+ const childPages = this.childPages;
435
+ // We don't display the arrows in "compact" variant under 6 items
436
+ if (!(propsHaveCompactView(this.props) || this.inputMode)) {
437
+ return null;
438
+ }
439
+ if (!this.withFirstAndLastButton && (direction === 'first' || direction === 'last')) {
440
+ return null;
441
+ }
442
+ const _this$getArrowVariant2 = this.getArrowVariant(direction, currentPageIndex, childPages.length),
443
+ pageIndex = _this$getArrowVariant2.pageIndex,
444
+ label = _this$getArrowVariant2.label,
445
+ shouldEnableIcon = _this$getArrowVariant2.shouldEnableIcon,
446
+ handleButtonRef = _this$getArrowVariant2.handleButtonRef;
447
+ const page = childPages[pageIndex];
448
+ 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;
449
+ const onClick = page === null || page === void 0 ? void 0 : (_page$props2 = page.props) === null || _page$props2 === void 0 ? void 0 : _page$props2.onClick;
450
+ return shouldEnableIcon || this.showDisabledButtons ? (0, _jsxRuntime.jsx)(_PaginationArrowButton.PaginationArrowButton, {
451
+ direction: direction,
452
+ "data-direction": direction,
453
+ label: label,
454
+ onClick: onClick,
455
+ disabled: disabled,
456
+ buttonRef: handleButtonRef
457
+ }) : null;
458
+ }
459
+ render() {
460
+ var _this$props$styles4, _this$props$styles5;
461
+ const currentPageIndex = fastFindIndex(this.childPages, p => p && p.props && p.props.current);
462
+ const passthroughProps = _latest2.View.omitViewProps((0, _omitProps.omitProps)(this.props, Pagination.allowedProps), Pagination);
463
+ return (0, _jsxRuntime.jsxs)(_latest2.View, {
464
+ ...passthroughProps,
465
+ role: "navigation",
466
+ as: this.props.as,
467
+ elementRef: this.handleElementRef,
468
+ margin: this.props.margin,
469
+ css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.pagination,
470
+ "aria-labelledby": this.props.label ? this._labelId : void 0,
471
+ "data-cid": "Pagination",
472
+ children: [this.props.label && this.renderLabel(), (0, _jsxRuntime.jsxs)(_latest2.View, {
473
+ display: "inline-block",
474
+ css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.pages,
475
+ children: [this.renderArrowButton('first', currentPageIndex), this.renderArrowButton('prev', currentPageIndex), this.inputMode ? this.renderPageInput(currentPageIndex) : this.renderPages(currentPageIndex), this.renderArrowButton('next', currentPageIndex), this.renderArrowButton('last', currentPageIndex)]
476
+ })]
477
+ });
478
+ }
479
+ }, _Pagination.displayName = "Pagination", _Pagination.componentId = 'Pagination', _Pagination.allowedProps = _props.allowedProps, _Pagination.defaultProps = {
480
+ disabled: false,
481
+ withFirstAndLastButton: false,
482
+ showDisabledButtons: false,
483
+ variant: 'full',
484
+ as: 'div',
485
+ labelNumberInput: numberOfPages => `of ${numberOfPages}`,
486
+ screenReaderLabelNumberInput: (currentPage, numberOfPages) => `Select page (${currentPage} of ${numberOfPages})`,
487
+ shouldHandleFocus: true,
488
+ totalPageNumber: 0,
489
+ currentPage: 1,
490
+ siblingCount: 1,
491
+ boundaryCount: 1,
492
+ ellipsis: '…',
493
+ renderPageIndicator: page => page,
494
+ margin: 'space8'
495
+ }, _Pagination.Page = _PaginationButton.PaginationButton, _Pagination.Navigation = _PaginationArrowButton.PaginationArrowButton, _Pagination.PageInput = _PaginationPageInput.PaginationPageInput, _Pagination)) || _class) || _class);
496
+ var _default = exports.default = Pagination;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.allowedProps = ['children', 'disabled', 'withFirstAndLastButton', 'showDisabledButtons', 'label', 'labelNext', 'labelPrev', 'labelFirst', 'labelLast', 'labelNumberInput', 'screenReaderLabelNumberInput', 'screenReaderLabelPageButton', 'variant', 'margin', 'as', 'elementRef', 'inputRef', 'shouldHandleFocus', 'totalPageNumber', 'currentPage', 'onPageChange', 'siblingCount', 'boundaryCount', 'renderPageIndicator', 'ellipsis', 'onMouseEnter'];
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} sharedTokens Shared token object that stores common values for the theme.
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+ const generateStyle = componentTheme => {
43
+ return {
44
+ pageIndicatorList: {
45
+ all: 'unset',
46
+ display: 'flex',
47
+ alignItems: 'center',
48
+ gap: componentTheme.pageIndicatorGap,
49
+ flexWrap: 'wrap',
50
+ justifyContent: 'center'
51
+ },
52
+ pagination: {
53
+ label: 'pagination',
54
+ textAlign: 'center'
55
+ },
56
+ pages: {
57
+ label: 'pagination__pages',
58
+ display: 'inline-flex',
59
+ alignItems: 'center',
60
+ gap: componentTheme.pageIndicatorGap
61
+ }
62
+ };
63
+ };
64
+ var _default = exports.default = generateStyle;
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "Pagination", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _Pagination.Pagination;
9
+ return _v.Pagination;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "PaginationButton", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _Pagination.PaginationButton;
15
+ return _v.PaginationButton;
16
16
  }
17
17
  });
18
- var _Pagination = require("./Pagination");
18
+ var _v = require("../Pagination/v1");
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Pagination", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _v.Pagination;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "PaginationButton", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _v.PaginationButton;
16
+ }
17
+ });
18
+ var _v = require("../Pagination/v2");