-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Prefers-Color-Scheme Support #16905
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
Comments
For now, we consider this to be an application-level concern. In particular, we never want to load both light and dark theme CSS at the same time out-of-the-box. Using a media query requires both sets of styles to be present at the same time, so we leave it up to the application to do this. That would look something like @import '~@angular/material/theming';
@include mat-core();
$light-primary: mat-palette($mat-indigo);
$light-accent: mat-palette($mat-pink, A200, A100, A400);
$light-theme: mat-light-theme($candy-app-primary, $candy-app-accent);
@media (prefers-color-scheme: light) {
@include angular-material-theme($light-theme);
}
$dark-primary: mat-palette($mat-blue-grey);
$dark-accent: mat-palette($mat-amber, A200, A100, A400);
$dark-warn: mat-palette($mat-deep-orange);
$dark-theme: mat-dark-theme($dark-primary, $dark-accent, $dark-warn);
@media (prefers-color-scheme: dark) {
@include angular-material-theme($dark-theme);
} |
Note that See this article on web.dev for details. Combined with a color scheme aware stylesheet architecture, this would allow for a performant setup. |
Ah, I actually didn't know about the It would be nice to document this approach, though, in our theming guide. |
I will take it @jelbourn . |
I wrote a little article about how I would solve it personally. Maybe it helps someone: https://medium.com/@svenbudak/how-to-implement-dark-light-mode-in-angular-mateiral-with-prefers-color-scheme-ce3e980e2ea5 |
I am working on a way to load depends on the The filenames are now:
When i try to load them with |
The code @jelbourn mentioned is leading to some weird issues for me where the styles for the second include in the file are getting messed up. In my case I'm seeing the height on some angular material components not being set. This happens even if both includes point to the same theme. If it's structured as shown then the light mode will work fine, but the dark mode will have issues. However, changing the order means the dark mode will work fine and the light mode will have issues. I've never really worked with SCSS before so I don't have any idea what's causing this. |
Closing since this is supported now. |
Feature Description
Would be very nice to have Prefers-Color-Scheme Support in Angular Components:
https://davidwalsh.name/prefers-color-scheme
Except mobile devices this has pretty good browser-support already:
https://caniuse.com/#search=prefers-color-scheme
Use Case
The user has dark or light mode in his operating system enabled and based on this the Angular components would look like accordingly.
The text was updated successfully, but these errors were encountered: