UNPKG

@anoki/fse-ui

Version:

FSE UI components library

3 lines (2 loc) 1.32 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/Tooltip/tooltip.css');const u=require("./index.cjs278.js"),e=require("react");;/* empty css */const C=({children:h,label:x,opened:a,defaultOpened:R=!1,position:r="top",withArrow:m=!0,delay:p=0,className:b=""})=>{const[g,i]=e.useState(R),l=e.useRef(null),n=e.useRef(null),c=e.useRef(null),[f,w]=e.useState({top:0,left:0}),d=a!==void 0?a:g,j=()=>{p>0?l.current=setTimeout(()=>i(!0),p):i(!0)},v=()=>{l.current&&clearTimeout(l.current),i(!1)};return e.useEffect(()=>{if(n.current&&c.current){const t=n.current.getBoundingClientRect(),T=c.current.getBoundingClientRect();let o=0,s=0;switch(r){case"top":o=t.top-8,s=t.left+t.width/2;break;case"bottom":o=t.height+8,s=t.width/2-T.width/2;break;case"left":o=t.top+t.height/2,s=(t.left-8)*-1;break;case"right":o=t.top+t.height/2,s=t.right+8;break}w({top:o,left:s})}},[d,r]),u.jsxRuntimeExports.jsxs("div",{className:"tooltip-wrapper",ref:n,onMouseEnter:j,onMouseLeave:v,children:[h,d&&u.jsxRuntimeExports.jsxs("div",{className:`tooltip-box tooltip-${r} ${b} p-x24`,style:{top:f.top,left:f.left},ref:c,children:[x,m&&u.jsxRuntimeExports.jsx("div",{className:`tooltip-arrow tooltip-arrow-${r}`})]})]})};exports.Tooltip=C; //# sourceMappingURL=index.cjs263.js.map