feat(rg): add onConnect callback
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
|
||||
import Graph, { isEdge, removeElements } from '../src';
|
||||
import Graph, { isEdge, removeElements, SourceHandle, TargetHandle } from '../src';
|
||||
// import Graph from '../dist/ReactGraph';
|
||||
|
||||
const SpecialNode = ({ data, onChange, styles }) => (
|
||||
<div
|
||||
style={{ background: '#FFCC00', padding: 10, borderRadius: 30, ...styles }}
|
||||
style={{ background: '#FFCC00', padding: 10, borderRadius: 2, ...styles }}
|
||||
>
|
||||
<TargetHandle style={{ left: 10, background: '#999' }} />
|
||||
<div>I am <strong>special</strong>!<br />{data.label}</div>
|
||||
<select onChange={(e) => onChange(e.target.value, data)}>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
</select>
|
||||
<SourceHandle style={{ left: 10, background: '#999' }} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -46,18 +48,20 @@ class App extends PureComponent {
|
||||
{ id: '3', data: { label: 'I bring my own style' }, position: { x: 100, y: 200 }, style: { background: '#eee', color: '#222', border: '1px solid #bbb' } },
|
||||
{ id: '4', type: 'output', data: { label: 'nody nodes' }, position: { x: 50, y: 300 } },
|
||||
{ id: '5', type: 'default', data: { label: 'Another node'}, position: { x: 400, y: 300 } },
|
||||
{ id: '6', type: 'special', onChange, data: { label: 'no option selected' }, position: { x: 425, y: 400 } },
|
||||
{ id: '6', type: 'special', onChange, data: { label: 'no option selected' }, position: { x: 425, y: 375 } },
|
||||
{ id: '7', type: 'output', data: { label: 'output' }, position: { x: 250, y: 500 } },
|
||||
{ source: '1', target: '2', animated: true },
|
||||
{ source: '2', target: '3' },
|
||||
{ source: '3', target: '4' },
|
||||
{ source: '3', target: '5' },
|
||||
{ source: '5', target: '6', type: 'straight', animated: true, style: { stroke: '#FFCC00' } }
|
||||
{ source: '5', target: '6', type: 'straight', animated: true, style: { stroke: '#FFCC00' } },
|
||||
{ source: '6', target: '7', style: { stroke: '#FFCC00' }},
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
onLoad(graphInstance) {
|
||||
console.log('graph loaded:', this.graphInstance);
|
||||
console.log('graph loaded:', graphInstance);
|
||||
window.rg = graphInstance;
|
||||
|
||||
this.graphInstance = graphInstance;
|
||||
@@ -109,6 +113,7 @@ class App extends PureComponent {
|
||||
elements={this.state.elements}
|
||||
onElementClick={node => console.log('clicked', node)}
|
||||
onElementsRemove={elements => this.onElementsRemove(elements)}
|
||||
onConnect={params => console.log(params)}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
onLoad={graphInstance => this.onLoad(graphInstance)}
|
||||
onChange={(elements) => this.onChange(elements)}
|
||||
|
||||
Reference in New Issue
Block a user