refactor(examples): cleanup

This commit is contained in:
moklick
2020-07-27 12:36:47 +02:00
parent a436260a1c
commit cbc41f244e
4 changed files with 30 additions and 19 deletions
+10 -6
View File
@@ -10,6 +10,12 @@ const onLoad = (reactFlowInstance) => console.log('flow loaded:', reactFlowInsta
const initBgColor = '#f0e742'; const initBgColor = '#f0e742';
const connectionLineStyle = { stroke: '#fff' };
const snapGrid = [16, 16];
const nodeTypes = {
selectorNode: ColorSelectorNode,
};
const CustomNodeFlow = () => { const CustomNodeFlow = () => {
const [elements, setElements] = useState([]); const [elements, setElements] = useState([]);
const [bgColor, setBgColor] = useState(initBgColor); const [bgColor, setBgColor] = useState(initBgColor);
@@ -66,14 +72,12 @@ const CustomNodeFlow = () => {
onElementsRemove={onElementsRemove} onElementsRemove={onElementsRemove}
onConnect={onConnect} onConnect={onConnect}
onNodeDragStop={onNodeDragStop} onNodeDragStop={onNodeDragStop}
style={{ width: '100%', height: '100%', background: bgColor }} style={{ background: bgColor }}
onLoad={onLoad} onLoad={onLoad}
nodeTypes={{ nodeTypes={nodeTypes}
selectorNode: ColorSelectorNode, connectionLineStyle={connectionLineStyle}
}}
connectionLineStyle={{ stroke: '#fff' }}
snapToGrid={true} snapToGrid={true}
snapGrid={[16, 16]} snapGrid={snapGrid}
> >
<MiniMap <MiniMap
nodeColor={(n) => { nodeColor={(n) => {
+6 -5
View File
@@ -41,9 +41,13 @@ const initialElements = [
labelBgStyle: { fill: '#eee', fillOpacity: 0.7 }, labelBgStyle: { fill: '#eee', fillOpacity: 0.7 },
arrowHeadType: 'arrowclosed', arrowHeadType: 'arrowclosed',
}, },
{ id: 'e5-8', source: '5', target: '8', type: 'custom', label: 'custom edge' }, { id: 'e5-8', source: '5', target: '8', type: 'custom', data: { text: 'custom edge' } },
]; ];
const edgeTypes = {
custom: CustomEdge,
};
const EdgesFlow = () => { const EdgesFlow = () => {
const [elements, setElements] = useState(initialElements); const [elements, setElements] = useState(initialElements);
@@ -57,12 +61,9 @@ const EdgesFlow = () => {
onElementsRemove={onElementsRemove} onElementsRemove={onElementsRemove}
onConnect={onConnect} onConnect={onConnect}
onNodeDragStop={onNodeDragStop} onNodeDragStop={onNodeDragStop}
style={{ width: '100%', height: '100%' }}
onLoad={onLoad} onLoad={onLoad}
snapToGrid={true} snapToGrid={true}
edgeTypes={{ edgeTypes={edgeTypes}
custom: CustomEdge,
}}
> >
<MiniMap /> <MiniMap />
<Controls /> <Controls />
+5 -3
View File
@@ -104,6 +104,9 @@ const initialElements = [
}, },
]; ];
const connectionLineStyle = { stroke: '#ddd' };
const snapGrid = [16, 16];
const OverviewFlow = () => { const OverviewFlow = () => {
const [elements, setElements] = useState(initialElements); const [elements, setElements] = useState(initialElements);
const onElementsRemove = (elementsToRemove) => setElements((els) => removeElements(elementsToRemove, els)); const onElementsRemove = (elementsToRemove) => setElements((els) => removeElements(elementsToRemove, els));
@@ -119,11 +122,10 @@ const OverviewFlow = () => {
onNodeDragStop={onNodeDragStop} onNodeDragStop={onNodeDragStop}
onSelectionChange={onSelectionChange} onSelectionChange={onSelectionChange}
onMoveEnd={onMoveEnd} onMoveEnd={onMoveEnd}
style={{ width: '100%', height: '100%' }}
onLoad={onLoad} onLoad={onLoad}
connectionLineStyle={{ stroke: '#ddd' }} connectionLineStyle={connectionLineStyle}
snapToGrid={true} snapToGrid={true}
snapGrid={[16, 16]} snapGrid={snapGrid}
> >
<MiniMap <MiniMap
nodeColor={(n) => { nodeColor={(n) => {
+9 -5
View File
@@ -13,6 +13,8 @@ const initialElements = [
const isValidConnection = (connection) => connection.target === 'B'; const isValidConnection = (connection) => connection.target === 'B';
const onLoad = (reactFlowInstance) => reactFlowInstance.fitView();
const CustomInput = () => ( const CustomInput = () => (
<> <>
<div>Only connectable with B</div> <div>Only connectable with B</div>
@@ -28,6 +30,11 @@ const CustomNode = ({ id }) => (
</> </>
); );
const nodeTypes = {
custominput: CustomInput,
customnode: CustomNode,
};
const HorizontalFlow = () => { const HorizontalFlow = () => {
const [elements, setElements] = useState(initialElements); const [elements, setElements] = useState(initialElements);
const onConnect = (params) => setElements((els) => addEdge(params, els)); const onConnect = (params) => setElements((els) => addEdge(params, els));
@@ -37,12 +44,9 @@ const HorizontalFlow = () => {
elements={elements} elements={elements}
onConnect={onConnect} onConnect={onConnect}
selectNodesOnDrag={false} selectNodesOnDrag={false}
onLoad={(reactFlowInstance) => reactFlowInstance.fitView()} onLoad={onLoad}
className="validationflow" className="validationflow"
nodeTypes={{ nodeTypes={nodeTypes}
custominput: CustomInput,
customnode: CustomNode,
}}
/> />
); );
}; };