UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 1.8 kB
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 l(l){const c=t(null),[a,d]=o("top"),[u,f]=o(!0),[p,v]=o({});return r(()=>{var e;if(!(null==l?void 0:l.visible)||!(null==l||null===(e=l.anchorRef)||void 0===e?void 0:e.current)||!c.current)return;const t=()=>{const e=l.anchorRef.current,t=c.current,o=e.getBoundingClientRect(),r=o.top+window.scrollY,n=o.left+window.scrollX,i=o.top,s=window.innerHeight-o.bottom;let a;a=i>=t.offsetHeight+8?"top":s>=t.offsetHeight+8||s>i?"bottom":"top";const u={position:"absolute",left:n+o.width/2,transform:"translateX(-50%)",willChange:"transform"};u.top="top"===a?r-t.offsetHeight-8:r+o.height+8,v(u),d(a)};return window.addEventListener("scroll",t,{capture:!0}),window.addEventListener("resize",t),t(),()=>{window.removeEventListener("scroll",t,{capture:!0}),window.removeEventListener("resize",t)}},[null==l?void 0:l.visible,null==l?void 0:l.anchorRef]),n(()=>{var e;const t=null==l||null===(e=l.anchorRef)||void 0===e?void 0:e.current;if(t&&"IntersectionObserver"in window){const e=new IntersectionObserver(([e])=>{f(e.isIntersecting)},{threshold:.1});return e.observe(t),()=>{e.disconnect()}}},[null==l?void 0:l.anchorRef]),i(e("div",{id:l.id,role:"tooltip","aria-live":"polite",className:s({"adyen-checkout-tooltip":!0,"adyen-checkout-tooltip--hidden":!l.visible||!u,[`adyen-checkout-tooltip--${a}`]:!0}),ref:c,style:p},l.text,e("div",{className:`adyen-checkout-tooltip-arrow adyen-checkout-tooltip-arrow--${a}`})),document.body)}export{l as Tooltip}; //# sourceMappingURL=Tooltip.js.map