Skip to content

Commit 66109c1

Browse files
committed
Fix stories issues, fix edge label
1 parent 33315d0 commit 66109c1

4 files changed

Lines changed: 48 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2020
- some more interfaces are exposed:
2121
- `IntentBlueprint`: BlueprintJS intent types, also available by `DefinitionsBlueprint`
2222
- `TableDataContainerProps`, `TableSimpleContainerProps`, `TableHeadProps`, `TableBodyProps`, `TableExpandedRowProps`, `TableHeaderProps` and `DataTableRenderProps` as interfaces for diverse table components
23+
- added support for `react-flow` v12 for `NodeContent` component, added v12-related components: `EdgeDefaultV12`, `NodeDefaultV12`, `EdgeDefs`
2324

2425
## [24.1.0] - 2025-04-16
2526

src/extensions/react-flow/edges/EdgeDefaultV12.tsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { memo } from "react";
22
import React from "react";
3-
import { BaseEdge, Edge, EdgeLabelRenderer, EdgeProps, getBezierPath } from "@xyflow/react";
3+
import { BaseEdge, Edge, EdgeProps, EdgeText, getBezierPath, getEdgeCenter } from "@xyflow/react";
44

55
import { IntentTypes } from "../../../common/Intent";
66
import { nodeContentUtils } from "../nodes/NodeContent";
@@ -76,29 +76,26 @@ export const EdgeDefaultV12 = memo(
7676
highlightColor
7777
);
7878

79+
const edgeCenter = getEdgeCenter({
80+
sourceX,
81+
sourceY,
82+
targetX,
83+
targetY,
84+
});
85+
7986
const renderedLabel =
8087
renderLabel?.([labelX, labelY, sourceX, targetX]) ??
8188
(label ? (
82-
<EdgeLabelRenderer>
83-
<div
84-
style={{
85-
position: "absolute",
86-
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
87-
...labelStyle,
88-
...(labelShowBg
89-
? {
90-
background: labelBgStyle?.fill || "white",
91-
padding: `${labelBgPadding[1]}px ${labelBgPadding[0]}px`,
92-
borderRadius: `${labelBgBorderRadius}px`,
93-
border: labelBgStyle?.stroke ? `1px solid ${labelBgStyle.stroke}` : undefined,
94-
}
95-
: {}),
96-
}}
97-
className="edge-label-renderer__custom-edge nodrag nopan"
98-
>
99-
{label}
100-
</div>
101-
</EdgeLabelRenderer>
89+
<EdgeText
90+
x={edgeCenter[0]}
91+
y={edgeCenter[1]}
92+
label={label}
93+
labelStyle={labelStyle}
94+
labelShowBg={labelShowBg}
95+
labelBgStyle={labelBgStyle}
96+
labelBgPadding={labelBgPadding || [5, 5]}
97+
labelBgBorderRadius={labelBgBorderRadius || 3}
98+
/>
10299
) : null);
103100

104101
return (

src/extensions/react-flow/edges/_edges.scss

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
stroke-opacity: $reactflow-edge-stroke-opacity-selected;
4646
}
4747

48-
// Edge interaction path with reduced opacity for selected state
49-
// The same as path.react-flow__edge-path-glow - in v12 we have a special class for edge-interaction
50-
path[class*="react-flow__edge-interaction"] {
51-
stroke-opacity: $reactflow-edge-stroke-opacity-selected * 0.2;
52-
}
53-
5448
text[class*="react-flow__edge"] {
5549
opacity: $reactflow-edge-stroke-opacity-selected;
5650
}
@@ -68,6 +62,24 @@ path.react-flow__edge-path {
6862
}
6963
}
7064

65+
path.react-flow__edge-interaction {
66+
fill: none;
67+
stroke: currentcolor;
68+
stroke-linecap: round;
69+
70+
.react-flow__edge & {
71+
stroke-opacity: 0;
72+
}
73+
74+
.react-flow__edge:hover & {
75+
stroke-opacity: $reactflow-edge-stroke-opacity-hover * 0.2;
76+
}
77+
78+
.react-flow__edge.selected & {
79+
stroke-opacity: $reactflow-edge-stroke-opacity-selected * 0.2;
80+
}
81+
}
82+
7183
path.react-flow__edge-path-glow {
7284
fill: none;
7385
stroke: currentcolor;

src/extensions/react-flow/nodes/stories/NodeContentV12.stories.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useCallback, useEffect, useState } from "react";
2-
import { Node, Position, ReactFlow, ReactFlowProvider } from "@xyflow/react";
32
import { LoremIpsum, loremIpsum } from "react-lorem-ipsum";
43
import { Meta, StoryFn } from "@storybook/react";
4+
import { Node, Position, ReactFlow, ReactFlowProvider, useNodesState } from "@xyflow/react";
55

66
import { Definitions } from "../../../../common/Intent";
7+
import { NodeDefaultV12 } from "../NodeDefaultV12";
78

89
import canonicalIcons from "./../../../../components/Icon/canonicalIconNames";
910
import {
@@ -22,7 +23,6 @@ import {
2223
Default as ContentExtensionExample,
2324
SlideOutOfNode as ContentExtensionExampleSlideOut,
2425
} from "./NodeContentExtension.stories";
25-
import { NodeDefaultV12 } from "../NodeDefaultV12";
2626

2727
export default {
2828
title: "Extensions/React Flow V12/Node Content",
@@ -144,7 +144,7 @@ const nodeTypes = { default: NodeDefaultV12 };
144144

145145
const NodeContentExample = (args: any) => {
146146
const [reactflowInstance, setReactflowInstance] = useState(null);
147-
const [elements, setElements] = useState([] as Node[]);
147+
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);
148148

149149
const defaultElement = {
150150
id: "example-1",
@@ -169,30 +169,30 @@ const NodeContentExample = (args: any) => {
169169
onClick={() => {
170170
// eslint-disable-next-line no-console
171171
console.log("reset size");
172-
setElements([
172+
setNodes([
173173
{
174174
...defaultElement,
175175
data: { ...defaultElement.data, ...sizeReset, ...{ nodeDimensions: {} } },
176176
},
177-
] as Node[]);
177+
]);
178178
}}
179179
/>
180180
);
181181
}
182-
setElements([
182+
setNodes([
183183
{
184184
...defaultElement,
185185
data: { ...defaultElement.data, ...sizeReset, ...{ nodeDimensions: dimensions } },
186186
},
187-
] as Node[]);
187+
]);
188188
};
189189
}
190-
setElements([
190+
setNodes([
191191
{
192192
...defaultElement,
193193
data: { ...defaultElement.data, ...sizeReset },
194194
},
195-
] as Node[]);
195+
]);
196196
}, [args]);
197197

198198
const onLoad = useCallback(
@@ -208,11 +208,12 @@ const NodeContentExample = (args: any) => {
208208
<div style={{ width: "100%", height: "400px" }}>
209209
<ReactFlowProvider>
210210
<ReactFlow
211-
nodes={elements}
211+
nodes={nodes}
212212
edges={[]}
213213
style={{ height: "400px" }}
214214
onLoad={onLoad}
215215
nodeTypes={nodeTypes}
216+
onNodesChange={onNodesChange}
216217
/>
217218
</ReactFlowProvider>
218219
</div>

0 commit comments

Comments
 (0)