@@ -34,11 +34,47 @@ html {
3434}
3535```
3636
37- High contrast override theme mixins are also generated in the file if specified
38- ( ` high- contrast-light-theme-overrides ` and ` high-contrast-dark- theme-overrides ` ) . These mixins
37+ ## High contrast override mixins
38+ High contrast override theme mixins are also generated in the file if specified . These mixins
3939override the system level variables with high contrast equivalent values from your theme. This is
4040helpful for users who prefer more contrastful colors for either preference or accessibility reasons.
4141
42+ ### Creating one theme for light and dark mode
43+ As of v19, the ` theme ` mixin can create one theme that detects and adapts to a user if they have
44+ light or dark theme with the [ ` light-dark ` function] ( https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark ) .
45+
46+ Apply the ` high-contrast-overrides(color-scheme) ` mixin wrapped inside ` @media (prefers-contrast: more) ` .
47+
48+ ``` scss
49+ @use ' @angular/material' ;
50+ @use ' ./path/to/my-theme' ; // location of generated file
51+
52+ html {
53+ // Must specify color-scheme for theme mixin to automatically work
54+ color-scheme : light ;
55+
56+ // Create one theme that works automatically for light and dark theme
57+ @include material .theme ((
58+ color : (
59+ primary: my-theme .$primary-palette ,
60+ tertiary: my-theme .$tertiary-palette ,
61+ ),
62+ typography: Roboto,
63+ density: 0 ,
64+ ));
65+
66+ // Use high contrast values when users prefer contrast
67+ @media (prefers-contrast : more) {
68+ @include my-theme .high-contrast-overrides (color-scheme );
69+ }
70+ }
71+ ```
72+
73+ ### Creating separate themes for light and dark mode
74+ You can manually define the light theme and dark theme separately. This is recommended if you need
75+ granular control over when to show each specific theme in your application. Prior to v19, this was
76+ the only way to create light and dark themes.
77+
4278``` scss
4379@use ' @angular/material' ;
4480@use ' ./path/to/my-theme' ; // location of generated file
@@ -49,14 +85,15 @@ html {
4985 color : (
5086 primary: my-theme .$primary-palette ,
5187 tertiary: my-theme .$tertiary-palette ,
88+ theme- type: light ,
5289 ),
5390 typography: Roboto,
5491 density: 0 ,
5592 ));
5693
5794 // Use high contrast light theme colors when users prefer contrast
5895 @media (prefers-contrast : more) {
59- @include my-theme .high-contrast-light-theme- overrides ();
96+ @include my-theme .high-contrast-overrides (light );
6097 }
6198
6299 // Apply dark theme when users prefer a dark color scheme
@@ -71,7 +108,7 @@ html {
71108
72109 // Use high contrast dark theme colors when users prefers a dark color scheme and contrast
73110 @media (prefers-contrast : more) {
74- @include my-theme .high-contrast-dark-theme- overrides ();
111+ @include my-theme .high-contrast-overrides (dark );
75112 }
76113 }
77114}
0 commit comments