Skip to content

Commit e143fef

Browse files
committed
Use CSS modules
1 parent 4b3f547 commit e143fef

4 files changed

Lines changed: 40 additions & 25 deletions

File tree

src/App.css renamed to src/App.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.App-container {
1+
.container {
22
width: 100vmin;
33
aspect-ratio: 1;
44

src/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22

3-
import "./App.css";
3+
import styles from "./App.module.css";
44

55
import { MOVE_CONFIG, MOVES, type Move } from "./constants";
66
import MoveButton from "./MoveButton";
@@ -13,7 +13,7 @@ function getRandomMove(): Move {
1313

1414
function getGameResult(
1515
moveA: Move,
16-
moveB: Move,
16+
moveB: Move
1717
): ["a" | "b", string] | ["tie", null] {
1818
const aBeatsB = MOVE_CONFIG[moveA][moveB];
1919
if (aBeatsB != null) {
@@ -34,7 +34,7 @@ function App() {
3434
const [computerMove, setComputerMove] = React.useState<Move>(getRandomMove());
3535
const [playerMove, setPlayerMove] = React.useState<Move | null>(null);
3636
const [{ wins, losses, draws }, setGameResults] = React.useState<GameResults>(
37-
{ wins: 0, losses: 0, draws: 0 },
37+
{ wins: 0, losses: 0, draws: 0 }
3838
);
3939

4040
const handleMove = (move: Move) => {
@@ -57,7 +57,7 @@ function App() {
5757

5858
if (playerMove == null) {
5959
return (
60-
<div className="App-container centered-container">
60+
<div className={`${styles.container} centered-container`}>
6161
<h1>Make your move!</h1>
6262
{MOVES.map((move, i) => (
6363
<MoveButton
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.MoveButton-button,
2-
.MoveButton-emoji {
1+
.button,
2+
.emoji {
33
width: 16vmin;
44
aspect-ratio: 1;
55

@@ -8,23 +8,37 @@
88
user-select: none;
99

1010
overflow: hidden;
11-
12-
backface-visibility: hidden;
13-
will-change: transform;
1411
}
1512

16-
.MoveButton-button {
17-
position: absolute;
18-
left: calc(50% - 8vmin);
19-
top: calc(50% - 8vmin);
20-
13+
.button {
2114
border-radius: 50%;
2215
padding: 0;
16+
17+
margin-left: -50%;
18+
margin-top: -50%;
19+
}
20+
21+
.container {
22+
position: absolute;
23+
left: 50%;
24+
top: 50%;
2325
}
2426

2527
@media (prefers-reduced-motion: no-preference) {
26-
.MoveButton-button:focus .MoveButton-emoji,
27-
.MoveButton-button:hover .MoveButton-emoji {
28+
.button,
29+
.emoji {
30+
backface-visibility: hidden;
31+
will-change: transform;
32+
}
33+
34+
.button:focus,
35+
.button:hover {
36+
scale: 1.2;
37+
transition: scale 0.1s;
38+
}
39+
40+
.button:focus .emoji,
41+
.button:hover .emoji {
2842
animation: wiggle infinite 0.4s linear;
2943
}
3044

src/MoveButton.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22

3-
import "./MoveButton.css";
3+
import styles from "./MoveButton.module.css";
44

55
import { MOVE_EMOJI, type Move } from "./constants";
66

@@ -12,12 +12,13 @@ type Props = {
1212

1313
export default function MoveButton({ move, onClick, transform }: Props) {
1414
return (
15-
<button
16-
onClick={onClick}
17-
className="MoveButton-button centered-container"
18-
style={{ transform }}
19-
>
20-
<div className="MoveButton-emoji">{MOVE_EMOJI[move]}</div>
21-
</button>
15+
<div className={styles.container} style={{ transform }}>
16+
<button
17+
onClick={onClick}
18+
className={`${styles.button} centered-container`}
19+
>
20+
<div className={styles.emoji}>{MOVE_EMOJI[move]}</div>
21+
</button>
22+
</div>
2223
);
2324
}

0 commit comments

Comments
 (0)