@instructure/ui-pagination 8.13.1-snapshot.9 → 8.14.0

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 (65) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/es/Pagination/PaginationArrowButton/index.js +36 -4
  3. package/es/Pagination/PaginationArrowButton/props.js +6 -3
  4. package/es/Pagination/PaginationButton/props.js +9 -2
  5. package/es/Pagination/PaginationLocator.js +4 -0
  6. package/es/Pagination/PaginationPageInput/PaginationPageInputLocator.js +35 -0
  7. package/es/Pagination/PaginationPageInput/index.js +208 -0
  8. package/es/Pagination/PaginationPageInput/props.js +35 -0
  9. package/es/Pagination/PaginationPageInput/styles.js +55 -0
  10. package/es/Pagination/PaginationPageInput/theme.js +40 -0
  11. package/es/Pagination/index.js +178 -52
  12. package/es/Pagination/props.js +32 -2
  13. package/lib/Pagination/PaginationArrowButton/index.js +39 -3
  14. package/lib/Pagination/PaginationArrowButton/props.js +6 -3
  15. package/lib/Pagination/PaginationButton/props.js +9 -2
  16. package/lib/Pagination/PaginationLocator.js +5 -0
  17. package/lib/Pagination/PaginationPageInput/PaginationPageInputLocator.js +46 -0
  18. package/lib/Pagination/PaginationPageInput/index.js +202 -0
  19. package/lib/Pagination/PaginationPageInput/props.js +46 -0
  20. package/lib/Pagination/PaginationPageInput/styles.js +63 -0
  21. package/lib/Pagination/PaginationPageInput/theme.js +48 -0
  22. package/lib/Pagination/index.js +179 -52
  23. package/lib/Pagination/props.js +32 -2
  24. package/package.json +23 -22
  25. package/src/Pagination/PaginationArrowButton/index.tsx +32 -4
  26. package/src/Pagination/PaginationArrowButton/props.ts +22 -6
  27. package/src/Pagination/PaginationButton/props.ts +18 -2
  28. package/src/Pagination/PaginationLocator.ts +5 -1
  29. package/src/Pagination/PaginationPageInput/PaginationPageInputLocator.ts +42 -0
  30. package/src/Pagination/PaginationPageInput/index.tsx +242 -0
  31. package/src/Pagination/PaginationPageInput/props.ts +112 -0
  32. package/src/Pagination/PaginationPageInput/styles.ts +60 -0
  33. package/src/Pagination/PaginationPageInput/theme.ts +46 -0
  34. package/src/Pagination/README.md +116 -0
  35. package/src/Pagination/index.tsx +213 -80
  36. package/src/Pagination/props.ts +53 -4
  37. package/tsconfig.build.json +26 -2
  38. package/tsconfig.build.tsbuildinfo +1 -0
  39. package/types/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.d.ts +57 -56
  40. package/types/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.d.ts.map +1 -1
  41. package/types/Pagination/PaginationArrowButton/index.d.ts +9 -4
  42. package/types/Pagination/PaginationArrowButton/index.d.ts.map +1 -1
  43. package/types/Pagination/PaginationArrowButton/props.d.ts +5 -3
  44. package/types/Pagination/PaginationArrowButton/props.d.ts.map +1 -1
  45. package/types/Pagination/PaginationButton/index.d.ts +2 -0
  46. package/types/Pagination/PaginationButton/index.d.ts.map +1 -1
  47. package/types/Pagination/PaginationButton/props.d.ts +1 -0
  48. package/types/Pagination/PaginationButton/props.d.ts.map +1 -1
  49. package/types/Pagination/PaginationLocator.d.ts +944 -234
  50. package/types/Pagination/PaginationLocator.d.ts.map +1 -1
  51. package/types/Pagination/PaginationPageInput/PaginationPageInputLocator.d.ts +581 -0
  52. package/types/Pagination/PaginationPageInput/PaginationPageInputLocator.d.ts.map +1 -0
  53. package/types/Pagination/PaginationPageInput/index.d.ts +63 -0
  54. package/types/Pagination/PaginationPageInput/index.d.ts.map +1 -0
  55. package/types/Pagination/PaginationPageInput/props.d.ts +46 -0
  56. package/types/Pagination/PaginationPageInput/props.d.ts.map +1 -0
  57. package/types/Pagination/PaginationPageInput/styles.d.ts +15 -0
  58. package/types/Pagination/PaginationPageInput/styles.d.ts.map +1 -0
  59. package/types/Pagination/PaginationPageInput/theme.d.ts +10 -0
  60. package/types/Pagination/PaginationPageInput/theme.d.ts.map +1 -0
  61. package/types/Pagination/index.d.ts +50 -14
  62. package/types/Pagination/index.d.ts.map +1 -1
  63. package/types/Pagination/props.d.ts +13 -3
  64. package/types/Pagination/props.d.ts.map +1 -1
  65. package/LICENSE.md +0 -27
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = exports.PaginationPageInput = void 0;
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _testable = require("@instructure/ui-testable/lib/testable.js");
15
+
16
+ var _emotion = require("@instructure/emotion");
17
+
18
+ var _NumberInput = require("@instructure/ui-number-input/lib/NumberInput");
19
+
20
+ var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
21
+
22
+ var _styles = _interopRequireDefault(require("./styles"));
23
+
24
+ var _theme = _interopRequireDefault(require("./theme"));
25
+
26
+ var _props = require("./props");
27
+
28
+ var _dec, _dec2, _class, _class2, _temp;
29
+
30
+ /**
31
+ ---
32
+ parent: Pagination
33
+ id: Pagination.PageInput
34
+ ---
35
+ @tsProps
36
+ **/
37
+ let PaginationPageInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class PaginationPageInput extends _react.Component {
38
+ constructor(props) {
39
+ super(props);
40
+ this.ref = null;
41
+ this._inputRef = null;
42
+
43
+ this.handleRef = el => {
44
+ this.ref = el;
45
+ };
46
+
47
+ this.handleInputRef = el => {
48
+ this._inputRef = el;
49
+
50
+ if (typeof this.props.inputRef === 'function') {
51
+ this.props.inputRef(el);
52
+ }
53
+ };
54
+
55
+ this.handleChange = (_event, value) => {
56
+ let newValue = value; // if the last character was not a number, don't accept it
57
+
58
+ if (value.length > 0 && isNaN(value.slice(-1))) {
59
+ newValue = value.slice(0, -1);
60
+ }
61
+
62
+ this.setState({
63
+ number: newValue ? Number(newValue) : this.MIN,
64
+ value: newValue
65
+ });
66
+ };
67
+
68
+ this.handleDecrement = event => {
69
+ this.setNewPage(event, Math.floor(this.currentPage - 1));
70
+ };
71
+
72
+ this.handleIncrement = event => {
73
+ this.setNewPage(event, Math.floor(this.currentPage + 1));
74
+ };
75
+
76
+ this.handleBlur = event => {
77
+ this.setNewPage(event, Math.round(this.state.number));
78
+ };
79
+
80
+ this.state = this.initialState;
81
+ }
82
+
83
+ get currentPage() {
84
+ return this.props.currentPageIndex + 1;
85
+ }
86
+
87
+ get initialState() {
88
+ return {
89
+ number: this.currentPage,
90
+ value: `${this.currentPage}`
91
+ };
92
+ }
93
+
94
+ get MIN() {
95
+ return 1;
96
+ }
97
+
98
+ get MAX() {
99
+ return this.props.numberOfPages;
100
+ }
101
+
102
+ componentDidMount() {
103
+ var _this$props$makeStyle, _this$props;
104
+
105
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
106
+ }
107
+
108
+ componentDidUpdate(prevProps) {
109
+ var _this$props$makeStyle2, _this$props2;
110
+
111
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2); // when the current page changes from outside (e.g.: from arrow buttons),
112
+ // we update the initial state
113
+
114
+ if (this.props.currentPageIndex !== prevProps.currentPageIndex) {
115
+ this.resetInitialState();
116
+ }
117
+ }
118
+
119
+ resetInitialState() {
120
+ this.setState(this.initialState);
121
+ }
122
+
123
+ handleKeyDown(event) {
124
+ const key = event.key;
125
+
126
+ if (key.toLowerCase() === 'enter') {
127
+ const _this$state = this.state,
128
+ value = _this$state.value,
129
+ number = _this$state.number; // If it is invalid, we reset the input to the current page
130
+
131
+ if (value === '' || isNaN(value)) {
132
+ this.resetInitialState();
133
+ return;
134
+ }
135
+
136
+ this.setNewPage(event, number);
137
+ }
138
+ }
139
+
140
+ getNumberWithinRange(n) {
141
+ if (n < this.MIN) return this.MIN;
142
+ if (n > this.MAX) return this.MAX;
143
+ return n;
144
+ }
145
+
146
+ setNewPage(event, n) {
147
+ const number = this.getNumberWithinRange(n);
148
+ this.setState({
149
+ number,
150
+ value: `${number}`
151
+ });
152
+ this.props.onChange(event, number - 1);
153
+ }
154
+
155
+ renderLabel() {
156
+ const _this$props3 = this.props,
157
+ label = _this$props3.label,
158
+ numberOfPages = _this$props3.numberOfPages,
159
+ styles = _this$props3.styles;
160
+ return typeof label === 'function' && label(numberOfPages) ? (0, _emotion.jsx)("span", {
161
+ css: styles === null || styles === void 0 ? void 0 : styles.inputLabel
162
+ }, label(numberOfPages)) : null;
163
+ }
164
+
165
+ renderScreenReaderLabel() {
166
+ const _this$props4 = this.props,
167
+ screenReaderLabel = _this$props4.screenReaderLabel,
168
+ numberOfPages = _this$props4.numberOfPages;
169
+ return (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, screenReaderLabel(this.currentPage, numberOfPages));
170
+ }
171
+
172
+ render() {
173
+ const _this$props5 = this.props,
174
+ styles = _this$props5.styles,
175
+ disabled = _this$props5.disabled;
176
+ return (0, _emotion.jsx)("span", {
177
+ css: styles === null || styles === void 0 ? void 0 : styles.paginationPageInput,
178
+ ref: this.handleRef
179
+ }, (0, _emotion.jsx)("span", {
180
+ css: styles === null || styles === void 0 ? void 0 : styles.numberInput
181
+ }, (0, _emotion.jsx)(_NumberInput.NumberInput, {
182
+ renderLabel: this.renderScreenReaderLabel(),
183
+ onBlur: this.handleBlur,
184
+ onChange: this.handleChange,
185
+ onDecrement: this.handleDecrement,
186
+ onIncrement: this.handleIncrement,
187
+ onKeyDown: this.handleKeyDown.bind(this),
188
+ interaction: disabled ? 'disabled' : 'enabled',
189
+ showArrows: false,
190
+ value: this.state.value,
191
+ width: "100%",
192
+ textAlign: "center",
193
+ inputRef: this.handleInputRef
194
+ })), this.renderLabel());
195
+ }
196
+
197
+ }, _class2.displayName = "PaginationPageInput", _class2.componentId = 'Pagination.PageInput', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
198
+ disabled: false
199
+ }, _temp)) || _class) || _class);
200
+ exports.PaginationPageInput = PaginationPageInput;
201
+ var _default = PaginationPageInput;
202
+ exports.default = _default;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.allowedProps = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ const propTypes = {
36
+ numberOfPages: _propTypes.default.number.isRequired,
37
+ currentPageIndex: _propTypes.default.number.isRequired,
38
+ onChange: _propTypes.default.func.isRequired,
39
+ screenReaderLabel: _propTypes.default.func.isRequired,
40
+ label: _propTypes.default.func,
41
+ disabled: _propTypes.default.bool,
42
+ inputRef: _propTypes.default.func
43
+ };
44
+ exports.propTypes = propTypes;
45
+ const allowedProps = ['numberOfPages', 'currentPageIndex', 'onChange', 'screenReaderLabel', 'label', 'disabled', 'inputRef'];
46
+ exports.allowedProps = allowedProps;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Generates the style object from the theme and provided additional information
37
+ * @param {Object} componentTheme The theme variable object.
38
+ * @param {Object} props the props of the component, the style is applied to
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
+ paginationPageInput: {
45
+ label: 'paginationPageInput',
46
+ display: 'inline-flex',
47
+ alignItems: 'center',
48
+ margin: `0 ${componentTheme.inputSpacing}`
49
+ },
50
+ numberInput: {
51
+ label: 'paginationPageInput__input',
52
+ width: componentTheme.inputWidth
53
+ },
54
+ inputLabel: {
55
+ label: 'paginationPageInput__inputLabel',
56
+ marginInlineStart: componentTheme.inputSpacing,
57
+ whiteSpace: 'nowrap'
58
+ }
59
+ };
60
+ };
61
+
62
+ var _default = generateStyle;
63
+ exports.default = _default;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * Generates the theme object for the component from the theme and provided additional information
34
+ * @param {Object} theme The actual theme object.
35
+ * @return {Object} The final theme object with the overrides and component variables
36
+ */
37
+ const generateComponentTheme = theme => {
38
+ const spacing = theme.spacing;
39
+ const componentVariables = {
40
+ inputSpacing: spacing.xSmall,
41
+ inputWidth: '4.5rem'
42
+ };
43
+ return { ...componentVariables
44
+ };
45
+ };
46
+
47
+ var _default = generateComponentTheme;
48
+ exports.default = _default;