react-clickout-ts
Version:
A simple clickout handler for React
52 lines • 1.11 kB
JavaScript
import { c as _c } from "react/compiler-runtime";
import { useRef } from 'react';
import { useClickOutside } from './hook';
import { Slot } from './slot';
import { jsx as _jsx } from "react/jsx-runtime";
export const ClickOutHandler = t0 => {
const $ = _c(8);
const {
children,
enabled: t1,
ignoredElements: t2,
onClickOut
} = t0;
const enabled = t1 === undefined ? true : t1;
let t3;
if ($[0] !== t2) {
t3 = t2 === undefined ? [] : t2;
$[0] = t2;
$[1] = t3;
} else {
t3 = $[1];
}
const ignoredElements = t3;
const wrapperRef = useRef(null);
let t4;
if ($[2] !== enabled || $[3] !== ignoredElements || $[4] !== onClickOut) {
t4 = {
enabled,
ignoredElements,
onClickOut
};
$[2] = enabled;
$[3] = ignoredElements;
$[4] = onClickOut;
$[5] = t4;
} else {
t4 = $[5];
}
useClickOutside(wrapperRef, t4);
let t5;
if ($[6] !== children) {
t5 = /*#__PURE__*/_jsx(Slot, {
ref: wrapperRef,
children: children
});
$[6] = children;
$[7] = t5;
} else {
t5 = $[7];
}
return t5;
};