@orfium/ictinus 4.62.0 → 4.62.1

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.
@@ -9,17 +9,16 @@ var _react = require("react");
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
11
 
12
- var usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offsetX, offsetY, visible) {
13
- var _useState = (0, _react.useState)({
14
- x: -1,
15
- y: -1
16
- }),
17
- position = _useState[0],
18
- setPosition = _useState[1];
12
+ var useHeights = function useHeights(parentRef, itemRef) {
13
+ var _itemRef$current2;
14
+
15
+ var _useState = (0, _react.useState)(0),
16
+ parentHeight = _useState[0],
17
+ setParentHeight = _useState[1];
19
18
 
20
19
  var _useState2 = (0, _react.useState)(0),
21
- parentHeight = _useState2[0],
22
- setParentHeight = _useState2[1];
20
+ childHeight = _useState2[0],
21
+ setChildHeight = _useState2[1];
23
22
  /**
24
23
  * We use this ResizeObserver in order to track any changes on the parent's height:
25
24
  * This is necessary for the case of the MultiSelect, where the height of the TextField is dynamic
@@ -30,45 +29,81 @@ var usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offse
30
29
 
31
30
  (0, _react.useEffect)(function () {
32
31
  if (!parentRef.current) return;
33
- var resizeObserver = new ResizeObserver(function (entries) {
32
+ var parentResizeObserver = new ResizeObserver(function (entries) {
34
33
  var parent = (0, _head["default"])(entries);
35
34
 
36
35
  if (parent) {
37
36
  setParentHeight(parent.contentRect.height);
38
37
  }
39
38
  });
40
- resizeObserver.observe(parentRef.current);
39
+ parentResizeObserver.observe(parentRef.current);
41
40
  return function () {
42
- return resizeObserver.disconnect();
41
+ return parentResizeObserver.disconnect();
43
42
  };
44
43
  }, [parentRef]);
44
+ /**
45
+ * Same here to track the child's height:
46
+ * This is necessary for the case where the SelectMenu is rendered above the TextField, we need to track the
47
+ * dynamic height of the SelectMenu in order to keep the gap between SelectMenu and TextField fixed.
48
+ */
49
+
50
+ (0, _react.useEffect)(function () {
51
+ var _itemRef$current;
52
+
53
+ var dropdownElement = (0, _head["default"])((_itemRef$current = itemRef.current) == null ? void 0 : _itemRef$current.children);
54
+ if (!dropdownElement) return;
55
+ var childResizeObserver = new ResizeObserver(function (entries) {
56
+ var dropdown = (0, _head["default"])(entries);
57
+
58
+ if (dropdown) {
59
+ setChildHeight(dropdown.contentRect.height);
60
+ }
61
+ });
62
+ childResizeObserver.observe(dropdownElement);
63
+ return function () {
64
+ return childResizeObserver.disconnect();
65
+ };
66
+ }, [itemRef, (_itemRef$current2 = itemRef.current) == null ? void 0 : _itemRef$current2.children]);
67
+ return {
68
+ parentHeight: parentHeight,
69
+ childHeight: childHeight
70
+ };
71
+ };
72
+
73
+ var usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offsetX, offsetY, visible) {
74
+ var _useState3 = (0, _react.useState)({
75
+ x: -1,
76
+ y: -1
77
+ }),
78
+ position = _useState3[0],
79
+ setPosition = _useState3[1];
80
+
81
+ var _useHeights = useHeights(parentRef, itemRef),
82
+ parentHeight = _useHeights.parentHeight,
83
+ childHeight = _useHeights.childHeight;
84
+
45
85
  (0, _react.useEffect)(function () {
46
- var _parentRef$current, _itemRef$current, _itemRef$current$chil;
86
+ var _parentRef$current, _itemRef$current3, _itemRef$current3$chi;
47
87
 
48
88
  // x,y are cordinates in screen
49
- // width, height are wrapper elements dimensions
89
+ // width is wrapper elements dimensions
50
90
  var _ref = parentRef != null && parentRef.current ? parentRef == null ? void 0 : (_parentRef$current = parentRef.current) == null ? void 0 : _parentRef$current.getBoundingClientRect() : {
51
91
  x: 0,
52
92
  y: 0,
53
- width: 0,
54
- height: 0
93
+ width: 0
55
94
  },
56
95
  parentX = _ref.x,
57
96
  parentY = _ref.y,
58
- parentWidth = _ref.width,
59
- parentTempHeight = _ref.height;
97
+ parentWidth = _ref.width; // width is the element's that's going to be positioned dimensions
60
98
 
61
- setParentHeight(parentTempHeight); // width, height are the element's that's going to be positioned dimensions
62
99
 
63
- var _ref2 = itemRef != null && itemRef.current ? itemRef == null ? void 0 : (_itemRef$current = itemRef.current) == null ? void 0 : (_itemRef$current$chil = _itemRef$current.children[0]) == null ? void 0 : _itemRef$current$chil.getBoundingClientRect() : {
64
- width: 0,
65
- height: 0
100
+ var _ref2 = itemRef != null && itemRef.current ? itemRef == null ? void 0 : (_itemRef$current3 = itemRef.current) == null ? void 0 : (_itemRef$current3$chi = _itemRef$current3.children[0]) == null ? void 0 : _itemRef$current3$chi.getBoundingClientRect() : {
101
+ width: 0
66
102
  },
67
- width = _ref2.width,
68
- height = _ref2.height; // If the item-to-be-positioned is out of screen height
103
+ width = _ref2.width; // If the item-to-be-positioned is out of screen height
69
104
 
70
105
 
71
- var itemYOutOfScreenHeight = parentY + parentHeight + height > window.innerHeight; // The element that we are positioning is absolutely positioned inside the relative
106
+ var itemYOutOfScreenHeight = parentY + parentHeight + childHeight > window.innerHeight; // The element that we are positioning is absolutely positioned inside the relative
72
107
  // container. So x,y are zero means the element will be positioned exactly on top
73
108
  // of the parent element.
74
109
 
@@ -77,7 +112,7 @@ var usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offse
77
112
 
78
113
  if (itemYOutOfScreenHeight) {
79
114
  // We place the element height+offsetY (px) above the parent
80
- y = y - height - offsetY;
115
+ y = y - childHeight - offsetY;
81
116
 
82
117
  if (parentY + y < 0) {
83
118
  // Rare case where client height is super small. We don't exactly support this.
@@ -104,16 +139,16 @@ var usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offse
104
139
  x: x,
105
140
  y: y
106
141
  });
107
- }, [parentRef, itemRef, visible, offsetY, offsetX, parentHeight]);
142
+ }, [parentRef, itemRef, visible, offsetY, offsetX, parentHeight, childHeight]);
108
143
  return position;
109
144
  };
110
145
 
111
146
  exports.usePositionInScreen = usePositionInScreen;
112
147
 
113
148
  var useWrapperWidth = function useWrapperWidth(hasWrapperWidth, wrapperRef) {
114
- var _useState3 = (0, _react.useState)(),
115
- width = _useState3[0],
116
- setWidth = _useState3[1];
149
+ var _useState4 = (0, _react.useState)(),
150
+ width = _useState4[0],
151
+ setWidth = _useState4[1];
117
152
 
118
153
  (0, _react.useEffect)(function () {
119
154
  if (hasWrapperWidth) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orfium/ictinus",
3
- "version": "4.62.0",
3
+ "version": "4.62.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",