Skip to content

Detect dark theme via css variable #17800

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

Merged
merged 6 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/content/doc/advanced/customizing-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ Community themes are listed in [gitea/awesome-gitea#themes](https://gitea.com/gi

The `arc-green` theme source can be found [here](https://github.com/go-gitea/gitea/blob/main/web_src/less/themes/theme-arc-green.less).

If your custom theme is considered a dark theme, set the global css variable `--is-dark-theme` to `true`.
This allows gitea to adjust the Monaco code editor's theme accordingly.

## Customizing fonts

Fonts can be customized using CSS variables:
Expand Down
9 changes: 2 additions & 7 deletions web_src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ export function isObject(obj) {

// returns whether a dark theme is enabled
export function isDarkTheme() {
if (document.documentElement.classList.contains('theme-auto')) {
return window.matchMedia('(prefers-color-scheme: dark)').matches;
}
if (document.documentElement.classList.contains('theme-arc-green')) {
return true;
}
return false;
const style = window.getComputedStyle(document.documentElement);
return style.getPropertyValue('--is-dark-theme').trim().toLowerCase() === 'true';
}

// removes duplicate elements in an array
Expand Down
1 change: 1 addition & 0 deletions web_src/less/themes/theme-arc-green.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../chroma/dark.less";

:root {
--is-dark-theme: true;
--color-primary: #87ab63;
--color-primary-dark-1: #93b373;
--color-primary-dark-2: #9fbc82;
Expand Down