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

Dark Mode Toggle #12

Merged
merged 5 commits into from
May 19, 2022
Merged

Dark Mode Toggle #12

merged 5 commits into from
May 19, 2022

Conversation

alairon
Copy link
Contributor

@alairon alairon commented May 9, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Themes are tied to the system's theme

Issue URL: N/A

What is the new behavior?

  • Users can now save their light/dark theme preference through the settings modal.
  • Users who do not manually configure the setting will still have their theme tied to the system theme

Does this introduce a breaking change?

  • Yes
  • No

Other information

Things to keep note of

I found that certain elements were colored using DaisyUI color values (e.g. bg-base-###). Since these are not standard tailwind values, they needed to be changed via a data-theme='dark' attribute on top of the usual tailwind className='dark' attribute. I also had to use a 'hacky' method and change these values in the <html> tag. Not my preference, but FoUC (Flash on Unstyled Content) was biting me pretty hard and this was the most reliable way for me to get around it atm.

Screenshots

If overridden, the site will create a localStorage variable called darkMode, with true enabling dark mode. If untouched, no variable is stored and the site will default to the user's system theme.

Light mode with a dark system theme
LightModeDarkTheme

Dark mode with a light system theme
DarkModeLightTheme

@vercel
Copy link

vercel bot commented May 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lostarktimer ✅ Ready (Inspect) Visit Preview May 9, 2022 at 8:20AM (UTC)

@alairon
Copy link
Contributor Author

alairon commented May 9, 2022

I should point out that the localization string is created in public/locales/[en,zh]/common, but the zh version is currently untranslated

@cwjoshuak cwjoshuak merged commit f65272c into cwjoshuak:main May 19, 2022
@cwjoshuak
Copy link
Owner

I want to change this to be a toggle on the navbar, i think. perhaps a slider or a switching icon button would look good

@alairon alairon mentioned this pull request Jun 3, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants