forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomNodeInner.tsx
68 lines (63 loc) · 1.71 KB
/
CustomNodeInner.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { cloneDeep, mapValues } from 'lodash'
import * as React from 'react'
import styled from 'styled-components'
import { FlowChart, INodeInnerDefaultProps } from '../src'
import * as actions from '../src/container/actions'
import { Page } from './components'
import { chartSimple } from './misc/exampleChartState'
const Outer = styled.div`
padding: 30px;
`
const Input = styled.input`
padding: 10px;
border: 1px solid cornflowerblue;
width: 100%;
`
/**
* Create the custom component,
* Make sure it has the same prop signature
*/
const NodeInnerCustom = ({ node, config }: INodeInnerDefaultProps) => {
if (node.type === 'output-only') {
return (
<Outer>
<p>Use Node inner to customise the content of the node</p>
</Outer>
)
} else {
return (
<Outer>
<p>Add custom displays for each node.type</p>
<p>You may need to stop event propagation so your forms work.</p>
<br />
<Input
type="number"
placeholder="Some Input"
onChange={(e) => console.log(e)}
onClick={(e) => e.stopPropagation()}
onMouseUp={(e) => e.stopPropagation()}
onMouseDown={(e) => e.stopPropagation()}
/>
</Outer>
)
}
}
export class CustomNodeInnerDemo extends React.Component {
public state = cloneDeep(chartSimple)
public render () {
const chart = this.state
const stateActions = mapValues(actions, (func: any) =>
(...args: any) => this.setState(func(...args))) as typeof actions
return (
<Page>
<FlowChart
chart={chart}
callbacks={stateActions}
Components={{
NodeInner: NodeInnerCustom,
}}
/>
</Page>
)
}
}