-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
36 lines (33 loc) · 959 Bytes
/
Copy pathApp.jsx
File metadata and controls
36 lines (33 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { useRef, RefObject } from "react";
import "./styles.css";
import useTooltip from "./hooks/useTooltip";
import Tooltip from "./components/Tooltip";
export default function App() {
const { showTooltip } = useTooltip();
const leftBtnRef = useRef<HTMLElement>();
const rightBtnRef = useRef<HTMLElement>();
const handleClick = (elRef: RefObject<HTMLElement>) => {
const { y, x } = elRef.current.getBoundingClientRect();
const elementId = elRef?.current?.id;
showTooltip(y - 60, x, `Tooltip on the ${elementId}`);
};
return (
<div className="App">
<button
ref={leftBtnRef}
id="left"
onClick={() => handleClick(leftBtnRef)}
>
Show the tooltip on the left
</button>
<button
ref={rightBtnRef}
id="right"
onClick={() => handleClick(rightBtnRef)}
>
Show the tooltip on the right
</button>
<Tooltip />
</div>
);
}