forked from lynn/hello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keyboard.tsx
48 lines (45 loc) · 1.24 KB
/
Keyboard.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
import { Clue, clueClass } from "./clue";
interface KeyboardProps {
layout: string;
letterInfo: Map<string, Clue>;
onKey: (key: string) => void;
}
export function Keyboard(props: KeyboardProps) {
const keyboard = props.layout
.split("-")
.map((row) =>
row
.split("")
.map((key) => key.replace("B", "Backspace").replace("E", "Enter"))
);
return (
<div className="Game-keyboard" aria-hidden="true">
{keyboard.map((row, i) => (
<div key={i} className="Game-keyboard-row">
{row.map((label, j) => {
let className = "Game-keyboard-button";
const clue = props.letterInfo.get(label);
if (clue !== undefined) {
className += " " + clueClass(clue);
}
if (label.length > 1) {
className += " Game-keyboard-button-wide";
}
return (
<button
tabIndex={-1}
key={j}
className={className}
onClick={() => {
props.onKey(label);
}}
>
{label.replace("Backspace", "⌫")}
</button>
);
})}
</div>
))}
</div>
);
}