Skip to content

Theme Detection (Dark Mode)#246

Merged
tlmii merged 6 commits intomicrosoft:mainfrom
tlmii:dev/system-theme-detection-and-dark-mode
Oct 12, 2023
Merged

Theme Detection (Dark Mode)#246
tlmii merged 6 commits intomicrosoft:mainfrom
tlmii:dev/system-theme-detection-and-dark-mode

Conversation

@tlmii
Copy link
Member

@tlmii tlmii commented Oct 11, 2023

Resolves #216

The TL;DR here is "dashboard will use dark mode if the system is set to dark mode, and will use light mode otherwise".

The implementation is a little more complicated. To avoid a flash of bright white when setting dark mode at runtime, we track the last system setting in a cookie and use that cookie to render the initial state. You'll still get a flash of bright white the first time you load the site at a particular URL, but every time after that (including after stopping the debugger, exiting the app, etc) you won't. We also use a basic inline CSS style to set the initial background color to a dark color to avoid the same thing.

I tweaked some of the colors in the /Traces and /Trace pages to work better with dark mode. I didn't try to be exhaustive, just make sure there wasn't any dark-on-dark or light-on-light colors happening. I also made a small adjustment to the menu background.

Screenshots to follow.

@tlmii
Copy link
Member Author

tlmii commented Oct 11, 2023

Cropped too much, but you can see the menu background is a solid color. It also extends to the bottom of the page now:
DarkModeMenuChanges

Traces:
DarkModeTraces

Trace:
DarkModeTraceDetail

@JamesNK
Copy link
Member

JamesNK commented Oct 11, 2023

Traces looks 100% better than I thought it would. Not great, but not a train wreak 😄

<link rel="stylesheet" href="_content/Aspire.Dashboard/css/app.css" />
<link rel="stylesheet" href="_content/Aspire.Dashboard/Aspire.Dashboard.bundle.scp.css" />
<HeadOutlet @rendermode="@RenderMode.InteractiveServer" />
<style>@@media (prefers-color-scheme: dark) { body { background-color: #333333; } }</style>
Copy link
Member

Choose a reason for hiding this comment

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

Is this to avoid flash of white on page load? Add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right. The custom properties (e.g. --neutral-fill-rest) aren't available at this point so I just took the raw color. Makes sure the page loads dark.

@tlmii
Copy link
Member Author

tlmii commented Oct 12, 2023

Traces looks 100% better than I thought it would. Not great, but not a train wreak 😄

Yeah most of the accent colors worked OK. There were just a few places where the background or foreground was hardcoded to white/gray/black that needed to be tweaked.

Some things definitely won't pass accessibility testing at the moment but I'll file bugs on those later this week.

@tlmii tlmii enabled auto-merge (squash) October 12, 2023 04:54
@tlmii tlmii disabled auto-merge October 12, 2023 05:01
tlmii and others added 4 commits October 11, 2023 22:44
Don't use FluentDesignSytemProvider and move injects to .cs file
Use standard luminosity values and use BaseLayerLuminance design token
Undo some unnecessary renaming
@tlmii tlmii enabled auto-merge (squash) October 12, 2023 08:20
@tlmii tlmii merged commit 3e24e55 into microsoft:main Oct 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard needs to support Dark mode

5 participants