Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import React, { useCallback } from 'react' | |
import { | |
ReactFlow, | |
useNodesState, | |
useEdgesState, | |
addEdge, | |
MiniMap, | |
Controls, | |
OnConnect, | |
} from '@xyflow/react' | |
import '@xyflow/react/dist/base.css' | |
import { Node } from './Node' | |
const nodeTypes = { | |
custom: Node, | |
} | |
const initNodes = [ | |
{ | |
id: '1', | |
type: 'custom', | |
data: { name: 'Jane Doe', job: 'CEO', emoji: 'π' }, | |
position: { x: 0, y: 50 }, | |
}, | |
{ | |
id: '2', | |
type: 'custom', | |
data: { name: 'Tyler Weary', job: 'Designer', emoji: 'π€' }, | |
position: { x: -200, y: 200 }, | |
}, | |
{ | |
id: '3', | |
type: 'custom', | |
data: { name: 'Kristi Price', job: 'Developer', emoji: 'π€©' }, | |
position: { x: 200, y: 200 }, | |
}, | |
] | |
const initEdges = [ | |
{ | |
id: 'e1-2', | |
source: '1', | |
target: '2', | |
}, | |
{ | |
id: 'e1-3', | |
source: '1', | |
target: '3', | |
}, | |
] | |
export function MoodboardView() { | |
const [nodes, setNodes, onNodesChange] = useNodesState(initNodes) | |
const [edges, setEdges, onEdgesChange] = useEdgesState(initEdges) | |
const onConnect: OnConnect = useCallback( | |
(params) => setEdges((eds) => addEdge(params, eds)), | |
[] | |
) | |
return ( | |
<ReactFlow | |
nodes={nodes} | |
edges={edges} | |
onNodesChange={onNodesChange} | |
onEdgesChange={onEdgesChange} | |
onConnect={onConnect} | |
nodeTypes={nodeTypes} | |
fitView | |
className="bg-teal-50" | |
> | |
<MiniMap /> | |
<Controls /> | |
</ReactFlow> | |
) | |
} | |