@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 1.65 kB
JavaScript
import{createElement as e}from"../../../external/preact/dist/preact.js";import{useRef as t,useState as o,useLayoutEffect as r,useEffect as n}from"../../../external/preact/hooks/dist/hooks.js";import{createPortal as i}from"../../../external/preact/compat/dist/compat.js";import s from"../../../_virtual/index.js";function c(c){const a=t(null),[l,d]=o("top"),[f,p]=o(!0),[u,h]=o({});return r(()=>{if(!c?.visible||!c?.anchorRef?.current||!a.current)return;const e=()=>{const e=c.anchorRef.current,t=a.current,o=e.getBoundingClientRect(),r=o.top+window.scrollY,n=o.left+window.scrollX,i=o.top,s=window.innerHeight-o.bottom;let l;l=i>=t.offsetHeight+8?"top":s>=t.offsetHeight+8||s>i?"bottom":"top";const f={position:"absolute",left:n+o.width/2,transform:"translateX(-50%)",willChange:"transform"};f.top="top"===l?r-t.offsetHeight-8:r+o.height+8,h(f),d(l)};return window.addEventListener("scroll",e,{capture:!0}),window.addEventListener("resize",e),e(),()=>{window.removeEventListener("scroll",e,{capture:!0}),window.removeEventListener("resize",e)}},[c?.visible,c?.anchorRef]),n(()=>{const e=c?.anchorRef?.current;if(e&&"IntersectionObserver"in window){const t=new IntersectionObserver(([e])=>{p(e.isIntersecting)},{threshold:.1});return t.observe(e),()=>{t.disconnect()}}},[c?.anchorRef]),i(e("div",{id:c.id,role:"tooltip","aria-live":"polite",className:s({"adyen-checkout-tooltip":!0,"adyen-checkout-tooltip--hidden":!c.visible||!f,[`adyen-checkout-tooltip--${l}`]:!0}),ref:a,style:u},c.text,e("div",{className:`adyen-checkout-tooltip-arrow adyen-checkout-tooltip-arrow--${l}`})),document.body)}export{c as Tooltip};
//# sourceMappingURL=Tooltip.js.map