@instructure/ui-position 8.33.1 → 8.33.2
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/Position/PositionContentLocator.js +1 -0
- package/es/Position/PositionLocator.js +2 -7
- package/es/Position/PositionTargetLocator.js +1 -0
- package/es/Position/index.js +4 -41
- package/es/Position/locator.js +1 -0
- package/es/Position/props.js +1 -0
- package/es/Position/styles.js +0 -1
- package/es/Position/theme.js +2 -2
- package/es/PositionPropTypes.js +2 -2
- package/es/calculateElementPosition.js +34 -101
- package/es/executeMirrorFunction.js +4 -6
- package/es/mirrorHorizontalPlacement.js +2 -2
- package/es/mirrorPlacement.js +2 -2
- package/lib/Position/PositionContentLocator.js +1 -3
- package/lib/Position/PositionLocator.js +1 -11
- package/lib/Position/PositionTargetLocator.js +1 -3
- package/lib/Position/index.js +4 -59
- package/lib/Position/locator.js +0 -2
- package/lib/Position/props.js +1 -5
- package/lib/Position/styles.js +0 -2
- package/lib/Position/theme.js +2 -3
- package/lib/PositionPropTypes.js +2 -7
- package/lib/calculateElementPosition.js +32 -110
- package/lib/executeMirrorFunction.js +4 -8
- package/lib/index.js +0 -7
- package/lib/mirrorHorizontalPlacement.js +0 -5
- package/lib/mirrorPlacement.js +0 -5
- package/lib/parsePlacement.js +0 -1
- package/package.json +16 -16
- package/tsconfig.build.tsbuildinfo +1 -1
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.33.2](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2) (2023-01-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-position
|
|
9
|
+
|
|
6
10
|
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-position
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
26
|
import { Position } from './index';
|
|
26
27
|
export const PositionContentLocator = locator(`[${Position.contentLocatorAttribute}]`);
|
|
@@ -29,31 +29,26 @@ export const customMethods = {
|
|
|
29
29
|
findTarget: function (element) {
|
|
30
30
|
if (element && element.getAttribute) {
|
|
31
31
|
const id = element.getAttribute(Position.locatorAttribute);
|
|
32
|
-
|
|
33
32
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
34
33
|
args[_key - 1] = arguments[_key];
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
return locator(`[${Position.targetLocatorAttribute}="${id}"]`).find(...args);
|
|
38
36
|
}
|
|
39
|
-
|
|
40
37
|
throw new Error('Element ' + element + ' not found');
|
|
41
38
|
},
|
|
42
39
|
findContent: function (element) {
|
|
43
40
|
if (element && element.getAttribute) {
|
|
44
41
|
const id = element.getAttribute(Position.locatorAttribute);
|
|
45
|
-
|
|
46
42
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
47
43
|
args[_key2 - 1] = arguments[_key2];
|
|
48
44
|
}
|
|
49
|
-
|
|
50
45
|
return locator(`[${Position.contentLocatorAttribute}="${id}"]`).find(...args);
|
|
51
46
|
}
|
|
52
|
-
|
|
53
47
|
throw new Error('Element ' + element + ' not found');
|
|
54
48
|
}
|
|
55
49
|
};
|
|
56
50
|
export { PositionContentLocator };
|
|
57
|
-
export { PositionTargetLocator };
|
|
51
|
+
export { PositionTargetLocator };
|
|
58
52
|
|
|
53
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
59
54
|
export const PositionLocator = locator(Position.selector, customMethods);
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { Position } from './index';
|
|
25
26
|
import { locator } from '@instructure/ui-test-locator';
|
|
26
27
|
export const PositionTargetLocator = locator(`[${Position.targetLocatorAttribute}]`);
|
package/es/Position/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _dec2, _dec3, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -37,7 +36,6 @@ import generateStyle from './styles';
|
|
|
37
36
|
import generateComponentTheme from './theme';
|
|
38
37
|
import { allowedProps, propTypes } from './props';
|
|
39
38
|
import { calculateElementPosition } from '../calculateElementPosition';
|
|
40
|
-
|
|
41
39
|
/**
|
|
42
40
|
---
|
|
43
41
|
category: components/utilities
|
|
@@ -53,23 +51,18 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
53
51
|
this._listener = null;
|
|
54
52
|
this._content = void 0;
|
|
55
53
|
this._target = void 0;
|
|
56
|
-
|
|
57
54
|
this.handleRef = el => {
|
|
58
55
|
const elementRef = this.props.elementRef;
|
|
59
56
|
this.ref = el;
|
|
60
|
-
|
|
61
57
|
if (typeof elementRef === 'function') {
|
|
62
58
|
elementRef(el);
|
|
63
59
|
}
|
|
64
60
|
};
|
|
65
|
-
|
|
66
61
|
this.handlePortalOpen = () => {
|
|
67
62
|
this.position();
|
|
68
|
-
|
|
69
63
|
if (this.props.shouldTrackPosition) {
|
|
70
64
|
this.startTracking();
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
this._timeouts.push(setTimeout(() => {
|
|
74
67
|
if (this.state.positioned && typeof this.props.onPositioned === 'function') {
|
|
75
68
|
this.props.onPositioned({
|
|
@@ -80,14 +73,12 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
80
73
|
}
|
|
81
74
|
}, 0));
|
|
82
75
|
};
|
|
83
|
-
|
|
84
76
|
this.position = () => {
|
|
85
77
|
this.setState({
|
|
86
78
|
positioned: true,
|
|
87
79
|
...this.calculatePosition(this.props)
|
|
88
80
|
});
|
|
89
81
|
};
|
|
90
|
-
|
|
91
82
|
this.state = {
|
|
92
83
|
positioned: false,
|
|
93
84
|
...this.calculatePosition(props)
|
|
@@ -98,32 +89,24 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
98
89
|
});
|
|
99
90
|
this._id = this.props.id || props.deterministicId();
|
|
100
91
|
}
|
|
101
|
-
|
|
102
92
|
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
|
103
93
|
return !deepEqual(this.state, nextState) || !shallowEqual(this.props, nextProps) || !shallowEqual(this.context, nextContext);
|
|
104
94
|
}
|
|
105
|
-
|
|
106
95
|
componentDidMount() {
|
|
107
96
|
var _this$props$makeStyle, _this$props;
|
|
108
|
-
|
|
109
97
|
this.toggleLocatorAttributes(true);
|
|
110
98
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
111
99
|
}
|
|
112
|
-
|
|
113
100
|
componentDidUpdate(prevProps, prevState) {
|
|
114
101
|
var _this$props$makeStyle2, _this$props2;
|
|
115
|
-
|
|
116
102
|
this.position();
|
|
117
103
|
this.toggleLocatorAttributes(true);
|
|
118
|
-
|
|
119
104
|
if (this.props.shouldTrackPosition !== prevProps.shouldTrackPosition) {
|
|
120
105
|
this.props.shouldTrackPosition ? this.startTracking() : this.stopTracking();
|
|
121
106
|
}
|
|
122
|
-
|
|
123
107
|
const _this$state = this.state,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
108
|
+
style = _this$state.style,
|
|
109
|
+
placement = _this$state.placement;
|
|
127
110
|
if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left) && typeof this.props.onPositionChanged === 'function') {
|
|
128
111
|
this.props.onPositionChanged({
|
|
129
112
|
top: style.top,
|
|
@@ -131,20 +114,15 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
131
114
|
placement
|
|
132
115
|
});
|
|
133
116
|
}
|
|
134
|
-
|
|
135
117
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
136
118
|
}
|
|
137
|
-
|
|
138
119
|
componentWillUnmount() {
|
|
139
120
|
;
|
|
140
121
|
this.position.cancel();
|
|
141
122
|
this.stopTracking();
|
|
142
|
-
|
|
143
123
|
this._timeouts.forEach(timeout => clearTimeout(timeout));
|
|
144
|
-
|
|
145
124
|
this.toggleLocatorAttributes(false);
|
|
146
125
|
}
|
|
147
|
-
|
|
148
126
|
toggleLocatorAttributes(set) {
|
|
149
127
|
// We have to find the actual DOM nodes and append the attributes
|
|
150
128
|
// directly, as we can't be sure when safe cloning the child that
|
|
@@ -152,21 +130,18 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
152
130
|
this.toggleLocatorAttribute(findDOMNode(this._content), Position.contentLocatorAttribute, set);
|
|
153
131
|
this.toggleLocatorAttribute(findDOMNode(this._target), Position.targetLocatorAttribute, set);
|
|
154
132
|
}
|
|
155
|
-
|
|
156
133
|
toggleLocatorAttribute(node, locator, set) {
|
|
157
134
|
if (node && node.hasAttribute) {
|
|
158
135
|
if (set && !node.hasAttribute(locator)) {
|
|
159
136
|
;
|
|
160
137
|
node.setAttribute(locator, this._id);
|
|
161
138
|
}
|
|
162
|
-
|
|
163
139
|
if (!set && node.hasAttribute(locator)) {
|
|
164
140
|
;
|
|
165
141
|
node.removeAttribute(locator);
|
|
166
142
|
}
|
|
167
143
|
}
|
|
168
144
|
}
|
|
169
|
-
|
|
170
145
|
calculatePosition(props) {
|
|
171
146
|
return calculateElementPosition(this._content, this._target, {
|
|
172
147
|
placement: props.placement,
|
|
@@ -177,26 +152,21 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
177
152
|
over: props.shouldPositionOverTarget
|
|
178
153
|
});
|
|
179
154
|
}
|
|
180
|
-
|
|
181
155
|
startTracking() {
|
|
182
156
|
this._listener = this._listener || addPositionChangeListener(this._target, this.position);
|
|
183
157
|
}
|
|
184
|
-
|
|
185
158
|
stopTracking() {
|
|
186
159
|
if (this._listener) {
|
|
187
160
|
this._listener.remove();
|
|
188
|
-
|
|
189
161
|
this._listener = null;
|
|
190
162
|
}
|
|
191
|
-
}
|
|
192
|
-
|
|
163
|
+
}
|
|
193
164
|
|
|
165
|
+
// content that needs to be positioned relative to the target
|
|
194
166
|
renderContent() {
|
|
195
167
|
let content = ensureSingleChild(this.props.children);
|
|
196
|
-
|
|
197
168
|
if (content) {
|
|
198
169
|
var _this$props$styles;
|
|
199
|
-
|
|
200
170
|
content = safeCloneElement(content, {
|
|
201
171
|
ref: el => {
|
|
202
172
|
this._content = el;
|
|
@@ -219,13 +189,10 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
219
189
|
insertAt: this.props.insertAt
|
|
220
190
|
}, content);
|
|
221
191
|
}
|
|
222
|
-
|
|
223
192
|
return content;
|
|
224
193
|
}
|
|
225
|
-
|
|
226
194
|
renderTarget() {
|
|
227
195
|
const target = callRenderProp(this.props.renderTarget);
|
|
228
|
-
|
|
229
196
|
if (target) {
|
|
230
197
|
return safeCloneElement(target, {
|
|
231
198
|
ref: el => {
|
|
@@ -236,13 +203,10 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
236
203
|
} else if (this.props.target) {
|
|
237
204
|
this._target = callRenderProp(this.props.target);
|
|
238
205
|
}
|
|
239
|
-
|
|
240
206
|
return null;
|
|
241
207
|
}
|
|
242
|
-
|
|
243
208
|
render() {
|
|
244
209
|
var _this$props$styles2;
|
|
245
|
-
|
|
246
210
|
const props = {
|
|
247
211
|
[Position.locatorAttribute]: this._id
|
|
248
212
|
};
|
|
@@ -251,7 +215,6 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
251
215
|
ref: this.handleRef
|
|
252
216
|
}), this.renderTarget(), this.renderContent());
|
|
253
217
|
}
|
|
254
|
-
|
|
255
218
|
}, _class2.displayName = "Position", _class2.componentId = 'Position', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
256
219
|
placement: 'bottom center',
|
|
257
220
|
mountNode: null,
|
package/es/Position/locator.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { PositionLocator } from './PositionLocator';
|
|
25
26
|
export { PositionContentLocator, PositionTargetLocator, customMethods } from './PositionLocator';
|
|
26
27
|
export { PositionLocator };
|
package/es/Position/props.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import PropTypes from 'prop-types';
|
|
25
26
|
import { element } from '@instructure/ui-prop-types';
|
|
26
27
|
import { PositionPropTypes } from '../PositionPropTypes';
|
package/es/Position/styles.js
CHANGED
package/es/Position/theme.js
CHANGED
|
@@ -32,8 +32,8 @@ const generateComponentTheme = theme => {
|
|
|
32
32
|
const componentVariables = {
|
|
33
33
|
zIndex: stacking === null || stacking === void 0 ? void 0 : stacking.topmost
|
|
34
34
|
};
|
|
35
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
...componentVariables
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
|
-
|
|
39
39
|
export default generateComponentTheme;
|
package/es/PositionPropTypes.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import PropTypes from 'prop-types';
|
|
25
26
|
import { element } from '@instructure/ui-prop-types';
|
|
26
27
|
const placementPropValues = ['top', 'bottom', 'start', 'end', 'top start', 'top center', 'top end', 'top stretch', 'bottom start', 'bottom center', 'bottom end', 'bottom stretch', 'start top', 'start center', 'start bottom', 'start stretch', 'end top', 'end center', 'end bottom', 'end stretch', 'center start', 'center end', 'offscreen'];
|
|
@@ -29,17 +30,16 @@ const PositionPropTypes = {
|
|
|
29
30
|
* The placement of the content in relation to the trigger
|
|
30
31
|
*/
|
|
31
32
|
placement: PropTypes.oneOf(placementPropValues),
|
|
32
|
-
|
|
33
33
|
/**
|
|
34
34
|
* An element or a function returning an element to use as the mount node
|
|
35
35
|
*/
|
|
36
36
|
mountNode: PropTypes.oneOfType([element, PropTypes.func]),
|
|
37
|
-
|
|
38
37
|
/**
|
|
39
38
|
* The parent in which to constrain a placement
|
|
40
39
|
*/
|
|
41
40
|
constrain: PropTypes.oneOfType([element, PropTypes.func, PropTypes.oneOf(['window', 'scroll-parent', 'parent', 'none'])])
|
|
42
41
|
};
|
|
42
|
+
|
|
43
43
|
/**
|
|
44
44
|
* The placement of the content in relation to the trigger
|
|
45
45
|
*/
|