Merge branch 'main' into feat/nodes-html-attributes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { MouseEvent } from 'react';
|
||||
import { MouseEvent, useState } from 'react';
|
||||
import {
|
||||
ReactFlow,
|
||||
MiniMap,
|
||||
@@ -8,15 +8,10 @@ import {
|
||||
ReactFlowProvider,
|
||||
Node,
|
||||
Edge,
|
||||
OnNodeDrag,
|
||||
AriaLabelConfig,
|
||||
Panel,
|
||||
} from '@xyflow/react';
|
||||
|
||||
const onNodeDrag: OnNodeDrag = (_, node: Node, nodes: Node[]) => console.log('drag', node, nodes);
|
||||
const onNodeDragStart = (_: MouseEvent, node: Node, nodes: Node[]) => console.log('drag start', node, nodes);
|
||||
const onNodeDragStop = (_: MouseEvent, node: Node, nodes: Node[]) => console.log('drag stop', node, nodes);
|
||||
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
|
||||
|
||||
const initialNodes: Node[] = [
|
||||
{
|
||||
id: '1',
|
||||
@@ -32,20 +27,39 @@ const initialNodes: Node[] = [
|
||||
{
|
||||
id: '2',
|
||||
data: { label: 'Node 2' },
|
||||
position: { x: 100, y: 100 },
|
||||
className: 'light',
|
||||
position: { x: 1000, y: 100 },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { label: 'Node 3' },
|
||||
position: { x: 400, y: 100 },
|
||||
position: { x: 100, y: 100 },
|
||||
className: 'light',
|
||||
ariaRoleDescription: 'custom node role',
|
||||
ariaRole: 'button',
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
data: { label: 'Node 4' },
|
||||
position: { x: 300, y: 100 },
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
data: { label: 'Node 5' },
|
||||
position: { x: 400, y: 200 },
|
||||
},
|
||||
{
|
||||
id: '6',
|
||||
data: { label: 'Node 6' },
|
||||
position: { x: -1000, y: 200 },
|
||||
},
|
||||
];
|
||||
|
||||
const initialEdges: Edge[] = [
|
||||
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
||||
{ id: 'e1-3', source: '1', target: '3' },
|
||||
{ id: 'e1-4', source: '1', target: '4' },
|
||||
{ id: 'e1-5', source: '4', target: '5' },
|
||||
{ id: 'e1-6', source: '3', target: '6' },
|
||||
];
|
||||
|
||||
const ariaLabelConfig: Partial<AriaLabelConfig> = {
|
||||
@@ -63,19 +77,13 @@ const ariaLabelConfig: Partial<AriaLabelConfig> = {
|
||||
};
|
||||
|
||||
const A11y = () => {
|
||||
const [autoPanOnNodeFocus, setAutoPanOnNodeFocus] = useState(true);
|
||||
|
||||
return (
|
||||
<ReactFlow
|
||||
defaultNodes={initialNodes}
|
||||
defaultEdges={initialEdges}
|
||||
onNodesChange={console.log}
|
||||
onNodeClick={onNodeClick}
|
||||
onNodeDragStop={onNodeDragStop}
|
||||
onNodeDragStart={onNodeDragStart}
|
||||
onNodeDrag={onNodeDrag}
|
||||
className="react-flow-basic-example"
|
||||
minZoom={0.2}
|
||||
maxZoom={4}
|
||||
fitView
|
||||
autoPanOnNodeFocus={autoPanOnNodeFocus}
|
||||
selectNodesOnDrag={false}
|
||||
elevateEdgesOnSelect
|
||||
elevateNodesOnSelect={false}
|
||||
@@ -85,6 +93,20 @@ const A11y = () => {
|
||||
<Background variant={BackgroundVariant.Dots} />
|
||||
<MiniMap />
|
||||
<Controls />
|
||||
<Panel position="top-right">
|
||||
<div>
|
||||
<label htmlFor="focusPannable">
|
||||
<input
|
||||
id="focusPannable"
|
||||
type="checkbox"
|
||||
checked={autoPanOnNodeFocus}
|
||||
onChange={(event) => setAutoPanOnNodeFocus(event.target.checked)}
|
||||
className="xy-theme__checkbox"
|
||||
/>
|
||||
autoPanOnNodeFocus
|
||||
</label>
|
||||
</div>
|
||||
</Panel>
|
||||
</ReactFlow>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user