Skip to content

Commit

Permalink
refactor(examples): hide old api examples
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 9, 2021
1 parent 32ee964 commit e01249a
Show file tree
Hide file tree
Showing 48 changed files with 162 additions and 2,774 deletions.
2 changes: 2 additions & 0 deletions example/.gitignore
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

src_oldapi
73 changes: 44 additions & 29 deletions example/src/Basic/index.tsx
@@ -1,49 +1,54 @@
import React, { useState, MouseEvent } from 'react';
import { useState, MouseEvent, useCallback } from 'react';

import ReactFlow, {
removeElements,
addEdge,
isNode,
Background,
Elements,
BackgroundVariant,
applyNodeChanges,
applyEdgeChanges,
MiniMap,
Controls,
FlowElement,
Node,
Edge,
Connection,
ElementChange,
OnLoadParams,
Connection,
} from 'react-flow-renderer';

const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
const onElementClick = (_: MouseEvent, element: FlowElement) => console.log('click', element);

const initialElements: Elements = [
const initialNodes: Node[] = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, className: 'light' },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, className: 'light' },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, className: 'light' },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, className: 'light' },
];

const initialEdges: Edge[] = [
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
];

const BasicFlow = () => {
const [rfInstance, setRfInstance] = useState<OnLoadParams | null>(null);
const [elements, setElements] = useState<Elements>(initialElements);
const onElementsRemove = (elementsToRemove: Elements) => setElements((els) => removeElements(elementsToRemove, els));
const onConnect = (params: Edge | Connection) => setElements((els) => addEdge(params, els));
const [nodes, setNodes] = useState<Node[]>(initialNodes);
const [edges, setEdges] = useState<Edge[]>(initialEdges);

const onConnect = useCallback((params: Edge | Connection, nds: Node[]) => {
setEdges((eds) => addEdge(params, nds, eds));
}, []);
const onLoad = (reactFlowInstance: OnLoadParams) => setRfInstance(reactFlowInstance);

const updatePos = () => {
setElements((elms) => {
return elms.map((el) => {
if (isNode(el)) {
el.position = {
x: Math.random() * 400,
y: Math.random() * 400,
};
}

return el;
setNodes((nds) => {
return nds.map((n) => {
n.position = {
x: Math.random() * 400,
y: Math.random() * 400,
};

return n;
});
});
};
Expand All @@ -52,31 +57,41 @@ const BasicFlow = () => {
const resetTransform = () => rfInstance?.setTransform({ x: 0, y: 0, zoom: 1 });

const toggleClassnames = () => {
setElements((elms) => {
return elms.map((el) => {
if (isNode(el)) {
el.className = el.className === 'light' ? 'dark' : 'light';
}
setNodes((nds) => {
return nds.map((n) => {
n.className = n.className === 'light' ? 'dark' : 'light';

return el;
return n;
});
});
};

const onNodesChange = useCallback((changes: ElementChange[]) => {
setNodes((ns) => applyNodeChanges(changes, ns));
}, []);

const onEdgesChange = useCallback((changes: ElementChange[]) => {
setEdges((es) => applyEdgeChanges(changes, es));
}, []);

return (
<ReactFlow
elements={elements}
nodes={nodes}
edges={edges}
onLoad={onLoad}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onElementClick={onElementClick}
onElementsRemove={onElementsRemove}
onConnect={onConnect}
onNodeDragStop={onNodeDragStop}
className="react-flow-basic-example"
defaultZoom={1.5}
minZoom={0.2}
maxZoom={4}
>
<Background variant={BackgroundVariant.Lines} />
<MiniMap />
<Controls />
<Background />

<div style={{ position: 'absolute', right: 10, top: 10, zIndex: 4 }}>
<button onClick={resetTransform} style={{ marginRight: 5 }}>
Expand Down
19 changes: 0 additions & 19 deletions example/src/CustomConnectionLine/ConnectionLine.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions example/src/CustomConnectionLine/index.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions example/src/CustomNode/ColorSelectorNode.tsx

This file was deleted.

135 changes: 0 additions & 135 deletions example/src/CustomNode/index.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions example/src/DragHandle/DragHandleNode.tsx

This file was deleted.

0 comments on commit e01249a

Please sign in to comment.