-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathSecondExample.tsx
81 lines (78 loc) · 2.14 KB
/
SecondExample.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
import React from 'react';
import ArcherContainer from '../src/ArcherContainer/ArcherContainer';
import ArcherElement from '../src/ArcherElement/ArcherElement';
const rootStyle = {
display: 'flex',
justifyContent: 'center',
};
const rowStyle = {
margin: '200px 0',
display: 'flex',
justifyContent: 'space-between',
};
const boxStyle = {
padding: '10px',
border: '1px solid black',
};
const SecondExample = () => {
const [nbElements, setNbElements] = React.useState(3);
const [labels, setLabels] = React.useState('hello');
return (
<div
style={{
height: '500px',
margin: '50px',
}}
>
<div>
<div>Change labels</div>
<input
data-cy="change-labels-input"
type="text"
onChange={(event) => {
setLabels(event.currentTarget.value);
}}
/>
</div>
<div>
<div>Add elements</div>
<button data-cy="add-element" onClick={() => setNbElements(nbElements + 1)}>
+
</button>
<button onClick={() => setNbElements(nbElements > 1 ? nbElements - 1 : 0)}>-</button>
</div>
<ArcherContainer strokeColor="red">
<div style={rootStyle}>
<ArcherElement id="root with spaces et accents héhéhéhé">
<div style={boxStyle}>Root</div>
</ArcherElement>
</div>
<div style={rowStyle}>
{Array(nbElements)
.fill(0)
.map((_, i) => (
<ArcherElement
key={`element${i}`}
id={`element${i}`}
relations={[
{
targetId: 'root with spaces et accents héhéhéhé',
targetAnchor: 'bottom',
sourceAnchor: 'top',
label: (
<div>
{i} {labels}
</div>
),
},
]}
>
<div style={boxStyle}>Element {i}</div>
</ArcherElement>
))}
</div>
</ArcherContainer>
</div>
);
};
export default SecondExample;