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

Feature: Generalised Dark Mode into General Theme #4348

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arjunjayan999
Copy link
Contributor

This PR address issue #4340 and focuses on refactoring the theme management system, replacing the old dark mode implementation with a more flexible theme selection mechanism. The changes introduce a new ThemeBox class to handle theme preferences and update various files to support this new approach.

Key changes include:

Theme Management Refactor:

  • Removed old dark mode styles from css/darkmode.css and css/activities.css. [1] [2]
  • Added new theme styles for light and dark modes to css/themes.css.
  • Updated index.html to reference css/themes.css instead of css/darkmode.css and added a theme selection dropdown. [1] [2] [3]
  • Updated README.md in js/utils to explain thoroughly how to customise theme, or add one.
  • Added automatic reload after choosing theme.

JavaScript Updates:

  • Introduced ThemeBox class in js/themebox.js to manage theme preferences.
  • Updated js/activity.js to integrate ThemeBox and remove old dark mode toggle logic. [1] [2] [3] [4] [5] [6] [7] [8]
  • Modified js/toolbar.js to render the new theme selection icon and handle theme changes. [1] [2] [3] [4] [5] [6] [7]

…heme selection, Updated README.md for theme customisation
@arjunjayan999
Copy link
Contributor Author

@walterbender here is the new PR without linting about General Theme Selection

css/themes.css Outdated
}


/* Your Custom Theme can go down if you dont want to modify the existing dark mode */
Copy link
Member

Choose a reason for hiding this comment

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

maybe ^can go down^can go here^ ?

js/themebox.js Outdated
@@ -0,0 +1,75 @@
// Copyright (c) 2018-21 Walter Bender
Copy link
Member

Choose a reason for hiding this comment

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

Should be your name here and 2025

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I saw that. I actually used the existing languagebox.js to make the new themebox.js to maintain consistency, so I didn't understand how copyright works in open source projects. But I will make the changes asked.

js/themebox.js Outdated
// * @returns {void}
// */
// custom_onclick() {
// this._theme = "pastel";
Copy link
Member

Choose a reason for hiding this comment

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

maybe replace pastel with "custom" or "your custom theme"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, my bad, missed it here and in other places, will make the changes

js/toolbar.js Outdated
["ur", _("اردو"), "innerHTML"],
["light", _("Light Mode"), "innerHTML"],
["dark", _("Dark Mode"), "innerHTML"]
// ["custom", _("Theme Name"), "innerHTML"],
Copy link
Member

Choose a reason for hiding this comment

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

We should be consistent with the string (even if it is commented out). How about "Custom Theme" everywhere?


1. **Refresh Required for Theme Application**
1. When the page loads for the first time, the default theme of light mode is used. (because no themePreference has been set yet)
Copy link
Member

Choose a reason for hiding this comment

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

maybe drop "(because... yet)"


The site must be refreshed to apply a new theme in Music Blocks.
2. When you choose a theme, an Object stores inside the localStorage called themePreference.
Copy link
Member

Choose a reason for hiding this comment

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

an object is stored...


2. **Canvas and Palette Button Styles**
3. As of now, all the styling of Music Blocks happens at the time of loading. So we will simply load the page.
Copy link
Member

Choose a reason for hiding this comment

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

  1. All styling... time of loading. When we change themes, we reload the page.


Styles for the canvas and palette buttons are initialized at the time of loading MB.
- These cannot be directly modified using CSS.
4. The stylings on the main page happen due to two things:
Copy link
Member

@walterbender walterbender Feb 5, 2025

Choose a reason for hiding this comment

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

  1. Most of the Music Blocks theme styles are defined in two places:

MB uses a combination of internal and external CSS:
- **Internal CSS**: Block colors, pie menu, background, and other essential styles are defined in `js/utils/platformstyle.js`.
- **External CSS**: Elements like the navbar and dropdown menu are styled using external CSS files.
5. the styling on the planet page happens due to one file
Copy link
Member

Choose a reason for hiding this comment

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

  1. The Plant theme styles are defined in:

