Skip to content

Commit 1809451

Browse files
committed
onclick animation added to cells
1 parent bd6dfcf commit 1809451

File tree

21 files changed

+115
-3
lines changed

21 files changed

+115
-3
lines changed

client/components/Cell.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
import { useState } from 'react'
2-
import { RiCheckboxBlankFill, RiCheckboxBlankLine } from 'react-icons/ri' // Import icons
2+
import { RiCheckboxBlankFill, RiCheckboxBlankLine } from 'react-icons/ri'
33

44
interface Props {
55
trackNumber: number
66
cellNumber: number
77
}
88

99
export default function Cell({ trackNumber, cellNumber }: Props) {
10-
const [isActive, setIsActive] = useState(false)
10+
const [isActive, setIsActive] = useState<boolean>(false)
11+
const [showImage, setShowImage] = useState<boolean>(false)
1112

1213
function handleClick() {
1314
setIsActive(!isActive)
15+
16+
// Show the image immediately
17+
setShowImage(true)
18+
19+
// Hide the image after 3 seconds, but start fading after 1 second
20+
setTimeout(() => {
21+
setShowImage(false)
22+
}, 3000)
23+
24+
// Start the fade-out after 1 second
25+
setTimeout(() => {
26+
setShowImage(false)
27+
}, 1000)
1428
}
1529

16-
const iconStyle = {
30+
const iconStyle: React.CSSProperties = {
1731
width: '100%',
1832
height: '100%',
1933
display: 'flex',
2034
alignItems: 'center',
2135
justifyContent: 'center',
36+
position: 'relative', // Add relative positioning to the container
2237
}
2338

2439
return (
@@ -36,6 +51,21 @@ export default function Cell({ trackNumber, cellNumber }: Props) {
3651
) : (
3752
<RiCheckboxBlankLine size="100%" />
3853
)}
54+
{showImage && (
55+
<img
56+
src={`../../public/images/lego${cellNumber}.png`}
57+
alt="Small"
58+
className="animated-image"
59+
style={{
60+
position: 'absolute',
61+
width: '80px', // Adjust the size as needed
62+
height: 'auto', // Adjust the size as needed
63+
animation: 'moveDown 2s ease-in-out, fadeOut 2s ease-in-out',
64+
top: '0',
65+
left: '0',
66+
}}
67+
/>
68+
)}
3969
</div>
4070
</button>
4171
</div>

client/styles/index.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,23 @@ $brick-colors: (
269269
border-width: 5px;
270270
}
271271
}
272+
273+
/////////////
274+
@keyframes moveDown {
275+
from {
276+
transform: translateY(0);
277+
}
278+
to {
279+
transform: translateY(200px); /* Adjust the distance to move */
280+
}
281+
}
282+
283+
@keyframes fadeOut {
284+
from {
285+
opacity: 1;
286+
}
287+
to {
288+
opacity: 0;
289+
}
290+
}
291+
////////////

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@chakra-ui/react": "^2.8.1",
3030
"@emotion/react": "^11.11.1",
3131
"@emotion/styled": "^11.11.0",
32+
"@react-spring/web": "^9.7.3",
3233
"express": "^4.17.2",
3334
"framer-motion": "^10.16.4",
3435
"knex": "^2.5.1",

public/images/lego0.png

657 KB
Loading

public/images/lego1.png

176 KB
Loading

public/images/lego10.png

22.9 KB
Loading

public/images/lego11.png

3.91 MB
Loading

public/images/lego12.png

159 KB
Loading

public/images/lego13.png

370 KB
Loading

0 commit comments

Comments
 (0)