Skip to content

Darkmode toggle take 2 #323

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

Merged
merged 2 commits into from
Jul 18, 2020
Merged

Darkmode toggle take 2 #323

merged 2 commits into from
Jul 18, 2020

Conversation

JuanitoFatas
Copy link
Contributor

@JuanitoFatas JuanitoFatas commented Mar 15, 2020

Summary

This Pull Request adds a dark mode switch (html button) in the top right nav menu. The switch defaults to user‘s system darkmode setting. Once toggled will store preference in the Window.localStorage. The switch icons are ☼, U+263C and ☾, U+263E.

The switch is managed by a Stimulus controller theme-switch_controller.js. When the page loads, we check the OS and localStorage to find user‘s preference and update the switch css class. When user clicks it, we toggle the css class and store preference in localStorage.

When we use tailwindcss-theming plugin, the tailwind‘s original colors are all gone. So I added back what we are using in theme.config.js, then extract all places using colors in the view into CSS classes.

Added css class for development search query‘s code block display.

Implements #290.

Try at local

$ git clone rubyapi/rubyapi && cd rubyapi
$ git co -b test-pr-323 && git am -3 https://github.com/rubyapi/rubyapi/pull/323
$ bundle install && yarn install && bin/rails s
$ open http://localhost:3000

Review

We could use the css classes separately or extract the common values into generic names. Suggestions welcome.

Screenshots

mobile light mobile dark
スクリーンショット 2020-03-15 23 45 49 スクリーンショット 2020-03-15 23 45 54

@AlexWayfer
Copy link
Contributor

Looks… good to me, I think. Just a small notice about icons: the Moon is filled (white), but the Sun is outlined (transparent).

Let's look what icons are used… oh, Unicode symbols.

I suggest black one, not white: https://unicode-table.com/en/2600/

But it can be rendered colorful, like Emoji, and probably we should use some (SVG) monotone external icons.

Also I've faced recently with problems of star icon (this one) on macOS and iOS, so we should check Unicode symbols there.

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.

Thank you for working on this! I am happy to merge this but need to just sort out a few minor things.

@@ -71,4 +71,18 @@ pre:not(.ruby) {
}
}

.light-switch:before {
content: '☾';
Copy link
Member

Choose a reason for hiding this comment

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

I've been using https://fontawesome.com for the UI icons, which you can find here. Would we be able to use the icons here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let‘s do this in later Pull Request? I did not find ones on fontawesome that are better than current unicode ones. Ideally we could have CSS icons like the ones in https://justjavascript.com/.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not find ones on fontawesome that are better than current unicode ones.

Moon: https://fontawesome.com/icons/moon?style=solid

Sun: https://fontawesome.com/icons/sun?style=solid (a bit another, but seems OK)

Bulb icons (like in Twitter) are paid in Font Awesome.

Also sometimes I think we can have too many icons/buttons in the header, and there will be some drop-down menu, and then it'd be better to do just toggle with text, without icon.

@JuanitoFatas JuanitoFatas force-pushed the jf.darkmode-toggle-v2 branch from 77f3286 to 7bfac6a Compare March 24, 2020 11:29
@AlexWayfer
Copy link
Contributor

@JuanitoFatas there are conflicts. Can you please resolve them? And do you need a help? I'm ready to try. ❤️

@JuanitoFatas JuanitoFatas force-pushed the jf.darkmode-toggle-v2 branch from 7bfac6a to 6460bfc Compare April 3, 2020 01:50
@JuanitoFatas
Copy link
Contributor Author

@AlexWayfer Conflicts resolved. Feel free to send a PR to this branch.

@AlexWayfer
Copy link
Contributor

@AlexWayfer Conflicts resolved. Feel free to send a PR to this branch.

Done in #357.

@colby-swandale
Copy link
Member

Apologies for the delay again 🙇‍♂️. I am looking at this now.

@AlexWayfer
Copy link
Contributor

Apologies for the delay again 🙇‍♂️. I am looking at this now.

No problem. I just tried to simplify selectors and actions in #357, and waiting when @JuanitoFatas will look at this.

@AlexWayfer
Copy link
Contributor

@JuanitoFatas can you please rebase this PR? Or should we a new one with such changes?

@colby-swandale
Copy link
Member

Ah i have a couple of big changes to this PR that i will try to push in the next few days. I'm happy to do the rebase myself

@colby-swandale colby-swandale merged commit 7194185 into master Jul 18, 2020
@colby-swandale colby-swandale deleted the jf.darkmode-toggle-v2 branch July 18, 2020 11:06
@colby-swandale
Copy link
Member

👋 @JuanitoFatas I'm really really sorry for the super long delay in getting this merged. I had a close look at the tailwindcss theming plugin and ended up not liking having to specify colours in a separate file. I really like specifying the colours inline via the tailwindcss colours, ie: text-gray-600 dark:text-gray-200 etc.

Your stimulus component was great and really liked the approach! But I ended up using the the awesome-font icon from #357 to keep the UI consistent.

The header is a bit of a mess at the moment, so I've hidden the theme icon on every page except the homepage for mobile devices. I'm about 1/2 way through redesigning the header from scratch and adding a hamburger menu option that will look much better and fit everything more nicely!

Thanks so much again for working on this!

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.

3 participants