forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfigValidateLink.tsx
33 lines (31 loc) · 938 Bytes
/
ConfigValidateLink.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as React from 'react'
import styled from 'styled-components'
import { FlowChartWithState } from '../src'
import { Page } from './components'
import { chartSimple } from './misc/exampleChartState'
const Note = styled.div`
position: absolute;
left: 30px;
top: 30px;
padding: 20px;
background: white;
border-radius: 10px;
border: 2px solid red;
`
export const ConfigValidateLinkDemo = () => {
return (
<Page>
<FlowChartWithState
initialValue={chartSimple}
config={ {
validateLink: ({ linkId, fromNodeId, fromPortId, toNodeId, toPortId, chart }): boolean => {
// no links between same type nodes
if (chart.nodes[fromNodeId].type === chart.nodes[toNodeId].type) return false
return true
},
} }
/>
<Note>Customise link validation. For example, only allow links between different Node Types</Note>
</Page>
)
}