akeneo-design-system 0.1.218 → 0.1.220

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,11 +76,7 @@ var SectionTitle = function (_a) {
76
76
  });
77
77
  }
78
78
  if ((0, react_1.isValidElement)(child) && child.type === components_1.Button) {
79
- return (0, react_1.cloneElement)(child, {
80
- level: 'tertiary',
81
- size: 'small',
82
- ghost: true,
83
- });
79
+ return (0, react_1.cloneElement)(child, __assign({ level: 'tertiary', size: 'small', ghost: true }, child.props));
84
80
  }
85
81
  return child;
86
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"SectionTitle.js","sourceRoot":"","sources":["../../../src/components/SectionTitle/SectionTitle.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+F;AAC/F,qEAA8C;AAC9C,qCAAqE;AACrE,+CAAkF;AAGlF,IAAM,qBAAqB,GAAG,2BAAM,CAAC,GAAG,kOAAuC,8IAOlD,EAAqB,SAE9C,EAOC,IACJ,KAV4B,IAAA,gBAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EAE9C,UAAC,EAAQ;QAAP,MAAM,YAAA;IACR,OAAA,SAAS,KAAK,MAAM,QACpB,uBAAG,2KAAA,wCAEM,EAAM,+BACO,EAAiB,4BAEtC,KAHQ,MAAM,EACO,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAEtC;AAND,CAMC,CACJ,CAAC;AAEF,IAAM,cAAc,GAAG,2BAAM,CAAC,EAAE,kOAAgC,aACrD,EAAqB,kBACjB,EAAkB,4CAEb,EAA0D,8EAI7E,KAPU,IAAA,gBAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EACjB,IAAA,mBAAW,EAAC,KAAK,CAAC,EAEb,UAAC,EAAO;QAAN,KAAK,WAAA;IAAM,OAAA,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;AAA7C,CAA6C,CAI7E,CAAC;AASF,IA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AAK,CAAC,IAAI,KAAK,mBAAM,EAAE;YAC/D,OAAO,IAAA,oBAAY,EAAC,KAAK,aACvB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,IAAI,IACR,KAAK,CAAC,KAAK,EACd,CAAC;SACJ;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,8BAAC,qBAAqB,eAAK,IAAI,GAAG,iBAAiB,CAAyB,CAAC;AACtF,CAAC,CAAC;AAOM,oCAAY;AALpB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC;AAC7B,YAAY,CAAC,SAAS,GAAG,SAAS,CAAC;AACnC,YAAY,CAAC,WAAW,GAAG,WAAW,CAAC"}
@@ -1,9 +1,11 @@
1
- import React from 'react';
2
- declare const Tooltip: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "width" | "direction" | "children" | "zIndex" | "iconSize"> & {
3
- direction?: "left" | "right" | "bottom" | "top" | undefined;
4
- zIndex?: number | undefined;
5
- iconSize?: number | undefined;
6
- children: React.ReactNode;
7
- width?: number | undefined;
8
- } & React.RefAttributes<HTMLDivElement>>;
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ import { Override } from '../../shared';
3
+ declare type Direction = 'top' | 'right' | 'bottom' | 'left';
4
+ declare type TooltipProps = Override<HTMLAttributes<HTMLDivElement>, {
5
+ direction?: Direction;
6
+ iconSize?: number;
7
+ children: ReactNode;
8
+ width?: number;
9
+ }>;
10
+ declare const Tooltip: ({ direction, iconSize, width, children, ...rest }: TooltipProps) => JSX.Element;
9
11
  export { Tooltip };
@@ -50,6 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.Tooltip = void 0;
52
52
  var react_1 = __importStar(require("react"));
53
+ var react_dom_1 = require("react-dom");
53
54
  var styled_components_1 = __importDefault(require("styled-components"));
54
55
  var icons_1 = require("../../icons");
55
56
  var theme_1 = require("../../theme");
@@ -62,36 +63,67 @@ var TooltipContainer = styled_components_1.default.div(templateObject_1 || (temp
62
63
  var size = _a.size;
63
64
  return size + TooltipIconMargin * 2;
64
65
  });
