@bothub-chat/ui
Version:
Bothub UI Components
2 lines (1 loc) • 862 B
JavaScript
import{__rest as r}from"tslib";import{jsxs as o,jsx as e}from"react/jsx-runtime";import{useState as t,useRef as n,useCallback as s,useEffect as c}from"react";import{SelectFieldGroupStyled as l,Shadow as i,SelectFieldGroupContent as p}from"./styled.js";const m=m=>{var{scrollTop:u,onScrollTopChange:a}=m,f=r(m,["scrollTop","onScrollTopChange"]);const[h,T]=t(!1),[v,d]=t(!1),g=n(null),b=s(()=>{const r=g.current;if(r){const{scrollTop:o,clientHeight:e,scrollHeight:t}=r;T(o>1),d(Math.floor(t-o-e)>1),a(o)}},[g.current,a]);return c(()=>{const r=g.current;if(!r)return;r.scrollTop=u;const o=new ResizeObserver(()=>{b()});return o.observe(r),b(),r.addEventListener("scroll",b),()=>{o.disconnect(),r.removeEventListener("scroll",b)}},[g.current,u]),o(l,{children:[e(i,{$onTop:!0,$show:h}),e(p,Object.assign({ref:g},f)),e(i,{$show:v})]})};export{m as SelectFieldGroup};