docs(website): interactive examples
This commit is contained in:
@@ -3,6 +3,7 @@ import ReactFlow, {
|
|||||||
ReactFlowProvider,
|
ReactFlowProvider,
|
||||||
Background,
|
Background,
|
||||||
Controls,
|
Controls,
|
||||||
|
addEdge,
|
||||||
} from 'react-flow-renderer';
|
} from 'react-flow-renderer';
|
||||||
|
|
||||||
import ColorPickerNode from './ColorPickerNode';
|
import ColorPickerNode from './ColorPickerNode';
|
||||||
@@ -45,6 +46,7 @@ const findNodeByColor = (color) => (n) =>
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [elements, setElements] = useState([]);
|
const [elements, setElements] = useState([]);
|
||||||
|
const onConnect = (params) => setElements((els) => addEdge(params, els));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onChange = (event, id) => {
|
const onChange = (event, id) => {
|
||||||
@@ -132,7 +134,12 @@ export default () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlowProvider>
|
<ReactFlowProvider>
|
||||||
<ReactFlow elements={elements} zoomOnScroll={false} nodeTypes={nodeTypes}>
|
<ReactFlow
|
||||||
|
elements={elements}
|
||||||
|
zoomOnScroll={false}
|
||||||
|
nodeTypes={nodeTypes}
|
||||||
|
onConnect={onConnect}
|
||||||
|
>
|
||||||
<Background />
|
<Background />
|
||||||
<Controls showInteractive={false} />
|
<Controls showInteractive={false} />
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
|
import ReactFlow, {
|
||||||
|
ReactFlowProvider,
|
||||||
|
Background,
|
||||||
|
Controls,
|
||||||
|
addEdge,
|
||||||
|
} from 'react-flow-renderer';
|
||||||
|
|
||||||
import TeaserFlow from 'components/TeaserFlow';
|
import TeaserFlow from 'components/TeaserFlow';
|
||||||
|
import { baseColors } from 'themes';
|
||||||
|
|
||||||
const elements = [
|
const initialElements = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
@@ -72,17 +79,28 @@ const elements = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const flowProps = {
|
const onLoad = (rf) => rf.fitView({ padding: 0.2 });
|
||||||
elements,
|
|
||||||
onLoad: (rf) => rf.fitView({ padding: 0.2 }),
|
|
||||||
};
|
|
||||||
|
|
||||||
export default () => (
|
export default () => {
|
||||||
<TeaserFlow
|
const [elements, setElements] = useState(initialElements);
|
||||||
title="Feature-rich"
|
const onConnect = (params) => setElements((els) => addEdge(params, els));
|
||||||
description="React Flow comes with seamless zooming & panning, different edge and node types, single and multi-selection, controls, several event handlers and more."
|
|
||||||
flowProps={flowProps}
|
return (
|
||||||
withControls
|
<TeaserFlow
|
||||||
fitView
|
title="Feature-rich"
|
||||||
/>
|
description="React Flow comes with seamless zooming & panning, different edge and node types, single and multi-selection, controls, several event handlers and more."
|
||||||
);
|
>
|
||||||
|
<ReactFlowProvider>
|
||||||
|
<ReactFlow
|
||||||
|
elements={elements}
|
||||||
|
onLoad={onLoad}
|
||||||
|
zoomOnScroll={false}
|
||||||
|
onConnect={onConnect}
|
||||||
|
>
|
||||||
|
<Background color={baseColors.silverDarken60} gap={15} />
|
||||||
|
<Controls showInteractive={false} />
|
||||||
|
</ReactFlow>
|
||||||
|
</ReactFlowProvider>
|
||||||
|
</TeaserFlow>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -158,12 +158,13 @@ export default () => {
|
|||||||
setElements(initialElements);
|
setElements(initialElements);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
console.log(elements);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TeaserFlow
|
<TeaserFlow
|
||||||
title="Customizable"
|
title="Customizable"
|
||||||
description="You can create your own node and edge types or just pass a custom style. You can implement custom UIs inside your nodes and add functionality to your edges."
|
description="You can create your own node and edge types or just pass a custom style. You can implement custom UIs inside your nodes and add functionality to your edges."
|
||||||
textPosition="right"
|
textPosition="right"
|
||||||
fitView
|
|
||||||
isDark
|
isDark
|
||||||
>
|
>
|
||||||
<ReactFlowProvider>
|
<ReactFlowProvider>
|
||||||
@@ -172,6 +173,7 @@ export default () => {
|
|||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
onLoad={onLoad}
|
onLoad={onLoad}
|
||||||
zoomOnScroll={false}
|
zoomOnScroll={false}
|
||||||
|
nodesConnectable={false}
|
||||||
>
|
>
|
||||||
<Background color={baseColors.silverDarken60} gap={15} />
|
<Background color={baseColors.silverDarken60} gap={15} />
|
||||||
<Controls showInteractive={false} />
|
<Controls showInteractive={false} />
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
|
import ReactFlow, {
|
||||||
|
ReactFlowProvider,
|
||||||
|
Background,
|
||||||
|
Controls,
|
||||||
|
addEdge,
|
||||||
|
} from 'react-flow-renderer';
|
||||||
|
|
||||||
import TeaserFlow from 'components/TeaserFlow';
|
import TeaserFlow from 'components/TeaserFlow';
|
||||||
|
|
||||||
@@ -10,7 +16,7 @@ const defaultNodeOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const elements = [
|
const initialElements = [
|
||||||
{
|
{
|
||||||
id: 'input',
|
id: 'input',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
@@ -155,19 +161,34 @@ const elements = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const flowProps = {
|
const onLoad = (rf) => rf.fitView({ padding: 0.2 });
|
||||||
elements,
|
|
||||||
onLoad: (rf) => rf.fitView({ padding: 0.2 }),
|
|
||||||
};
|
|
||||||
|
|
||||||
export default () => (
|
export default () => {
|
||||||
<TeaserFlow
|
const [elements, setElements] = useState(initialElements);
|
||||||
title="Additional Components"
|
const onConnect = (params) =>
|
||||||
description="React Flow includes a MiniMap, Controls, Background and a FlowProvider you can use to access internal state outside the ReactFlow component."
|
setElements((els) => {
|
||||||
flowProps={flowProps}
|
params.type = 'step';
|
||||||
withControls
|
return addEdge(params, els);
|
||||||
withMinimap
|
});
|
||||||
fitView
|
|
||||||
linesBg
|
return (
|
||||||
/>
|
<TeaserFlow
|
||||||
);
|
title="Additional Components"
|
||||||
|
description="React Flow includes a MiniMap, Controls, Background and a FlowProvider you can use to access internal state outside the ReactFlow component."
|
||||||
|
linesBg
|
||||||
|
>
|
||||||
|
<ReactFlowProvider>
|
||||||
|
<ReactFlow
|
||||||
|
elements={elements}
|
||||||
|
onLoad={onLoad}
|
||||||
|
zoomOnScroll={false}
|
||||||
|
onConnect={onConnect}
|
||||||
|
connectionLineType="step"
|
||||||
|
>
|
||||||
|
<Background variant="lines" gap={20} />
|
||||||
|
<Controls showInteractive={false} />
|
||||||
|
</ReactFlow>
|
||||||
|
</ReactFlowProvider>
|
||||||
|
</TeaserFlow>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user