import * as React from 'react'; import { useEffect, useRef } from 'react'; import Draggable from 'react-draggable'; import Styled from './styles'; interface FloatingWindowProps { left: number; top: number; key: string; backgroundColor: string; boxShadow: string; isDraggable: boolean; renderFunction: (element: HTMLElement) => void; } const renderComponent = ( elementRef: React.MutableRefObject, key: string, top: number, left: number, backgroundColor: string, boxShadow: string, ) => ( ); const FloatingWindow: React.FC = ({ left, top, key, backgroundColor, boxShadow, isDraggable, renderFunction, }: FloatingWindowProps) => { const elementRef = useRef(null); useEffect(() => { if (elementRef.current && renderFunction) { renderFunction(elementRef.current); } }, [elementRef]); const componentToRender = renderComponent( elementRef, key, top, left, backgroundColor, boxShadow, ); return ( isDraggable ? ( {componentToRender} ) : componentToRender ); }; export default FloatingWindow;