aboutsummaryrefslogtreecommitdiff
path: root/components/voerBord.tsx
blob: 8ee758b30bc1610be26c11911d672bc9be5a788d (plain)
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
function Disc() {
	return <div className="disk" style={{
		position: "absolute",
		top: 0, left: 0, right: 0, bottom: 0,
		borderRadius: 999999,
		margin: 3
	}}/>
}

export function VoerBord(props: {
	width: number;
	height: number;
	onMove: (move: number) => void;
	active: boolean;
}) {
	return <table className="voerBord" style={{
		borderSpacing: 8,
		width: "100%"
	}}>
		<tbody>
			{
				[...Array(props.height).keys()].map((row) => (
					<tr>
						{[...Array(props.width).keys()].map((column) => (
							<td style={{
								position: "relative",
								width: "100%",
								padding: 0
							}}>
								<div style={{
									display: "block",
									marginTop: "100%"
								}}/>
								<Disc/>
								<div style={{
									position: "absolute",
									top: 0, left: 0, right: 0, bottom: 0,
									borderRadius: 6,
									border: "2px solid var(--background-alt)",
									opacity: .5,
									cursor: props.active ? "pointer" : "default"
								}} id={`pos-${(props.height - row - 1) * props.width + column}`} onClick={event => {
									props.onMove(Number((event.target as HTMLElement).id.split("-")[1]))
								}}/>
							</td>
						))}
					</tr>
				))
			}
		</tbody>
	</table>
}