@wireapp/react-ui-kit 9.15.0 → 9.15.2
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.
- package/lib/Form/Tooltip.d.ts +1 -0
- package/lib/Form/Tooltip.d.ts.map +1 -1
- package/lib/Form/Tooltip.js +32 -24
- package/package.json +3 -3
package/lib/Form/Tooltip.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HTMLProps, ReactNode } from 'react';
|
|
2
2
|
interface TooltipProps<T = HTMLDivElement> extends HTMLProps<T> {
|
|
3
3
|
body: ReactNode;
|
|
4
|
+
selector?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare const Tooltip: ({ children, ...props }: TooltipProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAA0B,SAAS,EAAmB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAA0B,SAAS,EAAmB,MAAM,OAAO,CAAC;AAsGrF,UAAU,YAAY,CAAC,CAAC,GAAG,cAAc,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC7D,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,eAAO,MAAM,OAAO,2BAA0B,YAAY,qDAiCzD,CAAC"}
|
package/lib/Form/Tooltip.js
CHANGED
|
@@ -66,31 +66,39 @@ const tooltipStyle = theme => ({
|
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
|
-
const PortalComponent = ({ children, bounding }) => {
|
|
70
|
-
const bodyElement = document.querySelector('#wire-app');
|
|
69
|
+
const PortalComponent = ({ children, bounding, selector = '#wire-app' }) => {
|
|
71
70
|
const [isTouchingTop, setIsTouchingTop] = (0, react_1.useState)(false);
|
|
72
|
-
|
|
71
|
+
const targetElement = document.querySelector(selector);
|
|
72
|
+
if (!targetElement) {
|
|
73
73
|
return null;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
const tooltipRef = (element) => {
|
|
76
|
+
if (!bounding || !element) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const isTouchingTopEdge = bounding.y <= element.clientHeight + paddingTop * 2;
|
|
80
|
+
setIsTouchingTop(isTouchingTopEdge);
|
|
81
|
+
const elementWidth = (element.scrollWidth - bounding.width) / 2;
|
|
82
|
+
element.style.left = `${bounding.x - elementWidth}px`;
|
|
83
|
+
if (isTouchingTopEdge) {
|
|
84
|
+
element.style.top = `${bounding.y + bounding.height + paddingTop}px`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
element.style.top = `${bounding.y - element.clientHeight - paddingTop}px`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const tooltipArrowRef = (element) => {
|
|
91
|
+
if (!element) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { parentElement } = element;
|
|
95
|
+
if (!parentElement) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const parentElementRect = parentElement.getBoundingClientRect();
|
|
99
|
+
element.style.left = `${parentElementRect.width / 2 - paddingTop}px`;
|
|
100
|
+
};
|
|
101
|
+
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: tooltipRef, className: "tooltip", css: (theme) => tooltipStyle(theme), children: [(0, jsx_runtime_1.jsx)("div", { ref: tooltipArrowRef, className: "tooltip-arrow", "data-position": isTouchingTop ? 'bottom' : 'top' }), (0, jsx_runtime_1.jsx)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: children })] }), targetElement);
|
|
94
102
|
};
|
|
95
103
|
const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body']);
|
|
96
104
|
const Tooltip = (_a) => {
|
|
@@ -98,13 +106,13 @@ const Tooltip = (_a) => {
|
|
|
98
106
|
const [isHovered, setIsHovered] = (0, react_1.useState)(false);
|
|
99
107
|
const boundingRectRef = (0, react_1.useRef)();
|
|
100
108
|
const filteredProps = filterTooltipProps(props);
|
|
101
|
-
const { body } = props;
|
|
109
|
+
const { body, selector = '#wire-app' } = props;
|
|
102
110
|
const onElementEnter = (event) => {
|
|
103
111
|
const boundingRect = event.target.getBoundingClientRect();
|
|
104
112
|
setIsHovered(true);
|
|
105
113
|
boundingRectRef.current = boundingRect;
|
|
106
114
|
};
|
|
107
115
|
const onElementLeave = () => setIsHovered(false);
|
|
108
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ role: "presentation" }, filteredProps, { "data-testid": "tooltip-wrapper", onMouseEnter: onElementEnter, onMouseLeave: onElementLeave, onFocus: onElementEnter, onBlur: onElementLeave }, props, { children: [children, isHovered && (0, jsx_runtime_1.jsx)(PortalComponent, { bounding: boundingRectRef.current, children: body })] })));
|
|
116
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ role: "presentation" }, filteredProps, { "data-testid": "tooltip-wrapper", onMouseEnter: onElementEnter, onMouseLeave: onElementLeave, onFocus: onElementEnter, onBlur: onElementLeave }, props, { children: [children, isHovered && ((0, jsx_runtime_1.jsx)(PortalComponent, { bounding: boundingRectRef.current, selector: selector, children: body }))] })));
|
|
109
117
|
};
|
|
110
118
|
exports.Tooltip = Tooltip;
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@hot-loader/react-dom": "17.0.2",
|
|
27
27
|
"@swc/core": "^1.3.10",
|
|
28
28
|
"@swc/jest": "^0.2.23",
|
|
29
|
-
"@testing-library/jest-dom": "6.4.
|
|
29
|
+
"@testing-library/jest-dom": "6.4.2",
|
|
30
30
|
"@testing-library/react": "14.2.1",
|
|
31
31
|
"@testing-library/user-event": "14.5.2",
|
|
32
32
|
"@types/jest": "^29.2.0",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
"test:watch": "jest --watch",
|
|
71
71
|
"test:update": "jest --updateSnapshot"
|
|
72
72
|
},
|
|
73
|
-
"version": "9.15.
|
|
74
|
-
"gitHead": "
|
|
73
|
+
"version": "9.15.2",
|
|
74
|
+
"gitHead": "197aef37aae4c99370b12f929c7a52aec8cfbef0"
|
|
75
75
|
}
|