MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / CustomEdge

Function CustomEdge

react-flow-test/src/App.tsx:34–88  ·  view source on GitHub ↗
({
  id,
  sourceX,
  sourceY,
  targetX,
  targetY,
  sourcePosition,
  targetPosition,
  style = {},
  markerEnd,
}: EdgeProps)

Source from the content-addressed store, hash-verified

32}
33
34function CustomEdge({
35 id,
36 sourceX,
37 sourceY,
38 targetX,
39 targetY,
40 sourcePosition,
41 targetPosition,
42 style = {},
43 markerEnd,
44}: EdgeProps) {
45
46
47 const { setEdges } = useReactFlow();
48
49 // const [edgePath, labelX, labelY] = getBezierPath({
50 // sourceX,
51 // sourceY,
52 // sourcePosition,
53 // targetX,
54 // targetY,
55 // targetPosition,
56 // });
57 const [edgePath, labelX, labelY] = getStraightPath({
58 sourceX,
59 sourceY,
60 targetX,
61 targetY
62 })
63
64 const onEdgeClick = () => {
65 setEdges((edges) => edges.filter((edge) => edge.id !== id));
66 };
67
68 return (
69 <>
70 <BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
71 <EdgeLabelRenderer>
72 <div
73 style={{
74 position: 'absolute',
75 transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
76 fontSize: 12,
77 // EdgeLabelRenderer 里的组件默认不处理鼠标事件,如果要处理就要声明 pointerEvents: all
78 pointerEvents: 'all',
79 }}
80 >
81 <button onClick={onEdgeClick}>
82 ×
83 </button>
84 </div>
85 </EdgeLabelRenderer>
86 </>
87 );
88}
89
90export default function App() {
91 const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected