11import React , { FC , useCallback , useEffect , useState } from "react" ;
2- import { Elements , FlowElement , Position } from "react-flow-renderer" ;
32import {
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" ;
919import { Meta , StoryFn } from "@storybook/react" ;
1020import { fn } from "@storybook/test" ;
1121import {
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
2141const nodeExamples = {
2242 unspecified : {
@@ -411,7 +431,7 @@ export default {
411431} as Meta < typeof ReactFlowExtended > ;
412432
413433const 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
470493const 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