65
- var TooltipIcon = (0, styled_components_1.default)(icons_1.HelpPlainIcon)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin: ", "px;\n"], ["\n margin: ", "px;\n"])), TooltipIconMargin);
66
- var TooltipContent = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n border-radius: 4px;\n left: 50%;\n padding: 10px;\n width: ", "px;\n color: ", ";\n background: ", ";\n border: 1px solid ", ";\n font-size: ", ";\n line-height: 1;\n text-transform: none;\n z-index: ", ";\n box-shadow: 0 0 16px rgba(89, 146, 199, 0.25);\n\n ", "\n"], ["\n position: absolute;\n border-radius: 4px;\n left: 50%;\n padding: 10px;\n width: ", "px;\n color: ", ";\n background: ", ";\n border: 1px solid ", ";\n font-size: ", ";\n line-height: 1;\n text-transform: none;\n z-index: ", ";\n box-shadow: 0 0 16px rgba(89, 146, 199, 0.25);\n\n ", "\n"])), function (_a) {
66
+ var TooltipIcon = (0, styled_components_1.default)(icons_1.HelpPlainIcon)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin: ", "px;\n color: ", ";\n"], ["\n margin: ", "px;\n color: ", ";\n"])), TooltipIconMargin, (0, theme_1.getColor)('blue', 100));
67
+ var TooltipContent = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", "\n position: fixed;\n z-index: 1901;\n border-radius: 4px;\n padding: 10px;\n width: ", "px;\n color: ", ";\n background: ", ";\n border: 1px solid ", ";\n font-size: ", ";\n line-height: 1;\n text-transform: none;\n box-shadow: 0 0 16px rgba(89, 146, 199, 0.25);\n top: ", "px;\n left: ", "px;\n opacity: ", ";\n"], ["\n ", "\n position: fixed;\n z-index: 1901;\n border-radius: 4px;\n padding: 10px;\n width: ", "px;\n color: ", ";\n background: ", ";\n border: 1px solid ", ";\n font-size: ", ";\n line-height: 1;\n text-transform: none;\n box-shadow: 0 0 16px rgba(89, 146, 199, 0.25);\n top: ", "px;\n left: ", "px;\n opacity: ", ";\n"])), theme_1.CommonStyle, function (_a) {
67
68
  var width = _a.width;
68
69
  return width;
