-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
93 lines (85 loc) · 1.9 KB
/
index.js
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
90
91
92
93
import React, { useState } from "react";
import { Button } from "antd";
import { ArrowDownOutlined } from "@ant-design/icons";
import {
cell,
container,
current,
currentPointer,
layout2cols,
text,
} from "./Array.module.css";
function Array({ inputs, pointers }) {
return (
<div>
{inputs.map((input, i) => {
const hit = pointers.find((pointer) => pointer.pos === i);
return (
<div key={i} className={hit ? `${current} ${cell}` : cell}>
{hit && (
<span className={currentPointer}>
{hit.label}
<ArrowDownOutlined style={{ fontSize: "40px" }} />
</span>
)}
{input}
</div>
);
})}
</div>
);
}
function SingleValue({ label, value }) {
return (
<div className={text}>
<div>{value}</div>
<div>{label}</div>
</div>
);
}
function Layout({ flex, children }) {
return (
<div className={layout2cols}>
{children.map((child, i) => (
<div key={i} style={{ flex: flex[i] }}>
{child}
</div>
))}
</div>
);
}
let i = 0;
function App() {
const [pointers, setPointers] = useState([
{ label: "left", pos: 0 },
{ label: "right", pos: 3 },
]);
return (
<div className={container}>
<Layout flex={[1, 1]}>
<Array inputs={[1, 2, 3, 5]} pointers={pointers} />
<SingleValue label="target" value="5" />
</Layout>
<Button
onClick={() => {
if (i === 0) {
setPointers([
{ label: "left", pos: 0 },
{ label: "right", pos: 2 },
]);
}
if (i === 1) {
setPointers([
{ label: "left", pos: 1 },
{ label: "right", pos: 2 },
]);
}
i++;
}}
>
Next
</Button>
</div>
);
}
export default App;