Skip to content

Commit 75fc41b

Browse files
feat: Add animation feature with toggle functionality
- Introduced animation feature flag to control the display of animations in the app. - Created a new AnimationPage component that utilizes the animation feature flag. - Added AnimatedBox component to demonstrate animation effects with a toggle button. - Implemented CSS styles for the animated box and toggle button. - Updated Header component to include a link to the new Animation page. - Cleaned up imports in layout and page components.
1 parent 746146a commit 75fc41b

File tree

10 files changed

+249
-155
lines changed

10 files changed

+249
-155
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ yarn-error.log*
4141
next-env.d.ts
4242

4343
tests/reports
44-
playwright-report
44+
playwright-report
45+
.env*.local

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@types/node-fetch": "^2.6.12",
1414
"@vercel/toolbar": "^0.1.34",
1515
"flags": "^4.0.0",
16-
"next": "15.1.6",
16+
"next": "15.3.2",
1717
"node-fetch": "^3.3.2",
1818
"react": "^19.0.0",
1919
"react-dom": "^19.0.0"

pnpm-lock.yaml

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

src/app/animation/flags.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { flag } from "flags/next";
2+
3+
export const animationFeatureFlag = flag<boolean>({
4+
key: "animation-feature",
5+
description: "Enable animations in the app.",
6+
decide: () => {
7+
const isEnabled = process.env.ANIMATION_FEATURE_ENABLED === "true";
8+
console.log("Animation Feature Flag Enabled:", isEnabled);
9+
return isEnabled;
10+
},
11+
});

src/app/animation/page.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { animationFeatureFlag } from "./flags";
2+
import AnimatedBox from "../components/AnimatedBox";
3+
4+
export default async function AnimationPage() {
5+
const isAnimationFeatureEnabled = await animationFeatureFlag();
6+
7+
return (
8+
<div>
9+
<h1>Animation Feature Page</h1>
10+
{isAnimationFeatureEnabled ? (
11+
<div>
12+
<h2>Animation is Enabled</h2>
13+
<AnimatedBox />
14+
</div>
15+
) : (
16+
<p>🚫 Animation Feature is OFF</p>
17+
)}
18+
</div>
19+
);
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.box {
2+
width: 100px;
3+
height: 100px;
4+
background-color: blue;
5+
margin: 20px auto;
6+
transition: transform 0.5s ease-in-out;
7+
}
8+
9+
.animate {
10+
transform: rotate(360deg);
11+
}
12+
13+
.toggleButton {
14+
display: block;
15+
margin: 10px auto;
16+
padding: 10px 20px;
17+
background-color: #0070f3;
18+
color: white;
19+
border: none;
20+
border-radius: 5px;
21+
cursor: pointer;
22+
}
23+
24+
.toggleButton:hover {
25+
background-color: #005bb5;
26+
}

src/app/components/AnimatedBox.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
import styles from "./AnimatedBox.module.css";
5+
6+
export default function AnimatedBox() {
7+
const [isAnimating, setIsAnimating] = useState(false);
8+
9+
const toggleAnimation = () => {
10+
setIsAnimating((prev) => !prev);
11+
};
12+
13+
return (
14+
<div>
15+
<button onClick={toggleAnimation} className={styles.toggleButton}>
16+
{isAnimating ? "Stop Animation" : "Start Animation"}
17+
</button>
18+
<div
19+
className={`${styles.box} ${isAnimating ? styles.animate : ""}`}
20+
></div>
21+
</div>
22+
);
23+
}

src/app/header.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Link from "next/link";
22

3-
export default function Header({
3+
export default async function Header({
44
toggleDarkMode,
55
darkMode,
66
}: {
@@ -13,22 +13,25 @@ export default function Header({
1313
padding: "10px",
1414
borderBottom: "1px solid #ccc",
1515
display: "flex",
16-
justifyContent: "space-between",
17-
alignItems: "center",
1816
}}
1917
>
2018
<nav>
2119
<Link href="/" style={{ marginRight: "15px" }}>
2220
Home
2321
</Link>
24-
<a href="/form" style={{ marginRight: "15px" }}>
22+
<Link href="/form" style={{ marginRight: "15px" }}>
2523
Form
26-
</a>
27-
<a href="/about">About</a>
24+
</Link>
25+
<Link href="/animation" style={{ marginRight: "15px" }}>
26+
Animation
27+
</Link>
28+
<Link href="/about" style={{ marginRight: "15px" }}>
29+
About
30+
</Link>
31+
<button onClick={toggleDarkMode}>
32+
Toggle {darkMode ? "Light" : "Dark"} Mode
33+
</button>
2834
</nav>
29-
<button onClick={toggleDarkMode}>
30-
Toggle {darkMode ? "Light" : "Dark"} Mode
31-
</button>
3235
</header>
3336
);
3437
}

src/app/layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use client";
2-
32
import WeatherWidget from "./weather-widget";
43
import TaskList from "./task-list";
54
import Header from "./header"; // Import the Header component

src/app/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { weatherWidgetFlag } from "../../flags";
22
import WeatherWidget from "./weather-widget";
3+
// import { animationFeatureFlag } from "../../flags";
34

45
export default async function Home() {
56
const isWeatherWidgetEnabled = await weatherWidgetFlag();
7+
// const isAnimationFeatureEnabled = await animationFeatureFlag();
68

79
return (
810
<div>

0 commit comments

Comments
 (0)