69
70
  }, (0, theme_1.getColor)('grey', 120), (0, theme_1.getColor)('blue', 10), (0, theme_1.getColor)('blue', 40), (0, theme_1.getFontSize)('default'), function (_a) {
70
- var zIndex = _a.zIndex;
71
- return zIndex;
71
+ var top = _a.top;
72
+ return top;
72
73
  }, function (_a) {
73
- var direction = _a.direction;
74
+ var left = _a.left;
75
+ return left;
76
+ }, function (_a) {
77
+ var top = _a.top, left = _a.left;
78
+ return (-1 === top && -1 === left ? 0 : 1);
79
+ });
80
+ var computePosition = function (direction, parentRef, elementRef) {
81
+ if (undefined === parentRef ||
82
+ undefined === elementRef ||
83
+ null === parentRef.current ||
84
+ null === elementRef.current) {
85
+ return [-1, -1];
86
+ }
87
+ var _a = parentRef.current.getBoundingClientRect(), parentTop = _a.top, parentLeft = _a.left, parentWidth = _a.width, parentHeight = _a.height;
88
+ var _b = elementRef.current.getBoundingClientRect(), elementWidth = _b.width, elementHeight = _b.height;
89
+ var relativeCenterTop = parentTop + parentHeight / 2 - elementHeight / 2;
90
+ var relativeCenterLeft = parentLeft + parentWidth / 2 - elementWidth / 2;
74
91
  switch (direction) {
92
+ default:
93
+ case 'top':
94
+ return [parentTop - elementHeight, relativeCenterLeft];
95
+ case 'right':
96
+ return [relativeCenterTop, parentLeft + parentWidth];
75
97
  case 'bottom':
76
- return "\n top: calc(100%);\n transform: translateX(-50%);\n ";
98
+ return [parentTop + parentHeight, relativeCenterLeft];
77
99
  case 'left':
78
- return "\n left: auto;\n top: 50%;\n right: calc(100%);\n transform: translateY(-50%);\n ";
79
- case 'right':
80
- return "\n top: 50%;\n left: calc(100%);\n transform: translateY(-50%);\n ";
81
- default:
82
- return "\n bottom: calc(100%);\n transform: translateX(-50%);\n ";
100
+ return [relativeCenterTop, parentLeft - elementWidth];
83
101
  }
84
- });
85
- var Tooltip = (0, react_1.forwardRef)(function (_a, forwardedRef) {
86
- var _b = _a.direction, direction = _b === void 0 ? 'top' : _b, _c = _a.zIndex, zIndex = _c === void 0 ? 100 : _c, _d = _a.iconSize, iconSize = _d === void 0 ? 24 : _d, _e = _a.width, width = _e === void 0 ? 200 : _e, children = _a.children, rest = __rest(_a, ["direction", "zIndex", "iconSize", "width", "children"]);
87
- var _f = (0, react_1.useState)(false), visible = _f[0], setVisible = _f[1];
88
- var showTooltip = function () { return setVisible(true); };
89
- var hideTooltip = function () { return setVisible(false); };
90
- var theme = (0, hooks_1.useTheme)();
91
- return (react_1.default.createElement(TooltipContainer, __assign({ ref: forwardedRef }, rest, { size: iconSize, onMouseEnter: showTooltip, onMouseLeave: hideTooltip }),
92
- react_1.default.createElement(TooltipIcon, { size: iconSize, color: theme.color.blue100 }),
93
- visible && (react_1.default.createElement(TooltipContent, { direction: direction, zIndex: zIndex, width: width }, children))));
94
- });
102
+ };
103
+ var Tooltip = function (_a) {
104
+ var _b = _a.direction, direction = _b === void 0 ? 'top' : _b, _c = _a.iconSize, iconSize = _c === void 0 ? 24 : _c, _d = _a.width, width = _d === void 0 ? 200 : _d, children = _a.children, rest = __rest(_a, ["direction", "iconSize", "width", "children"]);
105
+ var _e = (0, hooks_1.useBooleanState)(false), isVisible = _e[0], showTooltip = _e[1], hideTooltip = _e[2];
106
+ var portalNode = document.createElement('div');
107
+ portalNode.setAttribute('id', 'tooltip-root');
108
+ var portalRef = (0, react_1.useRef)(portalNode);
109
+ var parentRef = (0, react_1.useRef)(null);
110
+ var contentRef = (0, react_1.useRef)(null);
111
+ var _f = (0, react_1.useState)([0, 0]), position = _f[0], setPosition = _f[1];
112
+ (0, react_1.useEffect)(function () {
113
+ document.body.appendChild(portalRef.current);
114
+ return function () {
115
+ document.body.removeChild(portalRef.current);
116
+ };
117
+ }, []);
118
+ (0, react_1.useEffect)(function () {
119
+ setPosition(computePosition(direction, parentRef, contentRef));
120
+ }, [children, direction, parentRef, contentRef, isVisible]);
121
+ var top = position[0], left = position[1];
122
+ return (react_1.default.createElement(TooltipContainer, __assign({ ref: parentRef, role: "tooltip" }, rest, { size: iconSize, onMouseEnter: showTooltip, onMouseLeave: hideTooltip }),
123
+ react_1.default.createElement(TooltipIcon, { size: iconSize }),
124
+ isVisible &&
125
+ (0, react_dom_1.createPortal)(react_1.default.createElement(TooltipContent, { ref: contentRef, direction: direction, width: width, top: top, left: left }, children), portalRef.current)));
126
+ };
95
127
  exports.Tooltip = Tooltip;
96
128
  var templateObject_1, templateObject_2, templateObject_3;
97
129
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAuE;AACvE,wEAAuC;AAEvC,qCAA0C;AAC1C,qCAAqE;AACrE,qCAAqC;AAErC,IAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,IAAM,gBAAgB,GAAG,2BAAM,CAAC,GAAG,6JAAgB,qCAEvC,EAAwC,gBACzC,EAAwC,iCAElD,KAHW,UAAC,EAAM;QAAL,IAAI,UAAA;IAAM,OAAA,IAAI,GAAG,iBAAiB,GAAG,CAAC;AAA5B,CAA4B,EACzC,UAAC,EAAM;QAAL,IAAI,UAAA;IAAM,OAAA,IAAI,GAAG,iBAAiB,GAAG,CAAC;AAA5B,CAA4B,CAElD,CAAC;AAEF,IAAM,WAAW,GAAG,IAAA,2BAAM,EAAC,qBAAa,CAAC,0FAAA,cAC7B,EAAiB,OAC5B,KADW,iBAAiB,CAC5B,CAAC;AAEF,IAAM,cAAc,GAAG,2BAAM,CAAC,GAAG,qXAAwE,2FAK9F,E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3
- "version": "0.1.218",
3
+ "version": "0.1.220",
4
4
  "description": "Akeneo design system",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -51,7 +51,7 @@ Use this component only for title, not for description or help message.
