@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 998 B
JavaScript
import{createContext as t,createElement as e}from"../../../external/preact/dist/preact.js";import{useState as o,useRef as r,useEffect as s,useMemo as i,useContext as n}from"../../../external/preact/hooks/dist/hooks.js";import{Tooltip as l}from"./Tooltip.js";import{TooltipController as a}from"./TooltipController.js";const c=t(null),u=({children:t})=>{const[n,u]=o(null),p=r(a.tooltipId),d=r(!1),[,m]=o(0);s(()=>{const t=()=>{a.canRegisterTooltipHandler()?(a.registerTooltipHandler(u),d.current=!0,m(t=>t+1)):(d.current=!1,m(t=>t+1))};t();const e=a.onPrimaryReset(()=>{t()});return()=>{e(),d.current&&a.reset()}},[]);const T=i(()=>({showTooltip:t=>a.showTooltip(t),hideTooltip:t=>a.hideTooltip(t),id:p.current}),[]);return e(c.Provider,{value:T},t,d.current&&e(l,{id:p.current,...n}))},p=()=>{const t=n(c);if(!t)throw new Error("useTooltip must be used within a TooltipProvider");return t};export{u as SingletonTooltipProvider,p as useTooltip};
//# sourceMappingURL=SingletonTooltipProvider.js.map