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

Color theme switcher and automatic dark mode based on browser prefers-color-scheme #83

Merged
merged 3 commits into from
Jun 18, 2024

Conversation

erdnaxe
Copy link
Contributor

@erdnaxe erdnaxe commented Jun 1, 2024

This patch introduces a color mode switcher in CTFd.
By clicking a button located at the right of the navbar, users can easily switch between light and dark mode.
Also the default color mode is chosen using prefers-color-scheme. This means that CTFd will automatically switch to light or dark mode depending on system settings.

This uses the Bootstrap 5.3 dark mode feature (https://getbootstrap.com/docs/5.3/customize/color-modes/#dark-mode). Most of the layout should already render correctly in dark mode, but I expect some sharp edges:

  • CTFd main page logo will be less legible,
  • scoreboard graphs won't switch to dark mode, and might be less legible in dark mode.

The new script is loaded without a defer to prevent blinking in dark mode (to prevent epileptic seizures).

Light mode:
image

Dark mode:
image

@erdnaxe erdnaxe force-pushed the darkmode_switch branch 2 times, most recently from 539de6c to 8ce15c3 Compare June 2, 2024 09:35
@erdnaxe erdnaxe force-pushed the darkmode_switch branch from 8ce15c3 to 795cda9 Compare June 2, 2024 19:51
@ColdHeat
Copy link
Member

ColdHeat commented Jun 2, 2024

Very cool! Give me some time to review this and will get back to you.

@ColdHeat ColdHeat requested a review from MilyMilo June 13, 2024 18:13
@ColdHeat
Copy link
Member

I think this is pretty good. My major question long term is whether or not the theme should be stored server side or just browser side. I think we can address that at a later date.

@ColdHeat ColdHeat merged commit dfc0d1c into CTFd:main Jun 18, 2024
1 check passed
ColdHeat added a commit that referenced this pull request Jun 18, 2024
* Add color mode switcher

* Add darkmode to syntax highlighter

* yarn build

* cleanup + minor fixes

* Remove merge leftover

---------

Co-authored-by: Alexandre Iooss <[email protected]>
Co-authored-by: Kevin Chung <[email protected]>
@ColdHeat
Copy link
Member

ColdHeat commented Aug 28, 2024

@erdnaxe I'm finding that your PR does introduce some flashing issues if you are on the dark theme.

I've found so far that embedding the color_mode_switcher.js code directly into base.html fixes this issue.

tailwindlabs/tailwindcss#3904 (comment)

Any opinion on this approach?

EDIT: For context here is the PR #88

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.

2 participants