51
51
  <SectionTitle.Information>10 results</SectionTitle.Information>
52
52
  <SectionTitle.Separator />
53
53
  <Button>Action</Button>
54
- <Button>Action</Button>
54
+ <Button level="danger">Action</Button>
55
55
  <IconButton icon={<MoreIcon />} title="More" />
56
56
  </SectionTitle>
57
57
  </Story>
@@ -94,6 +94,7 @@ const SectionTitle = ({children, ...rest}: SectionTitleProps) => {
94
94
  level: 'tertiary',
95
95
  size: 'small',
96
96
  ghost: true,
97
+ ...child.props,
97
98
  });
98
99
  }
99
100
 
@@ -1,50 +1,43 @@
1
1
  import {Meta, Story, ArgsTable, Canvas} from '@storybook/addon-docs';
2
2
  import {Tooltip} from './Tooltip.tsx';
3
3
 
4
- <Meta
5
- title="Components/Tooltip"
6
- component={Tooltip}
7
- args={{direction: 'top', content: 'Tooltip content'}}
8
- />
4
+ <Meta title="Components/Tooltip" component={Tooltip} args={{direction: 'top', content: 'Tooltip content'}} />
9
5
 
10
6
  # Tooltip
11
7
 
12
8
  ## Usage
13
9
 
14
- Its a complementary information that will help the user better understand what he sees / reads (e.g. definition, explication concerning the UI / wording)
10
+ It's a complementary information that will help the user better understand what he sees / reads (e.g. definition, explication concerning the UI / wording)
15
11
 
16
12
  👍 **Good reasons to use the tooltip :**
17
13
 
18
14
  - There are too many helpers in the page, it would blur the readability
19
- - There isnt enough space in the page to integrate a helper, so we need an overlay
15
+ - There isn't enough space in the page to integrate a helper, so we need an overlay
20
16
 
21
17
  👎 **Bad reasons to use the tooltip :**
22
18
 
