Skip to content

Commit cff65f0

Browse files
committed
enhance stories with canvas backgrounds and minimap
1 parent e29fb57 commit cff65f0

1 file changed

Lines changed: 45 additions & 10 deletions

File tree

src/cmem/react-flow/ReactFlow/ReactFlow.stories.tsx

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
import React, { FC, useCallback, useEffect, useState } from "react";
2-
import { Elements, FlowElement, Position } from "react-flow-renderer";
32
import {
3+
Background as BackgroundV9,
4+
BackgroundVariant as BackgroundVariantV9,
5+
Elements,
6+
FlowElement,
7+
Position,
8+
} from "react-flow-renderer";
9+
import {
10+
Background as BackgroundV10,
11+
BackgroundVariant as BackgroundVariantV10,
412
Edge as Edge10,
513
Node as Node10,
14+
OnInit as OnInitV10,
15+
ReactFlowInstance as ReactFlowInstanceV10,
616
useEdgesState as useEdgesState10,
717
useNodesState as useNodesState10,
818
} from "react-flow-renderer-lts";
919
import { Meta, StoryFn } from "@storybook/react";
1020
import { fn } from "@storybook/test";
1121
import {
22+
Background as BackgroundV12,
23+
BackgroundVariant as BackgroundVariantV12,
1224
Edge as Edge12,
1325
Node as Node12,
1426
useEdgesState as useEdgesState12,
1527
useNodesState as useNodesState12,
1628
} from "@xyflow/react";
1729

18-
import { ApplicationContainer, EdgeTools, NodeTools, ReactFlowExtended } from "./../../../index";
19-
import { ReactFlowExtendedProps } from "./ReactFlow";
30+
import {
31+
ApplicationContainer,
32+
EdgeTools,
33+
MiniMap,
34+
MiniMapV10,
35+
MiniMapV12,
36+
NodeTools,
37+
ReactFlowExtended,
38+
ReactFlowExtendedProps,
39+
} from "./../../../index";
2040

2141
const nodeExamples = {
2242
unspecified: {
@@ -411,7 +431,7 @@ export default {
411431
} as Meta<typeof ReactFlowExtended>;
412432

413433
const ReactFlowExampleV9: FC<ReactFlowExtendedProps> = (args) => {
414-
const [reactflowInstance, setReactflowInstance] = useState(null);
434+
const [reactflowInstance, setReactflowInstance] = useState(undefined);
415435
const [elements, setElements] = useState([] as Elements);
416436
const [edgeTools, setEdgeTools] = useState<JSX.Element>(<></>);
417437

@@ -460,27 +480,39 @@ const ReactFlowExampleV9: FC<ReactFlowExtendedProps> = (args) => {
460480
};
461481

462482
return (
463-
<ApplicationContainer monitorDropzonesFor={args.dropzoneFor}>
464-
<ReactFlowExtended {...reactFlowExtendedProps} />
483+
<ApplicationContainer monitorDropzonesFor={args.dropzoneFor} style={{ background: "white" }}>
484+
<ReactFlowExtended {...reactFlowExtendedProps}>
485+
<MiniMap flowInstance={reactflowInstance} enableNavigation={true} />
486+
<BackgroundV9 variant={BackgroundVariantV9.Lines} gap={16} />
487+
</ReactFlowExtended>
465488
{edgeTools}
466489
</ApplicationContainer>
467490
);
468491
};
469492

470493
const ReactFlowExampleV10: FC<ReactFlowExtendedProps> = (args) => {
494+
const [reactFlowInstance, setReactFlowInstance] = React.useState<ReactFlowInstanceV10 | undefined>(undefined);
471495
const [nodes, ,] = useNodesState10(nodeExamples[args.configuration ?? "unspecified"].nodes as Node10[]);
472496
const [edges, ,] = useEdgesState10(nodeExamples[args.configuration ?? "unspecified"].edges as Edge10[]);
473497

498+
const onInit: OnInitV10 = React.useCallback((_reactFlowInstance: ReactFlowInstanceV10) => {
499+
setReactFlowInstance(_reactFlowInstance);
500+
}, []);
501+
474502
const reactFlowExtendedProps = {
475503
...args,
476504
defaultZoom: 1,
477505
nodes,
478506
edges,
507+
onInit,
479508
} as ReactFlowExtendedProps;
480509

481510
return (
482-
<ApplicationContainer>
483-
<ReactFlowExtended {...reactFlowExtendedProps} />
511+
<ApplicationContainer monitorDropzonesFor={args.dropzoneFor} style={{ background: "white" }}>
512+
<ReactFlowExtended {...reactFlowExtendedProps}>
513+
<MiniMapV10 flowInstance={reactFlowInstance} enableNavigation={true} />
514+
<BackgroundV10 variant={BackgroundVariantV10.Lines} gap={16} />
515+
</ReactFlowExtended>
484516
</ApplicationContainer>
485517
);
486518
};
@@ -501,9 +533,12 @@ const ReactFlowExampleV12: FC<ReactFlowExtendedProps> = (args) => {
501533
};
502534

503535
return (
504-
<ApplicationContainer>
536+
<ApplicationContainer monitorDropzonesFor={args.dropzoneFor} style={{ background: "white" }}>
505537
<div style={{ height, width }}>
506-
<ReactFlowExtended {...reactFlowExtendedProps} />
538+
<ReactFlowExtended {...reactFlowExtendedProps}>
539+
<MiniMapV12 enableNavigation />
540+
<BackgroundV12 variant={BackgroundVariantV12.Lines} gap={16} />
541+
</ReactFlowExtended>
507542
</div>
508543
</ApplicationContainer>
509544
);

0 commit comments

Comments
 (0)