Files
Bogdan Chadkin a02e9d1afe refactor: prepare react 19 types (#4553)
React 19 simplified ref object story, moved JSX from global into react
package. Here prepared our code to not refactor too much in packages
bump.
2024-12-13 16:20:54 +07:00

33 lines
879 B
TypeScript

import { useEffect, useRef } from "react";
import type { Point } from "@webstudio-is/design-system";
// Draw a point where we think the pointer is to visualize if calculations are based on the right position
// Only needed for debugging.
export const usePointerOutline = () => {
const ref = useRef<undefined | HTMLDivElement>(undefined);
useEffect(() => {
const div = document.createElement("div");
div.style.cssText = `
position: absolute;
width: 5px;
height: 5px;
background: red;
`;
document.body.appendChild(div);
ref.current = div;
return () => {
document.body.removeChild(div);
ref.current = undefined;
};
}, []);
return (offset: Point) => {
if (ref.current === undefined) {
return;
}
ref.current.style.left = `${offset.x}px`;
ref.current.style.top = `${offset.y}px`;
};
};