23
- - Its an important guiding information to navigate, enrich or complete a task (use a helper instead)
24
- - I find it more beautiful (it shouldnt matter first)
25
- - Its an error explanation (this needs to be in a helper)
26
-
19
+ - It's an important guiding information to navigate, enrich or complete a task (use a helper instead)
20
+ - I find it more beautiful (it shouldn't matter first)
21
+ - It's an error explanation (this needs to be in a helper)
27
22
 
28
23
  ## Playground
29
24
 
30
25
  <Canvas>
31
26
  <Story
32
- name="Standard"
33
- parameters={{
27
+ name="Standard"
28
+ parameters={{
34
29
  layout: 'centered',
35
30
  }}
36
31
  decorators={[
37
- (Story) => (
32
+ Story => (
38
33
  <div style={{display: 'flex', justifyContent: 'center', alignItems: 'center', height: '200px'}}>
39
34
  <Story />
40
35
  </div>
41
36
  ),
42
37
  ]}
43
- >
38
+ >
44
39
  {args => {
45
- return <Tooltip {...args}>
46
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
47
- </Tooltip>;
40
+ return <Tooltip {...args}>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</Tooltip>;
48
41
  }}
49
42
  </Story>
50
43
  </Canvas>
@@ -1,9 +1,12 @@
1
- import React, {forwardRef, Ref, HTMLAttributes, useState} from 'react';
1
+ import React, {HTMLAttributes, ReactNode, useRef, useEffect, RefObject, useState} from 'react';
2
+ import {createPortal} from 'react-dom';
2
3
  import styled from 'styled-components';
3
4
  import {Override} from '../../shared';
4
5
  import {HelpPlainIcon} from '../../icons';
5
- import {AkeneoThemedProps, getColor, getFontSize} from '../../theme';
6
- import {useTheme} from '../../hooks';
6
+ import {AkeneoThemedProps, CommonStyle, getColor, getFontSize} from '../../theme';
7
+ import {useBooleanState} from '../../hooks';
8
+
9
+ type Direction = 'top' | 'right' | 'bottom' | 'left';
7
10
 
8
11
  const TooltipIconMargin = 5;
9
12
  const TooltipContainer = styled.div<{size: number}>`
@@ -15,12 +18,14 @@ const TooltipContainer = styled.div<{size: number}>`
15
18
 
16
19
  const TooltipIcon = styled(HelpPlainIcon)`
17
20
  margin: ${TooltipIconMargin}px;
21
+ color: ${getColor('blue', 100)};
18
22
  `;
19
23
 
20
- const TooltipContent = styled.div<{direction: string; zIndex: number; width: number} & AkeneoThemedProps>`
21
- position: absolute;
24
+ const TooltipContent = styled.div<{direction: Direction; width: number; top: number; left: number} & AkeneoThemedProps>`
25
+ ${CommonStyle}
26
+ position: fixed;
27
+ z-index: 1901;
22
28
  border-radius: 4px;
23
- left: 50%;
24
29
  padding: 10px;
25
30
  width: ${({width}) => width}px;
26
31
  color: ${getColor('grey', 120)};
@@ -29,91 +34,118 @@ const TooltipContent = styled.div<{direction: string; zIndex: number; width: num
29
34
  font-size: ${getFontSize('default')};
30
35
  line-height: 1;
31
36
  text-transform: none;
32
- z-index: ${({zIndex}) => zIndex};
33
37
  box-shadow: 0 0 16px rgba(89, 146, 199, 0.25);
34
-
35
- ${({direction}) => {
36
- switch (direction) {
37
- case 'bottom':
38
- return `
39
- top: calc(100%);
40
- transform: translateX(-50%);
41
- `;
42
- case 'left':
43
- return `
44
- left: auto;
45
- top: 50%;
46
- right: calc(100%);
47
- transform: translateY(-50%);
48
- `;
49
- case 'right':
50
- return `
51
- top: 50%;
52
- left: calc(100%);
53
- transform: translateY(-50%);
54
- `;
55
- default:
56
- return `
57
- bottom: calc(100%);
58
- transform: translateX(-50%);
59
- `;
60
- }
61
- }}
38
+ top: ${({top}) => top}px;
39
+ left: ${({left}) => left}px;
40
+ opacity: ${({top, left}) => (-1 === top && -1 === left ? 0 : 1)};
62
41
  `;
63
42
 
43
+ const computePosition = (
44
+ direction: Direction,
45
+ parentRef?: RefObject<HTMLDivElement>,
46
+ elementRef?: RefObject<HTMLDivElement>
47
+ ): number[] => {
48
+ if (
49
+ undefined === parentRef ||
50
+ undefined === elementRef ||
51
+ null === parentRef.current ||
52
+ null === elementRef.current
53
+ ) {
54
+ return [-1, -1];
55
+ }
56
+
57
+ const {
58
+ top: parentTop,
59
+ left: parentLeft,
60
+ width: parentWidth,
61
+ height: parentHeight,
62
+ } = parentRef.current.getBoundingClientRect();
63
+
64
+ const {width: elementWidth, height: elementHeight} = elementRef.current.getBoundingClientRect();
65
+
66
+ const relativeCenterTop = parentTop + parentHeight / 2 - elementHeight / 2;
67
+ const relativeCenterLeft = parentLeft + parentWidth / 2 - elementWidth / 2;
68
+
69
+ switch (direction) {
70
+ default:
71
+ case 'top':
72
+ return [parentTop - elementHeight, relativeCenterLeft];
73
+ case 'right':
74
+ return [relativeCenterTop, parentLeft + parentWidth];
75
+ case 'bottom':
76
+ return [parentTop + parentHeight, relativeCenterLeft];
77
+ case 'left':
78
+ return [relativeCenterTop, parentLeft - elementWidth];
79
+ }
80
+ };
81
+
64
82
  type TooltipProps = Override<
65
83
  HTMLAttributes<HTMLDivElement>,
66
84
  {
67
85
  /**
68
- * Define the direction in which the tooltip will be rendered
69
- */
70
- direction?: 'top' | 'right' | 'bottom' | 'left';
71
- /**
72
- * Define the position order of the tooltip
86
+ * Define the direction in which the tooltip will be rendered.
73
87
  */
74
- zIndex?: number;
88
+ direction?: Direction;
89
+
75
90
  /**
76
- * Define the icon size
91
+ * Define the icon size.
77
92
  */
78
93
  iconSize?: number;
94
+
79
95
  /**
80
- * Content of the tooltip
96
+ * Content of the tooltip.
81
97
  */
82
- children: React.ReactNode;
98
+ children: ReactNode;
99
+
83
100
  /**
84
- * Define the width of the tooltip
101
+ * Define the width of the tooltip.
85
102
  */
86
103
  width?: number;
87
104
  }
88
105
  >;
89
106
 
90
- const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
91
- (
92
- {direction = 'top', zIndex = 100, iconSize = 24, width = 200, children, ...rest}: TooltipProps,
93
- forwardedRef: Ref<HTMLDivElement>
94
- ) => {
95
- const [visible, setVisible] = useState(false);
96
- const showTooltip = () => setVisible(true);
97
- const hideTooltip = () => setVisible(false);
98
- const theme = useTheme();
99
-
100
- return (
101
- <TooltipContainer
102
- ref={forwardedRef}
103
- {...rest}
104
- size={iconSize}
105
- onMouseEnter={showTooltip}
106
- onMouseLeave={hideTooltip}
107
- >
108
- <TooltipIcon size={iconSize} color={theme.color.blue100} />
109
- {visible && (
110
- <TooltipContent direction={direction} zIndex={zIndex} width={width}>
107
+ const Tooltip = ({direction = 'top', iconSize = 24, width = 200, children, ...rest}: TooltipProps) => {
108
+ const [isVisible, showTooltip, hideTooltip] = useBooleanState(false);
109
+ const portalNode = document.createElement('div');
110
+ portalNode.setAttribute('id', 'tooltip-root');
111
+ const portalRef = useRef<HTMLDivElement>(portalNode);
112
+ const parentRef = useRef<HTMLDivElement>(null);
113
+ const contentRef = useRef<HTMLDivElement>(null);
114
+ const [position, setPosition] = useState<number[]>([0, 0]);
115
+
116
+ useEffect(() => {
117
+ document.body.appendChild(portalRef.current);
118
+
119
+ return () => {
120
+ document.body.removeChild(portalRef.current);
121
+ };
122
+ }, []);
123
+
124
+ useEffect(() => {
125
+ setPosition(computePosition(direction, parentRef, contentRef));
126
+ }, [children, direction, parentRef, contentRef, isVisible]);
127
+
128
+ const [top, left] = position;
129
+
130
+ return (
131
+ <TooltipContainer
132
+ ref={parentRef}
133
+ role="tooltip"
134
+ {...rest}
135
+ size={iconSize}
136
+ onMouseEnter={showTooltip}
137
+ onMouseLeave={hideTooltip}
138
+ >
139
+ <TooltipIcon size={iconSize} />
140
+ {isVisible &&
141
+ createPortal(
142
+ <TooltipContent ref={contentRef} direction={direction} width={width} top={top} left={left}>
111
143
  {children}
112
- </TooltipContent>
144
+ </TooltipContent>,
145
+ portalRef.current
113
146
  )}
114
- </TooltipContainer>
115
- );
116
- }
117
- );
147
+ </TooltipContainer>
148
+ );
149
+ };
118
150
 
119
151
  export {Tooltip};
@@ -47,13 +47,6 @@ test('it renders the tooltip with a right direction', () => {
47
47
  expect(screen.getByText('Tooltip content')).toBeInTheDocument();
48
48
  });
49
49
 
50
- test('Tooltip supports forwardRef', () => {
51
- const ref = {current: null};
52
-
53
- render(<Tooltip ref={ref}>Tooltip content</Tooltip>);
54
- expect(ref.current).not.toBe(null);
55
- });
56
-
57
50
  test('Tooltip supports ...rest props', () => {
58
51
  render(<Tooltip data-testid="my_value">Tooltip content</Tooltip>);
59
52
  expect(screen.getByTestId('my_value')).toBeInTheDocument();