ag-common 0.0.699 → 0.0.700

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
@@ -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,
@@ -9,6 +9,10 @@ interface IPos<T> {
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,20 @@ 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
41
  if (!ref.current) {
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) ||
46
+ if (tooltipHeight === (size === null || size === void 0 ? void 0 : size.tooltipHeight) ||
47
+ tooltipWidth === (size === null || size === void 0 ? void 0 : size.tooltipWidth) ||
49
48
  tooltipHeight === 0 ||
50
49
  tooltipWidth === 0) {
51
50
  return;
52
51
  }
53
52
  setSize({
54
- p: {
55
- tooltipWidth,
56
- tooltipHeight,
57
- },
53
+ tooltipWidth,
54
+ tooltipHeight,
58
55
  });
59
56
  }, [ref, size]);
60
57
  if (!pos) {
@@ -65,32 +62,36 @@ const Comp = ({ pos, children, }) => {
65
62
  let top;
66
63
  let bottom;
67
64
  const gap = 5;
68
- if (size === null || size === void 0 ? void 0 : size.p) {
65
+ if (size) {
69
66
  left = pos.x + gap;
70
67
  const newRight = pos.parentWidth - pos.x + gap;
71
- if (pos.x + gap + size.p.tooltipWidth > pos.parentWidth) {
68
+ if (pos.x + gap + size.tooltipWidth > pos.parentWidth) {
72
69
  left = undefined;
73
70
  right = newRight;
74
71
  }
75
72
  //
76
73
  top = pos.y + gap;
77
- if (top + size.p.tooltipHeight > pos.parentHeight) {
74
+ if (top + size.tooltipHeight > pos.parentHeight) {
78
75
  top = undefined;
79
76
  bottom = pos.parentHeight - pos.y;
80
77
  }
81
- if (right && right + size.p.tooltipWidth > pos.parentWidth) {
82
- right = undefined;
78
+ if (right && right + size.tooltipWidth > pos.parentWidth) {
79
+ if (!pos.usePortal) {
80
+ right = undefined;
81
+ }
83
82
  left = 0;
84
83
  }
85
- if (bottom && bottom + size.p.tooltipHeight > pos.parentHeight) {
86
- bottom = undefined;
84
+ if (bottom && bottom + size.tooltipHeight > pos.parentHeight) {
85
+ if (!pos.usePortal) {
86
+ bottom = undefined;
87
+ }
87
88
  top = 0;
88
89
  }
89
90
  }
90
91
  const Content = (react_1.default.createElement(Base, { "data-type": "tooltip-content", ref: ref, style: Object.assign(Object.assign({ left,
91
92
  right,
92
93
  top,
93
- bottom, zIndex: 10 }, (pos.usePortal && { position: 'fixed' })), (!(size === null || size === void 0 ? void 0 : size.p) && { zIndex: -1 })) }, children(pos.data)));
94
+ bottom, zIndex: 10, overflow: 'hidden' }, (pos.usePortal && { position: 'fixed' })), (!size && { zIndex: -1 })) }, children(pos, size)));
94
95
  const e = document.querySelector(`#${pos.portalId}`);
95
96
  if (pos.usePortal && e) {
96
97
  return (0, react_dom_1.createPortal)(Content, e);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.699",
2
+ "version": "0.0.700",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",