MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / TargetCursor

Function TargetCursor

src/tailwind/Animations/TargetCursor/TargetCursor.jsx:34–405  ·  view source on GitHub ↗
({
  targetSelector = '.cursor-target',
  spinDuration = 2,
  hideDefaultCursor = true,
  hoverDuration = 0.2,
  parallaxOn = true,
  cursorColor = '#ffffff',
  cursorColorOnTarget
})

Source from the content-addressed store, hash-verified

32};
33
34const TargetCursor = ({
35 targetSelector = '.cursor-target',
36 spinDuration = 2,
37 hideDefaultCursor = true,
38 hoverDuration = 0.2,
39 parallaxOn = true,
40 cursorColor = '#ffffff',
41 cursorColorOnTarget
42}) => {
43 const cursorRef = useRef(null);
44 const cornersRef = useRef(null);
45 const spinTl = useRef(null);
46 const dotRef = useRef(null);
47 const containingBlockRef = useRef(null);
48
49 const isActiveRef = useRef(false);
50 const targetCornerPositionsRef = useRef(null);
51 const tickerFnRef = useRef(null);
52 const activeStrengthRef = useRef(0);
53
54 const isMobile = useMemo(() => {
55 if (typeof window === 'undefined') return false;
56 const hasTouchScreen = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
57 const isSmallScreen = window.innerWidth <= 768;
58 const userAgent = navigator.userAgent || navigator.vendor || window.opera;
59 const mobileRegex = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i;
60 const isMobileUserAgent = mobileRegex.test(userAgent.toLowerCase());
61 return (hasTouchScreen && isSmallScreen) || isMobileUserAgent;
62 }, []);
63
64 const constants = useMemo(
65 () => ({
66 borderWidth: 3,
67 cornerSize: 12
68 }),
69 []
70 );
71
72 const moveCursor = useCallback((x, y) => {
73 if (!cursorRef.current) return;
74 const { x: offsetX, y: offsetY } = getContainingBlockOffset(containingBlockRef.current);
75 gsap.to(cursorRef.current, {
76 x: x - offsetX,
77 y: y - offsetY,
78 duration: 0.1,
79 ease: 'power3.out'
80 });
81 }, []);
82
83 useEffect(() => {
84 if (isMobile || !cursorRef.current) return;
85
86 const originalCursor = document.body.style.cursor;
87 if (hideDefaultCursor) {
88 document.body.style.cursor = 'none';
89 }
90
91 const cursor = cursorRef.current;

Callers

nothing calls this directly

Calls 5

getContainingBlockOffsetFunction · 0.70
getContainingBlockFunction · 0.70
getOffsetFunction · 0.70
createSpinTimelineFunction · 0.70
cleanupTargetFunction · 0.70

Tested by

no test coverage detected