Skip to content

Commit

Permalink
chore: hide cursor when no mouse activity
Browse files Browse the repository at this point in the history
  • Loading branch information
njm222 committed Sep 27, 2023
1 parent 744e6f0 commit 8eda4fd
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,37 @@ export const MouseActivityProvider: FC<MouseActivityProviderProps> = ({

const mouseTimeout: MutableRefObject<NodeJS.Timeout | null> = useRef(null);

const mouseMoveHandler = () => {
function handleCursorStyle(visible: boolean) {
const el = document.body;
if (!el) {
return;
}
if (
visible &&
(el.style.cursor === "pointer" || el.style.cursor === "auto")
) {
return;
}
el.style.cursor = visible ? "auto" : "none";
}

function handleMouseActive() {
setMouseActive(true);
handleCursorStyle(true);
}

function handleMouseInactive() {
setMouseActive(false);
handleCursorStyle(false);
}

const mouseMoveHandler = () => {
handleMouseActive();

if (mouseTimeout.current) {
clearTimeout(mouseTimeout.current);
}
mouseTimeout.current = setTimeout(() => setMouseActive(false), 3500);
mouseTimeout.current = setTimeout(() => handleMouseInactive(), 3500);
};

useEffect(() => {
Expand Down

1 comment on commit 8eda4fd

@vercel
Copy link

@vercel vercel bot commented on 8eda4fd Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tessellator-web – ./apps/tessellator

tessellator-web-njm222.vercel.app
tessellator-web-git-main-njm222.vercel.app
tessellator-web.vercel.app

Please sign in to comment.