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

Dark Mode #2

Open
ModischFabrications opened this issue May 30, 2022 · 9 comments
Open

Dark Mode #2

ModischFabrications opened this issue May 30, 2022 · 9 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@ModischFabrications
Copy link
Owner

Darkmode and switchable themes is something that is essential for cave dwellers, but SMUI somehow doesn't offer native integration.

  • Button and local store is already implemented.
  • Button centering needs some love
  • Theme needs to react to store
  • system preference shall be respected
@ModischFabrications ModischFabrications added the enhancement New feature or request label May 30, 2022
@ModischFabrications
Copy link
Owner Author

Theming seems to be possible with magic SCSS variables. "--mdc-theme-primary" is definitely the first target.

https://material.io/develop/web/theming/theming-guide -> "Step 3: Changing the theme with Sass"

Also look at hperrin/svelte-material-ui#23 (comment) for an example

@ModischFabrications
Copy link
Owner Author

oh wow, changing these variables was too easy...

:root {
	--mdc-theme-primary: hsl(204, 100%, 50%);
	--mdc-theme-secondary: hsl(184, 86%, 77%);
}

@ModischFabrications
Copy link
Owner Author

ModischFabrications commented May 31, 2022

mostly done, but the official instructions seem to be broken: hperrin/svelte-material-ui#465

My recommendation: Use the theme generator, it's much easier than tweaking the defaults

@ModischFabrications
Copy link
Owner Author

ModischFabrications commented May 31, 2022

Only thing missing is to set "prefers-color-scheme: dark" during runtime, I hope that works without hacking imports.

Using the colors from the theme would also greatly improve related color generation. See https://sveltematerialui.com/THEMING.md for a few variables that I'm too dumb to access.

Might also remove/merge my error-text class

@ModischFabrications
Copy link
Owner Author

This one is even simpler, probably easier to integrate/steal from: https://metonym.github.io/svelte-dark-mode/

@ModischFabrications
Copy link
Owner Author

ModischFabrications commented Jun 1, 2022

Previous instructions actually had a script for that, this might actually work: https://github.com/hperrin/svelte-material-ui/blob/bab2ff4f973bad462f9d4696333bd541f91987aa/THEMING.md

let lightTheme =
  typeof window === 'undefined' ||
  window.matchMedia('(prefers-color-scheme: light)').matches;
function switchTheme() {
  lightTheme = !lightTheme;
  let themeLink = document.head.querySelector('#theme');
  if (!themeLink) {
    themeLink = document.createElement('link');
    themeLink.rel = 'stylesheet';
    themeLink.id = 'theme';
  }
  themeLink.href = `client/smui${lightTheme ? '' : '-dark'}.css`;
  document.head.appendChild(themeLink);
}

@ModischFabrications
Copy link
Owner Author

ModischFabrications commented Jun 30, 2022

no idea how to add new variables so that I can reference them from svelte....

This is daisy's recommendation for a theme picker: https://github.com/saadeghi/theme-change
Another one, mostly selfmade: https://dev.to/lenaschnedlitz/create-a-simple-dark-mode-toggle-with-svelte-4b3g

@ModischFabrications ModischFabrications added the wontfix This will not be worked on label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant