-
Notifications
You must be signed in to change notification settings - Fork 0
Add dark mode #156
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: master
Are you sure you want to change the base?
Add dark mode #156
Conversation
This commit introduces an automatic dark mode feature. - Adds a `ThemeToggleButton.astro` component with an inline script to manage theme state. - The script respects user's system preference (`prefers-color-scheme`) on first visit and persists the choice in `localStorage`. - Updates `src/styles/global.css` with CSS variables for the dark theme. - Integrates the theme toggle button into the site header. - Fixes header and footer styling in dark mode. - Ensures the body background covers the entire viewport height.
Summary of ChangesHello @AustinAbbott, 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 by introducing a dark mode feature. It provides a user-friendly toggle to switch between themes, ensures theme preferences are saved and applied consistently across the site, and includes a robust set of CSS changes to support the new aesthetic. The addition of an automated Playwright test guarantees the reliability of the new functionality. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 successfully introduces a dark mode feature, complete with a theme toggle and respect for system preferences. The implementation is generally well-done, leveraging CSS variables and converting pixel values to relative rem units for better scalability. However, I've identified a critical bug in the CSS that prevents users from switching to light mode if their system preference is dark. Additionally, there's an opportunity to refactor the theme-switching JavaScript logic to eliminate code duplication and improve maintainability. I've also noted a minor CSS redundancy in the header component. Addressing these points will make the new feature more robust and easier to maintain.
I am having trouble creating individual review comments. Click here to see my feedback.
src/styles/global.css (33-46)
This @media (prefers-color-scheme: dark) block introduces a critical bug. If a user's system preference is dark, this rule applies the dark theme variables. However, if that user then uses the theme toggle to switch to light mode, the JavaScript will remove the html.dark class, but this media query will remain active. This forces the dark theme to persist and prevents the user from switching to light mode.
The JavaScript logic in BaseHead.astro already correctly handles the prefers-color-scheme check to set the initial theme. This CSS block is therefore both redundant and buggy and should be removed.
src/components/ThemeToggleButton.astro (79-85)
The theme-switching logic in handleToggleClick is a separate implementation from the applyTheme function in src/components/BaseHead.astro. This duplication of logic can lead to inconsistencies and maintenance issues.
To centralize theme management, you can expose the applyTheme function from BaseHead.astro and call it from here.
-
In
src/components/BaseHead.astro, after theapplyThemefunction definition (around line 76), add this line to expose it globally:window.applyTheme = applyTheme;
-
Then, you can simplify this
handleToggleClickfunction to use the sharedapplyThemefunction, ensuring a single source of truth for theme changes.
const handleToggleClick = () => {
const isDark = document.documentElement.classList.contains("dark");
// Calls the global applyTheme function exposed from BaseHead.astro
window.applyTheme?.(isDark ? "light" : "dark");
};
jules-scratch/verification/verify_dark_mode.py (8)
The base URL http://localhost:4321 is hardcoded. For better flexibility across different testing environments, consider reading this value from an environment variable. This would allow the script to be run against different deployments without code changes.
src/components/Header.astro (107-113)
This CSS rule block is problematic and should be removed:
- The styles for
.social-links aare already covered by thenav arule on line 91, making this part redundant. - The styles for
#theme-toggleare not appropriate for a<button>element and won't apply correctly due to Astro's style scoping (it would need to be:global(#theme-toggle)). TheThemeToggleButtoncomponent already contains its own, more suitable styles.
Removing this block will clean up the CSS and rely on the correct, existing styles.
No description provided.