add DetachedHandle example
This commit is contained in:
@@ -58,6 +58,7 @@ import AddNodeOnEdgeDrop from '../examples/AddNodeOnEdgeDrop';
|
||||
import DevTools from '../examples/DevTools';
|
||||
import Redux from '../examples/Redux';
|
||||
import MovingHandles from '../examples/MovingHandles';
|
||||
import DetachedHandle from '../examples/DetachedHandle';
|
||||
|
||||
export interface IRoute {
|
||||
name: string;
|
||||
@@ -146,6 +147,11 @@ const routes: IRoute[] = [
|
||||
path: 'default-nodes',
|
||||
component: DefaultNodes,
|
||||
},
|
||||
{
|
||||
name: 'DetachedHandle',
|
||||
path: 'detached-handle',
|
||||
component: DetachedHandle,
|
||||
},
|
||||
{
|
||||
name: 'DevTools',
|
||||
path: 'devtools',
|
||||
|
||||
53
examples/react/src/examples/DetachedHandle/index.tsx
Normal file
53
examples/react/src/examples/DetachedHandle/index.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { ReactFlow, Node, ReactFlowProvider, Background, BackgroundVariant, NodeProps, Handle, Position } from '@xyflow/react';
|
||||
|
||||
import './style.css';
|
||||
|
||||
const initialNodes: Node[] = [
|
||||
{
|
||||
id: '1',
|
||||
data: { label: 'Node 1' },
|
||||
position: { x: 250, y: 5 },
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
data: { label: 'Node 2' },
|
||||
position: { x: 50, y: 100 },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { label: 'Node 3' },
|
||||
position: { x: 450, y: 100 },
|
||||
},
|
||||
];
|
||||
|
||||
const CustomNode = (_: NodeProps) => {
|
||||
return (
|
||||
<>
|
||||
<Handle type="target" position={Position.Left} />
|
||||
<div>Custom node</div>
|
||||
<Handle type="source" position={Position.Right}>
|
||||
<button className="detached-handle">➡️</button>
|
||||
</Handle>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const nodeTypes = {
|
||||
default: CustomNode,
|
||||
};
|
||||
|
||||
const DetachedHandle = () => {
|
||||
return (
|
||||
<ReactFlow defaultNodes={initialNodes} nodeTypes={nodeTypes} fitView>
|
||||
<Background variant={BackgroundVariant.Lines} />
|
||||
</ReactFlow>
|
||||
);
|
||||
};
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<ReactFlowProvider>
|
||||
<DetachedHandle />
|
||||
</ReactFlowProvider>
|
||||
);
|
||||
}
|
||||
10
examples/react/src/examples/DetachedHandle/style.css
Normal file
10
examples/react/src/examples/DetachedHandle/style.css
Normal file
@@ -0,0 +1,10 @@
|
||||
.detached-handle {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 1rem;
|
||||
transform: translateY(-50%);
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
}
|
||||
Reference in New Issue
Block a user