Skip to content

Commit a38d588

Browse files
committed
added animation upon opening component
1 parent ab69023 commit a38d588

6 files changed

Lines changed: 65 additions & 12 deletions

File tree

src/components/InfoComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Image from 'react'
33
const InfoComponent = () => {
44
return (
55
<div className="flex-1 bg-[#2a2a2a] rounded-2xl p-3 flex flex-col gap-3">
6-
6+
77
{/* Title */}
88
<h1 className="text-center text-5xl tracking-widest text-green-400">
99
GLORPYTHON

src/components/LevelComponent.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import InfoComponent from './InfoComponent'
55
export default function LevelComponent() {
66

77
return (
8-
<div className="w-screen h-screen flex gap-10 p-4 font-mono overflow-hidden">
8+
<div className="animate-[zoomIn_0.3s_ease-out_forwards] origin-center w-screen h-screen flex gap-10 p-4 font-mono overflow-hidden">
99
<div className="flex gap-4 p-4 w-6/7 mx-auto">
1010

1111
<div className="flex-1 bg-[#2a2a2a] rounded-2xl p-3 flex flex-col gap-3">
@@ -14,7 +14,23 @@ export default function LevelComponent() {
1414
<div className="flex-1 bg-[#2a2a2a] rounded-2xl p-3 flex flex-col gap-3">
1515
<OutputComponent />
1616
</div>
17+
18+
</div>
19+
20+
<style>{`
21+
@keyframes zoomIn {
22+
from { transform: scaleY(0); }
23+
to { transform: scaleY(1); }
24+
}
25+
.zoom-in {
26+
animation: zoomIn 0.3s ease-out forwards;
27+
transform-origin: center;
28+
}
29+
`}</style>
30+
<div className="zoom-in">
31+
{/* your content */}
1732
</div>
33+
1834

1935
</div>
2036
)

src/index.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@
77
}
88
}
99
}
10+
11+
animation: var(--animate-bounce); /* bounce 1s infinite */
12+
13+
@keyframes bounce {
14+
0%, 100% {
15+
transform: translateY(-25%);
16+
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
17+
}
18+
50% {
19+
transform: none;
20+
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
21+
}
22+
}

src/pages/home/Home.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ import LevelComponent from "../../components/LevelComponent";
44
// The home page of the application.
55

66

7-
function Home() {
7+
export default function Home() {
8+
const [isVisible, setIsVisible] = useState(false);
9+
const [mountKey, setMountKey] = useState(0);
810

9-
return (
10-
<div>
11-
<LevelComponent />
12-
</div>
13-
14-
);
15-
}
11+
const handleToggle = () => {
12+
if (!isVisible) setMountKey(k => k + 1);
13+
setIsVisible(v => !v);
14+
};
1615

17-
export default Home;
16+
return (
17+
<div>
18+
<button onClick={handleToggle}>
19+
{isVisible ? 'Hide' : 'Show'} Component
20+
</button>
21+
22+
{isVisible && <LevelComponent key={mountKey} />}
23+
</div>
24+
);
25+
}

tailwind.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// tailwind.config.js
2+
module.exports = {
3+
theme: {
4+
extend: {
5+
keyframes: {
6+
zoomIn: {
7+
'0%': { transform: 'scale(0)' },
8+
'100%': { transform: 'scale(1)' },
9+
},
10+
},
11+
animation: {
12+
'zoom-in': 'zoomIn 0.3s ease-out forwards',
13+
},
14+
},
15+
},
16+
};

tsconfig.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"erasableSyntaxOnly": true,
2222
"noFallthroughCasesInSwitch": true
2323
},
24-
"include": ["src"]
24+
"include": ["src", "tailwind.config.js"]
2525
}

0 commit comments

Comments
 (0)