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 night mode #369

Open
martinbosma opened this issue May 3, 2024 · 2 comments
Open

Add night mode #369

martinbosma opened this issue May 3, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@martinbosma
Copy link
Contributor

No description provided.

@mman mman added the enhancement New feature or request label May 22, 2024
@mman mman self-assigned this Sep 12, 2024
@mman
Copy link
Collaborator

mman commented Sep 12, 2024

Here is the initial investigation how to best/easiest implement the functionality:

  1. The Theme module https://github.com/victronenergy/victron-mfd-modules/tree/master/src/Modules/Theme needs to add support for Light, Dark, and Night theme variants. It is currently done as a simple boolean switch Light / Dark that is used in all the previous variants of the app. To make the old code compile I'd figure out a way to provide three theme variants where Dark and Night would map to the existing darkMode property being true.
  2. The main logic of switching themes lies in the App.tsx where we observe the darkMode property and add/remove appropriate CSS class provided by tailwindcss to the root element. That switches the theme. So we will need here to add/remove dark and night CSS classes as appropriate.
    useEffect(() => {
    if (themeStore.darkMode) {
    document.body.classList.add("dark")
    } else {
    document.body.classList.remove("dark")
    }
    }, [themeStore.darkMode])
  3. All elements within the app currently use the traditional tailwindcss styling in the form of specifying a default color, and its dark variant. Like for example here: text-victron-gray dark:text-victron-gray-dark.
    <BatteriesIcon className={classNames("text-victron-gray dark:text-victron-gray-dark", activeStyles?.icon)} />
    . We can simply add a variant for night CSS class, but that would mean modifying around ~100 entries in 33 files. Therefore point 5.
  4. We should extract all those ~100 entries into symbolic colors provided via tailwind.config.js, I think majority of them may already be there. And then use CSS variables to customise each of these colors for default, dark, night mode. Finally we can remove the dark: prefix in all instances and only specify a symbolic color everywhere.

@mman
Copy link
Collaborator

mman commented Sep 12, 2024

Additionally, instead of switching between Light/Dark/Night modes, it would be better to make Night mode a variant of the Dark mode via toggle. That way user can still opt into Light / Dark automatic theme switching and when Dark mode kicks in, the app goes into Night mode when the switch is toggled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants