Passed
Pull Request — master (#312)
by
unknown
03:23 queued 01:23
created

actions.ts ➔ destroy   A

Complexity

Conditions 2

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
c 0
b 0
f 0
rs 10
cc 2
1
export const clickOutside = (
2
  node: HTMLElement,
3
  callback: () => void
4
): {
5
  destroy: () => void;
6
} => {
7
  const handleClick = (event: Event) => {
8
    if (!node.contains(event.target as HTMLElement)) {
9
      callback();
10
    }
11
  };
12
13
  document.addEventListener("click", handleClick, true);
14
15
  return {
16
    destroy() {
17
      document.removeEventListener("click", handleClick, true);
18
    },
19
  };
20
};
21