Skip to content

Fix #521: add smooth theme transition animation#526

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Pragzh:fix-theme-transition
May 29, 2026
Merged

Fix #521: add smooth theme transition animation#526
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Pragzh:fix-theme-transition

Conversation

@Pragzh
Copy link
Copy Markdown
Contributor

@Pragzh Pragzh commented May 25, 2026

Related Issue


Description

Added smooth animated transitions for switching between light and dark themes.

The update improves the theme toggle experience by adding transition effects for background colors, text colors, borders, shadows, and the theme toggle icon.


How Has This Been Tested?

  • Tested light to dark mode switching.
  • Tested dark to light mode switching.
  • Verified that the Sun/Moon icon animation works.(ROTATES)
  • Checked that the UI transition feels smoother and does not break the layout.

SCREENSHORT:

rec.mp4

Type of Change

  • Bug fix
  • New feature
  • Code style update
  • Breaking change
  • Documentation update

Summary by CodeRabbit

  • New Features
    • Enhanced theme switching experience with smooth CSS transitions applied across the interface when toggling between light and dark modes
    • Added pop animation effect to the theme toggle button for improved visual feedback
    • Theme transitions now respect user's reduced motion preferences for better accessibility

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 4ddd1ad
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a19c5ccc4363b00085ef9a1
😎 Deploy Preview https://deploy-preview-526--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Warning

Review limit reached

@mehul-m-prajapati, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 33 minutes and 14 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb38cc9a-ccfb-4512-ab55-8082b9ea30fb

📥 Commits

Reviewing files that changed from the base of the PR and between 6a9723f and 4ddd1ad.

📒 Files selected for processing (2)
  • src/components/Navbar.tsx
  • src/context/ThemeContext.tsx
📝 Walkthrough

Walkthrough

The PR adds smooth animated transitions to the theme toggle. When users click the theme button, a transient CSS class triggers coordinated property transitions and an icon pop animation, with built-in accessibility support for reduced-motion preferences.

Changes

Theme Transition Animation

Layer / File(s) Summary
Theme transition orchestration
src/context/ThemeContext.tsx
toggleTheme adds a theme-transitioning class to the document root, schedules its removal after 650ms, then updates the theme mode state to coordinate the transition timing.
Transition and animation styling
src/index.css
CSS rules apply smooth transitions to theme properties when html.theme-transitioning is active, a reduced-motion media query disables transitions for accessibility, and a theme-icon-pop keyframe animation (500ms ease-out) is applied to .theme-toggle-icon.
Icon rendering with animation support
src/components/Navbar.tsx
Desktop and mobile theme toggle icons now include key props and the theme-toggle-icon CSS class to enable proper React reconciliation and apply the pop animation.

Sequence Diagram

sequenceDiagram
  participant User
  participant Navbar
  participant ThemeContext
  participant DOM as DOM/CSS
  User->>Navbar: Click theme toggle
  Navbar->>ThemeContext: Call toggleTheme()
  ThemeContext->>DOM: Add theme-transitioning class
  DOM->>DOM: Start CSS transitions on colors/properties
  DOM->>DOM: Apply theme-icon-pop animation
  ThemeContext->>ThemeContext: Wait 650ms
  ThemeContext->>DOM: Remove theme-transitioning class
  ThemeContext->>ThemeContext: Update theme mode state
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • GitMetricsLab/github_tracker#237: Both PRs modify src/components/Navbar.tsx's theme toggle UI (changing the lucide Sun/Moon icon rendering and related styling/classes).

Suggested labels

level:intermediate, quality:clean, type:accessibility

Poem

🐰 A hop, a pop, a smooth transition bright,
From dark to light, the icons dance and spin,
With CSS grace and timing just right,
The theme now flows like a gentle wind,
Respecting those who prefer stillness—a win! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding smooth theme transition animation to address issue #521.
Description check ✅ Passed The description includes all required sections with adequate detail: related issue, description of changes, testing verification, and type of change selection.
Linked Issues check ✅ Passed All coding objectives from issue #521 are met: smooth theme transitions added, fade effects implemented, icon animation added, and performance preserved.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing theme transition animations as specified in issue #521; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Thank you @Pragzh for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Navbar.tsx`:
- Around line 83-87: The Sun icon in Navbar.tsx is missing the shared animation
class so only the Moon animates; update the Sun element (the Sun React component
used when mode === "dark") to include the same "theme-toggle-icon h-5 w-5 ..."
className used on the Moon (or merge its existing "h-5 w-5 text-yellow-400" with
the "theme-toggle-icon" class) so both icons use the identical animation
styling.

