Skip to content
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

Add dark mode toggle #43

Merged
merged 9 commits into from
Apr 4, 2024
Merged

Add dark mode toggle #43

merged 9 commits into from
Apr 4, 2024

Conversation

jaguilar89
Copy link
Collaborator

@jaguilar89 jaguilar89 commented Mar 30, 2024

Description

This code adds a toggle switch for dark mode and light mode.

This came about as I was working on a problem in my previous issue where the body of the app turned white while the header and nav stayed dark, after implementing CSS changes for the sign in alerts. I figured I'd give it a go!

Update

App now recognizes users system preference and will set the theme accordingly. It will also automatically change the theme if you change your system preference in your computer settings. AC and Testing Steps have been updated.

Related Issue

N/A

Acceptance Criteria

  • User can toggle between a dark mode and a light mode by clicking on the switch.
  • Users theme preference persists after refreshing the page.
  • App theme is initially set to the users system preference.
  • Changing theme preference in macOS/Windows settings automatically changes theme in the app.

Type of Changes

Enhancement, Accessibility

Updates

Before

image

After

Switch added for toggling dark mode and light mode
image
image

Testing Steps / QA Criteria

git pull
git checkout ja-feature-dark-mode-toggle
npm ci
npm start

  • Upon viewing the app for the first time, the theme should match your system preference by default.
  • Changing your system preference in macOS or Windows settings should automatically update the theme on the app.
  • Click on the toggle switch on the upper right corner to see if it correctly toggles between dark mode and light mode.
  • Choose light mode and refresh the page, then navigate between pages. The light mode preference should persist.
  • Choose dark mode and refresh the page, then navigate between pages. The dark mode preference should persist.

Notes

  • Right now this does not automatically set the theme based on the users system/browser preference as it did before. There are methods to detect the users preference using JS and the CSS media queries we currently have, if that's a functionality we want to implement.

@jaguilar89
Copy link
Collaborator Author

