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

Detect dark theme via css variable #17800

Merged
merged 6 commits into from Nov 25, 2021

Conversation

Theta-Dev
Copy link
Contributor

I have just created a custom dark theme for my Gitea instance. It looks good, but the Monaco text editor did not pick up the dark theme like it does with the arc-green theme enabled.

So I looked into the source and found out that the dark editor theme only gets enabled when the builtin arc-green or auto theme is chosen. Any additional themes are treated as light themes.

That's why I updated the isDarkTheme() function to look for the --is-dark-theme css variable. If that variable is set to true, the editor dark mode gets enabled.

And because CSS variables can be set within queries, too, responsive themes like auto are possible without additional js logic.

@silverwind
Copy link
Member

Seems like a good approach, the old way with the name check was a hack. I'm not sure about the removal of the theme-auto condition thought, maybe it should be kept.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 24, 2021
@silverwind
Copy link
Member

Thought I guess if a dark theme is loaded as part of the auto-detection, it will have the variable as well, so I guess it's fine this way.

web_src/js/utils.js Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #17800 (a11eb45) into main (7743f13) will decrease coverage by 0.00%.
The diff coverage is 63.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17800      +/-   ##
==========================================
- Coverage   45.54%   45.54%   -0.01%     
==========================================
  Files         807      808       +1     
  Lines       89859    90009     +150     
==========================================
+ Hits        40930    40993      +63     
- Misses      42381    42468      +87     
  Partials     6548     6548              
Impacted Files Coverage Δ
cmd/admin.go 0.00% <0.00%> (ø)
cmd/migrate_storage.go 0.00% <0.00%> (ø)
cmd/web_https.go 0.00% <ø> (ø)
models/consistency.go 8.84% <0.00%> (ø)
models/db/error.go 0.00% <ø> (ø)
models/error.go 39.24% <ø> (+0.48%) ⬆️
models/issue_lock.go 0.00% <ø> (ø)
models/project_issue.go 29.35% <0.00%> (ø)
models/ssh_key_authorized_keys.go 58.82% <ø> (ø)
models/ssh_key_principals.go 6.55% <0.00%> (ø)
... and 245 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a666829...a11eb45. Read the comment docs.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 24, 2021
web_src/js/utils.js Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 24, 2021
@silverwind silverwind added the type/changelog Adds the changelog for a new Gitea version label Nov 24, 2021
@wxiaoguang wxiaoguang merged commit af901a4 into go-gitea:main Nov 25, 2021
@delvh delvh added this to the 1.16.0 milestone Nov 25, 2021
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
* 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.
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
@delvh delvh removed the type/changelog Adds the changelog for a new Gitea version label Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants