import Portal from '@reach/portal'; import React, { useState, useRef } from 'react'; interface IHoverable { component: React.Component, } /** Wrapper to render a given component when hovered */ const Hoverable: React.FC = ({ component, children, }): JSX.Element => { const [portalActive, setPortalActive] = useState(false); const ref = useRef(null); const handleMouseEnter = () => { setPortalActive(true); }; const handleMouseLeave = () => { setPortalActive(false); }; const setPortalPosition = (): React.CSSProperties => { if (!ref.current) return {}; const { top, height, left, width } = ref.current.getBoundingClientRect(); return { top: top + height, left, width, }; }; return (
{children} {portalActive &&
{component}
}
); }; export default Hoverable;