clapper / src /experiments /moodboard /MoodboardView.tsx
jbilcke-hf's picture
jbilcke-hf HF staff
working on roadmap features
65b1bdb
raw
history blame
1.45 kB
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>
)
}