File tree Expand file tree Collapse file tree 4 files changed +60
-1
lines changed
Expand file tree Collapse file tree 4 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " react-use-cursor-follow" ,
3- "version" : " 1.0.3 " ,
3+ "version" : " 1.0.4 " ,
44 "description" : " A React hook that creates a smooth customizable animated cursor element that follows your mouse" ,
55 "main" : " dist/index.js" ,
66 "module" : " dist/index.esm.js" ,
Original file line number Diff line number Diff line change 11export interface CursorFollowOptions {
2+ /**
3+ * Whether to enable the mouse follower
4+ * @default true
5+ */
6+ isEnabled ?: boolean ;
27 /**
38 * The easing factor for the mouse follower animation
49 * @default 0.1
Original file line number Diff line number Diff line change @@ -22,10 +22,12 @@ function InteractiveDemo() {
2222 const [color , setColor ] = React .useState (0 );
2323 const [borderRadius , setBorderRadius ] = React .useState (" 100%" );
2424 const [hideCursor , setHideCursor ] = React .useState (true );
25+ const [isEnabled , setIsEnabled ] = React .useState (true );
2526 const [fadeDuration , setFadeDuration ] = React .useState (200 );
2627 const [fadeDistance , setFadeDistance ] = React .useState (10 );
2728
2829 useCursorFollow ({
30+ isEnabled,
2931 easingFactor,
3032 updateInterval,
3133 size,
@@ -312,6 +314,41 @@ function InteractiveDemo() {
312314 < / div>
313315 < / label>
314316 < / div>
317+
318+ {/* Hide Cursor */ }
319+ < div>
320+ < label
321+ style= {{
322+ display: " block" ,
323+ marginBottom: " 0.5rem" ,
324+ fontWeight: " bold" ,
325+ color: " #555" ,
326+ }}
327+ >
328+ ⚡️ Enable hook: {isEnabled ? " Yes" : " No" }
329+ < / label>
330+ < label style= {{ display: " flex" , alignItems: " center" }}>
331+ < input
332+ type= " checkbox"
333+ checked= {isEnabled}
334+ onChange= {(e ) => setIsEnabled (e .target .checked )}
335+ style= {{
336+ width: " 20px" ,
337+ height: " 20px" ,
338+ cursor: " pointer" ,
339+ }}
340+ / >
341+ < div
342+ style= {{
343+ fontSize: " 0.8rem" ,
344+ color: " #666" ,
345+ marginLeft: " 5px" ,
346+ }}
347+ >
348+ Enable the cursor follow hook
349+ < / div>
350+ < / label>
351+ < / div>
315352 < / div>
316353 < / div>
317354 );
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const CURSOR_HIDE_STYLE_ID = "react-use-cursor-follow-hide-cursor";
1010 */
1111const useCursorFollow = ( props ?: CursorFollowOptions ) => {
1212 const {
13+ isEnabled = true ,
1314 easingFactor = 0.1 ,
1415 updateInterval = 15 ,
1516 size = 14 ,
@@ -43,6 +44,21 @@ const useCursorFollow = (props?: CursorFollowOptions) => {
4344
4445 // Main cursor logic
4546 useEffect ( ( ) => {
47+ if ( ! isEnabled ) {
48+ // Clean up DOM element and cursor styles when disabled
49+ if ( elementRef . current ) {
50+ elementRef . current . remove ( ) ;
51+ elementRef . current = null ;
52+ }
53+ document . documentElement . style . cursor = "" ;
54+ document . body . style . cursor = "" ;
55+ const existingStyle = document . getElementById ( CURSOR_HIDE_STYLE_ID ) ;
56+ if ( existingStyle ) {
57+ existingStyle . remove ( ) ;
58+ }
59+ return ;
60+ }
61+
4662 // Function to create the cursor element
4763 const createCursorElement = ( x : number , y : number ) => {
4864 if ( elementRef . current ) return ; // Element already exists
@@ -254,6 +270,7 @@ const useCursorFollow = (props?: CursorFollowOptions) => {
254270 }
255271 } ;
256272 } , [
273+ isEnabled ,
257274 easingFactor ,
258275 updateInterval ,
259276 fadeDistance ,
You can’t perform that action at this time.
0 commit comments