@wireapp/react-ui-kit 9.14.1 → 9.15.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/Tooltip.d.ts +5 -6
- package/lib/Form/Tooltip.d.ts.map +1 -1
- package/lib/Form/Tooltip.js +87 -88
- package/package.json +2 -2
package/lib/Form/Tooltip.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
interface
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
isOpen?: boolean;
|
|
1
|
+
import { HTMLProps, ReactNode } from 'react';
|
|
2
|
+
interface TooltipProps<T = HTMLDivElement> extends HTMLProps<T> {
|
|
3
|
+
body: ReactNode;
|
|
4
|
+
selector?: string;
|
|
6
5
|
}
|
|
7
|
-
export declare const Tooltip: ({ children, ...props }:
|
|
6
|
+
export declare const Tooltip: ({ children, ...props }: TooltipProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=Tooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,
|
|
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
|
@@ -13,107 +13,106 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.Tooltip = void 0;
|
|
15
15
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
16
|
+
/*
|
|
17
|
+
* Wire
|
|
18
|
+
* Copyright (C) 2022 Wire Swiss GmbH
|
|
19
|
+
*
|
|
20
|
+
* This program is free software: you can redistribute it and/or modify
|
|
21
|
+
* it under the terms of the GNU General Public License as published by
|
|
22
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
23
|
+
* (at your option) any later version.
|
|
24
|
+
*
|
|
25
|
+
* This program is distributed in the hope that it will be useful,
|
|
26
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28
|
+
* GNU General Public License for more details.
|
|
29
|
+
*
|
|
30
|
+
* You should have received a copy of the GNU General Public License
|
|
31
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
const react_1 = require("react");
|
|
35
|
+
const react_dom_1 = require("react-dom");
|
|
16
36
|
const util_1 = require("../util");
|
|
37
|
+
const paddingTop = 6;
|
|
17
38
|
const tooltipStyle = theme => ({
|
|
18
|
-
position: '
|
|
19
|
-
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
zIndex: '99999',
|
|
41
|
+
maxWidth: '300px',
|
|
42
|
+
filter: 'drop-shadow(1px 2px 6px rgba(0, 0, 0, 0.3))',
|
|
43
|
+
borderRadius: '4px',
|
|
24
44
|
'.tooltip-content': {
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
visibility: 'hidden',
|
|
27
|
-
opacity: 0,
|
|
28
|
-
width: 'max-content',
|
|
29
|
-
height: 'max-content',
|
|
30
|
-
position: 'absolute',
|
|
31
|
-
boxSizing: 'border-box',
|
|
32
|
-
display: 'block',
|
|
33
|
-
margin: '0 auto',
|
|
34
|
-
padding: '4px 8px',
|
|
35
|
-
backgroundColor: theme.Tooltip.backgroundColor,
|
|
36
45
|
color: theme.Tooltip.color,
|
|
37
|
-
|
|
38
|
-
fontSize:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
backgroundColor: theme.Tooltip.backgroundColor,
|
|
47
|
+
fontSize: '12px',
|
|
48
|
+
lineHeight: '14px',
|
|
49
|
+
fontWeight: 400,
|
|
50
|
+
padding: `${paddingTop}px 8px`,
|
|
51
|
+
textAlign: 'center',
|
|
43
52
|
},
|
|
44
|
-
'
|
|
45
|
-
position: 'absolute',
|
|
53
|
+
'.tooltip-arrow': {
|
|
46
54
|
width: 0,
|
|
47
55
|
height: 0,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
'& .tooltip-arrow': {
|
|
55
|
-
filter: 'drop-shadow(0px 2px 1px rgba(0, 0, 0, 0.1))',
|
|
56
|
-
borderLeft: '12px solid transparent',
|
|
57
|
-
borderRight: '12px solid transparent',
|
|
58
|
-
borderTop: `12px solid ${theme.Tooltip.backgroundColor}`,
|
|
59
|
-
top: '90%',
|
|
60
|
-
left: '50%',
|
|
61
|
-
transform: 'translateX(-50%)',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
"&[data-position='right'] .tooltip-content": {
|
|
65
|
-
left: '100%',
|
|
66
|
-
marginLeft: '8px !important',
|
|
67
|
-
top: 0,
|
|
68
|
-
bottom: 0,
|
|
69
|
-
margin: 'auto 0',
|
|
70
|
-
'& .tooltip-arrow': {
|
|
71
|
-
filter: 'drop-shadow(-2px 0px 1px rgba(0, 0, 0, 0.1))',
|
|
72
|
-
borderTop: '8px solid transparent',
|
|
73
|
-
borderBottom: '8px solid transparent',
|
|
74
|
-
borderRight: `8px solid ${theme.Tooltip.backgroundColor}`,
|
|
75
|
-
top: '50%',
|
|
76
|
-
transform: 'translateY(-50%)',
|
|
77
|
-
left: -7,
|
|
56
|
+
borderLeft: '6px solid transparent',
|
|
57
|
+
borderRight: '6px solid transparent',
|
|
58
|
+
position: 'absolute',
|
|
59
|
+
"&[data-position='top']": {
|
|
60
|
+
borderTop: `10px solid ${theme.Tooltip.backgroundColor}`,
|
|
61
|
+
bottom: '-6px',
|
|
78
62
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
marginTop: 10,
|
|
83
|
-
left: '50%',
|
|
84
|
-
transform: 'translateX(-50%)',
|
|
85
|
-
'& .tooltip-arrow': {
|
|
86
|
-
filter: 'drop-shadow(0px -2px 1px rgba(0, 0, 0, 0.1))',
|
|
87
|
-
borderLeft: '12px solid transparent',
|
|
88
|
-
borderRight: '12px solid transparent',
|
|
89
|
-
borderBottom: `12px solid ${theme.Tooltip.backgroundColor}`,
|
|
90
|
-
bottom: '90%',
|
|
91
|
-
left: '50%',
|
|
92
|
-
transform: 'translateX(-50%)',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
"&[data-position='left'] .tooltip-content": {
|
|
96
|
-
right: '100%',
|
|
97
|
-
marginRight: '8px !important',
|
|
98
|
-
top: 0,
|
|
99
|
-
bottom: 0,
|
|
100
|
-
margin: 'auto 0',
|
|
101
|
-
'& .tooltip-arrow': {
|
|
102
|
-
filter: 'drop-shadow(2px 0px 1px rgba(0, 0, 0, 0.1))',
|
|
103
|
-
borderTop: '8px solid transparent',
|
|
104
|
-
borderBottom: '8px solid transparent',
|
|
105
|
-
borderLeft: `8px solid ${theme.Tooltip.backgroundColor}`,
|
|
106
|
-
top: '50%',
|
|
107
|
-
transform: 'translateY(-50%)',
|
|
108
|
-
right: -7,
|
|
63
|
+
"&[data-position='bottom']": {
|
|
64
|
+
borderBottom: `10px solid ${theme.Tooltip.backgroundColor}`,
|
|
65
|
+
top: '-6px',
|
|
109
66
|
},
|
|
110
67
|
},
|
|
111
68
|
});
|
|
112
|
-
const
|
|
69
|
+
const PortalComponent = ({ children, bounding, selector = '#wire-app' }) => {
|
|
70
|
+
const [isTouchingTop, setIsTouchingTop] = (0, react_1.useState)(false);
|
|
71
|
+
const targetElement = document.querySelector(selector);
|
|
72
|
+
if (!targetElement) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
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);
|
|
102
|
+
};
|
|
103
|
+
const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body']);
|
|
113
104
|
const Tooltip = (_a) => {
|
|
114
105
|
var { children } = _a, props = __rest(_a, ["children"]);
|
|
106
|
+
const [isHovered, setIsHovered] = (0, react_1.useState)(false);
|
|
107
|
+
const boundingRectRef = (0, react_1.useRef)();
|
|
115
108
|
const filteredProps = filterTooltipProps(props);
|
|
116
|
-
const { body,
|
|
117
|
-
|
|
109
|
+
const { body, selector = '#wire-app' } = props;
|
|
110
|
+
const onElementEnter = (event) => {
|
|
111
|
+
const boundingRect = event.target.getBoundingClientRect();
|
|
112
|
+
setIsHovered(true);
|
|
113
|
+
boundingRectRef.current = boundingRect;
|
|
114
|
+
};
|
|
115
|
+
const onElementLeave = () => setIsHovered(false);
|
|
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 }))] })));
|
|
118
117
|
};
|
|
119
118
|
exports.Tooltip = Tooltip;
|
package/package.json
CHANGED