forked from lynn/hello
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKeyboard.tsx
61 lines (56 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Clue, clueClass, IsLetterAllowed } 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 && clue !== Clue.None) {
className += " " + clueClass(clue);
}
let charLabel = label;
if (label === "Enter") {
charLabel = "*";
}
else if (label === "Backspace") {
charLabel = "%";
}
if (!IsLetterAllowed(charLabel)) {
className += " letter-notinkeyboardspec";
}
if (label.length > 1) {
className += " Game-keyboard-button-wide";
}
return (
<div
tabIndex={-1}
key={j}
role="button"
className={className}
onClick={() => {
props.onKey(label);
}}
>
{label.replace("Backspace", "⌫")}
</div>
);
})}
</div>
))}
</div>
);
}