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