@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
52 lines (49 loc) • 1.48 kB
JavaScript
'use client';
import Button_default from "../../Button/Button.mjs";
import { styles } from "./style.mjs";
import { memo, useEffect, useRef, useState } from "react";
import { jsx } from "react/jsx-runtime";
import { cx } from "antd-style";
import { ListEnd } from "lucide-react";
import { useScroll } from "ahooks";
//#region src/chat/BackBottom/BackBottom.tsx
const BackBottom = memo(({ visibilityHeight = 240, target, onClick, style, className, text }) => {
const [visible, setVisible] = useState(false);
const ref = useRef(null);
const current = target?.current;
const scrollHeight = current?.scrollHeight || 0;
const clientHeight = current?.clientHeight || 0;
const scroll = useScroll(target);
useEffect(() => {
if (scroll?.top) setVisible(scroll?.top + clientHeight + visibilityHeight < scrollHeight);
}, [
scrollHeight,
scroll,
visibilityHeight
]);
const scrollToBottom = (e) => {
target?.current?.scrollTo({
behavior: "smooth",
left: 0,
top: scrollHeight
});
onClick?.(e);
};
return /* @__PURE__ */ jsx(Button_default, {
className: cx(visible ? styles.visible : styles.hidden, className),
glass: true,
icon: ListEnd,
onClick: scrollToBottom,
ref,
shape: "round",
size: "small",
style,
variant: "filled",
children: text || "Back to bottom"
});
});
BackBottom.displayName = "BackBottom";
var BackBottom_default = BackBottom;
//#endregion
export { BackBottom_default as default };
//# sourceMappingURL=BackBottom.mjs.map