@lanaco/lnc-react-ui
Version:
React component library
48 lines (47 loc) • 1.25 kB
JavaScript
import { jsx as f } from "react/jsx-runtime";
import { useState as m, useMemo as a, useEffect as p, forwardRef as u, useRef as d } from "react";
import { P as c } from "./index-S5Cd7WrG.js";
import { n as I } from "./emotion-styled.browser.esm-CjCaF13H.js";
import { u as w } from "./useUpdateEffect-CuYWz7EA.js";
const b = (s) => {
const [r, t] = m(!1), e = a(
() => new IntersectionObserver(
([n]) => t(n.isIntersecting)
),
[]
);
return p(() => (e.observe(s.current), () => {
e.disconnect();
}), [s, e]), r;
}, h = I.div`
min-height: 1px;
${(s) => s.isHorizontal === !0 ? "min-width: 1px; width: 1px;" : "width: 100%;"}
`, v = u((s, r) => {
const {
onIsVisible: t = () => {
},
onIsNotVisible: e,
isHorizontal: n = !1,
className: l = ""
} = s, o = d(null), i = b(o);
return w(() => {
i ? t() : e == null || e();
}, [i]), /* @__PURE__ */ f(
h,
{
ref: o,
className: `scroller-element ${l}`,
isHorizontal: n
}
);
});
v.propTypes = {
onIsVisible: c.func,
/**
* For horizontal scroll InfiniteScrollEndElement has to have some widh otherwise it won't ever be visible and trigger onIsVisible callback
*/
isHorizontal: c.bool
};
export {
v as I
};