Skip to content

Add dark mode toggle #296

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

Closed
wants to merge 2 commits into from
Closed

Add dark mode toggle #296

wants to merge 2 commits into from

Conversation

JuanitoFatas
Copy link
Contributor

Summary

This Pull Request adds a dark mode switcher in the center of page top. The switcher defaults to user‘s system setting. Once toggled will store preference in the Window.localStorage.

The switcher (a checkbox) is added next to the body so we can use sibling ~ and scss ampersand selectors to target specific elements. A .main-container also added in order to apply styles on home page and other pages.

Implements #290.

Screenshots

mobile light mobile dark
スクリーンショット 2020-02-19 13 42 34 スクリーンショット 2020-02-19 13 42 41

Videos

Review

  • The name of css classes
  • If you want to try at local
    Checkout this branch. Start the server. Browse through pages, search something, hover on elements. See if anything looks inconsistent with https://rubyapi.org/. Click dark mode toggle, Browse through pages, search something, hover on elements. See if anything looks inconsistent with dark mode on https://rubyapi.org.

Downside

  • The switcher occupied 1rem space on top.
  • All color changes in the future need to follow this way (add a class then write css for light and dark mode respectively)

This will init with user‘s system darkmode, then change according to the checkbox state. Store the preference in the local storage.
Use CSS to toggle dark mode. The checkbox is the first child of body,
so we can use sibling selector `~` and scss ampersand selector `&` to
target specific child elements.

Wrap content in main container to work with home and object page.

Extract hardcoded color control utility classes into css, and apply correspondent
dark mode css.
@ioquatix
Copy link
Collaborator

Is this to make up for lack of browser support?

@JuanitoFatas
Copy link
Contributor Author

JuanitoFatas commented Feb 19, 2020

Is this to make up for lack of browser support?

Originally from https://twitter.com/arefiev/status/1227902424888881155, then became #290.

Browser support is at 78%.

I think this Pull Request is to give people an option to opt-in / opt-out. Some examples:

People may not know how to turn on dark mode.
People prefer light mode for their system UI, but want to browse the docs in dark mode.
People prefer dark mode for their system UI, but want to browse the docs in light mode.

@ioquatix
Copy link
Collaborator

ioquatix commented Feb 19, 2020

Do other websites with dark mode have a toggle like this?

@AlexWayfer
Copy link
Contributor

Do other websites with dark mode have a toggle like this?

Twitter, website:

image

In mobile there was simple toggle:

image

Then like Moon:

image

Now it's like bulb (with or without light):

image

What else… GitHub has no dark theme, GitLab too, Twitch!

image

YouTube (only in Premium, as I know):

image

image

@AlexWayfer
Copy link
Contributor

AlexWayfer commented Feb 19, 2020

TBH, I thinks it's better to place monochrome icon alongside GitHub icon, Ruby version drop-down, etc.

I know, this approach is quirky by using checkbox:checked in CSS, but you're anyway write JavaScript to save it. Maybe it should be inside body (header) and toggle a class for it.

  1. Colorful icon alongside monochrome is unconsistency.
  2. You have much empty space to the left and to the right of this icon.

@colby-swandale
Copy link
Member

apologies for not leaving a review yet, this week has just been super busy. I'll try and get time to look at this in the next few days.

Copy link
Member

@colby-swandale colby-swandale left a comment

Choose a reason for hiding this comment

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

Hey @JuanitoFatas! Apologies for taking so long to review the PR 😞. I think this is a great first step and have some feedback:

  • I agree with @AlexWayfer's comment about adding an icon along side the Github/Version selector buttons. I think it would look a lot cleaner and consistent. But this may not all fit neatly on mobile devices, so we may need to look into adding a sidebar that the user can toggle to fit everything. Would you like to pair on adding that?

  • I would like to avoid writing as much CSS as possible, could we leverage tailwindcss libraries https://github.com/hawezo/tailwindcss-theming to provide theme capabilities that can be toggled?

Let me know if you have any questions or if you would like to sit down and pair on this together.

Thank you for your work! 👏

@AlexWayfer
Copy link
Contributor

I want this feature too, so I can try to help with this PR, if you wish, @JuanitoFatas. 🙌

@JuanitoFatas
Copy link
Contributor Author

Thanks for the suggestions! I‘ll take another stab this weekend.

@JuanitoFatas
Copy link
Contributor Author

closing this in favor of #323.

@JuanitoFatas JuanitoFatas deleted the jf.dark-mode-switcher branch March 15, 2020 15:05
@AlexWayfer AlexWayfer mentioned this pull request Jul 20, 2020
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.

4 participants