ag-common 0.0.699 → 0.0.701

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.
@@ -31,7 +31,7 @@ const BarChart = ({ data: dataRaw, style: sRaw, className, }) => {
31
31
  const UT = (0, useTooltip_1.useTooltip)();
32
32
  const maxWidth = Math.max(...dataRaw.map((a) => a.total));
33
33
  return (react_1.default.createElement(BarChartBase, { "data-type": "bcb", style: style, className: className },
34
- react_1.default.createElement(UT.Comp, { pos: UT.pos }, (p) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, p, { style: style }))),
34
+ react_1.default.createElement(UT.Comp, { pos: UT.pos }, ({ data }) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, data, { style: style }))),
35
35
  dataRaw.map((data) => (react_1.default.createElement(ItemStyled, { style: style, key: data.name, data: data, maxWidth: maxWidth, onMouseLeave: () => UT.setPos(undefined), onMouseMove: (element) => {
36
36
  var _a, _b;
37
37
  const selectedKey = (_b = (_a = document
@@ -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)({
@@ -120,7 +120,7 @@ const TreeChart = (tnd) => {
120
120
  return react_1.default.createElement("div", null);
121
121
  }
122
122
  return (react_1.default.createElement(Base, { ref: r, className: tnd.className, style: tnd.style },
123
- react_1.default.createElement(UT.Comp, { pos: UT.pos }, (p) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, p))),
123
+ react_1.default.createElement(UT.Comp, { pos: UT.pos }, ({ data }) => react_1.default.createElement(TooltipContent_1.TooltipContent, Object.assign({}, data))),
124
124
  headDim &&
125
125
  Render({
126
126
  UT,
@@ -3,12 +3,16 @@ 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;
10
10
  y: number;
11
11
  }
12
+ interface IPosSize {
13
+ tooltipWidth: number;
14
+ tooltipHeight: number;
15
+ }
12
16
  type ITooltipProps = {
13
17
  /** default 'ag-tooltip-portal' */
14
18
  portalId: string;
@@ -16,7 +20,7 @@ type ITooltipProps = {
16
20
  export interface IUseTooltip<T> {
17
21
  Comp: <T>({ pos, children, }: {
18
22
  pos: IPos<T> | undefined;
19
- children: (data: T) => JSX.Element;
23
+ children: (pos: IPos<T>, size?: IPosSize) => JSX.Element;
20
24
  }) => JSX.Element | null;
21
25
  setPos: (p?: {
22
26
  element: MouseEvent;
@@ -38,23 +38,17 @@ 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
- var _a, _b;
42
- if (!ref.current) {
41
+ if (!ref.current || size) {
43
42
  return;
44
43
  }
45
44
  const tooltipWidth = Math.max(ref.current.clientWidth, ref.current.scrollWidth);
46
45
  const tooltipHeight = Math.max(ref.current.clientHeight, ref.current.scrollHeight);
47
- if (tooltipHeight === ((_a = size === null || size === void 0 ? void 0 : size.p) === null || _a === void 0 ? void 0 : _a.tooltipHeight) ||
48
- tooltipWidth === ((_b = size === null || size === void 0 ? void 0 : size.p) === null || _b === void 0 ? void 0 : _b.tooltipWidth) ||
49
- tooltipHeight === 0 ||
50
- tooltipWidth === 0) {
46
+ if (tooltipHeight === 0 || tooltipWidth === 0) {
51
47
  return;
52
48
  }
53
49
  setSize({
54
- p: {
55
- tooltipWidth,
56
- tooltipHeight,
57
- },
50
+ tooltipWidth,
51
+ tooltipHeight,
58
52
  });
59
53
  }, [ref, size]);
60
54
  if (!pos) {
@@ -65,34 +59,40 @@ const Comp = ({ pos, children, }) => {
65
59
  let top;
66
60
  let bottom;
67
61
  const gap = 5;
68
- if (size === null || size === void 0 ? void 0 : size.p) {
62
+ if (size) {
69
63
  left = pos.x + gap;
70
64
  const newRight = pos.parentWidth - pos.x + gap;
71
- if (pos.x + gap + size.p.tooltipWidth > pos.parentWidth) {
65
+ if (pos.x + gap + size.tooltipWidth > pos.parentWidth) {
72
66
  left = undefined;
73
67
  right = newRight;
74
68
  }
75
69
  //
76
70
  top = pos.y + gap;
77
- if (top + size.p.tooltipHeight > pos.parentHeight) {
78
- top = undefined;
71
+ if (top + size.tooltipHeight > pos.parentHeight) {
72
+ if (pos.hasParent) {
73
+ top = undefined;
74
+ }
79
75
  bottom = pos.parentHeight - pos.y;
80
76
  }
81
- if (right && right + size.p.tooltipWidth > pos.parentWidth) {
82
- right = undefined;
77
+ if (right && right + size.tooltipWidth > pos.parentWidth) {
78
+ if (pos.hasParent) {
79
+ right = undefined;
80
+ }
83
81
  left = 0;
84
82
  }
85
- if (bottom && bottom + size.p.tooltipHeight > pos.parentHeight) {
86
- bottom = undefined;
83
+ if (bottom && bottom + size.tooltipHeight > pos.parentHeight) {
84
+ if (pos.hasParent) {
85
+ bottom = undefined;
86
+ }
87
87
  top = 0;
88
88
  }
89
89
  }
90
90
  const Content = (react_1.default.createElement(Base, { "data-type": "tooltip-content", ref: ref, style: Object.assign(Object.assign({ left,
91
91
  right,
92
92
  top,
93
- bottom, zIndex: 10 }, (pos.usePortal && { position: 'fixed' })), (!(size === null || size === void 0 ? void 0 : size.p) && { zIndex: -1 })) }, children(pos.data)));
93
+ bottom, zIndex: 10, overflow: 'hidden' }, (!pos.hasParent && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
94
94
  const e = document.querySelector(`#${pos.portalId}`);
95
- if (pos.usePortal && e) {
95
+ if (!pos.hasParent && e) {
96
96
  return (0, react_dom_1.createPortal)(Content, e);
97
97
  }
98
98
  return Content;
@@ -152,7 +152,7 @@ const useTooltip = (p) => {
152
152
  parentHeight,
153
153
  x,
154
154
  y,
155
- usePortal: !p.parent,
155
+ hasParent: !!p.parent,
156
156
  portalId,
157
157
  };
158
158
  setPosRaw(p2);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.699",
2
+ "version": "0.0.701",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",