UNPKG

tdesign-react

Version:
55 lines (51 loc) 1.7 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { useEffect } from 'react'; import useConfig from './useConfig.js'; import '../config-provider/ConfigContext.js'; import '../_chunks/dep-cb0a3966.js'; import '../_chunks/dep-eca3a3de.js'; import 'lodash-es'; import '../locale/zh_CN.js'; import '../_chunks/dep-e29214cb.js'; import 'dayjs'; import '../_chunks/dep-3c9ab31a.js'; function useClickOutside(refs, handler, includePopup) { var _useConfig = useConfig(), classPrefix = _useConfig.classPrefix; var POPUP_SELECTOR = ".".concat(classPrefix, "-popup"); useEffect(function () { var listener = function listener(event) { if (!Array.isArray(refs)) { return; } var elements = []; if (includePopup) { document.querySelectorAll(POPUP_SELECTOR).forEach(function (ele) { elements.push(ele); }); } elements = Array.from(new Set(elements)); if (refs.find(function (ref) { var _ref$current; return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains(event.target); }) || elements.find(function (el) { return el === null || el === void 0 ? void 0 : el.contains(event.target); })) { return; } handler(event); }; document.addEventListener("mousedown", listener); document.addEventListener("touchstart", listener); return function () { document.removeEventListener("mousedown", listener); document.removeEventListener("touchstart", listener); }; }, [refs, handler, includePopup]); } export { useClickOutside as default }; //# sourceMappingURL=useClickOutside.js.map