Skip to content

Commit 5a9a673

Browse files
committed
add animations
1 parent 5849a91 commit 5a9a673

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

client/src/App.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ h1 {
7575
#definition {
7676
height: 20vh;
7777

78-
font-size: 20px;
78+
font-size: 24px;
7979
padding-left: 5%;
8080
padding-right: 5%;
8181
border-radius: 20px;
@@ -172,4 +172,5 @@ h1 {
172172
.word {
173173
font-weight: bold;
174174
background-color: light-dark(#ccc, #666);
175-
}
175+
}
176+

client/src/App.tsx

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import "./App.css";
33
import { pick_random_word } from "./main.ts";
44
import { get_definition } from "./main.ts";
55
import { is_valid } from "./main.ts";
6+
import "animate.css";
67

78

89
function Square( { letter, colors, onSquareClick } ) {
@@ -13,18 +14,39 @@ function Square( { letter, colors, onSquareClick } ) {
1314

1415
function Word( { current_attempt, success}) {
1516
let color = "";
16-
if (success) color = "square-attempted-present";
17+
let success_animation = "";
18+
if (success) {
19+
color = "square-attempted-present";
20+
success_animation = "animate__animated animate__flip";
21+
}
1722
return <>
18-
<button key="0" className={`square word ${color}`}>{current_attempt.length > 0 ? current_attempt[0]: ''}</button>
19-
<button key="1" className={`square word ${color}`}>{current_attempt.length > 1 ? current_attempt[1]: ''}</button>
20-
<button key="2" className={`square word ${color}`}>{current_attempt.length > 2 ? current_attempt[2]: ''}</button>
21-
<button key="3" className={`square word ${color}`}>{current_attempt.length > 3 ? current_attempt[3]: ''}</button>
22-
<button key="4" className={`square word ${color}`}>{current_attempt.length > 4 ? current_attempt[4]: ''}</button>
23+
<button key="0" className={`square word ${color} ${success_animation}`}>{current_attempt.length > 0 ? current_attempt[0]: ''}</button>
24+
<button key="1" className={`square word ${color} ${success_animation}`}>{current_attempt.length > 1 ? current_attempt[1]: ''}</button>
25+
<button key="2" className={`square word ${color} ${success_animation}`}>{current_attempt.length > 2 ? current_attempt[2]: ''}</button>
26+
<button key="3" className={`square word ${color} ${success_animation}`}>{current_attempt.length > 3 ? current_attempt[3]: ''}</button>
27+
<button key="4" className={`square word ${color} ${success_animation}`}>{current_attempt.length > 4 ? current_attempt[4]: ''}</button>
28+
</>
29+
}
30+
31+
function Logo() {
32+
return <>
33+
<div id="logo" className="animate__animated animate__slideInDown">
34+
<h1>ERUDITE</h1>
35+
</div>
36+
</>
37+
}
38+
39+
function Definition( { word, definition }) {
40+
return <>
41+
<div id="definition" key={word} >
42+
<p className="animate__animated animate__fadeInDown">{ definition }</p>
43+
</div>
2344
</>
2445
}
2546

2647
function App() {
2748
const [current_word, setCurrentWord] = useState(pick_random_word(5).toUpperCase());
49+
const [current_definition, setCurrentDefinition] = useState(get_definition(current_word.toLowerCase()));
2850
const [score, setScore] = useState(0);
2951
const [success, setSuccess] = useState(false);
3052
const [current_attempt, setCurrentAttempt] = useState('');
@@ -63,7 +85,10 @@ function App() {
6385

6486
if (current_attempt != current_word) {
6587
setMessage("Incorrect");
66-
setTimeout(() => { setMessage(""); }, 3000);
88+
89+
setTimeout(() => {
90+
setMessage("");
91+
}, 3000);
6792

6893
setAttempts([
6994
...attempts,
@@ -96,7 +121,9 @@ function App() {
96121
setSuccess(false);
97122
setMessage("");
98123
setTimeout(() => { setMessage(""); }, 3000);
99-
setCurrentWord(pick_random_word(5).toUpperCase());
124+
const new_word = pick_random_word(5).toUpperCase();
125+
setCurrentWord(new_word);
126+
setCurrentDefinition(get_definition(new_word.toLowerCase()));
100127
setCurrentAttempt("");
101128
setKeyboardColors(Array(26).fill("square-unattempted"));
102129
}
@@ -111,13 +138,8 @@ function App() {
111138
<span>version: 0.1 - Game developed by <a href="https://github.com/cathoderay">Ronald Kaiser</a></span>
112139
</div>
113140

114-
<div id="logo">
115-
<h1>ERUDITE</h1>
116-
</div>
117-
118-
<div id="definition">
119-
<p>{ get_definition(current_word.toLowerCase()) }</p>
120-
</div>
141+
<Logo />
142+
<Definition word={current_word} definition={current_definition} />
121143

122144
<div id="word-container">
123145
<Word current_attempt={ current_attempt } current_word={ current_word } success = { success } />

client/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
text-rendering: optimizeLegibility;
1212
-webkit-font-smoothing: antialiased;
1313
-moz-osx-font-smoothing: grayscale;
14+
15+
--animate-duration: 100ms;
16+
--animate-delay: 0.1s;
17+
1418
}
1519

1620
a {

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@std/assert": "jsr:@std/assert@1",
1212
"@types/react": "npm:@types/react@^18.3.12",
1313
"@vitejs/plugin-react": "npm:@vitejs/plugin-react@^4.3.3",
14+
"animate.css": "npm:animate.css@^4.1.1",
1415
"react": "npm:react@^18.3.1",
1516
"react-dom": "npm:react-dom@^18.3.1",
1617
"react-router-dom": "npm:react-router-dom@^6.28.0",

deno.lock

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

0 commit comments

Comments
 (0)