-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc266a5
commit e6b40c2
Showing
16 changed files
with
1,423 additions
and
1,884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.