File tree 4 files changed +80
-6
lines changed
4 files changed +80
-6
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { observe } from "react-observing" ;
2
+
3
+ import { INode } from 'flow-editor/src' ;
4
+
5
+ import { CustomNode } from './app/components/CustomNode' ;
6
+
7
+
8
+ export const FLOW : INode [ ] = [
9
+ {
10
+ id : observe ( crypto . randomUUID ( ) ) ,
11
+ connections : observe ( [ ] ) ,
12
+ height : observe ( 32 ) ,
13
+ width : observe ( 100 ) ,
14
+ left : observe ( 50 ) ,
15
+ top : observe ( 50 ) ,
16
+ render : CustomNode ,
17
+ } ,
18
+ {
19
+ id : observe ( crypto . randomUUID ( ) ) ,
20
+ connections : observe ( [ ] ) ,
21
+ height : observe ( 32 ) ,
22
+ width : observe ( 100 ) ,
23
+ left : observe ( 50 ) ,
24
+ top : observe ( 200 ) ,
25
+ render : CustomNode ,
26
+ } ,
27
+ {
28
+ id : observe ( crypto . randomUUID ( ) ) ,
29
+ connections : observe ( [ ] ) ,
30
+ height : observe ( 32 ) ,
31
+ width : observe ( 100 ) ,
32
+ left : observe ( 50 ) ,
33
+ top : observe ( 300 ) ,
34
+ render : CustomNode ,
35
+ } ,
36
+ {
37
+ id : observe ( crypto . randomUUID ( ) ) ,
38
+ connections : observe ( [ ] ) ,
39
+ height : observe ( 100 ) ,
40
+ width : observe ( 100 ) ,
41
+ left : observe ( 250 ) ,
42
+ top : observe ( 100 ) ,
43
+ render : CustomNode ,
44
+ } ,
45
+ ] ;
Original file line number Diff line number Diff line change
1
+ import { INodeRenderProps } from 'flow-editor' ;
2
+ import { useObserver } from 'react-observing' ;
3
+
4
+
5
+
6
+ export const CustomNode = ( props : INodeRenderProps ) => {
7
+ const [ isSelected ] = useObserver ( props . isSelected ) ;
8
+ const [ height ] = useObserver ( props . height ) ;
9
+ const [ width ] = useObserver ( props . width ) ;
10
+
11
+
12
+ return (
13
+ < div
14
+ style = { {
15
+ width : width - 2 ,
16
+ height : height - 2 ,
17
+ backgroundColor : 'red' ,
18
+ border : isSelected ? 'thin solid blue' : 'thin solid transparent' ,
19
+ } }
20
+ >
21
+ CustomNode
22
+ </ div >
23
+ ) ;
24
+ } ;
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ import { useRef } from 'react';
2
2
import { observe } from 'react-observing' ;
3
3
4
4
import { FlowEditor } from 'flow-editor/src' ;
5
+ import { INode } from 'flow-editor' ;
5
6
7
+ import { CustomNode } from './components/CustomNode' ;
6
8
import { FLOW } from './../Mock' ;
7
9
import './../styles.css' ;
8
10
9
11
10
12
export const App = ( ) => {
11
- const flow = useRef ( observe ( FLOW ) ) ;
13
+ const flow = useRef ( observe ( FLOW . map < INode > ( item => ( { ... item , render : props => < CustomNode { ... props } /> } ) ) ) ) ;
12
14
13
15
14
16
return (
@@ -27,6 +29,14 @@ export const App = () => {
27
29
< div className = 'w-[70vw] h-[90vh] bg-background rounded overflow-clip' >
28
30
< FlowEditor
29
31
items = { flow . current . value }
32
+ customCSS = { `
33
+ .bg-paper {
34
+ background-color: var(--color-background, #3a3a3a);
35
+ }
36
+ .border-selection {
37
+ border: thin solid var(--color-selection, #999fff);
38
+ }
39
+ ` }
30
40
/>
31
41
</ div >
32
42
</ div >
You can’t perform that action at this time.
0 commit comments