@frontify/fondue
Version:
Design system of Frontify
41 lines (40 loc) • 1.22 kB
JavaScript
import { useState as z, useEffect as D } from "react";
const u = (t) => ({
top: Math.ceil(t.scrollTop),
height: t.scrollHeight,
left: Math.ceil(t.scrollLeft),
width: t.scrollWidth
}), b = (t) => {
var d, w;
const [f, i] = z({ top: 0, height: 1 / 0, width: 1 / 0, left: 0 }), l = (e) => {
const s = e.target, c = u(s);
i(c);
};
D(() => {
const e = () => {
if (t.current) {
const c = u(t.current);
setTimeout(() => i(c), 0);
}
};
e();
const s = new ResizeObserver(e);
return t.current && s.observe(t.current), window.addEventListener("resize", e), () => {
s.disconnect(), window.removeEventListener("resize", e);
};
}, [t]);
const { top: n, height: o, left: h, width: r } = f, p = ((d = t.current) == null ? void 0 : d.clientHeight) ?? 0, m = o > 0 && n !== 0, S = o !== 0 && n < o - p, a = ((w = t.current) == null ? void 0 : w.clientWidth) ?? 0, v = r > 0 && h !== 0, g = r !== 0 && h < r - a;
return [
{
showTopShadow: m,
showBottomShadow: S,
showLeftShadow: v,
showRightShadow: g
},
{ onScroll: l }
];
};
export {
b as useScrollWrapper
};
//# sourceMappingURL=useScrollWrapper.es.js.map