Skip to content

Commit af901a4

Browse files
authored
Detect dark theme via css variable (#17800)
* detect dark theme via css variable * minor refactor, add documentation 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.
1 parent e0f81b4 commit af901a4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ Community themes are listed in [gitea/awesome-gitea#themes](https://gitea.com/gi
337337

338338
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).
339339

340+
If your custom theme is considered a dark theme, set the global css variable `--is-dark-theme` to `true`.
341+
This allows gitea to adjust the Monaco code editor's theme accordingly.
342+
340343
## Customizing fonts
341344

342345
Fonts can be customized using CSS variables:

web_src/js/utils.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ export function isObject(obj) {
2626

2727
// returns whether a dark theme is enabled
2828
export function isDarkTheme() {
29-
if (document.documentElement.classList.contains('theme-auto')) {
30-
return window.matchMedia('(prefers-color-scheme: dark)').matches;
31-
}
32-
if (document.documentElement.classList.contains('theme-arc-green')) {
33-
return true;
34-
}
35-
return false;
29+
const style = window.getComputedStyle(document.documentElement);
30+
return style.getPropertyValue('--is-dark-theme').trim().toLowerCase() === 'true';
3631
}
3732

3833
// removes duplicate elements in an array

web_src/less/themes/theme-arc-green.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import "../chroma/dark.less";
22

33
:root {
4+
--is-dark-theme: true;
45
--color-primary: #87ab63;
56
--color-primary-dark-1: #93b373;
67
--color-primary-dark-2: #9fbc82;

0 commit comments

Comments
 (0)