@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,109 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["label", "direction", "buttonRef"];
3
+ /*
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2015 - present Instructure, Inc.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+
27
+ import { Component } from 'react';
28
+ import { IconButton } from '@instructure/ui-buttons/latest';
29
+ import { PresentationContent } from '@instructure/ui-a11y-content';
30
+ import { Tooltip } from '@instructure/ui-tooltip/latest';
31
+ import { ChevronLeftInstUIIcon, ChevronRightInstUIIcon, ChevronsLeftInstUIIcon, ChevronsRightInstUIIcon, renderIconWithProps } from '@instructure/ui-icons';
32
+ import { allowedProps } from "./props.js";
33
+ /**
34
+ ---
35
+ parent: Pagination
36
+ id: Pagination.Navigation
37
+ ---
38
+ **/
39
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
40
+ class PaginationArrowButton extends Component {
41
+ constructor(...args) {
42
+ super(...args);
43
+ this.ref = null;
44
+ this.handleRef = el => {
45
+ this.ref = el;
46
+ };
47
+ }
48
+ get margin() {
49
+ switch (this.props.direction) {
50
+ case 'first':
51
+ return '0 xx-small 0 0';
52
+ case 'last':
53
+ return '0 0 0 xx-small';
54
+ default:
55
+ return void 0;
56
+ }
57
+ }
58
+ get Icon() {
59
+ switch (this.props.direction) {
60
+ case 'first':
61
+ return ChevronsLeftInstUIIcon;
62
+ case 'prev':
63
+ return ChevronLeftInstUIIcon;
64
+ case 'next':
65
+ return ChevronRightInstUIIcon;
66
+ case 'last':
67
+ return ChevronsRightInstUIIcon;
68
+ default:
69
+ return null;
70
+ }
71
+ }
72
+ renderIcon() {
73
+ const icon = this.Icon;
74
+ if (!icon) return null;
75
+ return renderIconWithProps(icon, 'md', 'actionTertiaryBaseColor');
76
+ }
77
+ render() {
78
+ const _this$props = this.props,
79
+ label = _this$props.label,
80
+ direction = _this$props.direction,
81
+ buttonRef = _this$props.buttonRef,
82
+ props = _objectWithoutProperties(_this$props, _excluded);
83
+ return _jsx(Tooltip, {
84
+ elementRef: this.handleRef,
85
+ on: ['hover', 'focus'],
86
+ renderTip: _jsx(PresentationContent, {
87
+ children: label
88
+ }),
89
+ children: _jsx(IconButton, {
90
+ ...props,
91
+ size: "small",
92
+ withBackground: false,
93
+ withBorder: false,
94
+ screenReaderLabel: label,
95
+ rel: props.href || props.to ? direction : void 0,
96
+ elementRef: buttonRef,
97
+ margin: this.margin,
98
+ "data-cid": "PaginationArrowButton",
99
+ children: this.renderIcon()
100
+ })
101
+ });
102
+ }
103
+ }
104
+ PaginationArrowButton.displayName = "PaginationArrowButton";
105
+ PaginationArrowButton.componentId = 'Pagination.Navigation';
106
+ PaginationArrowButton.allowedProps = allowedProps;
107
+ PaginationArrowButton.defaultProps = {};
108
+ export default PaginationArrowButton;
109
+ export { PaginationArrowButton };
@@ -0,0 +1,30 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['direction', 'label', 'buttonRef'
26
+
27
+ // we don't want to pass onClick
28
+ // 'onClick'
29
+ ];
30
+ export { allowedProps };
@@ -0,0 +1,77 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { Component } from 'react';
26
+ import { BaseButton } from '@instructure/ui-buttons/latest';
27
+ import { omitProps } from '@instructure/ui-react-utils';
28
+ import { allowedProps } from "./props.js";
29
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
30
+ /**
31
+ ---
32
+ parent: Pagination
33
+ id: Pagination.Page
34
+ ---
35
+ **/
36
+
37
+ class PaginationButton extends Component {
38
+ constructor(...args) {
39
+ super(...args);
40
+ this.ref = null;
41
+ this.handleRef = el => {
42
+ this.ref = el;
43
+ };
44
+ }
45
+ render() {
46
+ const exclude = this.props.current ? ['onClick', 'href'] : [];
47
+ const props = omitProps(this.props, PaginationButton.allowedProps, exclude);
48
+
49
+ // wrapped in an unstyled <li> for better a11y
50
+ return _jsx("li", {
51
+ style: {
52
+ all: 'unset'
53
+ },
54
+ children: _jsx(BaseButton, {
55
+ color: "primary",
56
+ "data-cid": "PaginationButton",
57
+ withBackground: this.props.current,
58
+ withBorder: this.props.current,
59
+ ...props,
60
+ "aria-current": this.props.current ? 'page' : void 0,
61
+ elementRef: this.handleRef,
62
+ ...(this.props.screenReaderLabel ? {
63
+ 'aria-label': this.props.screenReaderLabel
64
+ } : {}),
65
+ children: this.props.children
66
+ })
67
+ });
68
+ }
69
+ }
70
+ PaginationButton.displayName = "PaginationButton";
71
+ PaginationButton.componentId = 'Pagination.Page';
72
+ PaginationButton.allowedProps = allowedProps;
73
+ PaginationButton.defaultProps = {
74
+ current: false
75
+ };
76
+ export default PaginationButton;
77
+ export { PaginationButton };
@@ -0,0 +1,29 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['children', 'current', 'screenReaderLabel'
26
+ // we don't want to pass onClick
27
+ // 'onClick'
28
+ ];
29
+ export { allowedProps };
@@ -0,0 +1,189 @@
1
+ var _dec, _class, _PaginationPageInput;
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 { Component } from 'react';
27
+ import { withStyle } from '@instructure/emotion';
28
+ import { Text } from '@instructure/ui-text/latest';
29
+ import { NumberInput } from '@instructure/ui-number-input/latest';
30
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content';
31
+ import generateStyle from "./styles.js";
32
+ import { allowedProps } from "./props.js";
33
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
34
+ /**
35
+ ---
36
+ parent: Pagination
37
+ id: Pagination.PageInput
38
+ ---
39
+ **/
40
+ let PaginationPageInput = (_dec = withStyle(generateStyle, 'PaginationPageInput'), _dec(_class = (_PaginationPageInput = class PaginationPageInput extends Component {
41
+ constructor(props) {
42
+ super(props);
43
+ this.ref = null;
44
+ this.handleRef = el => {
45
+ this.ref = el;
46
+ };
47
+ this.handleInputRef = el => {
48
+ if (typeof this.props.inputRef === 'function') {
49
+ this.props.inputRef(el);
50
+ }
51
+ };
52
+ this.handleChange = (_event, value) => {
53
+ let newValue = value;
54
+
55
+ // if the last character was not a number, don't accept it
56
+ if (value.length > 0 && isNaN(value.slice(-1))) {
57
+ newValue = value.slice(0, -1);
58
+ }
59
+ this.setState({
60
+ number: newValue ? Number(newValue) : this.MIN,
61
+ value: newValue
62
+ });
63
+ };
64
+ this.handleDecrement = event => {
65
+ this.setNewPage(event, Math.floor(this.currentPage - 1));
66
+ };
67
+ this.handleIncrement = event => {
68
+ this.setNewPage(event, Math.floor(this.currentPage + 1));
69
+ };
70
+ this.handleBlur = event => {
71
+ if (Math.round(this.state.number) !== this.currentPage) {
72
+ this.setNewPage(event, Math.round(this.state.number));
73
+ }
74
+ };
75
+ this.state = this.initialState;
76
+ }
77
+ get currentPage() {
78
+ return this.props.currentPageIndex + 1;
79
+ }
80
+ get initialState() {
81
+ return {
82
+ number: this.currentPage,
83
+ value: `${this.currentPage}`
84
+ };
85
+ }
86
+ get MIN() {
87
+ return 1;
88
+ }
89
+ get MAX() {
90
+ return this.props.numberOfPages;
91
+ }
92
+ componentDidMount() {
93
+ var _this$props$makeStyle, _this$props;
94
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
95
+ }
96
+ componentDidUpdate(prevProps) {
97
+ var _this$props$makeStyle2, _this$props2;
98
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
99
+
100
+ // when the current page changes from outside (e.g.: from arrow buttons),
101
+ // we update the initial state
102
+ if (this.props.currentPageIndex !== prevProps.currentPageIndex) {
103
+ this.resetInitialState();
104
+ }
105
+ }
106
+ resetInitialState() {
107
+ this.setState(this.initialState);
108
+ }
109
+ handleKeyDown(event) {
110
+ const key = event.key;
111
+ if (key.toLowerCase() === 'enter') {
112
+ const _this$state = this.state,
113
+ value = _this$state.value,
114
+ number = _this$state.number;
115
+
116
+ // If it is invalid, we reset the input to the current page
117
+ if (value === '' || isNaN(value)) {
118
+ this.resetInitialState();
119
+ return;
120
+ }
121
+ this.setNewPage(event, number);
122
+ }
123
+ }
124
+ getNumberWithinRange(n) {
125
+ if (n < this.MIN) return this.MIN;
126
+ if (n > this.MAX) return this.MAX;
127
+ return n;
128
+ }
129
+ setNewPage(event, n) {
130
+ const number = this.getNumberWithinRange(n);
131
+ this.setState({
132
+ number,
133
+ value: `${number}`
134
+ });
135
+ this.props.onChange(event, number - 1);
136
+ }
137
+ renderLabel() {
138
+ const _this$props3 = this.props,
139
+ label = _this$props3.label,
140
+ numberOfPages = _this$props3.numberOfPages,
141
+ styles = _this$props3.styles;
142
+ return typeof label === 'function' && label(numberOfPages) ? _jsx(Text, {
143
+ variant: "content",
144
+ children: _jsx("span", {
145
+ css: styles === null || styles === void 0 ? void 0 : styles.inputLabel,
146
+ children: label(numberOfPages)
147
+ })
148
+ }) : null;
149
+ }
150
+ renderScreenReaderLabel() {
151
+ const _this$props4 = this.props,
152
+ screenReaderLabel = _this$props4.screenReaderLabel,
153
+ numberOfPages = _this$props4.numberOfPages;
154
+ return _jsx(ScreenReaderContent, {
155
+ children: screenReaderLabel(this.currentPage, numberOfPages)
156
+ });
157
+ }
158
+ render() {
159
+ const _this$props5 = this.props,
160
+ styles = _this$props5.styles,
161
+ disabled = _this$props5.disabled;
162
+ return _jsxs("span", {
163
+ css: styles === null || styles === void 0 ? void 0 : styles.paginationPageInput,
164
+ ref: this.handleRef,
165
+ "data-cid": "PaginationPageInput",
166
+ children: [_jsx("span", {
167
+ css: styles === null || styles === void 0 ? void 0 : styles.numberInput,
168
+ children: _jsx(NumberInput, {
169
+ renderLabel: this.renderScreenReaderLabel(),
170
+ onBlur: this.handleBlur,
171
+ onChange: this.handleChange,
172
+ onDecrement: this.handleDecrement,
173
+ onIncrement: this.handleIncrement,
174
+ onKeyDown: this.handleKeyDown.bind(this),
175
+ interaction: disabled ? 'disabled' : 'enabled',
176
+ showArrows: false,
177
+ value: this.state.value,
178
+ width: "100%",
179
+ textAlign: "center",
180
+ inputRef: this.handleInputRef
181
+ })
182
+ }), this.renderLabel()]
183
+ });
184
+ }
185
+ }, _PaginationPageInput.displayName = "PaginationPageInput", _PaginationPageInput.componentId = 'Pagination.PageInput', _PaginationPageInput.allowedProps = allowedProps, _PaginationPageInput.defaultProps = {
186
+ disabled: false
187
+ }, _PaginationPageInput)) || _class);
188
+ export default PaginationPageInput;
189
+ export { PaginationPageInput };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['numberOfPages', 'currentPageIndex', 'onChange', 'screenReaderLabel', 'label', 'disabled', 'inputRef'];
26
+ export { allowedProps };
@@ -0,0 +1,56 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} sharedTokens Shared token object that stores common values for the theme.
33
+ * @param {Object} state the state of the component, the style is applied to
34
+ * @return {Object} The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = componentTheme => {
37
+ return {
38
+ paginationPageInput: {
39
+ label: 'paginationPageInput',
40
+ display: 'inline-flex',
41
+ alignItems: 'center',
42
+ margin: `0 ${componentTheme.inputSpacing}`
43
+ },
44
+ numberInput: {
45
+ label: 'paginationPageInput__input',
46
+ width: componentTheme.inputWidth
47
+ },
48
+ inputLabel: {
49
+ label: 'paginationPageInput__inputLabel',
50
+ marginInlineStart: componentTheme.inputSpacing,
51
+ whiteSpace: 'nowrap',
52
+ color: componentTheme.labelColor
53
+ }
54
+ };
55
+ };
56
+ export default generateStyle;