@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 48 lines 1.5 KB
Raw
1 import { useEffect, useRef, useState } from "react";
2
3 import { cn } from "~/lib/utils";
4
5 const HIDE_AFTER_MS = 1500;
6 const ZOOM_EPSILON = 0.001;
7
8 interface Props {
9 zoomFactor: number;
10 }
11
12 export function ZoomIndicator({ zoomFactor }: Props) {
13 const [visible, setVisible] = useState(false);
14 const lastFactorRef = useRef(zoomFactor);
15 const timerRef = useRef<number | null>(null);
16
17 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- shows the indicator on a zoom change and hides it with a timer
18 useEffect(() => {
19 if (Math.abs(lastFactorRef.current - zoomFactor) < ZOOM_EPSILON) return;
20 lastFactorRef.current = zoomFactor;
21 setVisible(true);
22 if (timerRef.current !== null) window.clearTimeout(timerRef.current);
23 timerRef.current = window.setTimeout(() => {
24 setVisible(false);
25 timerRef.current = null;
26 }, HIDE_AFTER_MS);
27 return () => {
28 if (timerRef.current !== null) {
29 window.clearTimeout(timerRef.current);
30 timerRef.current = null;
31 }
32 };
33 }, [zoomFactor]);
34
35 const percent = `${Math.round(zoomFactor * 100)}%`;
36
37 return (
38 <div
39 aria-hidden={!visible}
40 className={cn(
41 "pointer-events-none absolute top-3 right-3 z-20 select-none rounded-full border border-border/70 bg-popover/95 px-2.5 py-1 text-xs font-medium text-foreground shadow-md/10 backdrop-blur transition-all duration-200 ease-out",
42 visible ? "opacity-100 translate-y-0" : "opacity-0 -translate-y-1",
43 )}
44 >
45 {percent}
46 </div>
47 );
48 }