ag-common 0.0.700 → 0.0.702

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.
@@ -32,6 +32,7 @@ const styled_1 = __importDefault(require("@emotion/styled"));
32
32
  const react_1 = __importStar(require("react"));
33
33
  const react_dom_1 = require("react-dom");
34
34
  const dom_1 = require("../../helpers/dom");
35
+ const useLockBodyScroll_1 = require("../../helpers/useLockBodyScroll");
35
36
  const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
36
37
  const styles_1 = require("../../styles");
37
38
  const Close_1 = require("../Close");
@@ -92,6 +93,7 @@ const Modal = (p) => {
92
93
  if (portalId === undefined) {
93
94
  portalId = globalId;
94
95
  }
96
+ (0, useLockBodyScroll_1.useLockBodyScroll)(p.open);
95
97
  const [portalElem, setPortalElem] = (0, react_1.useState)();
96
98
  (0, react_1.useEffect)(() => {
97
99
  if (portalId === null ||
@@ -114,15 +116,6 @@ const Modal = (p) => {
114
116
  };
115
117
  // eslint-disable-next-line react-hooks/exhaustive-deps
116
118
  }, []);
117
- (0, react_1.useEffect)(() => {
118
- const originalStyle = window.getComputedStyle(document.body).overflow || '';
119
- if (open) {
120
- document.body.style.overflow = 'hidden';
121
- }
122
- return () => {
123
- document.body.style.overflow = originalStyle;
124
- };
125
- }, [open]);
126
119
  const [bounced, setBounced] = (0, react_1.useState)(false);
127
120
  const ref = (0, react_1.useRef)(null);
128
121
  (0, useOnClickOutside_1.useOnClickOutside)({
@@ -10,6 +10,7 @@ const Base = styled_1.default.div `
10
10
  padding: 0.5rem;
11
11
  border: solid 1px black;
12
12
  background-color: white;
13
+ color: black;
13
14
  `;
14
15
  const Title = styled_1.default.div `
15
16
  font-weight: bold;
@@ -3,7 +3,7 @@ interface IPos<T> {
3
3
  cursor: MouseEvent;
4
4
  data: T;
5
5
  portalId: string;
6
- usePortal: boolean;
6
+ hasParent: boolean;
7
7
  parentWidth: number;
8
8
  parentHeight: number;
9
9
  x: number;
@@ -38,15 +38,12 @@ const Comp = ({ pos, children, }) => {
38
38
  const ref = (0, react_1.createRef)();
39
39
  const [size, setSize] = (0, react_1.useState)();
40
40
  (0, react_1.useEffect)(() => {
41
- if (!ref.current) {
41
+ if (!ref.current || size) {
42
42
  return;
43
43
  }
44
44
  const tooltipWidth = Math.max(ref.current.clientWidth, ref.current.scrollWidth);
45
45
  const tooltipHeight = Math.max(ref.current.clientHeight, ref.current.scrollHeight);
46
- if (tooltipHeight === (size === null || size === void 0 ? void 0 : size.tooltipHeight) ||
47
- tooltipWidth === (size === null || size === void 0 ? void 0 : size.tooltipWidth) ||
48
- tooltipHeight === 0 ||
49
- tooltipWidth === 0) {
46
+ if (tooltipHeight === 0 || tooltipWidth === 0) {
50
47
  return;
51
48
  }
52
49
  setSize({
@@ -72,17 +69,19 @@ const Comp = ({ pos, children, }) => {
72
69
  //
73
70
  top = pos.y + gap;
74
71
  if (top + size.tooltipHeight > pos.parentHeight) {
75
- top = undefined;
72
+ if (pos.hasParent) {
73
+ top = undefined;
74
+ }
76
75
  bottom = pos.parentHeight - pos.y;
77
76
  }
78
77
  if (right && right + size.tooltipWidth > pos.parentWidth) {
79
- if (!pos.usePortal) {
78
+ if (pos.hasParent) {
80
79
  right = undefined;
81
80
  }
82
81
  left = 0;
83
82
  }
84
83
  if (bottom && bottom + size.tooltipHeight > pos.parentHeight) {
85
- if (!pos.usePortal) {
84
+ if (pos.hasParent) {
86
85
  bottom = undefined;
87
86
  }
88
87
  top = 0;
@@ -91,9 +90,9 @@ const Comp = ({ pos, children, }) => {
91
90
  const Content = (react_1.default.createElement(Base, { "data-type": "tooltip-content", ref: ref, style: Object.assign(Object.assign({ left,
92
91
  right,
93
92
  top,
94
- bottom, zIndex: 10, overflow: 'hidden' }, (pos.usePortal && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
93
+ bottom, zIndex: 10, overflow: 'hidden' }, (!pos.hasParent && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
95
94
  const e = document.querySelector(`#${pos.portalId}`);
96
- if (pos.usePortal && e) {
95
+ if (!pos.hasParent && e) {
97
96
  return (0, react_dom_1.createPortal)(Content, e);
98
97
  }
99
98
  return Content;
@@ -153,7 +152,7 @@ const useTooltip = (p) => {
153
152
  parentHeight,
154
153
  x,
155
154
  y,
156
- usePortal: !p.parent,
155
+ hasParent: !!p.parent,
157
156
  portalId,
158
157
  };
159
158
  setPosRaw(p2);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.700",
2
+ "version": "0.0.702",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",