Module 720879

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