@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
38 lines (37 loc) • 1.43 kB
JavaScript
import { useChatScrollFunctions } from './useChatScrollFunctions';
export const useChatScroller = (thread, contentRef) => {
const { handleBottomScroll, scrollButtonEnabled, isTablet, handleCheckButtonState } = useChatScrollFunctions(thread, (top, behavior) => {
requestAnimationFrame(() => {
if (contentRef) {
contentRef.current?.scrollTo({
top,
behavior: behavior === 'smooth' ? 'smooth' : 'auto',
});
}
else {
window.scrollTo({
top,
behavior: behavior === 'smooth' ? 'smooth' : 'auto',
});
}
});
}, () => {
if (contentRef) {
return {
scrollHeight: contentRef.current?.scrollHeight ?? 0,
scrollTop: contentRef.current?.scrollTop ?? 0,
offsetHeight: contentRef.current?.offsetHeight ?? 0,
};
}
else {
return {
scrollHeight: document.documentElement.scrollHeight,
scrollTop: window.scrollY,
offsetHeight: window.innerHeight,
};
}
}, () => contentRef ? contentRef.current ?? undefined : window);
return {
handleBottomScroll, scrollButtonEnabled, isTablet, handleCheckButtonState
};
};