ohif-viewer/platform/ui/src/utils/useOnClickOutside.js
Igor Octaviano ef163cd702
Fix broken UI package build (#1990)
* Use path instead of alias

* Add missing pacakges

* Use path in viewers

* Use path in contextProviders

* Add base to config

* Add conditionals for window

* Copy config to avoid breaking build

* Update and lock versions

* Update lock file

* Remove scaling config

* Fix broken versions of react date

* Fix broken dev
2020-08-14 14:25:08 -04:00

27 lines
639 B
JavaScript

export default (element, onClickOutside) => {
const clickOutsideHandler = event => {
if (element.current && !element.current.contains(event.target)) {
onClickOutside();
if (typeof window !== 'undefined') {
window.removeEventListener('mousedown', clickOutsideHandler);
}
}
};
const add = () => {
if (typeof window !== 'undefined') {
window.addEventListener('mousedown', clickOutsideHandler);
}
};
const remove = () => {
if (typeof window !== 'undefined') {
window.removeEventListener('mousedown', clickOutsideHandler);
}
};
return {
add,
remove,
};
};