Build 541864stable
Module 720879
2,644 characters · in 2e055c7fdb71518b.jsDependencies
Source Raw
function(e,t,n){n.d(t,{L:()=>o,A:()=>d});var l=n(627968),r=n(64700),i=n(844222),a=n(350535),s=n(642481);function o(e){let{children:t,targetElementRef:n,estimatedTooltipHeight:o,delay:d=300,onShow:u,title:c,body:m,graphic:g,size:p="md",actions:_,gradientColor:f}=e,E=r.useContext(i.C),[h,v]=r.useState("closed"),R=r.useRef(null),x=r.useRef(!1),b="opening-mouse"===h||"open-mouse"===h,j="opening-keyboard"===h||"open-keyboard"===h,C="open-mouse"===h||"open-keyboard"===h,A=(E.keyboardModeEnabled||j)&&null!=_,[I,y]=r.useState(0),O=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:200,n=arguments.length>2?arguments[2]:void 0,[l,i]=r.useState("top");return r.useEffect(()=>{if(null==e.current)return void i("top");let n=e.current.getBoundingClientRect(),l=window.innerWidth,r=window.innerHeight,a={top:n.top,bottom:r-n.bottom,left:n.left,right:l-n.right},s=["top","bottom","right","left"];for(let e of s)if(a[e]>=t)return void i(e);i(s.reduce((e,t)=>a[t]>a[e]?t:e,"top"))},[e,t,n]),l}(n,o,h),T=r.useCallback(()=>{null!=R.current&&(clearTimeout(R.current),R.current=null)},[]),S=r.useCallback(e=>{e&&(x.current=!0),T(),v("closing")},[T]);r.useEffect(()=>T,[T]);let U=r.useCallback(()=>{("closed"===h||"closing"===h)&&(T(),v("opening-mouse"))},[T,h]),N=r.useCallback(()=>{b&&S(!1)},[S,b]),D=r.useCallback(()=>{if(x.current||"closed"!==h&&"closing"!==h){x.current=!1;return}T(),v("opening-keyboard")},[T,h]),k=r.useCallback(()=>{A&&"opening-keyboard"!==h||S(!1)},[S,h,A]);r.useEffect(()=>{if("opening-mouse"===h)return R.current=window.setTimeout(()=>{R.current=null,v("open-mouse"),u?.()},d),T},[h,d,u,T]),r.useEffect(()=>{if("opening-keyboard"===h)return R.current=window.setTimeout(()=>{R.current=null,v("open-keyboard"),u?.()},d),T},[h,d,u,T]),r.useEffect(()=>{if("closing"===h)return R.current=window.setTimeout(()=>{R.current=null,v("closed")},200),T},[h,T]),r.useEffect(()=>{if(!C)return;let e=e=>{("Escape"===e.key||"Esc"===e.key)&&(e.preventDefault(),e.stopPropagation(),S(!0))};return document.addEventListener("keydown",e,!0),()=>{document.removeEventListener("keydown",e,!0)}},[C,S]);let B=r.useMemo(()=>null==_?_:_.map(e=>({...e,onClick:t=>{e.onClick?.(t),S(!1)}})),[_,S]),L=r.useCallback(e=>{y(e)},[]);return(0,l.jsxs)("div",{onMouseEnter:U,onMouseLeave:N,onFocus:D,onBlur:k,children:[t,(0,l.jsx)(s.j,{targetElementRef:n,shouldShow:C,position:O,align:"center",title:c,body:m,graphic:g,size:p,actions:B,gradientColor:f,showCloseButton:A,shouldTrapFocus:A,returnRef:A?n:void 0,isCaretHoverable:!0,caretConfig:{align:"custom",customOffset:I},onNudgeChange:L,onRequestClose:e=>{S(null!=e&&(0,a.sg)(e))}})]})}let d=o}