Neural-MRI / frontend /src /components /Tooltip.tsx
Hiconcep's picture
Upload folder using huggingface_hub
0ce9643 verified
import { useState, useRef, type ReactNode } from 'react';
interface TooltipProps {
text: string;
children: ReactNode;
position?: 'top' | 'bottom';
}
export function Tooltip({ text, children, position = 'bottom' }: TooltipProps) {
const [visible, setVisible] = useState(false);
const timeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
const show = () => {
timeoutRef.current = setTimeout(() => setVisible(true), 300);
};
const hide = () => {
if (timeoutRef.current !== null) clearTimeout(timeoutRef.current);
setVisible(false);
};
return (
<div
className="relative"
onMouseEnter={show}
onMouseLeave={hide}
>
{children}
{visible && (
<div
style={{
position: 'absolute',
...(position === 'bottom'
? { top: '100%', marginTop: 6 }
: { bottom: '100%', marginBottom: 6 }),
left: '50%',
transform: 'translateX(-50%)',
background: 'var(--bg-surface)',
border: '1px solid var(--border)',
borderRadius: 4,
padding: '6px 10px',
color: 'var(--text-data)',
fontSize: 'var(--font-size-sm)',
fontFamily: 'var(--font-primary)',
whiteSpace: 'normal',
maxWidth: 260,
zIndex: 50,
pointerEvents: 'none',
boxShadow: '0 4px 12px rgba(0,0,0,0.5)',
animation: 'nmri-fade-in 150ms ease-out',
}}
>
{text}
</div>
)}
</div>
);
}