From eb81840c7537fa4bf714ab503a870d02c530ba0a Mon Sep 17 00:00:00 2001
From: Paul Stegeman
Date: Fri, 7 Oct 2022 11:46:07 +0200
Subject: [PATCH] Exposed setIsHovering state setter
---
dist/README.md | 26 +++++++++++++-------------
dist/index.d.ts | 4 ++--
dist/index.js | 26 ++++++++++++++------------
src/index.ts | 35 +++++++++++++++++++++++------------
4 files changed, 52 insertions(+), 39 deletions(-)
diff --git a/dist/README.md b/dist/README.md
index ef2fc07..d87039d 100644
--- a/dist/README.md
+++ b/dist/README.md
@@ -11,7 +11,7 @@
-react-use-hoverintent is a react hook which allows you to use classic hoverintent behaviour in modern, react way.
+react-use-hoverintent is a react hook which allows you to use classic hoverintent behavior in modern, react way.
"hoverIntent is a plug-in that attempts to determine the user's intent... like a crystal ball, only with mouse movement! It is similar to jQuery's hover method. However, instead of calling the handlerIn function immediately, hoverIntent waits until the user's mouse slows down enough before making the call."
@@ -52,20 +52,20 @@ Default `interval: 100`
Basic usage
```javascript
-import React from 'react';
-import { useHoverIntent } from 'react-use-hoverintent';
+import React from "react";
+import { useHoverIntent } from "react-use-hoverintent";
export const MyFunctionalComponent = (props) => {
const [isHovering, ref] = useHoverIntent();
- return ;
+ return ;
};
```
With options
```javascript
-import React from 'react';
-import { useHoverIntent } from 'react-use-hoverintent';
+import React from "react";
+import { useHoverIntent } from "react-use-hoverintent";
export const MyFunctionalComponent = (props) => {
const [isHovering, ref] = useHoverIntent({
@@ -73,19 +73,19 @@ export const MyFunctionalComponent = (props) => {
sensitivity: 10,
interval: 200,
});
- return ;
+ return ;
};
```
With ForwardRef
```js
-import React from 'react';
-import { useHoverIntent } from 'react-use-hoverintent';
+import React from "react";
+import { useHoverIntent } from "react-use-hoverintent";
export const MyFunctionalComponent = React.forwardRef((props, ref) => {
const [isHovering, intentRef] = useHoverIntent({ ref });
- return ;
+ return ;
});
```
@@ -94,15 +94,15 @@ With Custom UI lib
Check if they have `innerRef` prop or forwarded ref
```javascript
-import React from 'react';
-import { useHoverIntent } from 'react-use-hoverintent';
+import React from "react";
+import { useHoverIntent } from "react-use-hoverintent";
export const MyFunctionalComponent = (props) => {
const [isHovering, intentRef] = useHoverIntent();
return (
);
};
diff --git a/dist/index.d.ts b/dist/index.d.ts
index e291080..4db2955 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -1,9 +1,9 @@
-///
+import { Dispatch, SetStateAction } from "react";
interface optionType {
ref?: React.Ref;
sensitivity?: number;
interval?: number;
timeout?: number;
}
-export declare function useHoverIntent(options?: optionType): [boolean, React.RefObject];
+export declare const useHoverIntent: (options?: optionType | undefined) => [boolean, Dispatch>, import("react").RefObject];
export {};
diff --git a/dist/index.js b/dist/index.js
index 8e72ed6..5e56c8a 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
-exports.useHoverIntent = useHoverIntent;
+exports.useHoverIntent = void 0;
var _react = require("react");
@@ -19,7 +19,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
-function useHoverIntent(options) {
+var useHoverIntent = function useHoverIntent(options) {
var _ref = options !== null && options !== void 0 ? options : {},
ref = _ref.ref,
_ref$sensitivity = _ref.sensitivity,
@@ -77,7 +77,7 @@ function useHoverIntent(options) {
}
if (intentRef.current) {
- intentRef.current.removeEventListener('mousemove', tracker, false);
+ intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (!isHovering) {
@@ -85,7 +85,7 @@ function useHoverIntent(options) {
pY = e.clientY;
if (intentRef.current) {
- intentRef.current.addEventListener('mousemove', tracker, false);
+ intentRef.current.addEventListener("mousemove", tracker, false);
}
timer = window.setTimeout(function () {
@@ -100,7 +100,7 @@ function useHoverIntent(options) {
}
if (intentRef.current) {
- intentRef.current.removeEventListener('mousemove', tracker, false);
+ intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (isHovering) {
@@ -114,8 +114,8 @@ function useHoverIntent(options) {
var currentRef = intentRef.current;
if (currentRef) {
- currentRef.addEventListener('mouseover', dispatchOver, false);
- currentRef.addEventListener('mouseout', dispatchOut, false);
+ currentRef.addEventListener("mouseover", dispatchOver, false);
+ currentRef.addEventListener("mouseout", dispatchOut, false);
}
return function () {
@@ -124,14 +124,16 @@ function useHoverIntent(options) {
}
if (currentRef) {
- currentRef.removeEventListener('mouseover', dispatchOver, false);
- currentRef.removeEventListener('mouseout', dispatchOut, false);
+ currentRef.removeEventListener("mouseover", dispatchOver, false);
+ currentRef.removeEventListener("mouseout", dispatchOut, false);
}
};
});
(0, _react.useImperativeHandle)(ref, function () {
return intentRef.current;
}, [intentRef]);
- return [isHovering, intentRef];
-}
-//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6WyJ1c2VIb3ZlckludGVudCIsIm9wdGlvbnMiLCJyZWYiLCJzZW5zaXRpdml0eSIsImludGVydmFsIiwidGltZW91dCIsImludGVudFJlZiIsImlzSG92ZXJpbmciLCJzZXRJc0hvdmVyaW5nIiwieCIsInkiLCJwWCIsInBZIiwidGltZXIiLCJkZWxheSIsImUiLCJjbGVhclRpbWVvdXQiLCJ0cmFja2VyIiwiY2xpZW50WCIsImNsaWVudFkiLCJjb21wYXJlIiwiTWF0aCIsImFicyIsIndpbmRvdyIsInNldFRpbWVvdXQiLCJkaXNwYXRjaE92ZXIiLCJjdXJyZW50IiwicmVtb3ZlRXZlbnRMaXN0ZW5lciIsImFkZEV2ZW50TGlzdGVuZXIiLCJkaXNwYXRjaE91dCIsImN1cnJlbnRSZWYiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFBQTs7Ozs7Ozs7Ozs7Ozs7QUFTTyxTQUFTQSxjQUFULENBQ0xDLE9BREssRUFFd0M7QUFDN0MsYUFBOERBLE9BQTlELGFBQThEQSxPQUE5RCxjQUE4REEsT0FBOU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3VzZW92ZXInLCBkaXNwYXRjaE92ZXIsIGZhbHNlKTtcbiAgICAgIGN1cnJlbnRSZWYuYWRkRXZlbnRMaXN0ZW5lcignbW91c2VvdXQnLCBkaXNwYXRjaE91dCwgZmFsc2UpO1xuICAgIH1cblxuICAgIHJldHVybiAoKSA9PiB7XG4gICAgICBpZiAodGltZXIpIHtcbiAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgIH1cbiAgICAgIGlmIChjdXJyZW50UmVmKSB7XG4gICAgICAgIGN1cnJlbnRSZWYucmVtb3ZlRXZlbnRMaXN0ZW5lcignbW91c2VvdmVyJywgZGlzcGF0Y2hPdmVyLCBmYWxzZSk7XG4gICAgICAgIGN1cnJlbnRSZWYucmVtb3ZlRXZlbnRMaXN0ZW5lcignbW91c2VvdXQnLCBkaXNwYXRjaE91dCwgZmFsc2UpO1xuICAgICAgfVxuICAgIH07XG4gIH0pO1xuXG4gIHVzZUltcGVyYXRpdmVIYW5kbGUocmVmLCAoKSA9PiBpbnRlbnRSZWYuY3VycmVudCwgW2ludGVudFJlZl0pO1xuXG4gIHJldHVybiBbaXNIb3ZlcmluZywgaW50ZW50UmVmXTtcbn1cbiJdfQ==
\ No newline at end of file
+ return [isHovering, setIsHovering, intentRef];
+};
+
+exports.useHoverIntent = useHoverIntent;
+//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6WyJ1c2VIb3ZlckludGVudCIsIm9wdGlvbnMiLCJyZWYiLCJzZW5zaXRpdml0eSIsImludGVydmFsIiwidGltZW91dCIsImludGVudFJlZiIsImlzSG92ZXJpbmciLCJzZXRJc0hvdmVyaW5nIiwieCIsInkiLCJwWCIsInBZIiwidGltZXIiLCJkZWxheSIsImUiLCJjbGVhclRpbWVvdXQiLCJ0cmFja2VyIiwiY2xpZW50WCIsImNsaWVudFkiLCJjb21wYXJlIiwiT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udFJlZi5jdXJyZW50LCBbaW50ZW50UmVmXSk7XG5cbiAgcmV0dXJuIFtpc0hvdmVyaW5nLCBzZXRJc0hvdmVyaW5nLCBpbnRlbnRSZWZdO1xufTtcbiJdfQ==
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index d10342c..805ff64 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,4 +1,11 @@
-import { useEffect, useImperativeHandle, useRef, useState } from 'react';
+import {
+ Dispatch,
+ SetStateAction,
+ useState,
+ useEffect,
+ useImperativeHandle,
+ useRef,
+} from "react";
interface optionType {
ref?: React.Ref;
@@ -7,9 +14,13 @@ interface optionType {
timeout?: number;
}
-export function useHoverIntent(
+export const useHoverIntent = (
options?: optionType
-): [boolean, React.RefObject] {
+): [
+ boolean,
+ Dispatch>,
+ React.RefObject
+] => {
const { ref, sensitivity = 6, interval = 100, timeout = 0 } = options ?? {};
const intentRef = useRef(null);
const [isHovering, setIsHovering] = useState(false);
@@ -46,13 +57,13 @@ export function useHoverIntent(
clearTimeout(timer);
}
if (intentRef.current) {
- intentRef.current.removeEventListener('mousemove', tracker, false);
+ intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (!isHovering) {
pX = e.clientX;
pY = e.clientY;
if (intentRef.current) {
- intentRef.current.addEventListener('mousemove', tracker, false);
+ intentRef.current.addEventListener("mousemove", tracker, false);
}
timer = window.setTimeout(() => compare(e), interval);
}
@@ -62,7 +73,7 @@ export function useHoverIntent(
clearTimeout(timer);
}
if (intentRef.current) {
- intentRef.current.removeEventListener('mousemove', tracker, false);
+ intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (isHovering) {
timer = window.setTimeout(() => delay(e), timeout);
@@ -72,8 +83,8 @@ export function useHoverIntent(
useEffect(() => {
const currentRef = intentRef.current;
if (currentRef) {
- currentRef.addEventListener('mouseover', dispatchOver, false);
- currentRef.addEventListener('mouseout', dispatchOut, false);
+ currentRef.addEventListener("mouseover", dispatchOver, false);
+ currentRef.addEventListener("mouseout", dispatchOut, false);
}
return () => {
@@ -81,13 +92,13 @@ export function useHoverIntent(
clearTimeout(timer);
}
if (currentRef) {
- currentRef.removeEventListener('mouseover', dispatchOver, false);
- currentRef.removeEventListener('mouseout', dispatchOut, false);
+ currentRef.removeEventListener("mouseover", dispatchOver, false);
+ currentRef.removeEventListener("mouseout", dispatchOut, false);
}
};
});
useImperativeHandle(ref, () => intentRef.current, [intentRef]);
- return [isHovering, intentRef];
-}
+ return [isHovering, setIsHovering, intentRef];
+};