@wireapp/react-ui-kit 9.14.1 → 9.15.0

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.
@@ -1,9 +1,7 @@
1
- import * as React from 'react';
2
- interface ToolTipProps<T = HTMLDivElement> extends React.HTMLProps<T> {
3
- position?: 'top' | 'right' | 'left' | 'bottom';
4
- body: React.ReactNode;
5
- isOpen?: boolean;
1
+ import { HTMLProps, ReactNode } from 'react';
2
+ interface TooltipProps<T = HTMLDivElement> extends HTMLProps<T> {
3
+ body: ReactNode;
6
4
  }
7
- export declare const Tooltip: ({ children, ...props }: ToolTipProps) => import("@emotion/react/jsx-runtime").JSX.Element;
5
+ export declare const Tooltip: ({ children, ...props }: TooltipProps) => import("@emotion/react/jsx-runtime").JSX.Element;
8
6
  export {};
9
7
  //# sourceMappingURL=Tooltip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,UAAU,YAAY,CAAC,CAAC,GAAG,cAAc,CAAE,SAAQ,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACnE,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC/C,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAoGD,eAAO,MAAM,OAAO,2BAA0B,YAAY,qDAoBzD,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;AAgGrF,UAAU,YAAY,CAAC,CAAC,GAAG,cAAc,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC7D,IAAI,EAAE,SAAS,CAAC;CACjB;AAID,eAAO,MAAM,OAAO,2BAA0B,YAAY,qDA6BzD,CAAC"}
@@ -13,107 +13,98 @@ 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: 'relative',
19
- width: 'fit-content',
20
- '&:hover .tooltip-content, &:focus-within .tooltip-content,': {
21
- visibility: 'visible',
22
- opacity: 1,
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
- borderRadius: 4,
38
- fontSize: theme.fontSizes.small,
39
- fontWeight: 500,
40
- whiteSpace: 'nowrap',
41
- transition: 'opacity ease-out 150ms, bottom ease-out 150ms',
42
- boxShadow: '1px 2px 6px rgba(0, 0, 0, 0.3)',
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
- '& .tooltip-content .tooltip-arrow': {
45
- position: 'absolute',
53
+ '.tooltip-arrow': {
46
54
  width: 0,
47
55
  height: 0,
48
- },
49
- "&[data-position='top'] .tooltip-content": {
50
- bottom: '100%',
51
- marginBottom: 10,
52
- left: '50%',
53
- transform: 'translateX(-50%)',
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,
78
- },
79
- },
80
- "&[data-position='bottom'] .tooltip-content": {
81
- top: '100%',
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%)',
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',
93
62
  },
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 filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['position', 'body', 'isOpen']);
69
+ const PortalComponent = ({ children, bounding }) => {
70
+ const bodyElement = document.querySelector('#wire-app');
71
+ const [isTouchingTop, setIsTouchingTop] = (0, react_1.useState)(false);
72
+ if (!bodyElement) {
73
+ return null;
74
+ }
75
+ return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: element => {
76
+ if (!bounding) {
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
+ }, className: "tooltip", css: (theme) => tooltipStyle(theme), children: [(0, jsx_runtime_1.jsx)("div", { ref: element => {
90
+ const { parentElement } = element;
91
+ const parentElementRect = parentElement.getBoundingClientRect();
92
+ element.style.left = `${parentElementRect.width / 2 - paddingTop}px`;
93
+ }, className: "tooltip-arrow", "data-position": isTouchingTop ? 'bottom' : 'top' }), (0, jsx_runtime_1.jsx)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: children })] }), bodyElement);
94
+ };
95
+ const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body']);
113
96
  const Tooltip = (_a) => {
114
97
  var { children } = _a, props = __rest(_a, ["children"]);
98
+ const [isHovered, setIsHovered] = (0, react_1.useState)(false);
99
+ const boundingRectRef = (0, react_1.useRef)();
115
100
  const filteredProps = filterTooltipProps(props);
116
- const { body, position = 'top', isOpen = true } = props;
117
- return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: (theme) => tooltipStyle(theme), "data-position": position }, filteredProps, { "data-testid": "tooltip-wrapper", children: [isOpen && ((0, jsx_runtime_1.jsxs)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: [body, (0, jsx_runtime_1.jsx)("div", { className: "tooltip-arrow" })] })), children] })));
101
+ const { body } = props;
102
+ const onElementEnter = (event) => {
103
+ const boundingRect = event.target.getBoundingClientRect();
104
+ setIsHovered(true);
105
+ boundingRectRef.current = boundingRect;
106
+ };
107
+ 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 })] })));
118
109
  };
119
110
  exports.Tooltip = Tooltip;
package/package.json CHANGED
@@ -70,6 +70,6 @@
70
70
  "test:watch": "jest --watch",
71
71
  "test:update": "jest --updateSnapshot"
72
72
  },
73
- "version": "9.14.1",
74
- "gitHead": "fab0ea474634672e14aa2bd8a5026483e1b194da"
73
+ "version": "9.15.0",
74
+ "gitHead": "fe747cc950bfe5600b84d2164cb8f93a28c58a15"
75
75
  }