2 lines
1.8 KiB
JavaScript
2 lines
1.8 KiB
JavaScript
import{r as l,j as s}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{as as c}from"./main-af3pcbZa.js";const h=({children:d,text:f,placement:a="top",className:u=""})=>{const[i,p]=l.useState(!1),b=l.useRef(null),n=l.useRef(null),x=()=>{if(!b.current)return{};const t=b.current.getBoundingClientRect();let r=0,e=0,o="";switch(a){case"top":r=t.top-8,e=t.left+t.width/2,o="translate(-50%, -100%)";break;case"bottom":r=t.bottom+8,e=t.left+t.width/2,o="translateX(-50%)";break;case"left":r=t.top+t.height/2,e=t.left-8,o="translate(-100%, -50%)";break;case"right":r=t.top+t.height/2,e=t.right+8,o="translateY(-50%)";break}return{top:`${r}px`,left:`${e}px`,transform:o}};return l.useEffect(()=>{if(i&&n.current){const t=setTimeout(()=>{n.current&&(n.current.style.visibility="visible")},0);return()=>clearTimeout(t)}},[i]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:`relative inline-flex ${u}`,onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:d}),i&&c.createPortal(s.jsxs("span",{ref:n,className:"fixed z-[999999] px-3 py-1.5 text-xs font-medium text-white bg-gray-900 rounded-lg pointer-events-none whitespace-nowrap",style:x(),children:[f,s.jsx("span",{className:`absolute ${a==="top"?"top-full left-1/2 -translate-x-1/2 -mt-1 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-gray-900":a==="bottom"?"bottom-full left-1/2 -translate-x-1/2 -mb-1 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-b-[6px] border-b-gray-900":a==="left"?"left-full top-1/2 -translate-y-1/2 -ml-1 w-0 h-0 border-t-[6px] border-t-transparent border-b-[6px] border-b-transparent border-l-[6px] border-l-gray-900":"right-full top-1/2 -translate-y-1/2 -mr-1 w-0 h-0 border-t-[6px] border-t-transparent border-b-[6px] border-b-transparent border-r-[6px] border-r-gray-900"}`})]}),document.body)]})};export{h as T};
|