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

Activate dark mode #1938

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

Activate dark mode #1938

wants to merge 5 commits into from

Conversation

dometto
Copy link
Member

@dometto dometto commented Jan 12, 2023

Resolves #1893.

  • Dialogs don't use primer's dark mode styling, since we use our own dialog code and CSS
  • activate dark theme for memaid
  • Equally for the spinners
  • The ACE editor shows an ugly vertical line, probably because it isn't auto-configured to use dark mode
  • Update $border-standard definition
  • Update CSS for.toc and .toc_title
  • Update CSS for highlights (?)
  • Update CSS in editor.scss
  • Update syntax highlighting CSS in highlights.scss (not sure -- does this need separate colours in dark mode?)
  • Check background colour of code blocks in dark mode
  • Update CSS for help block (in editor)
  • Check all octicon occurrences, including the fillcolor (which is currently set to black)
    • Note: octicons are also generated by Macros. To support them in dark mode, we should look into using the filter trick for all svg's with the octicon class.

Please feel free to add to this todo and work on this branch!

@dometto dometto marked this pull request as draft January 12, 2023 16:09
@dometto dometto mentioned this pull request Jan 12, 2023
3 tasks
@dometto
Copy link
Member Author

dometto commented Jan 18, 2023

I've rebased this after merging #1914. Here's a screenshot of a page so we can see what needs tweaking:

Screenshot 2023-01-18 at 14 03 20

@dometto dometto added this to the 6.1 milestone Jan 18, 2023
@@ -53,6 +53,9 @@ h6 {

&:before {
content: url('data:image/svg+xml;utf8,<%= rocticon_css(:link) %>');
@media (prefers-color-scheme: dark) {
filter: invert(95%) sepia(4%) saturate(753%) hue-rotate(178deg) brightness(88%) contrast(92%);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity:

Since we're including the octicon SVG as content, we can't style it as a normal element (for instance by setting the fill color for svg path). This is a trick to transform the color of the svg. I used this to calculate the filters needed to get the color we want (which is just the main text color in dark mode).

Co-authored-by: chiragthakur09 <chiragthakur09@gmail.com>
@svoop
Copy link
Contributor

svoop commented Oct 26, 2023

@dometto With gollum/gollum-lib#441, the last box can be checked, can't it? (Btw, would love to help, but I'm pretty useless with CSS.)

@bartkamphorst
Copy link
Member

Screenshot 2023-11-01 at 15 23 41

CSS styling for the help section also needs work.

@bartkamphorst
Copy link
Member

Screenshot 2023-11-01 at 15 43 26

Still not perfect with the borders, but a little better overall nonetheless.

@bartkamphorst
Copy link
Member

bartkamphorst commented Nov 1, 2023

Screenshot 2023-11-01 at 16 52 53

This resolves the styling of the TOC.

@bartkamphorst
Copy link
Member

To ensure proper styling of the mermaid diagrams, we not only have to tell mermaid to use the dark theme, but ensure that the enclosing iframes get styled.

@bartkamphorst
Copy link
Member

To ensure proper styling of the mermaid diagrams, we not only have to tell mermaid to use the dark theme, but ensure that the enclosing iframes get styled.

So, this turns out to be a little more involved than I had anticipated, mostly because we use mermaid's sandbox security level. Normally, mermaid diagrams will be responsive to dark mode automatically; however, in sandbox mode, they are not. I've managed to work around this by checking for dark mode before rendering and listening for color scheme change to rerender the diagrams if needed. However, this does require storing the source of diagrams somewhere. I've opted to simply add the source to a hidden div, but we could also try to save it to localStorage or something.

@bartkamphorst
Copy link
Member

Also, to make mermaid responsive to my theme directive, I had to upgrade to v. 10.6.0.

@bartkamphorst
Copy link
Member

Before:

Screenshot 2023-11-03 at 13 10 29

After:

Screenshot 2023-11-03 at 11 14 59

@bartkamphorst
Copy link
Member

Manually adding

<meta name="color-scheme" content="light dark">

to the head of the iframe has the effect I'm after.

Screenshot 2023-11-03 at 16 07 19

Unfortunately, we cannot manipulate the contents of the iframe ourselves because this is considered cross-origin scripting (Uncaught DOMException: Permission denied to access property "document" on cross-origin object).

I'm not sure how to proceed from here. We could leave it (and have white background), or try to open an issue with mermaid (though they are already overburdened with issues and PRs). @dometto @benjaminwil Any ideas?

@benjaminwil
Copy link
Member

I haven't really dug into Mermaid at all yet and don't feel like I can weigh in fully. But as long as Mermaid documents remain readable, even if they don't fully respect dark mode, I think this is okay for the time being.

So, this turns out to be a little more involved than I had anticipated, mostly because we use mermaid's sandbox security level. Normally, mermaid diagrams will be responsive to dark mode automatically; however, in sandbox mode, they are not.

When you say responsive, do you mean when flipping the browser (or system) theme between light and dark without reloading the Gollum webpage?

@bartkamphorst
Copy link
Member

When you say responsive, do you mean when flipping the browser (or system) theme between light and dark without reloading the Gollum webpage?

Exactly.

@benjaminwil
Copy link
Member

Is everything working as expected on reload?

@bartkamphorst
Copy link
Member

Is everything working as expected on reload?

In my limited test setup, everything (with respect to mermaid) works as I expect it to. I'm on OS X, toggling the System's Light and Dark mode and seeing how Firefox (119.0) responds. On page reload the correct color scheme is detected and passed to mermaid. When the color scheme changes, gollum detects this and rerenders the mermaid diagrams. Others are very welcome to take this branch for a spin. Maybe @chiragthakur09 has anything to add?

@chiragthakur09
Copy link

Is everything working as expected on reload?

In my limited test setup, everything (with respect to mermaid) works as I expect it to. I'm on OS X, toggling the System's Light and Dark mode and seeing how Firefox (119.0) responds. On page reload the correct color scheme is detected and passed to mermaid. When the color scheme changes, gollum detects this and rerenders the mermaid diagrams. Others are very welcome to take this branch for a spin. Maybe @chiragthakur09 has anything to add?

I also have the same setup, OS X, toggled systems theme mode between light and dark. In fact it didn't require me to reload the page. Themes got rendered in real time as I kept toggling between light and dark.

Currently I am in the middle of a job switch, relocating to a new city. I won't be able to contribute further on the issue for some time.

@dometto
Copy link
Member Author

dometto commented Nov 6, 2023

I'm not sure how to proceed from here. We could leave it (and have white background), or try to open an issue with mermaid (though they are already overburdened with issues and PRs).

I also think the white background is ok for now, but we should also open an issue with mermaid. :) I opened a bug report there and it was picked up in a couple of month. Even if it takes longer this time, we'll eventually be able to have nice looking dark. mode diagrams.

Thanks for continuing work on this PR, @bartkamphorst!

@bartkamphorst
Copy link
Member

we should also open an issue with mermaid.

Done. See mermaid-js/mermaid#5034.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Dark mode
5 participants