Skip to content

Commit 76745a2

Browse files
committed
provide component that is used as default element for new connection lines in React Flow v12
1 parent dbe3b59 commit 76745a2

6 files changed

Lines changed: 64 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This is a major release, and it might be not compatible with your current usage
1717
- use `curvature` property in the edge `data` object to define the bezier layout (0..1, default: 0.25)
1818
- `<EdgeDefaultV12 />`
1919
- the `data` object provides `markerAppearance` to set and remove the edge arrows
20+
- `<EdgeNew />`
21+
- component for React Flow v12, displaying new connection lines
2022

2123
### Removed
2224

@@ -31,6 +33,8 @@ This is a major release, and it might be not compatible with your current usage
3133

3234
- `<EdgeDefault />` and `<EdgeStep />`
3335
- support now v9 and v12 of react flow
36+
- `<ReactFlowExtended />`
37+
- use `<EdgeNew />` by default for new connection lines, you can overwrite it by setting `connectionLineComponent` to `undefined`
3438

3539
### Deprecated
3640

src/cmem/react-flow/ReactFlow/ReactFlowV12.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "@xyflow/react";
1010

1111
import { CLASSPREFIX as eccgui } from "../../../configuration/constants";
12+
import { EdgeNew } from "./../../../extensions/react-flow/edges/EdgeNew";
1213

1314
export type ReactFlowV12ContainerProps = ReactFlowV12Props;
1415

@@ -43,6 +44,7 @@ export const ReactFlowV12Container = React.forwardRef<HTMLDivElement, ReactFlowV
4344
<ReactFlowV12
4445
ref={innerRef}
4546
className={`${eccgui}-graphviz__canvas--reactflow12` + (className ? ` ${className}` : "")}
47+
connectionLineComponent={EdgeNew}
4648
{...originalProps}
4749
{...missingNodesChangeCallback}
4850
{...missingEdgesChangeCallback}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from "react";
2+
import {
3+
ConnectionLineComponentProps,
4+
ConnectionLineType,
5+
} from "@xyflow/react";
6+
import { EdgeStraight, EdgeStep, EdgeBezier, EdgeDefaultV12Props } from "./../index";
7+
8+
import { CLASSPREFIX as eccgui } from "../../../configuration/constants";
9+
10+
export const EdgeNew = (edgeNewProps: ConnectionLineComponentProps) => {
11+
12+
const {
13+
connectionLineType,
14+
fromX,
15+
fromY,
16+
toX,
17+
toY,
18+
connectionStatus,
19+
fromPosition,
20+
toPosition,
21+
} = edgeNewProps;
22+
23+
let EdgeType;
24+
25+
switch(connectionLineType) {
26+
case ConnectionLineType.Step:
27+
case ConnectionLineType.SmoothStep:
28+
EdgeType = EdgeStep;
29+
break;
30+
case ConnectionLineType.Bezier:
31+
case ConnectionLineType.SimpleBezier:
32+
EdgeType = EdgeBezier;
33+
break;
34+
default:
35+
EdgeType = EdgeStraight;
36+
}
37+
38+
return <EdgeType {...{
39+
sourceX: fromX,
40+
sourceY: fromY,
41+
targetX: toX,
42+
targetY: toY,
43+
sourcePosition: fromPosition,
44+
targetPosition: toPosition,
45+
data: {
46+
strokeType: !connectionStatus ? "dashed" : undefined,
47+
edgeSvgProps: {className: `${eccgui}-graphviz__edge--dragged`},
48+
intent: connectionStatus === "valid" ? "success" : connectionStatus === "invalid" ? "warning" : "accent"
49+
},
50+
} as EdgeDefaultV12Props} />;
51+
};
52+

src/extensions/react-flow/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./edges/EdgeDefaultV12";
1212
export * from "./edges/EdgeDefs";
1313
export * from "./edges/EdgeStep";
1414
export * from "./edges/EdgeStraight";
15+
export * from "./edges/EdgeNew";
1516
export * from "./edges/EdgeTools";
1617
export * from "./edges/EdgeLabel";
1718
export * from "./edges/EdgeDefs";

src/extensions/react-flow/markers/ReactFlowMarkers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ReactFlowMarker = ({ className, appearance = "arrow-closed", intent, rever
5353
};
5454

5555
const ReactFlowMarkers: FC = () => {
56-
const intents = ["none", "primary", "success", "warning", "danger", "info"] as IntentTypes[];
56+
const intents = ["none", "primary", "accent", "success", "warning", "danger", "info" ] as IntentTypes[];
5757

5858
return (
5959
<svg>

src/extensions/react-flow/markers/_markers.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ marker[id|="react-flow__marker"] {
99
--marker-intent-color: #{$eccgui-color-primary};
1010
}
1111

12+
&.#{$eccgui}-intent--accent {
13+
--marker-intent-color: #{$eccgui-color-accent};
14+
}
15+
1216
&.#{$eccgui}-intent--info {
1317
--marker-intent-color: #{$eccgui-color-info-text};
1418
}

0 commit comments

Comments
 (0)