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 feature #26

Merged
merged 23 commits into from
Jun 3, 2023

Conversation

sumanbiswas7
Copy link
Contributor

@sumanbiswas7 sumanbiswas7 commented Feb 18, 2023

  • Added a button to toggle between light and dark modes.
  • Added toggle between dark mode and light mode feature
    Feature working on pages /, /news, news/[post], /donate
  • Made feature persistent using localStorage
  • Added moon and sun icon for toggle theme button
  • Requested Changes

Fixes #1

@netlify
Copy link

netlify bot commented Feb 18, 2023

Deploy Preview for makedeb ready!

Name Link
🔨 Latest commit a1697c1
🔍 Latest deploy log https://app.netlify.com/sites/makedeb/deploys/6479a2cc1ea4e6000810d2b1
😎 Deploy Preview https://deploy-preview-26--makedeb.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Heus-Sueh
Copy link
Contributor

Heus-Sueh commented Feb 18, 2023

would it be possible for you to change the button ''light mode'' to an icon similar to these:
image
image

@Heus-Sueh
Copy link
Contributor

I think it would be good to also change the gray color of the command to install makedeb
image
something similar to this would be fine in my opinion
image

@hwittenborn
Copy link
Member

Thanks a ton for this! I've been wanting this done for a while, I just never got around to doing it.

I'm gonna be busy for a bit today, but I'll get this checked out by the end of the day with some review comments. There's a few things I'd like changed, I agree with the comments @Heus-Sueh made, but I can give some when I get a chance to look at everything more later today.

@sumanbiswas7
Copy link
Contributor Author

@Heus-Sueh I agree with you. I'll be working on the button and the background of the code 🤓

@Heus-Sueh
Copy link
Contributor

I think I'm asking a lot but can you make the change that this issue proposes?
makedeb/mprweb#112
since you have knowledge in html and css

@sumanbiswas7
Copy link
Contributor Author

@Heus-Sueh Yeah, I'll look into it.

Copy link
Member

@hwittenborn hwittenborn left a comment

Choose a reason for hiding this comment

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

Most of my comments are visual, though one placement thing is under a separate comment below;

  • Is there any CDN to get the two icons you used from? Currently Jam icons is used for most things, but the icons you got look quite good with the text next to it in the header bar (the lines being close to the same width as the text next to it makes it work really good imo). Just because the Jam icons are loaded directly from the website though, I'd also like to load these two icons in the same manner.
  • The clipboard icon on the homepage (visible if you hover over the codeblock under Install makedeb) isn't changing colors with the rest of the codeblock.
  • The border color under the post boxes on the News page looks a bit too light under the dark mode. #464646 looked pretty good in my local testing.
  • With the border color change above, I also think the date text on post boxes could be a bit lighter on dark mode, I think #bfbfbf works pretty good.
  • The <hr> line elements on individual news post pages looks a bit too bright for me, #6a6a6a was a nice color when I tried changing it.
  • I think the theme changer icon could have no border on it, and then just have a background that blends in with the rest of the header. The line color for it could just change like the links in the header bar too, thus making it all look unified.

And then I also had some other issues, but I'm not quite sure how they should be solved yet:

  • The icon doesn't look quite in place on the mobile view - it feels like it should be separated from the links, but putting it on it's own line feels a bit off too.
  • The Authelia and Prism Launcher logos under Ready for Production don't stand out enough on the dark theme. I'll probably have to reach out to the two teams to see if I could get some dark-theme friendly icons.

I'll probably have to think about at least that first one, if you got any thoughts feel free to throw them out too.

With all of that though, thanks again for getting support for this going! It's definitely long overdue, and I'm really looking forward to getting it merged in :)

Comment on lines 39 to 99

<script>
initialThemeLoad()

const toggleThemeBtn = document.getElementById("toggle-theme-button")
toggleThemeBtn?.addEventListener("click",function(){
const body = document.body
if (body.className=="dark")
{
setBodyClass("")
toggleThemeBtn?.classList.remove("active")
changeBtnIcon("moon")
localStorage.removeItem("theme")
}
else {
toggleThemeBtn?.classList.add("active")
changeBtnIcon("sun")
localStorage.setItem("theme", "dark")
setBodyClass("dark")
}
})

