Skip to content

Commit

Permalink
animate connected edges on click
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix committed May 7, 2024
1 parent 06826e8 commit ba8d479
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ui/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useNodesState,
Node,
Edge,
ReactFlowProvider, Position, Handle, NodeProps
ReactFlowProvider, Position, Handle, NodeProps, getConnectedEdges
} from 'reactflow';
import { DateTime, Duration } from 'luxon';
import 'reactflow/dist/style.css';
Expand Down Expand Up @@ -78,6 +78,15 @@ export function Home() {
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
nodeTypes={nodeTypes}
onNodeClick={(_, node) => {
const connectedEdges = getConnectedEdges([node], edges);
const ids = connectedEdges.map((v) => v.id);

setEdges((prev) => prev.map((edge) => {
edge.animated = ids.includes(edge.id);
return edge;
}));
}}
>
<Controls />
<Background />
Expand Down

0 comments on commit ba8d479

Please sign in to comment.