Skip to content

Commit 729abd4

Browse files
committed
Update tooltip to use floating-ui instead of react-tether
1 parent a45cc46 commit 729abd4

File tree

6 files changed

+88
-91
lines changed

6 files changed

+88
-91
lines changed

airbyte-webapp/package-lock.json

Lines changed: 47 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airbyte-webapp/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"validate-links": "ts-node --skip-project ./scripts/validate-links.ts"
2323
},
2424
"dependencies": {
25+
"@floating-ui/react-dom": "^1.0.0",
2526
"@fortawesome/fontawesome-svg-core": "^6.1.1",
2627
"@fortawesome/free-brands-svg-icons": "^6.1.1",
2728
"@fortawesome/free-regular-svg-icons": "^6.1.1",
@@ -52,7 +53,6 @@
5253
"react-router-dom": "^6.3.0",
5354
"react-select": "^4.3.1",
5455
"react-table": "^7.8.0",
55-
"react-tether": "^2.0.8",
5656
"react-use": "^15.3.8",
5757
"react-use-intercom": "^1.5.2",
5858
"react-widgets": "^4.6.1",
@@ -92,7 +92,6 @@
9292
"@types/react-lazylog": "^4.5.1",
9393
"@types/react-select": "^4.0.16",
9494
"@types/react-table": "^7.7.12",
95-
"@types/react-tether": "^1.0.0",
9695
"@types/react-widgets": "^4.4.7",
9796
"@types/sanitize-html": "^2.6.2",
9897
"@types/styled-components": "^5.1.25",

airbyte-webapp/src/components/ToolTip/ToolTip.module.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
position: relative;
77
}
88

9-
.toolTip {
9+
.tooltip {
1010
font-size: 12px;
1111
line-height: initial;
1212

1313
padding: variables.$spacing-md;
14-
margin: variables.$spacing-sm;
1514
border-radius: 5px;
1615
max-width: 300px;
1716
z-index: variables.$z-tooltip;
Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
import { flip, offset, shift, useFloating } from "@floating-ui/react-dom";
12
import classNames from "classnames";
23
import React, { useState, useEffect } from "react";
3-
import TetherComponent from "react-tether";
44

55
import { tooltipContext } from "./context";
66
import styles from "./ToolTip.module.scss";
7-
import { ToolTipAlignment, ToolTipProps } from "./types";
7+
import { ToolTipProps } from "./types";
88

9-
const MOUSE_OUT_TIMEOUT_MS: Readonly<number> = 50;
10-
11-
const TETHER_ATTACHMENT_BY_ALIGNMENT: Readonly<Record<ToolTipAlignment, string>> = {
12-
top: "bottom center",
13-
right: "middle left",
14-
bottom: "top center",
15-
left: "middle right",
16-
};
9+
const MOUSE_OUT_TIMEOUT_MS = 50;
1710

1811
export const ToolTip: React.FC<ToolTipProps> = (props) => {
19-
const { children, control, className, disabled, cursor, theme = "dark", align = "bottom" } = props;
12+
const { children, control, className, disabled, cursor, theme = "dark", placement = "bottom" } = props;
2013

2114
const [isMouseOver, setIsMouseOver] = useState(false);
2215
const [isVisible, setIsVisible] = useState(false);
2316

17+
const { x, y, reference, floating, strategy } = useFloating({
18+
placement,
19+
middleware: [
20+
offset(5), // $spacing-sm
21+
flip(),
22+
shift(),
23+
],
24+
});
25+
2426
useEffect(() => {
2527
if (isMouseOver) {
2628
setIsVisible(true);
@@ -47,31 +49,32 @@ export const ToolTip: React.FC<ToolTipProps> = (props) => {
4749
};
4850

4951
return (
50-
<TetherComponent
51-
attachment={TETHER_ATTACHMENT_BY_ALIGNMENT[align]}
52-
renderTarget={(ref) => (
52+
<>
53+
<div
54+
ref={reference}
55+
className={styles.container}
56+
style={disabled ? undefined : { cursor }}
57+
onMouseOver={onMouseOver}
58+
onMouseOut={onMouseOut}
59+
>
60+
{control}
61+
</div>
62+
{canShowTooltip && (
5363
<div
54-
ref={ref as React.LegacyRef<HTMLDivElement>}
55-
className={styles.container}
56-
style={disabled ? undefined : { cursor }}
64+
role="tooltip"
65+
ref={floating}
66+
className={classNames(styles.tooltip, theme === "light" && styles.light, className)}
67+
style={{
68+
position: strategy,
69+
top: y ?? 0,
70+
left: x ?? 0,
71+
}}
5772
onMouseOver={onMouseOver}
5873
onMouseOut={onMouseOut}
5974
>
60-
{control}
75+
<tooltipContext.Provider value={props}>{children}</tooltipContext.Provider>
6176
</div>
6277
)}
63-
renderElement={(ref) =>
64-
canShowTooltip && (
65-
<div
66-
ref={ref as React.LegacyRef<HTMLDivElement>}
67-
className={classNames(styles.toolTip, theme === "light" && styles.light, className)}
68-
onMouseOver={onMouseOver}
69-
onMouseOut={onMouseOut}
70-
>
71-
<tooltipContext.Provider value={props}>{children}</tooltipContext.Provider>
72-
</div>
73-
)
74-
}
75-
/>
78+
</>
7679
);
7780
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { Placement } from "@floating-ui/react-dom";
2+
13
export type ToolTipCursor = "pointer" | "help" | "not-allowed" | "initial";
24
export type ToolTipTheme = "dark" | "light";
3-
export type ToolTipAlignment = "top" | "right" | "bottom" | "left";
45

56
export interface ToolTipProps {
67
control: React.ReactNode;
78
className?: string;
89
disabled?: boolean;
910
cursor?: ToolTipCursor;
1011
theme?: ToolTipTheme;
11-
align?: ToolTipAlignment;
12+
placement?: Placement;
1213
}
1314

1415
export type TooltipContext = ToolTipProps;

airbyte-webapp/src/scss/_variables.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ $width-modal-md: 585px;
2323
$width-modal-lg: 940px;
2424
$width-modal-xl: 1008px;
2525

26-
$z-tooltip: 10;
26+
$z-sidebar: 9999;
27+
$z-tooltip: $z-sidebar + 1;

0 commit comments

Comments
 (0)