DB-GPT/web/components/flow/button-edge.tsx
Dreammy23 471689ba20
feat(web): Unified frontend code style (#1923)
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
Co-authored-by: 谨欣 <echo.cmy@antgroup.com>
Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com>
Co-authored-by: yanzhiyong <932374019@qq.com>
2024-08-30 14:03:06 +08:00

52 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
import { BaseEdge, EdgeProps, getBezierPath, useReactFlow } from 'reactflow';
const ButtonEdge: React.FC<EdgeProps> = ({
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
style = {},
markerEnd,
}) => {
const [edgePath, edgeCenterX, edgeCenterY] = getBezierPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
});
const reactFlow = useReactFlow();
function onEdgeClick(event: React.MouseEvent, id: string) {
event.stopPropagation();
reactFlow.setEdges(reactFlow.getEdges().filter(edge => edge.id !== id));
}
return (
<>
<BaseEdge id={id} style={style} path={edgePath} markerEnd={markerEnd} />
<foreignObject
width={40}
height={40}
x={edgeCenterX - 40 / 2}
y={edgeCenterY - 40 / 2}
className='bg-transparent w-10 h-10 relative'
requiredExtensions='http://www.w3.org/1999/xhtml'
>
<button
className='absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-5 h-5 rounded-full bg-stone-400 dark:bg-zinc-700 cursor-pointer text-sm'
onClick={event => onEdgeClick(event, id)}
>
×
</button>
</foreignObject>
</>
);
};
export default ButtonEdge;