/**
* Makes nessesary changes for initial theme load
*/
function initialThemeLoad(){
const toggleThemeBtn = document.getElementById("toggle-theme-button")
const theme = localStorage.getItem("theme")
if (theme == "dark") {
setBodyClass("dark")
changeBtnIcon("sun")
toggleThemeBtn?.classList.add("active")
} else changeBtnIcon("moon")
}

/**
* Changes the body class
* @param {string} className - class name to be set
*/
function setBodyClass(className){
const body = document.body
body.className = className
}

/**
* Changes theme toggle button's icon
* @param {"sun" | "moon"} iconType - icon type to be displayed
*/
function changeBtnIcon(iconType){
const sunIcon = document.getElementById("sun-icon")
const moonIcon = document.getElementById("moon-icon")
if (iconType == "sun"){
moonIcon?.classList.remove("active-icon")
sunIcon?.classList.add("active-icon")
}
if (iconType == "moon"){
sunIcon?.classList.remove("active-icon")
moonIcon?.classList.add("active-icon")
}
}
</script>
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this in a separate file just so the code doesn't get too messy? Just somewhere like static/js/color-theme.js would work.

@hwittenborn
Copy link
Member

Pinging @hiddeninthesand too since you were the one originally wanting it. Do you any comments about how you'd like all this implemented?

@hwittenborn
Copy link
Member

I think I'm asking a lot but can you make the change that this issue proposes?
https://github.com/makedeb/makedeb/issues/254

@Heus-Sueh: That probably needs to be done as a separate PR under the mprweb repository, right?

@Heus-Sueh
Copy link
Contributor

I think I'm asking a lot but can you make the change that this issue proposes?
https://github.com/makedeb/makedeb/issues/254

@Heus-Sueh: That probably needs to be done as a separate PR under the mprweb repository, right?

yeah... because maybe that requires more drastic changes in the structure 👍

@hwittenborn
Copy link
Member

Yeah it'll probably take more work on the MPR side just because there's more pages to set up, nothing much should have to change for this PR though - every project has it's own code for the CSS, I just kind of copy-paste through the projects as I've needed

Copy link
Member

@hwittenborn hwittenborn left a comment

Choose a reason for hiding this comment

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

Hey, I just got one tiny change. I didn't quite like how the JavaScript file was added (there was some indentation stuff that looked a bit foreign to me), so I went ahead an added Prettier for code formatting as well so everything's looking clean.

Comment on lines 36 to 39
function setBodyClass(className) {
const body = document.body;
body.className = className;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't this just be written in one line as document.body.className = blahBlah and then put directly in the toggleThemeBtn?.addEventListener callback above? Since that's how things like toggleThemeBtn?.classList.remove are being used I think that'd make the code more consistent.

@hwittenborn
Copy link
Member

Some other things too:

  • Could the cards at /news have a slightly darker background color? #262626 looked good to me.
  • Could the header background color on the dark theme be changed so the <hr> right below it stands out more? #1e1e1e looked good on my end.
  • Could we try putting the theme icon in the footer? When using the desktop layout, I'm thinking we could put it in the middle:
    image
    And then on the mobile view right above the copyright text on its own line:
    image

Copy link
Member

@hwittenborn hwittenborn left a comment

Choose a reason for hiding this comment

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

Alright, this is looking really good! I just need to get the two logos from Authelia/Prism Launcher, get one last issue fixed, and this should be good to merge :)

Comment on lines 14 to 50
.dark .themeHeaderColor {
background-color: #1e1e1e;
}
.dark .themeTextColor {
color: #fff;
}
.dark .themeHeaderHrColor {
color: #111111;
background-color: #111111;
}
.dark .themeBackgroundColor {
color: #fff;
background-color: #2d2d2d;
border-color: #464646;
}
.dark .themeFactsColor {
color: #fff;
background-color: #272727;
}
.dark .themeCodeColor {
color: #fff;
background-color: #202020;
}
.dark .themeClipboardCheckedColor {
color: #40a85c;
background-color: #202020;
}
.dark .themePostContentDateColor {
color: #bfbfbf;
}
.dark .themePostHrColor {
background-color: #6a6a6a;
}
.dark .themeCardsColor {
background-color: #262626;
color: #fff;
}
Copy link
Member

Choose a reason for hiding this comment

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

