source: imaps-frontend/node_modules/react-use/lib/useClickAway.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var util_1 = require("./misc/util");
5var defaultEvents = ['mousedown', 'touchstart'];
6var useClickAway = function (ref, onClickAway, events) {
7 if (events === void 0) { events = defaultEvents; }
8 var savedCallback = react_1.useRef(onClickAway);
9 react_1.useEffect(function () {
10 savedCallback.current = onClickAway;
11 }, [onClickAway]);
12 react_1.useEffect(function () {
13 var handler = function (event) {
14 var el = ref.current;
15 el && !el.contains(event.target) && savedCallback.current(event);
16 };
17 for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {
18 var eventName = events_1[_i];
19 util_1.on(document, eventName, handler);
20 }
21 return function () {
22 for (var _i = 0, events_2 = events; _i < events_2.length; _i++) {
23 var eventName = events_2[_i];
24 util_1.off(document, eventName, handler);
25 }
26 };
27 }, [events, ref]);
28};
29exports.default = useClickAway;
Note: See TracBrowser for help on using the repository browser.