Skip to content

Commit b9bcd2f

Browse files
committed
more updates
1 parent e06c195 commit b9bcd2f

File tree

8 files changed

+631
-261
lines changed

8 files changed

+631
-261
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Basic Flow Example
2+
3+
This example demonstrates a simple flow diagram with three nodes and two edges, showing how nodes can be connected and how edges can be animated.
4+
5+
### Nodes
6+
7+
- Input Node – starting point
8+
- Default Node – standard content node
9+
- Output Node – endpoint of the flow
10+
11+
### Edges
12+
13+
- Input → Default (animated)
14+
- Default → Output
15+
16+
### Interactivity
17+
18+
- Nodes can be moved
19+
- Edges update dynamically
20+
- Users can drag from handles to create new edges
21+
- Zoom, pan, and mini-map controls are available
22+
23+
### Visual Layout
24+
25+
- Flow fits viewport automatically
26+
- Background grid for orientation
27+
- Light and dark color modes supported
28+
29+
### Example Flow
30+
31+
```python
32+
import reflex as rx
33+
import reflex_enterprise as rxe
34+
from reflex_enterprise.components.flow.types import Node, Edge
35+
36+
class FlowState(rx.State):
37+
nodes: list[Node] = [
38+
{
39+
"id": "1",
40+
"type": "input",
41+
"position": {"x": 100, "y": 100},
42+
"data": {"label": "Input Node"}
43+
},
44+
{
45+
"id": "2",
46+
"type": "default",
47+
"position": {"x": 300, "y": 200},
48+
"data": {"label": "Default Node"}
49+
},
50+
{
51+
"id": "3",
52+
"type": "output",
53+
"position": {"x": 500, "y": 100},
54+
"data": {"label": "Output Node"}
55+
},
56+
]
57+
58+
edges: list[Edge] = [
59+
{"id": "e1-2", "source": "1", "target": "2", "animated": True},
60+
{"id": "e2-3", "source": "2", "target": "3"},
61+
]
62+
63+
@rx.event
64+
def on_nodes_change(self, changes: list[dict]):
65+
self.nodes = rxe.flow.util.apply_node_changes(self.nodes, changes)
66+
67+
@rx.event
68+
def on_edges_change(self, changes: list[dict]):
69+
self.edges = rxe.flow.util.apply_edge_changes(self.edges, changes)
70+
71+
@rx.event
72+
def on_connect(self, connection: dict):
73+
self.edges = rxe.flow.util.add_edge(connection, self.edges)
74+
75+
def flow_example():
76+
return rx.box(
77+
rxe.flow(
78+
# Core flow components
79+
rxe.flow.controls(), # Zoom and pan controls
80+
rxe.flow.background(), # Grid background
81+
rxe.flow.mini_map(), # Mini map for navigation
82+
83+
# Flow configuration
84+
nodes=FlowState.nodes,
85+
edges=FlowState.edges,
86+
on_nodes_change=lambda node_changes: FlowState.set_nodes(
87+
rxe.flow.util.apply_node_changes(FlowState.nodes, node_changes)
88+
),
89+
on_edges_change=lambda edge_changes: FlowState.set_edges(
90+
rxe.flow.util.apply_edge_changes(FlowState.edges, edge_changes)
91+
),
92+
fit_view=True,
93+
94+
# Visual settings
95+
color_mode="light",
96+
attribution_position="bottom-right",
97+
),
98+
height="100vh",
99+
width="100vw",
100+
)
101+
```
102+
103+
104+
```python exec
105+
import reflex as rx
106+
from reflex_image_zoom import image_zoom
107+
108+
def render_image():
109+
return rx.el.div(
110+
image_zoom(
111+
rx.image(
112+
src="/enterprise/flow-simple.gif",
113+
class_name="p-2 rounded-md h-auto",
114+
border=f"0.81px solid {rx.color('slate', 5)}",
115+
),
116+
class_name="rounded-md overflow-hidden",
117+
),
118+
class_name="w-full flex flex-col rounded-md cursor-pointer",
119+
)
120+
```
121+
122+
```python eval
123+
124+
rx.el.div(render_image(), class_name="py-4")
125+
126+
```

docs/enterprise/react_flow/components.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ The `FlowProvider` component is a context provider that makes it possible to acc
99
**Props:**
1010

1111
- `initial_nodes`: `Sequence[Node]` - These nodes are used to initialize the flow. They are not dynamic.
12-
- `initial_edges`: `Sequence[Edge]` - These edges are used to initialize the flow. They are not dynamic.
13-
- `default_nodes`: `Sequence[Node]` - These nodes are used to initialize the flow. They are not dynamic.
1412
- `default_edges`: `Sequence[Edge]` - These edges are used to initialize the flow. They are not dynamic.
1513
- `initial_width`: `float` - The initial width is necessary to be able to use fitView on the server.
1614
- `initial_height`: `float` - The initial height is necessary to be able to use fitView on the server.
@@ -27,8 +25,6 @@ The `Flow` component is the main component that renders the flow. It takes in no
2725

2826
**Props:**
2927

30-
*Many of the props are documented in the official [React Flow documentation](https://reactflow.dev/api-reference/react-flow). Below are some of the most common props.*
31-
3228
- `nodes`: `Sequence[Node]` - An array of nodes to render in a controlled flow.
3329
- `edges`: `Sequence[Edge]` - An array of edges to render in a controlled flow.
3430
- `default_nodes`: `Sequence[Node]` - The initial nodes to render in an uncontrolled flow.

0 commit comments

Comments
 (0)