forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomNode.tsx
62 lines (58 loc) · 1.35 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
import * as React from 'react'
import styled from 'styled-components'
import { FlowChartWithState, INodeDefaultProps } from '../src'
import { Page } from './components'
import { chartSimple } from './misc/exampleChartState'
const DarkBox = styled.div`
position: absolute;
width: 300px;
height: 150px;
padding: 30px;
background: #3e3e3e;
color: white;
border-radius: 10px;
`
const Circle = styled.div`
position: absolute;
width: 150px;
height: 150px;
padding: 30px;
display: flex;
justify-content: center;
align-items: center;
background: #d30000;
color: white;
border-radius: 50%;
`
/**
* 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>
)
}