react-useportal
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -57,3 +57,3 @@ "use strict"; | ||
}, [isServer, bindTo]); | ||
var useCustomEventCallback = function (cb, deps) { return react_1.useCallback(function (e) { | ||
var customEvent = react_1.useCallback(function (e) { | ||
var event = e || {}; | ||
@@ -65,12 +65,5 @@ if (event.persist) | ||
event.event = e; | ||
cb(event); | ||
}, deps); }; | ||
var handleEvent = react_1.useCallback(function (func, event) { | ||
if (!func || isServer) | ||
return; | ||
if (event && event.currentTarget && event.currentTarget !== document) | ||
targetEl.current = event.currentTarget; | ||
// i.e. onClick, etc. inside usePortal({ onClick({ portal, targetEl }) {} }) | ||
func(event); | ||
}, [portal, targetEl]); | ||
return event; | ||
}, []); | ||
var useCustomEventCallback = function (cb, deps) { return react_1.useCallback(function (e) { return cb(customEvent(event)); }, deps); }; | ||
// this should handle all eventHandlers like onClick, onMouseOver, etc. passed into the config | ||
@@ -81,3 +74,7 @@ var customEventHandlers = Object | ||
var handlerName = _a[0], eventHandler = _a[1]; | ||
acc[handlerName] = function (event) { return handleEvent(eventHandler, event); }; | ||
acc[handlerName] = function (event) { | ||
if (isServer) | ||
return; | ||
eventHandler(customEvent(event)); | ||
}; | ||
return acc; | ||
@@ -100,5 +97,5 @@ }, {}); | ||
if (onOpen) | ||
handleEvent(onOpen, event); | ||
onOpen(event); | ||
setOpen(true); | ||
}, [isServer, portal, setOpen, handleEvent, targetEl, onOpen]); | ||
}, [isServer, portal, setOpen, targetEl, onOpen]); | ||
var closePortal = useCustomEventCallback(function (event) { | ||
@@ -108,6 +105,6 @@ if (isServer) | ||
if (onClose && open.current) | ||
handleEvent(onClose, event); | ||
onClose(event); | ||
if (open.current) | ||
setOpen(false); | ||
}, [isServer, handleEvent, onClose, setOpen]); | ||
}, [isServer, onClose, setOpen]); | ||
var togglePortal = react_1.useCallback(function (e) { | ||
@@ -126,7 +123,7 @@ return open.current ? closePortal(e) : openPortal(e); | ||
}, [isServer, closePortal, closeOnOutsideClick, portal]); | ||
var handleMouseDown = react_1.useCallback(function (e) { | ||
var handleMouseDown = useCustomEventCallback(function (e) { | ||
if (isServer || !(portal.current instanceof HTMLElement)) | ||
return; | ||
if (portal.current.contains(e.target) && onPortalClick) | ||
handleEvent(onPortalClick, e); | ||
onPortalClick(e); | ||
handleOutsideMouseClick(e); | ||
@@ -155,3 +152,3 @@ }, [handleOutsideMouseClick]); | ||
return; | ||
eventListeners.current[handlerName] = function (e) { return handleEvent(eventHandlers[handlerName], e); }; | ||
eventListeners.current[handlerName] = function (e) { return eventHandlers[handlerName](e); }; | ||
document.addEventListener(eventListenerName, eventListeners.current[handlerName]); | ||
@@ -158,0 +155,0 @@ }); |
{ | ||
"name": "react-useportal", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"homepage": "https://codesandbox.io/s/w6jp7z4pkk", | ||
@@ -5,0 +5,0 @@ "main": "dist/usePortal.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30129
198