Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
natelindev committed Jun 8, 2023
1 parent cc266a5 commit e6b40c2
Show file tree
Hide file tree
Showing 16 changed files with 1,423 additions and 1,884 deletions.
20 changes: 10 additions & 10 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs"
}
],
"@babel/preset-react",
"@babel/typescript"
],
"sourceMaps": "inline"
}
],
"@babel/preset-react",
"@babel/typescript"
],
"sourceMaps": false
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ export const MyFunctionalComponent = (props) => {
};
```

After v1.3.0

use version of your desire

index.js - commonjs

\*.cjs - commonjs

\*.esm.js - es module

\*.min.\* minified version

## License

MIT
8 changes: 0 additions & 8 deletions dist/LICENSE.md

This file was deleted.

113 changes: 0 additions & 113 deletions dist/README.md

This file was deleted.

80 changes: 80 additions & 0 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

var react = require('react');

var useHoverIntent = function (options) {
var _a = options !== null && options !== void 0 ? options : {}, ref = _a.ref, _b = _a.sensitivity, sensitivity = _b === void 0 ? 6 : _b, _c = _a.interval, interval = _c === void 0 ? 100 : _c, _d = _a.timeout, timeout = _d === void 0 ? 0 : _d;
var intentRef = react.useRef(null);
var _e = react.useState(false), isHovering = _e[0], setIsHovering = _e[1];
var x = 0, y = 0, pX = 0, pY = 0, timer = 0;
var delay = function (e) {
if (timer) {
clearTimeout(timer);
}
return setIsHovering(false);
};
var tracker = function (e) {
x = e.clientX;
y = e.clientY;
};
var compare = function (e) {
if (timer) {
clearTimeout(timer);
}
if (Math.abs(pX - x) + Math.abs(pY - y) < sensitivity) {
return setIsHovering(true);
}
else {
pX = x;
pY = y;
timer = window.setTimeout(function () { return compare(); }, interval);
}
};
var dispatchOver = function (e) {
if (timer) {
clearTimeout(timer);
}
if (intentRef.current) {
intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (!isHovering) {
pX = e.clientX;
pY = e.clientY;
if (intentRef.current) {
intentRef.current.addEventListener("mousemove", tracker, false);
}
timer = window.setTimeout(function () { return compare(); }, interval);
}
};
var dispatchOut = function (e) {
if (timer) {
clearTimeout(timer);
}
if (intentRef.current) {
intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (isHovering) {
timer = window.setTimeout(function () { return delay(); }, timeout);
}
};
react.useEffect(function () {
var currentRef = intentRef.current;
if (currentRef) {
currentRef.addEventListener("mouseover", dispatchOver, false);
currentRef.addEventListener("mouseout", dispatchOut, false);
}
return function () {
if (timer) {
clearTimeout(timer);
}
if (currentRef) {
currentRef.removeEventListener("mouseover", dispatchOver, false);
currentRef.removeEventListener("mouseout", dispatchOut, false);
}
};
});
react.useImperativeHandle(ref, function () { return intentRef.current; }, [intentRef]);
return [isHovering, intentRef, setIsHovering];
};

exports.useHoverIntent = useHoverIntent;
1 change: 1 addition & 0 deletions dist/index.cjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Dispatch, SetStateAction } from "react";
import * as react from 'react';
import { Dispatch, SetStateAction } from 'react';

interface optionType {
ref?: React.Ref<HTMLElement | null>;
sensitivity?: number;
interval?: number;
timeout?: number;
}
export declare const useHoverIntent: <T>(options?: optionType) => [boolean, import("react").RefObject<HTMLElement & T>, Dispatch<SetStateAction<boolean>>];
export {};
declare const useHoverIntent: <T>(options?: optionType) => [boolean, react.RefObject<HTMLElement & T>, Dispatch<SetStateAction<boolean>>];

export { useHoverIntent };
78 changes: 78 additions & 0 deletions dist/index.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { useRef, useState, useEffect, useImperativeHandle } from 'react';

var useHoverIntent = function (options) {
var _a = options !== null && options !== void 0 ? options : {}, ref = _a.ref, _b = _a.sensitivity, sensitivity = _b === void 0 ? 6 : _b, _c = _a.interval, interval = _c === void 0 ? 100 : _c, _d = _a.timeout, timeout = _d === void 0 ? 0 : _d;
var intentRef = useRef(null);
var _e = useState(false), isHovering = _e[0], setIsHovering = _e[1];
var x = 0, y = 0, pX = 0, pY = 0, timer = 0;
var delay = function (e) {
if (timer) {
clearTimeout(timer);
}
return setIsHovering(false);
};
var tracker = function (e) {
x = e.clientX;
y = e.clientY;
};
var compare = function (e) {
if (timer) {
clearTimeout(timer);
}
if (Math.abs(pX - x) + Math.abs(pY - y) < sensitivity) {
return setIsHovering(true);
}
else {
pX = x;
pY = y;
timer = window.setTimeout(function () { return compare(); }, interval);
}
};
var dispatchOver = function (e) {
if (timer) {
clearTimeout(timer);
}
if (intentRef.current) {
intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (!isHovering) {
pX = e.clientX;
pY = e.clientY;
if (intentRef.current) {
intentRef.current.addEventListener("mousemove", tracker, false);
}
timer = window.setTimeout(function () { return compare(); }, interval);
}
};
var dispatchOut = function (e) {
if (timer) {
clearTimeout(timer);
}
if (intentRef.current) {
intentRef.current.removeEventListener("mousemove", tracker, false);
}
if (isHovering) {
timer = window.setTimeout(function () { return delay(); }, timeout);
}
};
useEffect(function () {
var currentRef = intentRef.current;
if (currentRef) {
currentRef.addEventListener("mouseover", dispatchOver, false);
currentRef.addEventListener("mouseout", dispatchOut, false);
}
return function () {
if (timer) {
clearTimeout(timer);
}
if (currentRef) {
currentRef.removeEventListener("mouseover", dispatchOver, false);
currentRef.removeEventListener("mouseout", dispatchOut, false);
}
};
});
useImperativeHandle(ref, function () { return intentRef.current; }, [intentRef]);
return [isHovering, intentRef, setIsHovering];
};

export { useHoverIntent };
1 change: 1 addition & 0 deletions dist/index.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e6b40c2

Please sign in to comment.