@oruga-ui/oruga-next
Version:
UI components for Vue.js and CSS framework agnostic
35 lines (34 loc) • 1.16 kB
JavaScript
/*! Oruga v0.11.0 | MIT License | github.com/oruga-ui/oruga */
import "vue";
import { u as useEventListener } from "./useEventListener-nW3U5kAY.mjs";
import { u as unrefElement } from "./unrefElement-cze__WCi.mjs";
function useClickOutside(elements, handler, options) {
if (!window) return () => {
};
const listenerOptions = Object.assign({ ignore: [] }, options);
const ignores = Array.isArray(elements) ? elements : [elements];
const shouldIgnore = (event) => {
return ignores.some((target) => {
if (typeof target === "string") {
return Array.from(
window.document.querySelectorAll(target)
).some(
(el) => el === event.target || event.composedPath().includes(el)
);
} else {
const el = unrefElement(target);
return el && (event.target === el || event.composedPath().includes(el));
}
});
};
function listener(event) {
if (shouldIgnore(event)) return;
handler(event);
}
const stop = useEventListener(window, "click", listener, listenerOptions);
return stop;
}
export {
useClickOutside as u
};
//# sourceMappingURL=useClickOutside-Cq7Otb3W.mjs.map