@dynamic-labs/sdk-react-core 4.0.0-alpha.20 → 4.0.0-alpha.21
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/CHANGELOG.md +2 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/lib/components/Button/Button.cjs +2 -2
- package/src/lib/components/Button/Button.d.ts +2 -1
- package/src/lib/components/Button/Button.js +2 -2
- package/src/lib/components/CopyButton/CopyButton.cjs +5 -5
- package/src/lib/components/CopyButton/CopyButton.js +7 -7
- package/src/lib/components/Tooltip/Tooltip.cjs +38 -6
- package/src/lib/components/Tooltip/Tooltip.d.ts +16 -1
- package/src/lib/components/Tooltip/Tooltip.js +38 -6
- package/src/lib/utils/hooks/useHover/useHover.types.d.ts +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.0.0-alpha.21](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.20...v4.0.0-alpha.21) (2024-10-30)
|
|
3
|
+
|
|
2
4
|
## [4.0.0-alpha.20](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.19...v4.0.0-alpha.20) (2024-10-30)
|
|
3
5
|
|
|
4
6
|
## [4.0.0-alpha.19](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.18...v4.0.0-alpha.19) (2024-10-29)
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@dynamic-labs/sdk-api-core": "0.0.559",
|
|
6
6
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"react-i18next": "13.5.0",
|
|
13
13
|
"yup": "0.32.11",
|
|
14
14
|
"react-international-phone": "4.2.5",
|
|
15
|
-
"@dynamic-labs/assert-package-version": "4.0.0-alpha.
|
|
16
|
-
"@dynamic-labs/iconic": "4.0.0-alpha.
|
|
17
|
-
"@dynamic-labs/logger": "4.0.0-alpha.
|
|
18
|
-
"@dynamic-labs/multi-wallet": "4.0.0-alpha.
|
|
19
|
-
"@dynamic-labs/rpc-providers": "4.0.0-alpha.
|
|
20
|
-
"@dynamic-labs/store": "4.0.0-alpha.
|
|
21
|
-
"@dynamic-labs/types": "4.0.0-alpha.
|
|
22
|
-
"@dynamic-labs/utils": "4.0.0-alpha.
|
|
23
|
-
"@dynamic-labs/wallet-book": "4.0.0-alpha.
|
|
24
|
-
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.
|
|
15
|
+
"@dynamic-labs/assert-package-version": "4.0.0-alpha.21",
|
|
16
|
+
"@dynamic-labs/iconic": "4.0.0-alpha.21",
|
|
17
|
+
"@dynamic-labs/logger": "4.0.0-alpha.21",
|
|
18
|
+
"@dynamic-labs/multi-wallet": "4.0.0-alpha.21",
|
|
19
|
+
"@dynamic-labs/rpc-providers": "4.0.0-alpha.21",
|
|
20
|
+
"@dynamic-labs/store": "4.0.0-alpha.21",
|
|
21
|
+
"@dynamic-labs/types": "4.0.0-alpha.21",
|
|
22
|
+
"@dynamic-labs/utils": "4.0.0-alpha.21",
|
|
23
|
+
"@dynamic-labs/wallet-book": "4.0.0-alpha.21",
|
|
24
|
+
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.21",
|
|
25
25
|
"eventemitter3": "5.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -9,7 +9,7 @@ var React = require('react');
|
|
|
9
9
|
var classNames = require('../../utils/functions/classNames/classNames.cjs');
|
|
10
10
|
var spinner = require('../Spinner/spinner.cjs');
|
|
11
11
|
|
|
12
|
-
const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant = 'primary', children, feedback, expanded, dataTestId, disabled = false, showInternalLoading = true, loading = false, onClick, type, startSlot, endSlot, }) => {
|
|
12
|
+
const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant = 'primary', buttonRef, children, feedback, expanded, dataTestId, disabled = false, showInternalLoading = true, loading = false, onClick, type, startSlot, endSlot, }) => {
|
|
13
13
|
const [internalButtonLoading, setInternalButtonLoading] = React.useState(false);
|
|
14
14
|
const [isFeedbackVisible, setIsFeedbackVisible] = React.useState(false);
|
|
15
15
|
const buttonVariantClassNameMap = {
|
|
@@ -54,7 +54,7 @@ const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant
|
|
|
54
54
|
});
|
|
55
55
|
const buttonContent = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [startSlot && jsxRuntime.jsx("div", { className: 'button__start-slot', children: startSlot }), (feedback || children) &&
|
|
56
56
|
(isFeedbackVisible && feedback ? feedback : children), endSlot && jsxRuntime.jsx("div", { className: 'button__end-slot', children: endSlot })] }));
|
|
57
|
-
return (jsxRuntime.jsxs("button", { type: type, onClick: handleClick, className: buttonEffectiveClassName, disabled: disabled || internalButtonLoading || loading, "data-testid": dataTestId, children: [(internalButtonLoading || loading) && (jsxRuntime.jsx("div", { className: 'button__spinner-container', "data-testid": 'button__spinner', children: jsxRuntime.jsx(spinner.Spinner, { className: 'button__spinner' }) })), buttonContent] }));
|
|
57
|
+
return (jsxRuntime.jsxs("button", { type: type, ref: buttonRef, onClick: handleClick, className: buttonEffectiveClassName, disabled: disabled || internalButtonLoading || loading, "data-testid": dataTestId, children: [(internalButtonLoading || loading) && (jsxRuntime.jsx("div", { className: 'button__spinner-container', "data-testid": 'button__spinner', children: jsxRuntime.jsx(spinner.Spinner, { className: 'button__spinner' }) })), buttonContent] }));
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
exports.Button = Button;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ButtonHTMLAttributes, FC, MouseEventHandler, ReactNode } from 'react';
|
|
1
|
+
import { ButtonHTMLAttributes, FC, MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
2
|
type ButtonVariant = 'primary' | 'secondary' | 'tertiary' | 'brand-primary';
|
|
3
3
|
type ButtonPadding = 'small' | 'medium' | 'large' | 'none' | 'default' | 'login-screen-height';
|
|
4
4
|
export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> & {
|
|
5
5
|
buttonClassName?: string;
|
|
6
6
|
buttonPadding?: ButtonPadding;
|
|
7
7
|
buttonVariant?: ButtonVariant;
|
|
8
|
+
buttonRef?: RefObject<HTMLButtonElement>;
|
|
8
9
|
dataTestId?: string;
|
|
9
10
|
disabled?: boolean;
|
|
10
11
|
endSlot?: JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { useState } from 'react';
|
|
|
5
5
|
import { classNames } from '../../utils/functions/classNames/classNames.js';
|
|
6
6
|
import { Spinner } from '../Spinner/spinner.js';
|
|
7
7
|
|
|
8
|
-
const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant = 'primary', children, feedback, expanded, dataTestId, disabled = false, showInternalLoading = true, loading = false, onClick, type, startSlot, endSlot, }) => {
|
|
8
|
+
const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant = 'primary', buttonRef, children, feedback, expanded, dataTestId, disabled = false, showInternalLoading = true, loading = false, onClick, type, startSlot, endSlot, }) => {
|
|
9
9
|
const [internalButtonLoading, setInternalButtonLoading] = useState(false);
|
|
10
10
|
const [isFeedbackVisible, setIsFeedbackVisible] = useState(false);
|
|
11
11
|
const buttonVariantClassNameMap = {
|
|
@@ -50,7 +50,7 @@ const Button = ({ buttonClassName = '', buttonPadding = 'medium', buttonVariant
|
|
|
50
50
|
});
|
|
51
51
|
const buttonContent = (jsxs(Fragment, { children: [startSlot && jsx("div", { className: 'button__start-slot', children: startSlot }), (feedback || children) &&
|
|
52
52
|
(isFeedbackVisible && feedback ? feedback : children), endSlot && jsx("div", { className: 'button__end-slot', children: endSlot })] }));
|
|
53
|
-
return (jsxs("button", { type: type, onClick: handleClick, className: buttonEffectiveClassName, disabled: disabled || internalButtonLoading || loading, "data-testid": dataTestId, children: [(internalButtonLoading || loading) && (jsx("div", { className: 'button__spinner-container', "data-testid": 'button__spinner', children: jsx(Spinner, { className: 'button__spinner' }) })), buttonContent] }));
|
|
53
|
+
return (jsxs("button", { type: type, ref: buttonRef, onClick: handleClick, className: buttonEffectiveClassName, disabled: disabled || internalButtonLoading || loading, "data-testid": dataTestId, children: [(internalButtonLoading || loading) && (jsx("div", { className: 'button__spinner-container', "data-testid": 'button__spinner', children: jsx(Spinner, { className: 'button__spinner' }) })), buttonContent] }));
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export { Button };
|
|
@@ -12,16 +12,16 @@ var Tooltip = require('../Tooltip/Tooltip.cjs');
|
|
|
12
12
|
|
|
13
13
|
const CopyButton = ({ children, className = '', textToCopy, onClick, variant = 'text', copykey, buttonPadding = 'small', buttonVariant = 'primary', buttonClassName = '', startSlot, disabled, }) => {
|
|
14
14
|
const [copied, setCopied] = React.useState(false);
|
|
15
|
+
const buttonRef = React.useRef(null);
|
|
15
16
|
const copyToClipboard = () => {
|
|
16
17
|
navigator.clipboard.writeText(textToCopy);
|
|
17
18
|
setCopied(true);
|
|
18
19
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
setCopied(false);
|
|
22
|
+
}, 5000);
|
|
19
23
|
};
|
|
20
|
-
|
|
21
|
-
if (variant === 'text') {
|
|
22
|
-
return (jsxRuntime.jsx(TextButton.TextButton, { className: classNames.classNames('copy-button__container', className), onClick: () => copyToClipboard(), onMouseLeave: () => setCopied(false), copykey: copykey, disabled: disabled, children: jsxRuntime.jsx(CopyButtonTooltip, {}) }));
|
|
23
|
-
}
|
|
24
|
-
return (jsxRuntime.jsx(TypographyButton.TypographyButton, { expanded: true, buttonPadding: buttonPadding, buttonVariant: buttonVariant, buttonClassName: buttonClassName, onClick: () => copyToClipboard(), copykey: copykey, startSlot: startSlot, disabled: disabled, children: jsxRuntime.jsx(CopyButtonTooltip, {}) }));
|
|
24
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [variant === 'text' ? (jsxRuntime.jsx(TextButton.TextButton, { className: classNames.classNames('copy-button__container', className), onClick: () => copyToClipboard(), onMouseLeave: () => setCopied(false), copykey: copykey, disabled: disabled, children: children })) : (jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonRef: buttonRef, expanded: true, buttonPadding: buttonPadding, buttonVariant: buttonVariant, buttonClassName: buttonClassName, onClick: () => copyToClipboard(), copykey: copykey, startSlot: startSlot, disabled: disabled, children: children })), jsxRuntime.jsx(Tooltip.Tooltip, { className: 'copy-button__tooltip', content: copied ? 'Copied' : 'Copy', targetRef: buttonRef })] }));
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
exports.CopyButton = CopyButton;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useState } from 'react';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useRef } from 'react';
|
|
4
4
|
import { classNames } from '../../utils/functions/classNames/classNames.js';
|
|
5
5
|
import { TextButton } from '../TextButton/TextButton.js';
|
|
6
6
|
import { TypographyButton } from '../TypographyButton/TypographyButton.js';
|
|
@@ -8,16 +8,16 @@ import { Tooltip } from '../Tooltip/Tooltip.js';
|
|
|
8
8
|
|
|
9
9
|
const CopyButton = ({ children, className = '', textToCopy, onClick, variant = 'text', copykey, buttonPadding = 'small', buttonVariant = 'primary', buttonClassName = '', startSlot, disabled, }) => {
|
|
10
10
|
const [copied, setCopied] = useState(false);
|
|
11
|
+
const buttonRef = useRef(null);
|
|
11
12
|
const copyToClipboard = () => {
|
|
12
13
|
navigator.clipboard.writeText(textToCopy);
|
|
13
14
|
setCopied(true);
|
|
14
15
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
setCopied(false);
|
|
18
|
+
}, 5000);
|
|
15
19
|
};
|
|
16
|
-
|
|
17
|
-
if (variant === 'text') {
|
|
18
|
-
return (jsx(TextButton, { className: classNames('copy-button__container', className), onClick: () => copyToClipboard(), onMouseLeave: () => setCopied(false), copykey: copykey, disabled: disabled, children: jsx(CopyButtonTooltip, {}) }));
|
|
19
|
-
}
|
|
20
|
-
return (jsx(TypographyButton, { expanded: true, buttonPadding: buttonPadding, buttonVariant: buttonVariant, buttonClassName: buttonClassName, onClick: () => copyToClipboard(), copykey: copykey, startSlot: startSlot, disabled: disabled, children: jsx(CopyButtonTooltip, {}) }));
|
|
20
|
+
return (jsxs(Fragment, { children: [variant === 'text' ? (jsx(TextButton, { className: classNames('copy-button__container', className), onClick: () => copyToClipboard(), onMouseLeave: () => setCopied(false), copykey: copykey, disabled: disabled, children: children })) : (jsx(TypographyButton, { buttonRef: buttonRef, expanded: true, buttonPadding: buttonPadding, buttonVariant: buttonVariant, buttonClassName: buttonClassName, onClick: () => copyToClipboard(), copykey: copykey, startSlot: startSlot, disabled: disabled, children: children })), jsx(Tooltip, { className: 'copy-button__tooltip', content: copied ? 'Copied' : 'Copy', targetRef: buttonRef })] }));
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export { CopyButton };
|
|
@@ -86,21 +86,37 @@ require('../../../index.cjs');
|
|
|
86
86
|
require('../../store/state/tokenBalances.cjs');
|
|
87
87
|
require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
/** Map from useHover React handlers to JS ones */
|
|
90
|
+
const handlerMapping = {
|
|
91
|
+
onMouseDown: 'mousedown',
|
|
92
|
+
onMouseEnter: 'mouseenter',
|
|
93
|
+
onMouseLeave: 'mouseleave',
|
|
94
|
+
onMouseUp: 'mouseup',
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Sets up a Tooltip that appears on hover
|
|
98
|
+
*
|
|
99
|
+
* Note: Prefer to use targetRef instead of nesting children!
|
|
100
|
+
* Children of Tooltip will eventually replace content.
|
|
101
|
+
*/
|
|
102
|
+
const Tooltip = ({ children, content, className, as: Tag = 'span', copykey, targetRef, }) => {
|
|
90
103
|
const { createRootElement } = useElementById.useElementById();
|
|
91
104
|
const portalRoot = createRootElement('dynamic-tooltips');
|
|
92
105
|
const [vector, setVector] = React.useState([0, 0]);
|
|
93
|
-
const childrenRef = React.useRef(null);
|
|
94
106
|
const [visible, setVisible] = React.useState(false);
|
|
107
|
+
/** If targetRef is not set, fall back to this ref */
|
|
108
|
+
const childrenWrapperRef = React.useRef(null);
|
|
109
|
+
/** Centers the tooltip to top-center of the target */
|
|
95
110
|
const calcPosition = React.useCallback(() => {
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
const ref = targetRef !== null && targetRef !== void 0 ? targetRef : childrenWrapperRef;
|
|
112
|
+
if (ref.current) {
|
|
113
|
+
const childrenBounding = ref.current.getBoundingClientRect();
|
|
98
114
|
setVector([
|
|
99
115
|
childrenBounding.left + childrenBounding.width / 2,
|
|
100
116
|
childrenBounding.top - 6, //add 6px margin over the children
|
|
101
117
|
]);
|
|
102
118
|
}
|
|
103
|
-
}, []);
|
|
119
|
+
}, [targetRef]);
|
|
104
120
|
const [, childrenHoverHandlers] = useHover.useHover({
|
|
105
121
|
falseOnClick: true,
|
|
106
122
|
initialValue: false,
|
|
@@ -123,9 +139,25 @@ const Tooltip = ({ children, content, className, as: Tag = 'span', copykey, }) =
|
|
|
123
139
|
window.removeEventListener('resize', resizeListener);
|
|
124
140
|
};
|
|
125
141
|
}, [calcPosition]);
|
|
142
|
+
// Set handlers manually
|
|
143
|
+
React.useEffect(() => {
|
|
144
|
+
var _a;
|
|
145
|
+
const element = (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) !== null && _a !== void 0 ? _a : childrenWrapperRef.current;
|
|
146
|
+
if (element) {
|
|
147
|
+
for (const handler in childrenHoverHandlers) {
|
|
148
|
+
element.addEventListener(handlerMapping[handler], childrenHoverHandlers[handler]);
|
|
149
|
+
}
|
|
150
|
+
return () => {
|
|
151
|
+
for (const handler in childrenHoverHandlers) {
|
|
152
|
+
element.removeEventListener(handlerMapping[handler], childrenHoverHandlers[handler]);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}, [targetRef, childrenHoverHandlers]);
|
|
126
158
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [reactDom.createPortal(jsxRuntime.jsx(ShadowDOM.ShadowDOM, { zIndex: index.tooltipZIndex, children: jsxRuntime.jsxs("div", { "data-testid": 'dynamicTooltip', className: classNames.classNames('dynamic-tooltip', {
|
|
127
159
|
'dynamic-tooltip--visible': visible,
|
|
128
|
-
}, className), style: { left: vector[0], top: vector[1] }, copykey: copykey, children: [content, jsxRuntime.jsx(tooltipArrow.ReactComponent, { className: 'dynamic-tooltip__arrow' })] }) }), portalRoot.current), jsxRuntime.jsx(Tag,
|
|
160
|
+
}, className), style: { left: vector[0], top: vector[1] }, copykey: copykey, children: [content, jsxRuntime.jsx(tooltipArrow.ReactComponent, { className: 'dynamic-tooltip__arrow' })] }) }), portalRoot.current), targetRef === undefined && (jsxRuntime.jsx(Tag, { ref: childrenWrapperRef, children: children }))] }));
|
|
129
161
|
};
|
|
130
162
|
|
|
131
163
|
exports.Tooltip = Tooltip;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { FC, PropsWithChildren, ReactElement, ElementType } from 'react';
|
|
1
|
+
import { FC, PropsWithChildren, ReactElement, ElementType, RefObject } from 'react';
|
|
2
2
|
import { CopyKey } from '../../shared';
|
|
3
3
|
export type TooltipProps = {
|
|
4
|
+
/** DEPRECATED: Generate an element to use as a wrapper for children */
|
|
4
5
|
as?: ElementType;
|
|
6
|
+
/** Classnames string */
|
|
5
7
|
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Content rendered inside the Tooltip
|
|
10
|
+
*
|
|
11
|
+
* Note that this will eventually be replaced by children
|
|
12
|
+
*/
|
|
6
13
|
content: string | ReactElement;
|
|
14
|
+
/** If set, use this element as the ref instead */
|
|
15
|
+
targetRef?: RefObject<HTMLElement>;
|
|
7
16
|
} & CopyKey;
|
|
17
|
+
/**
|
|
18
|
+
* Sets up a Tooltip that appears on hover
|
|
19
|
+
*
|
|
20
|
+
* Note: Prefer to use targetRef instead of nesting children!
|
|
21
|
+
* Children of Tooltip will eventually replace content.
|
|
22
|
+
*/
|
|
8
23
|
export declare const Tooltip: FC<PropsWithChildren<TooltipProps>>;
|
|
@@ -82,21 +82,37 @@ import '../../../index.js';
|
|
|
82
82
|
import '../../store/state/tokenBalances.js';
|
|
83
83
|
import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
/** Map from useHover React handlers to JS ones */
|
|
86
|
+
const handlerMapping = {
|
|
87
|
+
onMouseDown: 'mousedown',
|
|
88
|
+
onMouseEnter: 'mouseenter',
|
|
89
|
+
onMouseLeave: 'mouseleave',
|
|
90
|
+
onMouseUp: 'mouseup',
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Sets up a Tooltip that appears on hover
|
|
94
|
+
*
|
|
95
|
+
* Note: Prefer to use targetRef instead of nesting children!
|
|
96
|
+
* Children of Tooltip will eventually replace content.
|
|
97
|
+
*/
|
|
98
|
+
const Tooltip = ({ children, content, className, as: Tag = 'span', copykey, targetRef, }) => {
|
|
86
99
|
const { createRootElement } = useElementById();
|
|
87
100
|
const portalRoot = createRootElement('dynamic-tooltips');
|
|
88
101
|
const [vector, setVector] = useState([0, 0]);
|
|
89
|
-
const childrenRef = useRef(null);
|
|
90
102
|
const [visible, setVisible] = useState(false);
|
|
103
|
+
/** If targetRef is not set, fall back to this ref */
|
|
104
|
+
const childrenWrapperRef = useRef(null);
|
|
105
|
+
/** Centers the tooltip to top-center of the target */
|
|
91
106
|
const calcPosition = useCallback(() => {
|
|
92
|
-
|
|
93
|
-
|
|
107
|
+
const ref = targetRef !== null && targetRef !== void 0 ? targetRef : childrenWrapperRef;
|
|
108
|
+
if (ref.current) {
|
|
109
|
+
const childrenBounding = ref.current.getBoundingClientRect();
|
|
94
110
|
setVector([
|
|
95
111
|
childrenBounding.left + childrenBounding.width / 2,
|
|
96
112
|
childrenBounding.top - 6, //add 6px margin over the children
|
|
97
113
|
]);
|
|
98
114
|
}
|
|
99
|
-
}, []);
|
|
115
|
+
}, [targetRef]);
|
|
100
116
|
const [, childrenHoverHandlers] = useHover({
|
|
101
117
|
falseOnClick: true,
|
|
102
118
|
initialValue: false,
|
|
@@ -119,9 +135,25 @@ const Tooltip = ({ children, content, className, as: Tag = 'span', copykey, }) =
|
|
|
119
135
|
window.removeEventListener('resize', resizeListener);
|
|
120
136
|
};
|
|
121
137
|
}, [calcPosition]);
|
|
138
|
+
// Set handlers manually
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
var _a;
|
|
141
|
+
const element = (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) !== null && _a !== void 0 ? _a : childrenWrapperRef.current;
|
|
142
|
+
if (element) {
|
|
143
|
+
for (const handler in childrenHoverHandlers) {
|
|
144
|
+
element.addEventListener(handlerMapping[handler], childrenHoverHandlers[handler]);
|
|
145
|
+
}
|
|
146
|
+
return () => {
|
|
147
|
+
for (const handler in childrenHoverHandlers) {
|
|
148
|
+
element.removeEventListener(handlerMapping[handler], childrenHoverHandlers[handler]);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}, [targetRef, childrenHoverHandlers]);
|
|
122
154
|
return (jsxs(Fragment, { children: [createPortal(jsx(ShadowDOM, { zIndex: tooltipZIndex, children: jsxs("div", { "data-testid": 'dynamicTooltip', className: classNames('dynamic-tooltip', {
|
|
123
155
|
'dynamic-tooltip--visible': visible,
|
|
124
|
-
}, className), style: { left: vector[0], top: vector[1] }, copykey: copykey, children: [content, jsx(SvgTooltipArrow, { className: 'dynamic-tooltip__arrow' })] }) }), portalRoot.current), jsx(Tag,
|
|
156
|
+
}, className), style: { left: vector[0], top: vector[1] }, copykey: copykey, children: [content, jsx(SvgTooltipArrow, { className: 'dynamic-tooltip__arrow' })] }) }), portalRoot.current), targetRef === undefined && (jsx(Tag, { ref: childrenWrapperRef, children: children }))] }));
|
|
125
157
|
};
|
|
126
158
|
|
|
127
159
|
export { Tooltip };
|