vdk-components
Version:
React component library built with TypeScript and SCSS
3 lines (2 loc) • 1.51 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react/jsx-runtime"),require("react")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).VDKTooltip={},t.jsxRuntime,t.React)}(this,(function(t,e,o){"use strict";t.Tooltip=function(t){var i,n=t.content,r=t.children,c=t.position,l=void 0===c?"top":c,u=t.delay,s=void 0===u?0:u,f=t.className,a=void 0===f?"":f,p=o.useState(!1),d=p[0],h=p[1],g=o.useState({top:0,left:0}),m=g[0],v=g[1],x=o.useRef(null),b=o.useRef(null),j=function(){i=setTimeout((function(){if(x.current&&b.current){var t=x.current.getBoundingClientRect(),e=b.current.getBoundingClientRect(),o=0,i=0;switch(l){case"top":o=t.top-e.height-8,i=t.left+(t.width-e.width)/2;break;case"right":o=t.top+(t.height-e.height)/2,i=t.right+8;break;case"bottom":o=t.bottom+8,i=t.left+(t.width-e.width)/2;break;case"left":o=t.top+(t.height-e.height)/2,i=t.left-e.width-8}v({top:o,left:i}),h(!0)}}),s)},T=function(){clearTimeout(i),h(!1)};o.useEffect((function(){return function(){return clearTimeout(i)}}),[]);var w=["tooltip","tooltip--".concat(l),d?"tooltip--visible":"",a].filter(Boolean).join(" ");return e.jsxs("div",{ref:x,className:"tooltip-trigger",onMouseEnter:j,onMouseLeave:T,onFocus:j,onBlur:T,children:[r,e.jsx("div",{ref:b,className:w,style:{top:"".concat(m.top,"px"),left:"".concat(m.left,"px")},role:"tooltip",children:n})]})}}));
//# sourceMappingURL=index.umd.js.map