UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 865 B
import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as r}from"react";import{MessageListScrollButton as l,MessageListArrowNarrowDownIcon as o}from"./styled.js";const n=({scrollbarRef:n})=>{const[c,i]=t(!1),[s,u]=t(!1);return r((()=>{var e;const t=()=>{var e;if(null===(e=n.current)||void 0===e?void 0:e.element){const{scrollHeight:e,clientHeight:t,scrollTop:r}=n.current.element,l=Math.round(r+t)>=e-10,o=e>t;i(l),u(o)}},r=null===(e=n.current)||void 0===e?void 0:e.element;return null==r||r.addEventListener("scroll",t),t(),()=>{null==r||r.removeEventListener("scroll",t)}}),[n.current]),c||!s?null:e(l,{$visible:!c&&s,onClick:()=>{var e;const t=null===(e=n.current)||void 0===e?void 0:e.element;t&&t.scrollTo({top:t.scrollHeight,behavior:"smooth"})},type:"button","data-test":"scroll-button",children:e(o,{size:18})})};export{n as ScrollButton};