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 implementation #69

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

Conversation

Silverbullet069
Copy link

@Silverbullet069 Silverbullet069 commented Feb 4, 2025

Resolve issue #18.

Light mode Dark mode
Screenshot 2025-02-04 at 15-45-20 D2 Playground-light Screenshot 2025-02-04 at 15-40-32 D2 Playground-dark

My dark mode implementation is based on 3 techniques, as follows:

  1. Using this CSS design pattern to add theme classes and dynamic variables inside main.css whose value is changed based on the changes of prefer-color-scheme: light|dark media query. These variables are referenced in other CSS files.
  2. For SVG images that can't be dark-moded using CSS filter:, I've used this approach on W3School to create <picture> wraps around multiple <source media="(prefer-color-scheme: light|dark)" > in index.html.
  3. Technique 1 and 2 are OS-level, they applied when system color scheme is changed via OS setting or browser dev tool. Based on someland2's answer on SOF, I've added a toggle button in the playground's header that when clicked can change theme at browser-level.

P/s: I've changed some nitty-gritty stuffs such as padding, margin, copyright year, id name, class name, ... hope it didn't cause much problem :")

P/s 2: There are 2 bugs, 1 at editor.js#L82 and 1 at modal.css#L65

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.

1 participant