Open gitauto-for-dev[bot] opened 1 month ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
sample-website | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 14, 2024 0:29am |
Resolves #80
What is the feature
This feature introduces a new icon located in the top right corner of the website that allows users to switch between dark mode and light mode themes.
Why we need the feature
Implementing a dark mode toggle enhances user experience by accommodating individual preferences and reducing eye strain in low-light environments. Many users prefer dark mode for its aesthetic and comfort, and providing this option keeps the website competitive and user-friendly. It aligns with modern web design standards where theme customization is expected.
How to implement and why
Step 1: Create a Theme Context
Step 2: Develop the Theme Toggle Component
ThemeToggle.js
, within thepages
directory or a designated components directory.Step 3: Implement Theme Styles
.dark-mode
class that overrides the default CSS variables with dark mode values.Step 4: Apply Theme Class to the Root Element
.dark-mode
class on the root HTML element or a top-level div.Step 5: Persist User Preference
localStorage
to save the user's theme preference so it persists across sessions.localStorage
and apply it accordingly.Step 6: Update the Layout
ThemeToggle
icon in the top right corner.pages
directory.Step 7: Test Across All Pages and Devices
Why these steps
About backward compatibility
The addition of the dark mode toggle is backward compatible:
This approach ensures that we improve the website without disrupting the experience for existing users.
Test these changes locally