@instructure/ui-position 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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 +5 -2
- package/es/Position/index.js +64 -58
- package/es/Position/theme.js +4 -2
- package/es/calculateElementPosition.js +43 -46
- package/es/executeMirrorFunction.js +1 -5
- package/lib/Position/index.js +64 -58
- package/lib/Position/theme.js +4 -2
- package/lib/calculateElementPosition.js +45 -49
- package/lib/executeMirrorFunction.js +1 -6
- package/package.json +13 -13
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
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
|
-
## [11.7.3-snapshot-
|
|
6
|
+
## [11.7.3-snapshot-26](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-26) (2026-05-05)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** update dependencies, remove lots of Babel plugins, remove Webpack 4 support ([f916fca](https://github.com/instructure/instructure-ui/commit/f916fcafdddcb2d7de401f93e8ff92cfdfa47bba))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/es/Position/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _dec, _dec2, _class
|
|
1
|
+
var _dec, _dec2, _class;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -40,43 +40,26 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
40
40
|
category: components/utilities
|
|
41
41
|
---
|
|
42
42
|
**/
|
|
43
|
-
let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class =
|
|
43
|
+
let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = class Position extends Component {
|
|
44
|
+
static displayName = "Position";
|
|
45
|
+
static componentId = 'Position';
|
|
46
|
+
static allowedProps = allowedProps;
|
|
47
|
+
static defaultProps = {
|
|
48
|
+
placement: 'bottom center',
|
|
49
|
+
mountNode: null,
|
|
50
|
+
insertAt: 'bottom',
|
|
51
|
+
constrain: 'window',
|
|
52
|
+
offsetX: 0,
|
|
53
|
+
offsetY: 0,
|
|
54
|
+
shouldTrackPosition: true,
|
|
55
|
+
shouldPositionOverTarget: false,
|
|
56
|
+
children: null
|
|
57
|
+
};
|
|
58
|
+
static locatorAttribute = 'data-position';
|
|
59
|
+
static targetLocatorAttribute = 'data-position-target';
|
|
60
|
+
static contentLocatorAttribute = 'data-position-content';
|
|
44
61
|
constructor(props) {
|
|
45
62
|
super(props);
|
|
46
|
-
this.ref = null;
|
|
47
|
-
this._id = void 0;
|
|
48
|
-
this._timeouts = [];
|
|
49
|
-
this._listener = null;
|
|
50
|
-
this._content = void 0;
|
|
51
|
-
this._target = void 0;
|
|
52
|
-
this.handleRef = el => {
|
|
53
|
-
const elementRef = this.props.elementRef;
|
|
54
|
-
this.ref = el;
|
|
55
|
-
if (typeof elementRef === 'function') {
|
|
56
|
-
elementRef(el);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
this.handlePortalOpen = () => {
|
|
60
|
-
this.position();
|
|
61
|
-
if (this.props.shouldTrackPosition) {
|
|
62
|
-
this.startTracking();
|
|
63
|
-
}
|
|
64
|
-
this._timeouts.push(setTimeout(() => {
|
|
65
|
-
if (this.state.positioned && typeof this.props.onPositioned === 'function') {
|
|
66
|
-
this.props.onPositioned({
|
|
67
|
-
top: this.state.style.top,
|
|
68
|
-
left: this.state.style.left,
|
|
69
|
-
placement: this.state.placement
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}, 0));
|
|
73
|
-
};
|
|
74
|
-
this.position = () => {
|
|
75
|
-
this.setState({
|
|
76
|
-
positioned: true,
|
|
77
|
-
...this.calculatePosition(this.props)
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
63
|
this.state = {
|
|
81
64
|
positioned: false,
|
|
82
65
|
...this.calculatePosition(props)
|
|
@@ -87,24 +70,38 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
87
70
|
});
|
|
88
71
|
this._id = this.props.id || props.deterministicId();
|
|
89
72
|
}
|
|
73
|
+
ref = null;
|
|
74
|
+
_id;
|
|
75
|
+
_timeouts = [];
|
|
76
|
+
_listener = null;
|
|
77
|
+
_content;
|
|
78
|
+
_target;
|
|
79
|
+
handleRef = el => {
|
|
80
|
+
const {
|
|
81
|
+
elementRef
|
|
82
|
+
} = this.props;
|
|
83
|
+
this.ref = el;
|
|
84
|
+
if (typeof elementRef === 'function') {
|
|
85
|
+
elementRef(el);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
90
88
|
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
|
91
89
|
return !deepEqual(this.state, nextState) || !shallowEqual(this.props, nextProps) || !shallowEqual(this.context, nextContext);
|
|
92
90
|
}
|
|
93
91
|
componentDidMount() {
|
|
94
|
-
var _this$props$makeStyle, _this$props;
|
|
95
92
|
this.toggleLocatorAttributes(true);
|
|
96
|
-
|
|
93
|
+
this.props.makeStyles?.();
|
|
97
94
|
}
|
|
98
95
|
componentDidUpdate(prevProps, prevState) {
|
|
99
|
-
var _this$props$makeStyle2, _this$props2;
|
|
100
96
|
this.position();
|
|
101
97
|
this.toggleLocatorAttributes(true);
|
|
102
98
|
if (this.props.shouldTrackPosition !== prevProps.shouldTrackPosition) {
|
|
103
99
|
this.props.shouldTrackPosition ? this.startTracking() : this.stopTracking();
|
|
104
100
|
}
|
|
105
|
-
const
|
|
106
|
-
style
|
|
107
|
-
placement
|
|
101
|
+
const {
|
|
102
|
+
style,
|
|
103
|
+
placement
|
|
104
|
+
} = this.state;
|
|
108
105
|
if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left) && typeof this.props.onPositionChanged === 'function') {
|
|
109
106
|
this.props.onPositionChanged({
|
|
110
107
|
top: style.top,
|
|
@@ -112,7 +109,7 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
112
109
|
placement
|
|
113
110
|
});
|
|
114
111
|
}
|
|
115
|
-
|
|
112
|
+
this.props.makeStyles?.();
|
|
116
113
|
}
|
|
117
114
|
componentWillUnmount() {
|
|
118
115
|
;
|
|
@@ -140,6 +137,21 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
}
|
|
140
|
+
handlePortalOpen = () => {
|
|
141
|
+
this.position();
|
|
142
|
+
if (this.props.shouldTrackPosition) {
|
|
143
|
+
this.startTracking();
|
|
144
|
+
}
|
|
145
|
+
this._timeouts.push(setTimeout(() => {
|
|
146
|
+
if (this.state.positioned && typeof this.props.onPositioned === 'function') {
|
|
147
|
+
this.props.onPositioned({
|
|
148
|
+
top: this.state.style.top,
|
|
149
|
+
left: this.state.style.left,
|
|
150
|
+
placement: this.state.placement
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, 0));
|
|
154
|
+
};
|
|
143
155
|
calculatePosition(props) {
|
|
144
156
|
return calculateElementPosition(this._content, this._target, {
|
|
145
157
|
placement: props.placement,
|
|
@@ -150,6 +162,12 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
150
162
|
over: props.shouldPositionOverTarget
|
|
151
163
|
});
|
|
152
164
|
}
|
|
165
|
+
position = () => {
|
|
166
|
+
this.setState({
|
|
167
|
+
positioned: true,
|
|
168
|
+
...this.calculatePosition(this.props)
|
|
169
|
+
});
|
|
170
|
+
};
|
|
153
171
|
startTracking() {
|
|
154
172
|
this._listener = this._listener || addPositionChangeListener(this._target, this.position);
|
|
155
173
|
}
|
|
@@ -164,14 +182,13 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
164
182
|
renderContent() {
|
|
165
183
|
let content = ensureSingleChild(this.props.children);
|
|
166
184
|
if (content) {
|
|
167
|
-
var _this$props$styles;
|
|
168
185
|
content = safeCloneElement(content, {
|
|
169
186
|
ref: el => {
|
|
170
187
|
this._content = el;
|
|
171
188
|
},
|
|
172
189
|
style: {
|
|
173
190
|
boxSizing: 'border-box',
|
|
174
|
-
zIndex:
|
|
191
|
+
zIndex: this.props.styles?.zIndex,
|
|
175
192
|
...content.props.style,
|
|
176
193
|
...this.state.style
|
|
177
194
|
},
|
|
@@ -205,28 +222,17 @@ let Position = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
205
222
|
return null;
|
|
206
223
|
}
|
|
207
224
|
render() {
|
|
208
|
-
var _this$props$styles2;
|
|
209
225
|
const props = {
|
|
210
226
|
[Position.locatorAttribute]: this._id
|
|
211
227
|
};
|
|
212
228
|
return _jsxs("span", {
|
|
213
229
|
...props,
|
|
214
|
-
css:
|
|
230
|
+
css: this.props.styles?.position,
|
|
215
231
|
ref: this.handleRef,
|
|
216
232
|
"data-cid": combineDataCid('Position', this.props),
|
|
217
233
|
children: [this.renderTarget(), this.renderContent()]
|
|
218
234
|
});
|
|
219
235
|
}
|
|
220
|
-
}
|
|
221
|
-
placement: 'bottom center',
|
|
222
|
-
mountNode: null,
|
|
223
|
-
insertAt: 'bottom',
|
|
224
|
-
constrain: 'window',
|
|
225
|
-
offsetX: 0,
|
|
226
|
-
offsetY: 0,
|
|
227
|
-
shouldTrackPosition: true,
|
|
228
|
-
shouldPositionOverTarget: false,
|
|
229
|
-
children: null
|
|
230
|
-
}, _Position.locatorAttribute = 'data-position', _Position.targetLocatorAttribute = 'data-position-target', _Position.contentLocatorAttribute = 'data-position-content', _Position)) || _class) || _class);
|
|
236
|
+
}) || _class) || _class);
|
|
231
237
|
export default Position;
|
|
232
238
|
export { Position };
|
package/es/Position/theme.js
CHANGED
|
@@ -28,9 +28,11 @@
|
|
|
28
28
|
* @return {Object} The final theme object with the overrides and component variables
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
|
-
const
|
|
31
|
+
const {
|
|
32
|
+
stacking
|
|
33
|
+
} = theme;
|
|
32
34
|
const componentVariables = {
|
|
33
|
-
zIndex: stacking
|
|
35
|
+
zIndex: stacking?.topmost
|
|
34
36
|
};
|
|
35
37
|
return {
|
|
36
38
|
...componentVariables
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
/*
|
|
3
2
|
* The MIT License (MIT)
|
|
4
3
|
*
|
|
@@ -74,10 +73,6 @@ class PositionedElement {
|
|
|
74
73
|
top: 0,
|
|
75
74
|
left: 0
|
|
76
75
|
}) {
|
|
77
|
-
this.node = void 0;
|
|
78
|
-
this.placement = void 0;
|
|
79
|
-
this.rect = void 0;
|
|
80
|
-
this._offset = void 0;
|
|
81
76
|
this.node = findDOMNode(element);
|
|
82
77
|
if (typeof placement === 'string') {
|
|
83
78
|
this.placement = parsePlacement(placement);
|
|
@@ -89,6 +84,10 @@ class PositionedElement {
|
|
|
89
84
|
this.rect = getBoundingClientRect(this.node);
|
|
90
85
|
this._offset = offsetToPx(offset, this.size, this.node);
|
|
91
86
|
}
|
|
87
|
+
node;
|
|
88
|
+
placement;
|
|
89
|
+
rect;
|
|
90
|
+
_offset;
|
|
92
91
|
get width() {
|
|
93
92
|
return this.rect.width;
|
|
94
93
|
}
|
|
@@ -131,14 +130,10 @@ class PositionedElement {
|
|
|
131
130
|
end: '100%',
|
|
132
131
|
stretch: 0
|
|
133
132
|
};
|
|
134
|
-
let
|
|
135
|
-
first = _placement[0],
|
|
136
|
-
second = _placement[1];
|
|
133
|
+
let [first, second] = placement;
|
|
137
134
|
if (['start', 'end'].indexOf(first) >= 0) {
|
|
138
135
|
;
|
|
139
|
-
|
|
140
|
-
first = _ref[0];
|
|
141
|
-
second = _ref[1];
|
|
136
|
+
[first, second] = [second, first];
|
|
142
137
|
}
|
|
143
138
|
let top = 0;
|
|
144
139
|
let left = 0;
|
|
@@ -181,7 +176,7 @@ class PositionedElement {
|
|
|
181
176
|
// If there is more than one parent, the offset on the
|
|
182
177
|
// documentElement should be calculated appropriately.
|
|
183
178
|
// Otherwise we need to explictly account for that offset
|
|
184
|
-
let offsetY = parents.length > 1 ? 0 : getBoundingClientRect(doc
|
|
179
|
+
let offsetY = parents.length > 1 ? 0 : getBoundingClientRect(doc?.documentElement).top;
|
|
185
180
|
let offsetX = 0;
|
|
186
181
|
let scrollY = 0;
|
|
187
182
|
for (let i = 1; i < parents.length; i++) {
|
|
@@ -189,7 +184,7 @@ class PositionedElement {
|
|
|
189
184
|
const child = getBoundingClientRect(parents[i - 1]);
|
|
190
185
|
offsetY = offsetY + (child.top - parent.top);
|
|
191
186
|
offsetX = offsetX + (child.left - parent.left);
|
|
192
|
-
if (parents[i] ===
|
|
187
|
+
if (parents[i] === doc?.body) {
|
|
193
188
|
// accounts for any margin on body
|
|
194
189
|
offsetY = offsetY + parent.top;
|
|
195
190
|
offsetX = offsetX + parent.left;
|
|
@@ -206,27 +201,22 @@ class PositionedElement {
|
|
|
206
201
|
};
|
|
207
202
|
}
|
|
208
203
|
normalizeScrollTop(element) {
|
|
209
|
-
var _ownerDocument;
|
|
210
204
|
// Account for cross browser differences with scrollTop attribute on the
|
|
211
205
|
// body element https://bugs.chromium.org/p/chromium/issues/detail?id=766938
|
|
212
|
-
return
|
|
206
|
+
return ownerDocument(this.node)?.body === element ? 0 : element.scrollTop;
|
|
213
207
|
}
|
|
214
208
|
}
|
|
215
209
|
class PositionData {
|
|
216
210
|
constructor(element, target, options) {
|
|
217
|
-
var _ownerDocument2;
|
|
218
|
-
this.options = void 0;
|
|
219
|
-
this.container = void 0;
|
|
220
|
-
this.element = void 0;
|
|
221
|
-
this.target = void 0;
|
|
222
211
|
this.options = options || {};
|
|
223
|
-
const
|
|
224
|
-
container
|
|
225
|
-
constrain
|
|
226
|
-
placement
|
|
227
|
-
over
|
|
212
|
+
const {
|
|
213
|
+
container,
|
|
214
|
+
constrain,
|
|
215
|
+
placement,
|
|
216
|
+
over
|
|
217
|
+
} = this.options;
|
|
228
218
|
if (!element || placement === 'offscreen') return;
|
|
229
|
-
this.container = container ||
|
|
219
|
+
this.container = container || ownerDocument(element)?.body;
|
|
230
220
|
this.element = new PositionedElement(element, placement, {
|
|
231
221
|
top: this.options.offsetY,
|
|
232
222
|
left: this.options.offsetX
|
|
@@ -244,10 +234,15 @@ class PositionData {
|
|
|
244
234
|
this.constrainTo(findDOMNode(constrain));
|
|
245
235
|
}
|
|
246
236
|
}
|
|
237
|
+
options;
|
|
238
|
+
container;
|
|
239
|
+
element;
|
|
240
|
+
target;
|
|
247
241
|
get offset() {
|
|
248
|
-
const
|
|
249
|
-
top
|
|
250
|
-
left
|
|
242
|
+
const {
|
|
243
|
+
top,
|
|
244
|
+
left
|
|
245
|
+
} = this.target.calculateOffset(this.element.placement);
|
|
251
246
|
const offset = addOffsets([this.element.calculateOffset(this.target.placement), this.element.scrollParentsOffset, this.element.positionedParentsOffset]);
|
|
252
247
|
return {
|
|
253
248
|
top: top - offset.top,
|
|
@@ -265,10 +260,11 @@ class PositionData {
|
|
|
265
260
|
}
|
|
266
261
|
get position() {
|
|
267
262
|
const win = ownerWindow(this.target.node);
|
|
268
|
-
let
|
|
269
|
-
left
|
|
270
|
-
top
|
|
271
|
-
|
|
263
|
+
let {
|
|
264
|
+
left,
|
|
265
|
+
top
|
|
266
|
+
} = addOffsets([this.target.position, this.offset]);
|
|
267
|
+
if (canUseDOM && win?.matchMedia) {
|
|
272
268
|
const retina = win.matchMedia('only screen and (min-resolution: 1.3dppx)').matches || win.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3)').matches;
|
|
273
269
|
if (!retina) {
|
|
274
270
|
left = Math.round(left);
|
|
@@ -283,9 +279,10 @@ class PositionData {
|
|
|
283
279
|
get style() {
|
|
284
280
|
// when rendered offscreen first, element has no dimension on first calculation,
|
|
285
281
|
// so we hide it offscreen until measurements are completed
|
|
286
|
-
const
|
|
287
|
-
width
|
|
288
|
-
height
|
|
282
|
+
const {
|
|
283
|
+
width,
|
|
284
|
+
height
|
|
285
|
+
} = this.element.size;
|
|
289
286
|
const elementNotFullyRendered = width === 0 && height === 0;
|
|
290
287
|
return {
|
|
291
288
|
top: 0,
|
|
@@ -434,8 +431,10 @@ function addOffsets(offsets) {
|
|
|
434
431
|
});
|
|
435
432
|
}
|
|
436
433
|
function parseOffset(offset, placement) {
|
|
437
|
-
let
|
|
438
|
-
|
|
434
|
+
let {
|
|
435
|
+
top,
|
|
436
|
+
left
|
|
437
|
+
} = offset;
|
|
439
438
|
if (typeof left === 'string') {
|
|
440
439
|
left = parseFloat(left);
|
|
441
440
|
}
|
|
@@ -456,8 +455,10 @@ function parseOffset(offset, placement) {
|
|
|
456
455
|
function offsetToPx(offset, size,
|
|
457
456
|
// @ts-expect-error will be needed for the TODO below
|
|
458
457
|
node) {
|
|
459
|
-
let
|
|
460
|
-
|
|
458
|
+
let {
|
|
459
|
+
left,
|
|
460
|
+
top
|
|
461
|
+
} = offset;
|
|
461
462
|
if (typeof left === 'string') {
|
|
462
463
|
if (left.indexOf('%') !== -1) {
|
|
463
464
|
left = parseFloat(left) / 100 * size.width;
|
|
@@ -480,14 +481,10 @@ node) {
|
|
|
480
481
|
};
|
|
481
482
|
}
|
|
482
483
|
function sortPlacement(placement) {
|
|
483
|
-
let
|
|
484
|
-
first = _placement2[0],
|
|
485
|
-
second = _placement2[1];
|
|
484
|
+
let [first, second] = placement;
|
|
486
485
|
if (first === 'center') {
|
|
487
486
|
;
|
|
488
|
-
|
|
489
|
-
first = _ref2[0];
|
|
490
|
-
second = _ref2[1];
|
|
487
|
+
[first, second] = [second, first];
|
|
491
488
|
}
|
|
492
489
|
return [first, second];
|
|
493
490
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
/*
|
|
3
2
|
* The MIT License (MIT)
|
|
4
3
|
*
|
|
@@ -24,10 +23,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
24
23
|
*/
|
|
25
24
|
|
|
26
25
|
function executeMirrorFunction(placement, mirrorFunction, delimiter) {
|
|
27
|
-
const
|
|
28
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
29
|
-
first = _ref2[0],
|
|
30
|
-
second = _ref2[1];
|
|
26
|
+
const [first, second] = Array.isArray(placement) ? placement : placement.split(' ');
|
|
31
27
|
const result = mirrorFunction(first, second).filter(value => value);
|
|
32
28
|
return delimiter ? result.join(delimiter) : result;
|
|
33
29
|
}
|
package/lib/Position/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var _theme = _interopRequireDefault(require("./theme"));
|
|
|
23
23
|
var _props = require("./props");
|
|
24
24
|
var _calculateElementPosition = require("../calculateElementPosition");
|
|
25
25
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
26
|
-
var _dec, _dec2, _class
|
|
26
|
+
var _dec, _dec2, _class;
|
|
27
27
|
/*
|
|
28
28
|
* The MIT License (MIT)
|
|
29
29
|
*
|
|
@@ -52,43 +52,26 @@ var _dec, _dec2, _class, _Position;
|
|
|
52
52
|
category: components/utilities
|
|
53
53
|
---
|
|
54
54
|
**/
|
|
55
|
-
let Position = exports.Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class =
|
|
55
|
+
let Position = exports.Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = class Position extends _react.Component {
|
|
56
|
+
static displayName = "Position";
|
|
57
|
+
static componentId = 'Position';
|
|
58
|
+
static allowedProps = _props.allowedProps;
|
|
59
|
+
static defaultProps = {
|
|
60
|
+
placement: 'bottom center',
|
|
61
|
+
mountNode: null,
|
|
62
|
+
insertAt: 'bottom',
|
|
63
|
+
constrain: 'window',
|
|
64
|
+
offsetX: 0,
|
|
65
|
+
offsetY: 0,
|
|
66
|
+
shouldTrackPosition: true,
|
|
67
|
+
shouldPositionOverTarget: false,
|
|
68
|
+
children: null
|
|
69
|
+
};
|
|
70
|
+
static locatorAttribute = 'data-position';
|
|
71
|
+
static targetLocatorAttribute = 'data-position-target';
|
|
72
|
+
static contentLocatorAttribute = 'data-position-content';
|
|
56
73
|
constructor(props) {
|
|
57
74
|
super(props);
|
|
58
|
-
this.ref = null;
|
|
59
|
-
this._id = void 0;
|
|
60
|
-
this._timeouts = [];
|
|
61
|
-
this._listener = null;
|
|
62
|
-
this._content = void 0;
|
|
63
|
-
this._target = void 0;
|
|
64
|
-
this.handleRef = el => {
|
|
65
|
-
const elementRef = this.props.elementRef;
|
|
66
|
-
this.ref = el;
|
|
67
|
-
if (typeof elementRef === 'function') {
|
|
68
|
-
elementRef(el);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
this.handlePortalOpen = () => {
|
|
72
|
-
this.position();
|
|
73
|
-
if (this.props.shouldTrackPosition) {
|
|
74
|
-
this.startTracking();
|
|
75
|
-
}
|
|
76
|
-
this._timeouts.push(setTimeout(() => {
|
|
77
|
-
if (this.state.positioned && typeof this.props.onPositioned === 'function') {
|
|
78
|
-
this.props.onPositioned({
|
|
79
|
-
top: this.state.style.top,
|
|
80
|
-
left: this.state.style.left,
|
|
81
|
-
placement: this.state.placement
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}, 0));
|
|
85
|
-
};
|
|
86
|
-
this.position = () => {
|
|
87
|
-
this.setState({
|
|
88
|
-
positioned: true,
|
|
89
|
-
...this.calculatePosition(this.props)
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
75
|
this.state = {
|
|
93
76
|
positioned: false,
|
|
94
77
|
...this.calculatePosition(props)
|
|
@@ -99,24 +82,38 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
99
82
|
});
|
|
100
83
|
this._id = this.props.id || props.deterministicId();
|
|
101
84
|
}
|
|
85
|
+
ref = null;
|
|
86
|
+
_id;
|
|
87
|
+
_timeouts = [];
|
|
88
|
+
_listener = null;
|
|
89
|
+
_content;
|
|
90
|
+
_target;
|
|
91
|
+
handleRef = el => {
|
|
92
|
+
const {
|
|
93
|
+
elementRef
|
|
94
|
+
} = this.props;
|
|
95
|
+
this.ref = el;
|
|
96
|
+
if (typeof elementRef === 'function') {
|
|
97
|
+
elementRef(el);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
102
100
|
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
|
103
101
|
return !(0, _deepEqual.deepEqual)(this.state, nextState) || !(0, _shallowEqual.shallowEqual)(this.props, nextProps) || !(0, _shallowEqual.shallowEqual)(this.context, nextContext);
|
|
104
102
|
}
|
|
105
103
|
componentDidMount() {
|
|
106
|
-
var _this$props$makeStyle, _this$props;
|
|
107
104
|
this.toggleLocatorAttributes(true);
|
|
108
|
-
|
|
105
|
+
this.props.makeStyles?.();
|
|
109
106
|
}
|
|
110
107
|
componentDidUpdate(prevProps, prevState) {
|
|
111
|
-
var _this$props$makeStyle2, _this$props2;
|
|
112
108
|
this.position();
|
|
113
109
|
this.toggleLocatorAttributes(true);
|
|
114
110
|
if (this.props.shouldTrackPosition !== prevProps.shouldTrackPosition) {
|
|
115
111
|
this.props.shouldTrackPosition ? this.startTracking() : this.stopTracking();
|
|
116
112
|
}
|
|
117
|
-
const
|
|
118
|
-
style
|
|
119
|
-
placement
|
|
113
|
+
const {
|
|
114
|
+
style,
|
|
115
|
+
placement
|
|
116
|
+
} = this.state;
|
|
120
117
|
if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left) && typeof this.props.onPositionChanged === 'function') {
|
|
121
118
|
this.props.onPositionChanged({
|
|
122
119
|
top: style.top,
|
|
@@ -124,7 +121,7 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
124
121
|
placement
|
|
125
122
|
});
|
|
126
123
|
}
|
|
127
|
-
|
|
124
|
+
this.props.makeStyles?.();
|
|
128
125
|
}
|
|
129
126
|
componentWillUnmount() {
|
|
130
127
|
;
|
|
@@ -152,6 +149,21 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
151
|
}
|
|
152
|
+
handlePortalOpen = () => {
|
|
153
|
+
this.position();
|
|
154
|
+
if (this.props.shouldTrackPosition) {
|
|
155
|
+
this.startTracking();
|
|
156
|
+
}
|
|
157
|
+
this._timeouts.push(setTimeout(() => {
|
|
158
|
+
if (this.state.positioned && typeof this.props.onPositioned === 'function') {
|
|
159
|
+
this.props.onPositioned({
|
|
160
|
+
top: this.state.style.top,
|
|
161
|
+
left: this.state.style.left,
|
|
162
|
+
placement: this.state.placement
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}, 0));
|
|
166
|
+
};
|
|
155
167
|
calculatePosition(props) {
|
|
156
168
|
return (0, _calculateElementPosition.calculateElementPosition)(this._content, this._target, {
|
|
157
169
|
placement: props.placement,
|
|
@@ -162,6 +174,12 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
162
174
|
over: props.shouldPositionOverTarget
|
|
163
175
|
});
|
|
164
176
|
}
|
|
177
|
+
position = () => {
|
|
178
|
+
this.setState({
|
|
179
|
+
positioned: true,
|
|
180
|
+
...this.calculatePosition(this.props)
|
|
181
|
+
});
|
|
182
|
+
};
|
|
165
183
|
startTracking() {
|
|
166
184
|
this._listener = this._listener || (0, _addPositionChangeListener.addPositionChangeListener)(this._target, this.position);
|
|
167
185
|
}
|
|
@@ -176,14 +194,13 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
176
194
|
renderContent() {
|
|
177
195
|
let content = (0, _ensureSingleChild.ensureSingleChild)(this.props.children);
|
|
178
196
|
if (content) {
|
|
179
|
-
var _this$props$styles;
|
|
180
197
|
content = (0, _safeCloneElement.safeCloneElement)(content, {
|
|
181
198
|
ref: el => {
|
|
182
199
|
this._content = el;
|
|
183
200
|
},
|
|
184
201
|
style: {
|
|
185
202
|
boxSizing: 'border-box',
|
|
186
|
-
zIndex:
|
|
203
|
+
zIndex: this.props.styles?.zIndex,
|
|
187
204
|
...content.props.style,
|
|
188
205
|
...this.state.style
|
|
189
206
|
},
|
|
@@ -217,27 +234,16 @@ let Position = exports.Position = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
217
234
|
return null;
|
|
218
235
|
}
|
|
219
236
|
render() {
|
|
220
|
-
var _this$props$styles2;
|
|
221
237
|
const props = {
|
|
222
238
|
[Position.locatorAttribute]: this._id
|
|
223
239
|
};
|
|
224
240
|
return (0, _jsxRuntime.jsxs)("span", {
|
|
225
241
|
...props,
|
|
226
|
-
css:
|
|
242
|
+
css: this.props.styles?.position,
|
|
227
243
|
ref: this.handleRef,
|
|
228
244
|
"data-cid": (0, _combineDataCid.combineDataCid)('Position', this.props),
|
|
229
245
|
children: [this.renderTarget(), this.renderContent()]
|
|
230
246
|
});
|
|
231
247
|
}
|
|
232
|
-
}
|
|
233
|
-
placement: 'bottom center',
|
|
234
|
-
mountNode: null,
|
|
235
|
-
insertAt: 'bottom',
|
|
236
|
-
constrain: 'window',
|
|
237
|
-
offsetX: 0,
|
|
238
|
-
offsetY: 0,
|
|
239
|
-
shouldTrackPosition: true,
|
|
240
|
-
shouldPositionOverTarget: false,
|
|
241
|
-
children: null
|
|
242
|
-
}, _Position.locatorAttribute = 'data-position', _Position.targetLocatorAttribute = 'data-position-target', _Position.contentLocatorAttribute = 'data-position-content', _Position)) || _class) || _class);
|
|
248
|
+
}) || _class) || _class);
|
|
243
249
|
var _default = exports.default = Position;
|
package/lib/Position/theme.js
CHANGED
|
@@ -34,9 +34,11 @@ exports.default = void 0;
|
|
|
34
34
|
* @return {Object} The final theme object with the overrides and component variables
|
|
35
35
|
*/
|
|
36
36
|
const generateComponentTheme = theme => {
|
|
37
|
-
const
|
|
37
|
+
const {
|
|
38
|
+
stacking
|
|
39
|
+
} = theme;
|
|
38
40
|
const componentVariables = {
|
|
39
|
-
zIndex: stacking
|
|
41
|
+
zIndex: stacking?.topmost
|
|
40
42
|
};
|
|
41
43
|
return {
|
|
42
44
|
...componentVariables
|