orcs-design-system 2.1.13 → 2.1.15
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.
|
@@ -336,7 +336,7 @@ export var keepInViewExample = function keepInViewExample() {
|
|
|
336
336
|
}, "Remove")), /*#__PURE__*/React.createElement(ActionsMenu, {
|
|
337
337
|
menuTopPosition: "30px",
|
|
338
338
|
menuLeftPosition: "0",
|
|
339
|
-
menuWidth: "
|
|
339
|
+
menuWidth: "200px",
|
|
340
340
|
customTriggerComponent: /*#__PURE__*/React.createElement(Button, {
|
|
341
341
|
variant: "ghost",
|
|
342
342
|
type: "button",
|
|
@@ -165,13 +165,14 @@ export var ActionsMenuBody = function ActionsMenuBody(_ref) {
|
|
|
165
165
|
|
|
166
166
|
var _useKeepInView = useKeepInView({
|
|
167
167
|
direction: direction,
|
|
168
|
-
callback: setMenuPosition
|
|
169
|
-
shown: true
|
|
168
|
+
callback: setMenuPosition
|
|
170
169
|
}),
|
|
171
|
-
_useKeepInView2 = _slicedToArray(_useKeepInView,
|
|
172
|
-
ref = _useKeepInView2[0]
|
|
170
|
+
_useKeepInView2 = _slicedToArray(_useKeepInView, 2),
|
|
171
|
+
ref = _useKeepInView2[0],
|
|
172
|
+
setIsShown = _useKeepInView2[1];
|
|
173
173
|
|
|
174
174
|
var onToggleInView = function onToggleInView(e) {
|
|
175
|
+
setIsShown(!toggleState);
|
|
175
176
|
onToggle(e);
|
|
176
177
|
};
|
|
177
178
|
|
package/es/hooks/keepInView.js
CHANGED
|
@@ -20,6 +20,14 @@ export var oppositeDirection = function oppositeDirection(direction) {
|
|
|
20
20
|
if (!direction || !directions[direction]) return "left";
|
|
21
21
|
return directions[direction];
|
|
22
22
|
};
|
|
23
|
+
|
|
24
|
+
var isWithinRootBounds = function isWithinRootBounds(intersectionObserverEntry) {
|
|
25
|
+
var rootBounds = intersectionObserverEntry.rootBounds;
|
|
26
|
+
var intersectionRect = intersectionObserverEntry.intersectionRect;
|
|
27
|
+
var topDiff = intersectionRect.top - rootBounds.top;
|
|
28
|
+
var bottomDiff = intersectionRect.bottom - rootBounds.bottom;
|
|
29
|
+
return topDiff > 0 && bottomDiff < -100;
|
|
30
|
+
};
|
|
23
31
|
/**
|
|
24
32
|
* This hook keeps track of the in view status of a component that has a direction setting, like a Popover or ActionsMenu.
|
|
25
33
|
*
|
|
@@ -39,6 +47,7 @@ export var oppositeDirection = function oppositeDirection(direction) {
|
|
|
39
47
|
*
|
|
40
48
|
*/
|
|
41
49
|
|
|
50
|
+
|
|
42
51
|
export var useKeepInView = function useKeepInView(_ref) {
|
|
43
52
|
var direction = _ref.direction,
|
|
44
53
|
_ref$shown = _ref.shown,
|
|
@@ -64,14 +73,17 @@ export var useKeepInView = function useKeepInView(_ref) {
|
|
|
64
73
|
|
|
65
74
|
var _useInView = useInView(inViewOptions),
|
|
66
75
|
ref = _useInView.ref,
|
|
67
|
-
inView = _useInView.inView
|
|
76
|
+
inView = _useInView.inView,
|
|
77
|
+
entry = _useInView.entry;
|
|
68
78
|
|
|
69
79
|
useEffect(function () {
|
|
70
80
|
if (!inView && isShown) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
if (isWithinRootBounds(entry)) {
|
|
82
|
+
var newDirection = oppositeDirection(lastDirection.direction);
|
|
83
|
+
callback(newDirection);
|
|
84
|
+
lastDirection.direction = newDirection;
|
|
85
|
+
}
|
|
74
86
|
}
|
|
75
|
-
}, [inView,
|
|
87
|
+
}, [inView, entry, isShown, callback, lastDirection]);
|
|
76
88
|
return [ref, setIsShown];
|
|
77
89
|
};
|