import React, { memo, ComponentType, CSSProperties } from 'react'; import cx from 'classnames'; import { useStoreActions } from '../../store/hooks'; import { ElementId, Edge, EdgeCompProps } from '../../types'; interface EdgeWrapperProps { id: ElementId; source: ElementId; target: ElementId; type: any; label?: string; labelStyle?: CSSProperties; labelShowBg?: boolean; labelBgStyle: CSSProperties; className?: string; onClick?: (edge: Edge) => void; animated?: boolean; selected: boolean; isInteractive: boolean; } export default (EdgeComponent: ComponentType) => { const EdgeWrapper = memo( ({ id, source, target, type, animated, selected, onClick, isInteractive, label, labelStyle, labelShowBg, labelBgStyle, className, ...rest }: EdgeWrapperProps) => { const setSelectedElements = useStoreActions((a) => a.setSelectedElements); const edgeClasses = cx('react-flow__edge', `react-flow__edge-${type}`, className, { selected, animated }); const edgeGroupStyle: CSSProperties = { pointerEvents: isInteractive ? 'all' : 'none', }; const onEdgeClick = (): void => { if (!isInteractive) { return; } setSelectedElements({ id, source, target }); if (onClick) { onClick({ id, source, target, type }); } }; return ( ); } ); EdgeWrapper.displayName = 'EdgeWrapper'; return EdgeWrapper; };