@progress/kendo-react-conversational-ui
Version:
React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components
47 lines (46 loc) • 1.58 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as r from "react";
const m = 100, i = 1, p = (l, a) => {
const { enabled: t, dir: e, itemsDependency: S = [], scrollSpeed: c = m } = a, [f, L] = r.useState(!1), [d, b] = r.useState(!1), o = r.useCallback(() => {
if (l.current && t) {
const { scrollLeft: s, scrollWidth: n, clientWidth: u } = l.current, E = s === 0, C = e !== "rtl" ? s + u >= n - i : u - s >= n - i;
L(!E), b(!C);
}
}, [t, e]), h = r.useCallback(() => {
l.current && t && l.current.scrollBy({
left: e !== "rtl" ? -c : c,
behavior: "smooth"
});
}, [t, e, c]), v = r.useCallback(() => {
l.current && t && l.current.scrollBy({
left: e !== "rtl" ? c : -c,
behavior: "smooth"
});
}, [t, e, c]);
return r.useEffect(() => {
const s = l.current;
if (s && t) {
o(), s.addEventListener("scroll", o);
const n = new ResizeObserver(o);
return n.observe(s), () => {
s.removeEventListener("scroll", o), n.disconnect();
};
}
}, [t, e]), r.useLayoutEffect(() => {
t && o();
}, [t, e, S]), {
canScrollLeft: f,
canScrollRight: d,
scrollLeft: h,
scrollRight: v
};
};
export {
p as useScrollWithButtons
};