<a id="dark"></a>
</li>
<li>
<a id="pastel"></a>
Copy link
Member

Choose a reason for hiding this comment

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

this is no longer there.

string = [[...],
["light", _("Light Mode"), "innerHTML"],
["dark", _("Dark Mode"), "innerHTML"],
["pastel", _("Pastel Theme"), "innerHTML"],
Copy link
Member

Choose a reason for hiding this comment

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

same

string = [_(...),
_("Light Mode"),
_("Dark Mode"),
_("Pastel Theme"),
Copy link
Member

Choose a reason for hiding this comment

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

same

class Activity {
constructor(
...
this.themes = ["light", "pastel", "dark", "your_theme"];
Copy link
Member

Choose a reason for hiding this comment

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

no pastel


5. **Applying the Theme After Reload**
If no theme is selected, i.e., there is no themePreference in localStorage. The styles will default to light mode, as it is the base styling without a class in themes.css. But when there is a themePreference in localStorage, the class respective to the chosen theme will be added to the elements which will apply because of higher specificity.
Copy link
Member

Choose a reason for hiding this comment

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

If no theme has been selected (i.e., themePreference has not been defined in localStorage), the styles will default to "light". Otherwise, the theme defined in themePreference will be applied.

});
```

Add your theme here as well. This for loop above checks (after the DOM is loaded) for all themes in themes array to add the class in planetThemes.css (which you will add in later steps) which match themePreference in localStorage to the elements on planet/index.html. That is why the changes happen after the reload.
Copy link
Member

Choose a reason for hiding this comment

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

The "for" loop shown above...

```

Add your theme here as well. This for loop above checks (after the DOM is loaded) for all themes in themes array to add the class in planetThemes.css (which you will add in later steps) which match themePreference in localStorage to the elements on planet/index.html. That is why the changes happen after the reload.
If no theme is selected (i.e., there is no themePreference in localStorage), the styles will default to light mode because it is the base styling with no class in planetThemes.css . But when there is a themePreference in localStorage, the class respective to the chosen theme will be added to the elements which will apply because of higher specificity.
Copy link
Member

Choose a reason for hiding this comment

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

use the same text as in the comment above.

* @returns {void}
*/
pastel_onclick() {
this._theme = "pastel";
Copy link
Member

Choose a reason for hiding this comment

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

again...

@arjunjayan999
Copy link
Contributor Author

@walterbender Made the revisions, please review it.

@omsuneri
Copy link
Contributor

omsuneri commented Feb 6, 2025

@arjunjayan999 i dont think we need to have a dropdown menu of theme list as we currently only have 2 modes and switching means chnaging to another theme
as by default you are in light mode so the option for light theme while we are light mode is not seems suitable to me needs to be recreated what we have earlier
@walterbender what do you think over this
Screenshot 2025-02-06 at 11 50 12 PM

@omsuneri
Copy link
Contributor

omsuneri commented Feb 6, 2025

@walterbender Also i m confused what sort of changes do this creates as we can can simply use css variable for the selection of different themes in my mind this needs more dicussion i guess

@arjunjayan999
Copy link
Contributor Author

arjunjayan999 commented Feb 7, 2025

A drop-down simplifies the approach in which a user can customise an existing theme, or maybe they want some (or many) changes but don't want to loose their previous themes.
It also is a plus in UI since users can immediately see the two options, making it clear they are choosing between light and dark themes and offers clarity, especially if there are other theme-related options or settings in the future.
Graying out or disabling a current theme is a good option like if you are in light mode, then disable the light mode option.
And if you are confused about the changes, please read the README.md in the PR, I have explained where the stylings are set aside from CSS. If you are thinking of using CSS variables, then you need to transcribe the platformColor object to those variables, which can turn out to be a good thing since keeping styling in css has always been good separation of concerns(but a lengthy thing to do)

@omsuneri
Copy link
Contributor

omsuneri commented Feb 7, 2025

@arjunjayan999 but I ll feel the drop-down option weird must get review from Walterv

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