@instructure/ui-pages 8.12.1-snapshot.7 → 8.13.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.
- package/CHANGELOG.md +4 -0
- package/es/Pages/Page/index.js +18 -15
- package/es/Pages/Page/props.js +0 -11
- package/es/Pages/PagesContext.js +30 -0
- package/es/Pages/index.js +24 -22
- package/es/Pages/props.js +0 -14
- package/lib/Pages/Page/index.js +18 -15
- package/lib/Pages/Page/props.js +1 -12
- package/lib/Pages/PagesContext.js +39 -0
- package/lib/Pages/index.js +24 -23
- package/lib/Pages/props.js +1 -15
- package/package.json +14 -17
- package/src/Pages/Page/index.tsx +9 -10
- package/src/Pages/Page/props.ts +22 -15
- package/src/Pages/PagesContext.ts +39 -0
- package/src/Pages/README.md +3 -6
- package/src/Pages/index.tsx +33 -46
- package/src/Pages/props.ts +21 -18
- package/types/Pages/Page/index.d.ts +7 -6
- package/types/Pages/Page/index.d.ts.map +1 -1
- package/types/Pages/Page/props.d.ts +13 -3
- package/types/Pages/Page/props.d.ts.map +1 -1
- package/types/Pages/PagesContext.d.ts +10 -0
- package/types/Pages/PagesContext.d.ts.map +1 -0
- package/types/Pages/index.d.ts +15 -17
- package/types/Pages/index.d.ts.map +1 -1
- package/types/Pages/props.d.ts +17 -3
- package/types/Pages/props.d.ts.map +1 -1
- package/LICENSE.md +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [8.13.0](https://github.com/instructure/instructure-ui/compare/v8.12.0...v8.13.0) (2021-12-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-pages
|
|
9
|
+
|
|
6
10
|
# [8.12.0](https://github.com/instructure/instructure-ui/compare/v8.11.1...v8.12.0) (2021-11-17)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-pages
|
package/es/Pages/Page/index.js
CHANGED
|
@@ -29,18 +29,19 @@ import PropTypes from 'prop-types';
|
|
|
29
29
|
import { findDOMNode, findTabbable } from '@instructure/ui-dom-utils';
|
|
30
30
|
import { logError as error } from '@instructure/console';
|
|
31
31
|
import { View } from '@instructure/ui-view';
|
|
32
|
-
import { PagesContext } from '
|
|
32
|
+
import { PagesContext } from '../PagesContext';
|
|
33
33
|
import { allowedProps, propTypes } from './props';
|
|
34
|
+
|
|
34
35
|
/**
|
|
35
36
|
---
|
|
36
37
|
parent: Pages
|
|
37
38
|
id: Pages.Page
|
|
38
39
|
---
|
|
40
|
+
@tsProps
|
|
39
41
|
**/
|
|
40
|
-
|
|
41
42
|
class Page extends Component {
|
|
42
|
-
constructor(
|
|
43
|
-
super(...
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
44
45
|
this.ref = null;
|
|
45
46
|
|
|
46
47
|
this.handleRef = el => {
|
|
@@ -68,17 +69,18 @@ class Page extends Component {
|
|
|
68
69
|
defaultFocusElement = tabbable && tabbable[0];
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
error(defaultFocusElement && defaultFocusElement.focus, '[Page] A default focusable element is required or focus will be lost.');
|
|
72
|
+
error(defaultFocusElement && !!defaultFocusElement.focus, '[Page] A default focusable element is required or focus will be lost.');
|
|
72
73
|
return defaultFocusElement;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
get focusable() {
|
|
76
77
|
const element = this.defaultFocusElement;
|
|
77
|
-
return element && typeof element.focus === 'function';
|
|
78
|
+
return !!element && typeof element.focus === 'function';
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
focus() {
|
|
81
82
|
if (this.focusable) {
|
|
83
|
+
;
|
|
82
84
|
this.defaultFocusElement.focus();
|
|
83
85
|
}
|
|
84
86
|
}
|
|
@@ -88,15 +90,16 @@ class Page extends Component {
|
|
|
88
90
|
children = _this$props.children,
|
|
89
91
|
props = _objectWithoutProperties(_this$props, _excluded);
|
|
90
92
|
|
|
91
|
-
return /*#__PURE__*/React.createElement(PagesContext.Consumer, null,
|
|
92
|
-
history,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
return /*#__PURE__*/React.createElement(PagesContext.Consumer, null, _ref => {
|
|
94
|
+
let history = _ref.history,
|
|
95
|
+
navigateToPreviousPage = _ref.navigateToPreviousPage;
|
|
96
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
97
|
+
as: "div",
|
|
98
|
+
padding: props.padding,
|
|
99
|
+
textAlign: props.textAlign,
|
|
100
|
+
elementRef: this.handleRef
|
|
101
|
+
}, children && typeof children === 'function' ? children(history, navigateToPreviousPage) : children);
|
|
102
|
+
});
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
}
|
package/es/Pages/Page/props.js
CHANGED
|
@@ -24,19 +24,8 @@
|
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
import { ThemeablePropTypes } from '@instructure/emotion';
|
|
26
26
|
const propTypes = {
|
|
27
|
-
/**
|
|
28
|
-
* The children to be rendered
|
|
29
|
-
*/
|
|
30
27
|
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* An element or a function returning an element to focus by default
|
|
34
|
-
*/
|
|
35
28
|
defaultFocusElement: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Set the padding using familiar CSS shorthand
|
|
39
|
-
*/
|
|
40
29
|
padding: ThemeablePropTypes.spacing,
|
|
41
30
|
textAlign: PropTypes.oneOf(['start', 'center', 'end'])
|
|
42
31
|
};
|
|
@@ -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
|
+
import { createContext } from 'react';
|
|
25
|
+
const PagesContext = /*#__PURE__*/createContext({
|
|
26
|
+
history: [],
|
|
27
|
+
navigateToPreviousPage: () => {}
|
|
28
|
+
});
|
|
29
|
+
export default PagesContext;
|
|
30
|
+
export { PagesContext };
|
package/es/Pages/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var _dec, _class, _class2, _temp;
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/** @jsx jsx */
|
|
28
|
-
import React, { Component
|
|
28
|
+
import React, { Component } from 'react';
|
|
29
29
|
import { View } from '@instructure/ui-view';
|
|
30
30
|
import { containsActiveElement, findTabbable } from '@instructure/ui-dom-utils';
|
|
31
31
|
import { safeCloneElement } from '@instructure/ui-react-utils';
|
|
@@ -35,17 +35,15 @@ import { Page } from './Page';
|
|
|
35
35
|
import { withStyle, jsx } from '@instructure/emotion';
|
|
36
36
|
import generateStyle from './styles';
|
|
37
37
|
import generateComponentTheme from './theme';
|
|
38
|
+
import { PagesContext } from './PagesContext';
|
|
38
39
|
import { allowedProps, propTypes } from './props';
|
|
39
|
-
|
|
40
|
-
history: [],
|
|
41
|
-
navigateToPreviousPage: () => {}
|
|
42
|
-
});
|
|
40
|
+
|
|
43
41
|
/**
|
|
44
42
|
---
|
|
45
43
|
category: components
|
|
46
44
|
---
|
|
45
|
+
@tsProps
|
|
47
46
|
**/
|
|
48
|
-
|
|
49
47
|
let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Pages extends Component {
|
|
50
48
|
get _contentElement() {
|
|
51
49
|
return this.ref;
|
|
@@ -54,6 +52,9 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
54
52
|
constructor(props) {
|
|
55
53
|
super(props);
|
|
56
54
|
this._timeouts = [];
|
|
55
|
+
this._history = void 0;
|
|
56
|
+
this._activePage = null;
|
|
57
|
+
this._contentId = void 0;
|
|
57
58
|
this.ref = null;
|
|
58
59
|
|
|
59
60
|
this.handleRef = el => {
|
|
@@ -61,10 +62,12 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
this.handleBackButtonClick = () => {
|
|
65
|
+
var _this$props$onPageInd, _this$props;
|
|
66
|
+
|
|
64
67
|
const oldPageIndex = this._history.pop();
|
|
65
68
|
|
|
66
69
|
const newPageIndex = this._history[this._history.length - 1];
|
|
67
|
-
this.props.onPageIndexChange(newPageIndex || 0, oldPageIndex);
|
|
70
|
+
(_this$props$onPageInd = (_this$props = this.props).onPageIndexChange) === null || _this$props$onPageInd === void 0 ? void 0 : _this$props$onPageInd.call(_this$props, newPageIndex || 0, oldPageIndex);
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
this._history = [typeof props.defaultPageIndex === 'number' ? props.defaultPageIndex : props.activePageIndex];
|
|
@@ -72,25 +75,26 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
componentDidMount() {
|
|
75
|
-
var _this$props$makeStyle, _this$
|
|
78
|
+
var _this$props$makeStyle, _this$props2;
|
|
76
79
|
|
|
77
|
-
(_this$props$makeStyle = (_this$
|
|
80
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
componentWillReceiveProps
|
|
83
|
+
// TODO: componentWillReceiveProps has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.
|
|
84
|
+
componentWillReceiveProps(nextProps) {
|
|
81
85
|
if (nextProps && typeof nextProps.activePageIndex === 'number' && (this._history.length === 0 || nextProps.activePageIndex !== this._history[this._history.length - 1])) {
|
|
82
86
|
this._history.push(nextProps.activePageIndex);
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
componentDidUpdate() {
|
|
87
|
-
var _this$props$makeStyle2, _this$
|
|
91
|
+
var _this$props$makeStyle2, _this$props3;
|
|
88
92
|
|
|
89
93
|
this._timeouts.push(setTimeout(() => {
|
|
90
94
|
!this.focused && this.focus();
|
|
91
95
|
}, 0));
|
|
92
96
|
|
|
93
|
-
(_this$props$makeStyle2 = (_this$
|
|
97
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
componentWillUnmount() {
|
|
@@ -117,12 +121,12 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
get activePage() {
|
|
120
|
-
const _this$
|
|
121
|
-
activePageIndex = _this$
|
|
122
|
-
children = _this$
|
|
124
|
+
const _this$props4 = this.props,
|
|
125
|
+
activePageIndex = _this$props4.activePageIndex,
|
|
126
|
+
children = _this$props4.children;
|
|
123
127
|
const pages = React.Children.toArray(children);
|
|
124
128
|
const activePage = activePageIndex < pages.length ? pages[activePageIndex] : null;
|
|
125
|
-
error(activePage, '[Pages] Invalid `activePageIndex`.');
|
|
129
|
+
error(!!activePage, '[Pages] Invalid `activePageIndex`.');
|
|
126
130
|
return activePage ? safeCloneElement(activePage, {
|
|
127
131
|
ref: el => {
|
|
128
132
|
this._activePage = el;
|
|
@@ -133,7 +137,8 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
133
137
|
render() {
|
|
134
138
|
var _this$props$styles;
|
|
135
139
|
|
|
136
|
-
|
|
140
|
+
const activePage = this.activePage;
|
|
141
|
+
return activePage ? jsx(PagesContext.Provider, {
|
|
137
142
|
value: {
|
|
138
143
|
history: this._history,
|
|
139
144
|
navigateToPreviousPage: () => {
|
|
@@ -147,14 +152,11 @@ let Pages = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
147
152
|
margin: this.props.margin,
|
|
148
153
|
role: "region",
|
|
149
154
|
elementRef: this.handleRef
|
|
150
|
-
},
|
|
155
|
+
}, activePage)) : null;
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
}, _class2.displayName = "Pages", _class2.componentId = 'Pages', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
154
|
-
|
|
155
|
-
defaultPageIndex: null,
|
|
156
|
-
activePageIndex: 0,
|
|
157
|
-
onPageIndexChange: function () {}
|
|
159
|
+
activePageIndex: 0
|
|
158
160
|
}, _class2.Page = Page, _temp)) || _class);
|
|
159
161
|
export default Pages;
|
|
160
162
|
export { Pages, Page };
|
package/es/Pages/props.js
CHANGED
|
@@ -28,22 +28,8 @@ import { Page } from './Page';
|
|
|
28
28
|
const propTypes = {
|
|
29
29
|
children: Children.oneOf([Page]),
|
|
30
30
|
defaultPageIndex: PropTypes.number,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The currently active page index
|
|
34
|
-
*/
|
|
35
31
|
activePageIndex: controllable(PropTypes.number, 'onPageIndexChange', 'defaultPageIndex'),
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Event handler fired anytime page index has changed due to back button being clicked
|
|
39
|
-
*/
|
|
40
32
|
onPageIndexChange: PropTypes.func,
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
44
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
45
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
46
|
-
*/
|
|
47
33
|
margin: ThemeablePropTypes.spacing
|
|
48
34
|
};
|
|
49
35
|
const allowedProps = ['children', 'defaultPageIndex', 'activePageIndex', 'onPageIndexChange', 'margin'];
|
package/lib/Pages/Page/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports.
|
|
10
|
+
exports.default = exports.Page = void 0;
|
|
11
11
|
|
|
12
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
13
|
|
|
@@ -23,7 +23,7 @@ var _console = require("@instructure/console");
|
|
|
23
23
|
|
|
24
24
|
var _View = require("@instructure/ui-view/lib/View");
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _PagesContext = require("../PagesContext");
|
|
27
27
|
|
|
28
28
|
var _props = require("./props");
|
|
29
29
|
|
|
@@ -34,10 +34,11 @@ const _excluded = ["children"];
|
|
|
34
34
|
parent: Pages
|
|
35
35
|
id: Pages.Page
|
|
36
36
|
---
|
|
37
|
+
@tsProps
|
|
37
38
|
**/
|
|
38
39
|
class Page extends _react.Component {
|
|
39
|
-
constructor(
|
|
40
|
-
super(...
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
41
42
|
this.ref = null;
|
|
42
43
|
|
|
43
44
|
this.handleRef = el => {
|
|
@@ -65,17 +66,18 @@ class Page extends _react.Component {
|
|
|
65
66
|
defaultFocusElement = tabbable && tabbable[0];
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
(0, _console.logError)(defaultFocusElement && defaultFocusElement.focus, '[Page] A default focusable element is required or focus will be lost.');
|
|
69
|
+
(0, _console.logError)(defaultFocusElement && !!defaultFocusElement.focus, '[Page] A default focusable element is required or focus will be lost.');
|
|
69
70
|
return defaultFocusElement;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
get focusable() {
|
|
73
74
|
const element = this.defaultFocusElement;
|
|
74
|
-
return element && typeof element.focus === 'function';
|
|
75
|
+
return !!element && typeof element.focus === 'function';
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
focus() {
|
|
78
79
|
if (this.focusable) {
|
|
80
|
+
;
|
|
79
81
|
this.defaultFocusElement.focus();
|
|
80
82
|
}
|
|
81
83
|
}
|
|
@@ -84,15 +86,16 @@ class Page extends _react.Component {
|
|
|
84
86
|
const _this$props = this.props,
|
|
85
87
|
children = _this$props.children,
|
|
86
88
|
props = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
87
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
88
|
-
history,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(_PagesContext.PagesContext.Consumer, null, _ref => {
|
|
90
|
+
let history = _ref.history,
|
|
91
|
+
navigateToPreviousPage = _ref.navigateToPreviousPage;
|
|
92
|
+
return /*#__PURE__*/_react.default.createElement(_View.View, {
|
|
93
|
+
as: "div",
|
|
94
|
+
padding: props.padding,
|
|
95
|
+
textAlign: props.textAlign,
|
|
96
|
+
elementRef: this.handleRef
|
|
97
|
+
}, children && typeof children === 'function' ? children(history, navigateToPreviousPage) : children);
|
|
98
|
+
});
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
}
|
package/lib/Pages/Page/props.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.propTypes = exports.allowedProps = void 0;
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -35,19 +35,8 @@ var _emotion = require("@instructure/emotion");
|
|
|
35
35
|
* SOFTWARE.
|
|
36
36
|
*/
|
|
37
37
|
const propTypes = {
|
|
38
|
-
/**
|
|
39
|
-
* The children to be rendered
|
|
40
|
-
*/
|
|
41
38
|
children: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* An element or a function returning an element to focus by default
|
|
45
|
-
*/
|
|
46
39
|
defaultFocusElement: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set the padding using familiar CSS shorthand
|
|
50
|
-
*/
|
|
51
40
|
padding: _emotion.ThemeablePropTypes.spacing,
|
|
52
41
|
textAlign: _propTypes.default.oneOf(['start', 'center', 'end'])
|
|
53
42
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.PagesContext = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
const PagesContext = /*#__PURE__*/(0, _react.createContext)({
|
|
34
|
+
history: [],
|
|
35
|
+
navigateToPreviousPage: () => {}
|
|
36
|
+
});
|
|
37
|
+
exports.PagesContext = PagesContext;
|
|
38
|
+
var _default = PagesContext;
|
|
39
|
+
exports.default = _default;
|
package/lib/Pages/index.js
CHANGED
|
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "Page", {
|
|
|
13
13
|
return _Page.Page;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
exports.
|
|
16
|
+
exports.default = exports.Pages = void 0;
|
|
17
17
|
|
|
18
18
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
19
|
|
|
@@ -37,21 +37,18 @@ var _styles = _interopRequireDefault(require("./styles"));
|
|
|
37
37
|
|
|
38
38
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
39
39
|
|
|
40
|
+
var _PagesContext = require("./PagesContext");
|
|
41
|
+
|
|
40
42
|
var _props = require("./props");
|
|
41
43
|
|
|
42
44
|
var _dec, _class, _class2, _temp;
|
|
43
45
|
|
|
44
|
-
const PagesContext = /*#__PURE__*/(0, _react.createContext)({
|
|
45
|
-
history: [],
|
|
46
|
-
navigateToPreviousPage: () => {}
|
|
47
|
-
});
|
|
48
46
|
/**
|
|
49
47
|
---
|
|
50
48
|
category: components
|
|
51
49
|
---
|
|
50
|
+
@tsProps
|
|
52
51
|
**/
|
|
53
|
-
|
|
54
|
-
exports.PagesContext = PagesContext;
|
|
55
52
|
let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_temp = _class2 = class Pages extends _react.Component {
|
|
56
53
|
get _contentElement() {
|
|
57
54
|
return this.ref;
|
|
@@ -60,6 +57,9 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
60
57
|
constructor(props) {
|
|
61
58
|
super(props);
|
|
62
59
|
this._timeouts = [];
|
|
60
|
+
this._history = void 0;
|
|
61
|
+
this._activePage = null;
|
|
62
|
+
this._contentId = void 0;
|
|
63
63
|
this.ref = null;
|
|
64
64
|
|
|
65
65
|
this.handleRef = el => {
|
|
@@ -67,10 +67,12 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
this.handleBackButtonClick = () => {
|
|
70
|
+
var _this$props$onPageInd, _this$props;
|
|
71
|
+
|
|
70
72
|
const oldPageIndex = this._history.pop();
|
|
71
73
|
|
|
72
74
|
const newPageIndex = this._history[this._history.length - 1];
|
|
73
|
-
this.props.onPageIndexChange(newPageIndex || 0, oldPageIndex);
|
|
75
|
+
(_this$props$onPageInd = (_this$props = this.props).onPageIndexChange) === null || _this$props$onPageInd === void 0 ? void 0 : _this$props$onPageInd.call(_this$props, newPageIndex || 0, oldPageIndex);
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
this._history = [typeof props.defaultPageIndex === 'number' ? props.defaultPageIndex : props.activePageIndex];
|
|
@@ -78,25 +80,26 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
componentDidMount() {
|
|
81
|
-
var _this$props$makeStyle, _this$
|
|
83
|
+
var _this$props$makeStyle, _this$props2;
|
|
82
84
|
|
|
83
|
-
(_this$props$makeStyle = (_this$
|
|
85
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
componentWillReceiveProps
|
|
88
|
+
// TODO: componentWillReceiveProps has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.
|
|
89
|
+
componentWillReceiveProps(nextProps) {
|
|
87
90
|
if (nextProps && typeof nextProps.activePageIndex === 'number' && (this._history.length === 0 || nextProps.activePageIndex !== this._history[this._history.length - 1])) {
|
|
88
91
|
this._history.push(nextProps.activePageIndex);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
componentDidUpdate() {
|
|
93
|
-
var _this$props$makeStyle2, _this$
|
|
96
|
+
var _this$props$makeStyle2, _this$props3;
|
|
94
97
|
|
|
95
98
|
this._timeouts.push(setTimeout(() => {
|
|
96
99
|
!this.focused && this.focus();
|
|
97
100
|
}, 0));
|
|
98
101
|
|
|
99
|
-
(_this$props$makeStyle2 = (_this$
|
|
102
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
componentWillUnmount() {
|
|
@@ -123,14 +126,14 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
get activePage() {
|
|
126
|
-
const _this$
|
|
127
|
-
activePageIndex = _this$
|
|
128
|
-
children = _this$
|
|
129
|
+
const _this$props4 = this.props,
|
|
130
|
+
activePageIndex = _this$props4.activePageIndex,
|
|
131
|
+
children = _this$props4.children;
|
|
129
132
|
|
|
130
133
|
const pages = _react.default.Children.toArray(children);
|
|
131
134
|
|
|
132
135
|
const activePage = activePageIndex < pages.length ? pages[activePageIndex] : null;
|
|
133
|
-
(0, _console.logError)(activePage, '[Pages] Invalid `activePageIndex`.');
|
|
136
|
+
(0, _console.logError)(!!activePage, '[Pages] Invalid `activePageIndex`.');
|
|
134
137
|
return activePage ? (0, _safeCloneElement.safeCloneElement)(activePage, {
|
|
135
138
|
ref: el => {
|
|
136
139
|
this._activePage = el;
|
|
@@ -141,7 +144,8 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
141
144
|
render() {
|
|
142
145
|
var _this$props$styles;
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
const activePage = this.activePage;
|
|
148
|
+
return activePage ? (0, _emotion.jsx)(_PagesContext.PagesContext.Provider, {
|
|
145
149
|
value: {
|
|
146
150
|
history: this._history,
|
|
147
151
|
navigateToPreviousPage: () => {
|
|
@@ -155,14 +159,11 @@ let Pages = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
155
159
|
margin: this.props.margin,
|
|
156
160
|
role: "region",
|
|
157
161
|
elementRef: this.handleRef
|
|
158
|
-
},
|
|
162
|
+
}, activePage)) : null;
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
}, _class2.displayName = "Pages", _class2.componentId = 'Pages', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
|
162
|
-
|
|
163
|
-
defaultPageIndex: null,
|
|
164
|
-
activePageIndex: 0,
|
|
165
|
-
onPageIndexChange: function () {}
|
|
166
|
+
activePageIndex: 0
|
|
166
167
|
}, _class2.Page = _Page.Page, _temp)) || _class);
|
|
167
168
|
exports.Pages = Pages;
|
|
168
169
|
var _default = Pages;
|
package/lib/Pages/props.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.propTypes = exports.allowedProps = void 0;
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -43,22 +43,8 @@ var _Page = require("./Page");
|
|
|
43
43
|
const propTypes = {
|
|
44
44
|
children: _Children.Children.oneOf([_Page.Page]),
|
|
45
45
|
defaultPageIndex: _propTypes.default.number,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The currently active page index
|
|
49
|
-
*/
|
|
50
46
|
activePageIndex: (0, _controllable.controllable)(_propTypes.default.number, 'onPageIndexChange', 'defaultPageIndex'),
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Event handler fired anytime page index has changed due to back button being clicked
|
|
54
|
-
*/
|
|
55
47
|
onPageIndexChange: _propTypes.default.func,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
59
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
60
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
61
|
-
*/
|
|
62
48
|
margin: _emotion.ThemeablePropTypes.spacing
|
|
63
49
|
};
|
|
64
50
|
exports.propTypes = propTypes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-pages",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.13.0",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,23 +24,21 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/ui-babel-preset": "8.
|
|
28
|
-
"@instructure/ui-color-utils": "8.
|
|
29
|
-
"@instructure/ui-test-utils": "8.
|
|
30
|
-
"@instructure/ui-themes": "8.
|
|
27
|
+
"@instructure/ui-babel-preset": "8.13.0",
|
|
28
|
+
"@instructure/ui-color-utils": "8.13.0",
|
|
29
|
+
"@instructure/ui-test-utils": "8.13.0",
|
|
30
|
+
"@instructure/ui-themes": "8.13.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.13.10",
|
|
34
|
-
"@instructure/console": "8.
|
|
35
|
-
"@instructure/emotion": "8.
|
|
36
|
-
"@instructure/shared-types": "8.
|
|
37
|
-
"@instructure/ui-
|
|
38
|
-
"@instructure/ui-
|
|
39
|
-
"@instructure/ui-
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/
|
|
42
|
-
"@instructure/ui-view": "8.12.1-snapshot.7+1e7ac8219",
|
|
43
|
-
"@instructure/uid": "8.12.1-snapshot.7+1e7ac8219",
|
|
34
|
+
"@instructure/console": "8.13.0",
|
|
35
|
+
"@instructure/emotion": "8.13.0",
|
|
36
|
+
"@instructure/shared-types": "8.13.0",
|
|
37
|
+
"@instructure/ui-dom-utils": "8.13.0",
|
|
38
|
+
"@instructure/ui-prop-types": "8.13.0",
|
|
39
|
+
"@instructure/ui-react-utils": "8.13.0",
|
|
40
|
+
"@instructure/ui-view": "8.13.0",
|
|
41
|
+
"@instructure/uid": "8.13.0",
|
|
44
42
|
"prop-types": "^15"
|
|
45
43
|
},
|
|
46
44
|
"peerDependencies": {
|
|
@@ -49,6 +47,5 @@
|
|
|
49
47
|
"publishConfig": {
|
|
50
48
|
"access": "public"
|
|
51
49
|
},
|
|
52
|
-
"sideEffects": false
|
|
53
|
-
"gitHead": "1e7ac821932a91fe9ef761c96f747c7ea1f3925a"
|
|
50
|
+
"sideEffects": false
|
|
54
51
|
}
|