@wireapp/react-ui-kit 9.22.0 → 9.23.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.
- package/lib/Form/SelectComponents.js +1 -1
- package/lib/Form/Tooltip.d.ts.map +1 -1
- package/lib/Form/Tooltip.js +51 -25
- package/package.json +4 -4
|
@@ -12,7 +12,7 @@ const SelectContainer = (props) => {
|
|
|
12
12
|
};
|
|
13
13
|
exports.SelectContainer = SelectContainer;
|
|
14
14
|
const isGroup = (options) => {
|
|
15
|
-
return options
|
|
15
|
+
return options?.length > 0 && 'options' in options[0];
|
|
16
16
|
};
|
|
17
17
|
exports.isGroup = isGroup;
|
|
18
18
|
const DropdownIndicator = (props) => {
|
|
@@ -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;AAoJrF,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,qDAmCzD,CAAC"}
|
package/lib/Form/Tooltip.js
CHANGED
|
@@ -62,52 +62,78 @@ const tooltipStyle = theme => ({
|
|
|
62
62
|
position: 'absolute',
|
|
63
63
|
},
|
|
64
64
|
});
|
|
65
|
-
const
|
|
65
|
+
const TooltipArrow = ({ wrapperRect }) => {
|
|
66
|
+
const tooltipArrowRef = (element) => {
|
|
67
|
+
if (!element) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { parentElement } = element;
|
|
71
|
+
if (!parentElement) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const tooltipRect = parentElement.getBoundingClientRect();
|
|
75
|
+
const isTouchingLeftEdge = wrapperRect.x <= tooltipRect.width / 2 + paddingDistance * 2;
|
|
76
|
+
const isTouchingRightEdge = wrapperRect.left + tooltipRect.width / 2 + paddingDistance * 2 >= window.innerWidth;
|
|
77
|
+
if (isTouchingLeftEdge) {
|
|
78
|
+
element.style.left = `${wrapperRect.left - paddingDistance}px`;
|
|
79
|
+
}
|
|
80
|
+
else if (isTouchingRightEdge) {
|
|
81
|
+
const calculateX = window.innerWidth - wrapperRect.right - paddingDistance;
|
|
82
|
+
element.style.right = `${calculateX}px`;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
element.style.left = `50%`;
|
|
86
|
+
element.style.transform = `translateX(-50%)`;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return (0, jsx_runtime_1.jsx)("div", { ref: tooltipArrowRef, className: "tooltip-arrow" });
|
|
90
|
+
};
|
|
91
|
+
const PortalComponent = ({ children, wrapperRect, selector = '#wire-app' }) => {
|
|
66
92
|
const [isTouchingTop, setIsTouchingTop] = (0, react_1.useState)(false);
|
|
67
93
|
const targetElement = document.querySelector(selector);
|
|
68
|
-
if (!targetElement) {
|
|
94
|
+
if (!targetElement || !wrapperRect) {
|
|
69
95
|
return null;
|
|
70
96
|
}
|
|
71
97
|
const tooltipRef = (element) => {
|
|
72
|
-
if (!
|
|
98
|
+
if (!element) {
|
|
73
99
|
return;
|
|
74
100
|
}
|
|
75
|
-
const
|
|
101
|
+
const tooltipRect = element.getBoundingClientRect();
|
|
102
|
+
const isTouchingTopEdge = wrapperRect.y <= tooltipRect.height + paddingDistance * 2;
|
|
76
103
|
setIsTouchingTop(isTouchingTopEdge);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
element.style.
|
|
104
|
+
const isTouchingLeftEdge = wrapperRect.x <= tooltipRect.width / 2 + paddingDistance * 2;
|
|
105
|
+
const isTouchingRightEdge = wrapperRect.left + tooltipRect.width / 2 + paddingDistance * 2 >= window.innerWidth;
|
|
106
|
+
if (isTouchingLeftEdge) {
|
|
107
|
+
element.style.left = `${paddingDistance}px`;
|
|
108
|
+
}
|
|
109
|
+
else if (isTouchingRightEdge) {
|
|
110
|
+
element.style.right = `${paddingDistance}px`;
|
|
81
111
|
}
|
|
82
112
|
else {
|
|
83
|
-
|
|
113
|
+
const elementWidth = (element.scrollWidth - wrapperRect.width) / 2;
|
|
114
|
+
element.style.left = `${wrapperRect.x - elementWidth}px`;
|
|
84
115
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!element) {
|
|
88
|
-
return;
|
|
116
|
+
if (isTouchingTopEdge) {
|
|
117
|
+
element.style.top = `${wrapperRect.y + wrapperRect.height}px`;
|
|
89
118
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return;
|
|
119
|
+
else {
|
|
120
|
+
element.style.top = `${wrapperRect.y - element.clientHeight}px`;
|
|
93
121
|
}
|
|
94
|
-
const parentElementRect = parentElement.getBoundingClientRect();
|
|
95
|
-
element.style.left = `${parentElementRect.width / 2 - paddingDistance}px`;
|
|
96
122
|
};
|
|
97
|
-
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: tooltipRef, className: "tooltip", css: (theme) => tooltipStyle(theme), "data-position": isTouchingTop ? 'bottom' : 'top', children: [(0, jsx_runtime_1.jsx)(
|
|
123
|
+
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: tooltipRef, className: "tooltip", css: (theme) => tooltipStyle(theme), "data-position": isTouchingTop ? 'bottom' : 'top', children: [(0, jsx_runtime_1.jsx)(TooltipArrow, { wrapperRect: wrapperRect }), (0, jsx_runtime_1.jsx)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: children })] }), targetElement);
|
|
98
124
|
};
|
|
99
|
-
const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body']);
|
|
125
|
+
const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body', 'selector']);
|
|
100
126
|
const Tooltip = ({ children, ...props }) => {
|
|
101
127
|
const [isHovered, setIsHovered] = (0, react_1.useState)(false);
|
|
102
|
-
const
|
|
128
|
+
const wrapperRectRef = (0, react_1.useRef)();
|
|
103
129
|
const filteredProps = filterTooltipProps(props);
|
|
104
130
|
const { body, selector = '#wire-app' } = props;
|
|
105
|
-
const onElementEnter = (
|
|
106
|
-
const
|
|
131
|
+
const onElementEnter = ({ currentTarget }) => {
|
|
132
|
+
const wrapperRect = currentTarget.getBoundingClientRect();
|
|
107
133
|
setIsHovered(true);
|
|
108
|
-
|
|
134
|
+
wrapperRectRef.current = wrapperRect;
|
|
109
135
|
};
|
|
110
136
|
const onElementLeave = () => setIsHovered(false);
|
|
111
|
-
return ((0, jsx_runtime_1.jsxs)("div", { role: "presentation",
|
|
137
|
+
return ((0, jsx_runtime_1.jsxs)("div", { role: "presentation", "data-testid": "tooltip-wrapper", onMouseEnter: onElementEnter, onMouseLeave: onElementLeave, onFocus: onElementEnter, onBlur: onElementLeave, style: { width: 'max-content' }, ...filteredProps, children: [(0, jsx_runtime_1.jsx)("div", { id: "childrenElement", children: children }), isHovered && ((0, jsx_runtime_1.jsx)(PortalComponent, { wrapperRect: wrapperRectRef.current, selector: selector, children: body }))] }));
|
|
112
138
|
};
|
|
113
139
|
exports.Tooltip = Tooltip;
|
package/package.json
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@babel/cli": "7.24.8",
|
|
19
|
-
"@babel/core": "7.
|
|
20
|
-
"@babel/preset-env": "7.25.
|
|
19
|
+
"@babel/core": "7.25.2",
|
|
20
|
+
"@babel/preset-env": "7.25.3",
|
|
21
21
|
"@babel/preset-react": "7.24.7",
|
|
22
22
|
"@babel/preset-typescript": "7.24.7",
|
|
23
23
|
"@emotion/babel-preset-css-prop": "^11.10.0",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
"test:watch": "jest --watch",
|
|
71
71
|
"test:update": "jest --updateSnapshot"
|
|
72
72
|
},
|
|
73
|
-
"version": "9.
|
|
74
|
-
"gitHead": "
|
|
73
|
+
"version": "9.23.1",
|
|
74
|
+
"gitHead": "770b4a01d2b88aa3e07a0f737c481fcb0819bcc6"
|
|
75
75
|
}
|