After adding this functionality I noticed the sign in alert background was no longer transparent (can't see the page).
image

Not sure why, so for now I have each modal with its own description text e.g. "In order to perform this action..." is now "In order to create a list...", "In order to add a new item...", etc for clarity.

image
image

@rachelspencer
Copy link
Collaborator

Hey Jose!

Nice job! When I set my default setting to light or dark the app opens up in the correct mode.

I am having an issue where if I set my system preferences to dark mode, but then refresh the page it goes to light mode (see video). I am using Chrome.

I also tested all the alerts to see the new messages, I like how they are specific to the action. Are you working on making the background transparent? I think it would be a better user experience as you don't look so 'locked out' when the alert pops up.

Dark.Light.mode.toggle.mp4

Copy link
Collaborator

@sillytsundere sillytsundere left a comment

Choose a reason for hiding this comment

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

Hey Jose! This all looks great! Thanks for doing this! However I am having a similar problem to rachel. If I open the app it will be in dark mode, with the body and nav bar backgrounds being the dark color. However if i switch with the toggle to light mode the body changes to a white background color but the navbar background color remains the dark color unless i switch to light mode on my device. and the reverse happens as well. if my device is in light mode and i click the toggle to go to dark mode the body background color changes to the dark color but the navbar background color remains white.

It seems like the navbar is staying with the theme set by the device and not the toggle.

That was the only issue i noticed though!

@trushmi
Copy link
Member

trushmi commented Apr 1, 2024

Hi @jaguilar89! Nice work on addressing this issue! I like that we now have a toggle button! Speaking about enhancing user experience, I've noticed that when I toggle the button, there's a slight delay, and the theme changes faster than the toggle button switches. Is it possible to make them synchronize simultaneously?

@rachelspencer
Copy link
Collaborator

@jaguilar89 I wanted to note, that my Chrome browser is set to light mode, I wonder if when I refresh if this overrides the system preferences?

I'm not sure if this is helpful or not but worth mentioning!

@jaguilar89
Copy link
Collaborator Author

Hi @jaguilar89! Nice work on addressing this issue! I like that we now have a toggle button! Speaking about enhancing user experience, I've noticed that when I toggle the button, there's a slight delay, and the theme changes faster than the toggle button switches. Is it possible to make them synchronize simultaneously?

@trushmi That's the default animation speed of the button, I've sped it up a bit so it should be little better now.

@jaguilar89
Copy link
Collaborator Author

@rachelspencer The issue with the theme changing on refresh should be fixed now!
@sillytsundere I've set the colors for the navbar for both dark and light modes. Let me know if it looks ok!

@rachelspencer
Copy link
Collaborator

Hey @jaguilar89!

The mode isn't changing now when I refresh! Nice!

I am not seeing the nav bar change colors for both modes, they stay white with the blue text.

I was also wondering if you have played around with making the modal backgrounds transparent yet?

Copy link
Collaborator

@rachelspencer rachelspencer left a comment

Choose a reason for hiding this comment

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

Hey Jose!

Approving this now, hopefully you can alter the modal background to be transparent.

Great job on this!

@trushmi
Copy link
Member

trushmi commented Apr 3, 2024

Hi @jaguilar89! Nice work on addressing this issue! I like that we now have a toggle button! Speaking about enhancing user experience, I've noticed that when I toggle the button, there's a slight delay, and the theme changes faster than the toggle button switches. Is it possible to make them synchronize simultaneously?

@trushmi That's the default animation speed of the button, I've sped it up a bit so it should be little better now.

@jaguilar89 Thank you for speed of the button! Now the delay is less noticeable!

Copy link
Member

@trushmi trushmi left a comment

Choose a reason for hiding this comment

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

Looks good to me! Nice work tackling this issue @jaguilar89 !!

@jaguilar89 jaguilar89 requested a review from polly89 April 3, 2024 22:06
Copy link
Collaborator

@polly89 polly89 left a comment

Choose a reason for hiding this comment

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

Great job implementing this feature. It worked as described in the PR. I left non-blocking comments in the code.

Sign Out
</button>
</Button>
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion - right now your signIn and signOut buttons are hard to distinguish visually. You can solve this issue a few different ways:

  • make the SignOut button red and the SignIn button green

  • add an icon to each button

{children}
</DarkModeContext.Provider>
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great job accounting for all the different use cases.

@@ -49,7 +49,7 @@ export function Home({ data, setListPath }) {
required
/>
{user ? (
<Button className="custom-button" type="submit">
<Button className="custom-button" type="submit" variant="solid">
Create a list
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion - right now both of this and the button to add an item look the same. I think in this case they are both acting like primary buttons, which is fine, but perhaps consider changing the wording of this one to Share or make it a secondary button so the styling is slightly different.

src/index.css Outdated
--color-border: hsla(220, 13%, 78%, 1);
--color-text: var(--color-black);
--color-bg-dark: var(--color-black);
--color-bg-light: var(--color-white);
Copy link
Collaborator

@polly89 polly89 Apr 4, 2024

Choose a reason for hiding this comment

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

I spoke to Tim because I was having a hard time figuring out the transparency issues with the modal. If you comment out line 8 and 9 it resolves it, BUT it creates a whole set of other styling issues with your dark mode.
Screenshot 2024-04-03 at 5 08 54 PM

You can talk to the team to see how they feel about keeping the solid background. If there are other issues that still remain unfinished you may want focus on those rather than worry about the transparency of the background in this issue.

Copy link

github-actions bot commented Apr 4, 2024

Visit the preview URL for this PR (updated for commit c2f2a95):

https://tcl-73-smart-shopping-list--pr43-ja-feature-dark-mode-7lo4k34h.web.app

(expires Thu, 11 Apr 2024 20:09:15 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 99eed22fcca8bd9874e77f7b7f7d1eeb554a1666

@jaguilar89 jaguilar89 merged commit 4e031c2 into main Apr 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants