@atlaskit/spotlight
Version:
A spotlight introduces users to points of interest, from focused messages to multi-step tours.
31 lines • 919 B
JavaScript
import { useContext, useEffect } from 'react';
import { bind } from 'bind-event-listener';
import { getDocument } from '@atlaskit/browser-apis';
import { SpotlightContext } from '../../controllers/context';
export var useOnClickOutside = function useOnClickOutside(onClickOutside) {
var _useContext = useContext(SpotlightContext),
card = _useContext.card;
var ref = card.ref;
useEffect(function () {
var doc = getDocument();
if (!doc) {
return;
}
var unbindMouseUp = bind(doc, {
type: 'mouseup',
listener: function listener(event) {
if (!ref || !ref.current) {
return;
}
var target = event.target instanceof Node ? event.target : null;
if (ref.current.contains(target)) {
return;
}
onClickOutside(event);
}
});
return function () {
unbindMouseUp();
};
}, [onClickOutside, ref]);
};