-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat: Add dark theme toggle support #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@thotaDeepika is attempting to deploy a commit to the lamsta Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello @thotaDeepika, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the user experience of DevB.io by introducing full dark theme support. It integrates a new theme provider and a user-friendly toggle into the navigation, ensuring that the site's appearance can be customized or automatically adjusted based on user preferences and system settings. The changes leverage Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces dark theme support, which is a great feature addition. The implementation using next-themes is solid and follows best practices, including handling hydration issues. I've identified a few areas for improvement to enhance UI consistency and accessibility in dark mode, particularly concerning the site logo, embedded third-party widgets, and the theme toggle button's initial state. Overall, great work on this feature.
| <motion.nav | ||
| className={`fixed top-0 left-0 right-0 z-40 transition-all duration-300 backdrop-blur-md ${ | ||
| isScrolled ? "bg-white/75 shadow-sm" : "bg-transparent" | ||
| isScrolled ? "bg-white/75 dark:bg-gray-900/75 shadow-sm" : "bg-transparent" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a dark background for the navigation bar is great for dark mode. However, this will likely cause issues with the site logo (/images/logo-full.png), which seems designed for a light background and may become invisible.
To fix this, you should use a different logo for dark mode. Here's a suggested approach:
- Import
useThemefromnext-themesat the top of the file. - Get the theme in the component:
const { resolvedTheme } = useTheme(); - Create a dark mode version of your logo (e.g.,
/images/logo-full-dark.png). - Conditionally set the logo
srcin theImagecomponent (lines 41-47) based on the theme:
<Image
src={resolvedTheme === 'dark' ? '/images/logo-full-dark.png' : '/images/logo-full.png'}
alt="DevB Logo"
// ... other props
/>This will ensure your branding is always visible and looks great in both themes.
| import { Moon, Sun } from "lucide-react"; | ||
|
|
||
| export function ThemeToggle() { | ||
| const { theme, setTheme, resolvedTheme } = useTheme(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return ( | ||
| <button | ||
| className="inline-flex items-center justify-center rounded-md p-2.5 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" | ||
| aria-label="Toggle theme" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder button rendered before the component mounts is interactive (e.g., shows hover effects) but has no onClick handler. This can be confusing for users and is not ideal for accessibility. It's better to disable the button in this state by adding the disabled attribute.
| aria-label="Toggle theme" | |
| aria-label="Toggle theme" disabled |
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="flex items-center gap-2 px-4 py-2 bg-black text-white rounded-lg hover:bg-gray-800 transition-colors" | ||
| className="flex items-center gap-2 px-4 py-2 bg-black dark:bg-white text-white dark:text-black rounded-lg hover:bg-gray-800 dark:hover:bg-gray-200 transition-colors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The embedded GitHub star button iframe will not automatically adapt to the theme change, leading to a light-themed button on a dark background.
To ensure UI consistency, you can dynamically set the color_scheme for the button. The GitHub buttons service supports this via a URL parameter.
Here's how you could implement this:
- Import
useThemefromnext-themesand get theresolvedTheme. - Construct the
iframesource URL dynamically before thereturnstatement:
const ghButtonSrc = `https://ghbtns.com/github-btn.html?user=sunithvs&repo=devb.io&type=star&count=true&color_scheme=${resolvedTheme === 'dark' ? 'dark' : 'light'}`;- Use this
ghButtonSrcvariable for thesrcattribute of both the desktop (lines 61-69) and mobile (lines 114-121)iframes. This will make the button's theme match the site's theme.
Summary
Implements dark theme support for DevB.io, addressing #61.
Changes
New Files
Modified Files
Features
Dependencies Added
Testing
Closes #61