I just realized this, but could .light .theme* variants also be created? The places where these are used already have a background-color defined manually (such as in scss/post.scss:5), and if they were defined in a .light .theme* block in here (and the the background-color/color/etc. calls removed in the other places) it would make the code more consistent.

initialThemeLoad();

const toggleThemeBtn = document.getElementById("toggle-theme-button");
toggleThemeBtn?.addEventListener("click", function () {
Copy link
Member

Choose a reason for hiding this comment

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

I actually didn't know about this ? stuff until now, apparently it's called optional chaining? If so, we should probably remove it so that errors are raised when elements don't exist (since they always should), right?

@hiddeninthesand
Copy link

Pinging @hiddeninthesand too since you were the one originally wanting it. Do you any comments about how you'd like all this implemented?

It all looks good to me! I can't see anything questionable.

@sumanbiswas7
Copy link
Contributor Author

@hwittenborn Hey! I just wanted to inquire about the status of my pull request. Can you please let me know if any further changes or updates are needed before it can be merged? I am looking forward to seeing it incorporated into the project.

@hwittenborn
Copy link
Member

Sorry about that @sumanbiswas7, I got a bit sidetracked with some stuff and forget to get this looked at.

Once I'm home (in about 4 hours) I'll get this reviewed. Everything was pretty much fine the last time I checked though, I'm pretty sure I just need to get a dark theme friendly icon from Authelia and we're set.

Comment on lines 21 to 26
hr {
@extend .themePostHrColor;
}
hr {
@extend .themePostHrColor;
}
Copy link
Member

Choose a reason for hiding this comment

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

This duplication isn't needed, right? Also I think we could just remove it entirely and apply this styling to all <hr> in main.scss, as places like /donate have the <hr> element a bit too bright on the dark theme.

Comment on lines +32 to +34
border-color: darken($silver, 10%);
border-width: 0.15em;
@extend .themeCardsColor;
Copy link
Member

Choose a reason for hiding this comment

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

The border-color here is a bit too light on the dark theme (see the cards on /news) - could this be one of the theme-toggleable colors, with the dark theme having it set to something like #4d4d4d?

@hwittenborn
Copy link
Member

Those should be the last two things, other than that it should be ready to go once I get the Authelia icon.

@sumanbiswas7
Copy link
Contributor Author

@hwittenborn The Authelia website link which is attached to homepage is using a different logo. Seems like they have updated their logo. If that's the case can we use the below logos that I extracted?

authelia-dark
authelia-light

@hwittenborn
Copy link
Member

The Authelia website link which is attached to homepage is using a different logo.

I'm pretty sure that's just the font style from the documentation theme they use :p.

@hwittenborn
Copy link
Member

Just need to get those two icons figured out and this'll be good to merge :)

@hwittenborn
Copy link
Member

Hey, just sending a message so you know what's going on @sumanbiswas7:

I'm messaging the Authelia people in that issue above, and everything's in the process for getting a dark logo going. Once that's done I'll get the two logos added, get the needed JS code going, and then I'll just have you look over the changes to make sure you're fine with them. After that everything should be good to go, and I'll get this merged in :).

@sumanbiswas7
Copy link
Contributor Author

@hwittenborn Hello 👋.
Thanks for the update. Everything sounds good!

@hwittenborn
Copy link
Member

Hey @sumanbiswas7, I just added in the new dark-friendly logos, and I made a few other changes while I was at it. Let me know if there's anything I did that you'd like changed, and then this can get merged right in!

@hwittenborn
Copy link
Member

I'm terribly sorry on the wait too, it's definitely not the way I wanted everything to go. I've been juggling about 5 projects right now, and some end up falling behind like this when I'm zoning in on a specific one. I'm still trying to figure out how to balance everything in a good way with all my daily activities, but I just wanted to send a message about all that's been going on.

@sumanbiswas7
Copy link
Contributor Author

@hwittenborn no worries. hoping to see this getting merged soo. :)

@hwittenborn
Copy link
Member

Alright, sounds great! Thanks a ton for all the work you put in for thing, I'm really happy to finally see some stuff for a dark mode! I'll go ahead and get this merged in :)

@hwittenborn hwittenborn merged commit cbe3e2a into makedeb:main Jun 3, 2023
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.

[Feature Request] Night mode switch :(
4 participants