forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomNode.tsx
89 lines (84 loc) · 1.98 KB
/
CustomNode.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react'
import { FlowChartWithState, INodeDefaultProps } from '../src'
import { Page } from './components'
import { chartSimple } from './misc/exampleChartState'
import clsx from 'clsx'
import { makeStyles } from '@material-ui/styles'
const useStyles = makeStyles({
darkBox: {
position: 'absolute',
padding: '20px',
background: '#3e3e3e',
color: 'white',
borderRadius: '10px'
},
circle: {
position: 'absolute',
width: '110px',
height: '110px',
padding: '20px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
background: '#d30000',
color: 'white',
borderRadius: '50%'
}
})
const DarkBox = React.forwardRef(
({ children, className, ...props }: any, ref: React.Ref<any>) => {
const classes = useStyles()
return (
<div className={clsx(className, classes.darkBox)} {...props} ref={ref}>
{children}
</div>
)
}
)
const Circle = React.forwardRef(
({ children, className, ...props }: any, ref: React.Ref<any>) => {
const classes = useStyles()
return (
<div className={clsx(className, classes.circle)} {...props} ref={ref}>
{children}
</div>
)
}
)
/**
* Create the custom component,
* Make sure it has the same prop signature
* You'll need to add {...otherProps} so the event listeners are added to your component
*/
const NodeCustom = React.forwardRef(
(
{ node, children, ...otherProps }: INodeDefaultProps,
ref: React.Ref<HTMLDivElement>
) => {
if (node.type === 'output-only') {
return (
<DarkBox ref={ref} {...otherProps}>
{children}
</DarkBox>
)
} else {
return (
<Circle ref={ref} {...otherProps}>
{children}
</Circle>
)
}
}
)
export const CustomNodeDemo = () => {
return (
<Page>
<FlowChartWithState
initialValue={chartSimple}
Components={{
Node: NodeCustom
}}
/>
</Page>
)
}