In `@src/context/ThemeContext.tsx`:
- Around line 30-38: The toggleTheme function can let earlier timeouts remove
the "theme-transitioning" class during a newer transition; fix this by storing
the timeout id (e.g., in a ref like transitionTimeoutRef) and clearing any
existing timeout before creating a new one, then assign the new timeout id and
use it to remove the class when it fires; also clear the timeout on unmount to
avoid leaks. Update toggleTheme and add the transitionTimeoutRef (and cleanup)
so only the latest timeout removes "theme-transitioning".

In `@src/index.css`:
- Around line 102-109: The reduced-motion media rule only sets
transition-duration to 0ms but doesn't disable keyframe animations like
theme-icon-pop; update the prefers-reduced-motion block to also disable
animations by targeting .theme-toggle-icon (and its pseudo-elements if used) and
setting animation: none and animation-duration: 0ms so the theme-toggle-icon and
any theme-icon-pop keyframe animation are suppressed for users who prefer
reduced motion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3face32-b0a4-48ca-a1f7-4b6ff25e886b

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and 6a9723f.

📒 Files selected for processing (3)
  • src/components/Navbar.tsx
  • src/context/ThemeContext.tsx
  • src/index.css

Comment thread src/components/Navbar.tsx
Comment on lines 83 to 87
{mode === "dark" ? (
<Sun className="h-5 w-5 text-yellow-400" />
) : (
<Moon className="h-5 w-5 text-white" />
<Moon key="moon-icon-mobile" className="theme-toggle-icon h-5 w-5 text-slate-700 dark:text-white" />
)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Apply theme-toggle-icon to the mobile Sun icon too.

Currently mobile only animates one side of the toggle state because Sun (Line 84) is missing the animation class.

💡 Suggested fix
 {mode === "dark" ? (
-  <Sun className="h-5 w-5 text-yellow-400" />
+  <Sun key="sun-icon-mobile" className="theme-toggle-icon h-5 w-5 text-yellow-400" />
 ) : (
   <Moon key="moon-icon-mobile" className="theme-toggle-icon h-5 w-5 text-slate-700 dark:text-white" />
 )}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{mode === "dark" ? (
<Sun className="h-5 w-5 text-yellow-400" />
) : (
<Moon className="h-5 w-5 text-white" />
<Moon key="moon-icon-mobile" className="theme-toggle-icon h-5 w-5 text-slate-700 dark:text-white" />
)}
{mode === "dark" ? (
<Sun key="sun-icon-mobile" className="theme-toggle-icon h-5 w-5 text-yellow-400" />
) : (
<Moon key="moon-icon-mobile" className="theme-toggle-icon h-5 w-5 text-slate-700 dark:text-white" />
)}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Navbar.tsx` around lines 83 - 87, The Sun icon in Navbar.tsx
is missing the shared animation class so only the Moon animates; update the Sun
element (the Sun React component used when mode === "dark") to include the same
"theme-toggle-icon h-5 w-5 ..." className used on the Moon (or merge its
existing "h-5 w-5 text-yellow-400" with the "theme-toggle-icon" class) so both
icons use the identical animation styling.

Comment thread src/context/ThemeContext.tsx
Comment thread src/index.css
Comment on lines +102 to +109
@media (prefers-reduced-motion: reduce) {
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
transition-duration: 0ms;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Disable icon keyframe animation for reduced-motion users.

The reduced-motion block only cancels transitions, but .theme-toggle-icon still runs theme-icon-pop (Line 124). That bypasses the accessibility preference.

💡 Suggested fix
 `@media` (prefers-reduced-motion: reduce) {
   html.theme-transitioning,
   html.theme-transitioning *,
   html.theme-transitioning *::before,
   html.theme-transitioning *::after {
     transition-duration: 0ms;
   }
+
+  .theme-toggle-icon {
+    animation: none !important;
+  }
 }

Also applies to: 123-125

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/index.css` around lines 102 - 109, The reduced-motion media rule only
sets transition-duration to 0ms but doesn't disable keyframe animations like
theme-icon-pop; update the prefers-reduced-motion block to also disable
animations by targeting .theme-toggle-icon (and its pseudo-elements if used) and
setting animation: none and animation-duration: 0ms so the theme-toggle-icon and
any theme-icon-pop keyframe animation are suppressed for users who prefer
reduced motion.

@mehul-m-prajapati mehul-m-prajapati merged commit 82c53c6 into GitMetricsLab:main May 29, 2026
4 of 6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #526 has been merged! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Add Theme Transition Animation Between Light/Dark Mode

2 participants