@payfit/unity-components
Version:
67 lines (66 loc) • 2.21 kB
JavaScript
import { useScrollEdges as e } from "../../hooks/use-scroll-edges.js";
import { scrollArea as t } from "./ScrollArea.variants.js";
import { forwardRef as n, useCallback as r } from "react";
import { uyMerge as i } from "@payfit/unity-themes";
import { jsx as a, jsxs as o } from "react/jsx-runtime";
//#region src/core/components/scroll-area/ScrollArea.tsx
function s(e) {
return e === "inline" || e === "both";
}
function c(e) {
return e === "block" || e === "both";
}
function l(e, t) {
return e === "both" || e === t;
}
var u = n(({ axis: n = "block", children: u, className: d, fade: f = "none", fadeColor: p, onScroll: m, viewportProps: h, ...g }, _) => {
let { onScroll: v, scrollEdges: y, scrollRef: b } = e({ axis: n }), { blockEndFade: x, blockStartFade: S, inlineEndFade: C, inlineStartFade: w, root: T, viewport: E } = t({
axis: n,
fadeColor: p
}), D = r((e) => {
b.current = e, typeof _ == "function" ? _(e) : _ && (_.current = e);
}, [_, b]), O = r((e) => {
v(e), m?.(e);
}, [m, v]);
return /* @__PURE__ */ o("div", {
...g,
className: i(T(), d),
"data-axis": n,
"data-overflow-inline": y.hasOverflowInline || void 0,
"data-overflow-block": y.hasOverflowBlock || void 0,
"data-scrollable-inline-start": y.canScrollInlineStart || void 0,
"data-scrollable-inline-end": y.canScrollInlineEnd || void 0,
"data-scrollable-block-start": y.canScrollBlockStart || void 0,
"data-scrollable-block-end": y.canScrollBlockEnd || void 0,
"data-unity-component": "scroll-area",
children: [
/* @__PURE__ */ a("div", {
...h,
ref: D,
className: i(E(), h?.className),
"data-unity-slot": "scroll-area.viewport",
onScroll: O,
children: u
}),
s(n) && l(f, "start") && /* @__PURE__ */ a("span", {
"aria-hidden": "true",
className: w()
}),
s(n) && l(f, "end") && /* @__PURE__ */ a("span", {
"aria-hidden": "true",
className: C()
}),
c(n) && l(f, "start") && /* @__PURE__ */ a("span", {
"aria-hidden": "true",
className: S()
}),
c(n) && l(f, "end") && /* @__PURE__ */ a("span", {
"aria-hidden": "true",
className: x()
})
]
});
});
u.displayName = "ScrollArea";
//#endregion
export { u as ScrollArea };