Skip to content

Commit ac307d8

Browse files
committed
update styles
1 parent 872206a commit ac307d8

File tree

6 files changed

+73
-15
lines changed

6 files changed

+73
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"@babel/core": "^7.19.3",
2424
"@emotion/react": "^11.10.4",
25+
"@emotion/styled": "^11.10.4",
2526
"@mantine/core": "^5.5.5",
2627
"@mantine/hooks": "^5.5.5",
2728
"react": "^18.2.0",

pnpm-lock.yaml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ActionBar.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@ export function ActionBar({
1010
onRestart: () => void;
1111
}) {
1212
return (
13-
<Stack sx={{ width: "400px" }}>
14-
<Group position="apart">
15-
<Text>WPM</Text>
16-
<NumberInput disabled value={wpm} />
17-
</Group>
18-
19-
<Group position="apart">
20-
<Text>Time left</Text>
21-
<NumberInput disabled value={timeLeft} />
22-
</Group>
23-
13+
<Group position="center">
2414
<Button onClick={onRestart}>Restart</Button>
25-
</Stack>
15+
</Group>
2616
);
2717
}

src/components/StatsBar.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NumberInput, Text, Group, Button, Stack } from "@mantine/core";
2+
import styled from "@emotion/styled";
3+
4+
export function StatsBar({ wpm, timeLeft }: { wpm: number; timeLeft: number }) {
5+
return (
6+
<Group position="apart">
7+
<StatsBox>
8+
<Group position="apart" align="baseline">
9+
<Text>WPM:</Text>
10+
<div>{Math.floor(wpm)}</div>
11+
</Group>
12+
</StatsBox>
13+
14+
<StatsBox>
15+
<Group position="apart" align="baseline">
16+
<Text>Time left:</Text>
17+
<div>{Math.floor(timeLeft / 1000)}</div>
18+
</Group>
19+
</StatsBox>
20+
</Group>
21+
);
22+
}
23+
24+
const StatsBox = styled.div({
25+
backgroundColor: "rgb(253, 253, 253)",
26+
border: "1px solid lightgray",
27+
padding: "5px",
28+
});

src/components/TypingGame.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Container, Title } from "@mantine/core";
1+
import { Container, Group, Title } from "@mantine/core";
22
import { Stack } from "@mantine/core";
33
import { useCallback, useEffect, useState } from "react";
44
import { ActionBar } from "./ActionBar";
@@ -8,18 +8,23 @@ import { init, moveByKey } from "../models/Board";
88
import { useCountdown } from "../utils/useCountdown";
99
import { useTypingCapture } from "../utils/useTypingCapture";
1010
import { useMeasureWpm } from "../utils/useMeasureWpm";
11+
import { StatsBar } from "./StatsBar";
1112

1213
export function TypingGame() {
1314
const { wpm, timeLeft, board, restart } = useTypingGame();
1415

1516
return (
1617
<Container>
17-
<Stack align="center">
18-
<Title order={1}>Typing Test</Title>
18+
<Stack align="stretch">
19+
<Group position="center">
20+
<Title order={1}>Typing Test</Title>
21+
</Group>
1922

2023
<ActionBar wpm={wpm} timeLeft={timeLeft} onRestart={restart} />
2124

2225
<WordsCard board={board} />
26+
27+
<StatsBar wpm={wpm} timeLeft={timeLeft} />
2328
</Stack>
2429
</Container>
2530
);

src/utils/useTypingCapture.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function useTypingCapture(
88

99
const typingCallback = useCallback((event: KeyboardEvent) => {
1010
event.stopPropagation();
11+
event.preventDefault();
1112
onCapture({ code: event.code as KeyCode, char: event.key });
1213
}, []);
1314

0 commit comments

Comments
 (0)