Skip to content

Commit 2822de9

Browse files
committed
docs: add examples
1 parent a0e1f7e commit 2822de9

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

example/src/Mock.ts

-5
This file was deleted.

example/src/Mock.tsx

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
];
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
};

example/src/app/index.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { useRef } from 'react';
22
import { observe } from 'react-observing';
33

44
import { FlowEditor } from 'flow-editor/src';
5+
import { INode } from 'flow-editor';
56

7+
import { CustomNode } from './components/CustomNode';
68
import { FLOW } from './../Mock';
79
import './../styles.css';
810

911

1012
export const App = () => {
11-
const flow = useRef(observe(FLOW));
13+
const flow = useRef(observe(FLOW.map<INode>(item => ({ ...item, render: props => <CustomNode {...props} /> }))));
1214

1315

1416
return (
@@ -27,6 +29,14 @@ export const App = () => {
2729
<div className='w-[70vw] h-[90vh] bg-background rounded overflow-clip'>
2830
<FlowEditor
2931
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+
`}
3040
/>
3141
</div>
3242
</div>

0 commit comments

Comments
 (0)