You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This schematic allows users to create new Material 3 theme palettes based
8
8
on custom colors by using [Material Color Utilities](https://github.com/material-foundation/material-color-utilities).
9
+
This is an alternative to using the available [predefined theme palettes](https://material.angular.io/guide/theming#prebuilt-color-palettes).
9
10
10
11
The generated [color palettes](https://m3.material.io/styles/color/roles) are
11
-
optimized to have enough contrast to be more accessible. See [Science of Color Design](https://material.io/blog/science-of-color-design) for more information about Material's color design.
12
+
optimized to have enough contrast to be more accessible. See [Science of Color Design](https://material.io/blog/science-of-color-design)
13
+
for more information about Material's color design.
12
14
13
15
For more customization, custom colors can be also be provided for the
14
16
secondary, tertiary, and neutral palette colors. It is recommended to choose colors that
15
-
are contrastful, Material has more detailed guidance for [accessible design](https://m3.material.io/foundations/accessible-design/patterns).
17
+
are contrastful. Material has more detailed guidance for [accessible design](https://m3.material.io/foundations/accessible-design/patterns).
18
+
19
+
## Options
20
+
21
+
### Required
22
+
*`primaryColor` - Color to use for app's primary color palette (Note: the other
23
+
palettes described in the Material 3 spec will be automatically chosen based on
24
+
your primary palette unless specified, to ensure a harmonious color combination).
25
+
26
+
### Optional
27
+
*`secondaryColor` - Color to use for app's secondary color palette. Defaults to
28
+
secondary color generated from Material based on the primary.
29
+
*`tertiaryColor` - Color to use for app's tertiary color palette. Defaults to
30
+
tertiary color generated from Material based on the primary.
31
+
*`neutralColor` - Color to use for app's neutral color palette. Defaults to
32
+
neutral color generated from Material based on the primary.
33
+
*`includeHighContrast` - Whether to define high contrast values for the custom colors in the
34
+
generated file. For Sass files a mixin is defined, see the [high contrast override mixins section](#high-contrast-override-mixins)
35
+
for more information. Defaults to false.
36
+
*`directory` - Relative path to a directory within the project that the
37
+
generated theme file should be created in. Defaults to the project root.
38
+
*`isScss` - Whether to generate output file in Sass or CSS. Angular recommends generating a Sass
39
+
file, see the [file output section](#generated-file-output) below for more information. Defaults to
40
+
true.
41
+
42
+
## Generated file output
43
+
The result of running the schematic is a new file with the generated custom colors.
44
+
45
+
Angular recommendeds generating a Sass file since our theming system Sass APIs are supported and
46
+
have benefits such as error handling and relate to the [theming documentation](https://material.angular.io/guide/theming).
47
+
If there are ever changes to the theming system or system variable names, your styles will continue
48
+
to work and be supported. Color palettes get defined in the generated file that you can pass into
49
+
the `theme()` mixin in your own theme file. See the [Sass themes section](#sass-themes) for more
50
+
information.
16
51
17
-
The output of the schematic will create a file named `_theme-colors.scss` at the
18
-
specified directory or the project root with the generated palettes. The exported
19
-
palettes (`$primary-palette` and `$tertiary-palette`) can be provided to the `theme` mixin within your theme file to use the custom colors.
52
+
You can generate a CSS file which defines all the system variables directly. This allows for
53
+
applications that do not use Sass to still interact with our theming. See the [CSS themes section](#css-themes)
54
+
for more specific information.
55
+
56
+
## Sass themes
57
+
The output of the schematic will create a file named `_theme-colors.scss` at the specified directory
58
+
or the project root. The exported palettes (`$primary-palette` and `$tertiary-palette`) can be
59
+
provided to the `theme` mixin within your theme file to use the custom colors.
20
60
21
61
```scss
22
62
@use'@angular/material'asmat;
23
-
@use'./path/to/my-theme'; // location of generated file
63
+
@use'./path/to/_theme-colors'asmy-theme; // location of generated file
24
64
25
65
html {
26
66
@includemat.theme(
@@ -34,104 +74,151 @@ html {
34
74
}
35
75
```
36
76
37
-
## High contrast override mixins
77
+
###High contrast override mixins
38
78
High contrast override theme mixins are also generated in the file if specified. These mixins
39
79
override the system level variables with high contrast equivalent values from your theme. This is
40
80
helpful for users who prefer more contrastful colors for either preference or accessibility reasons.
41
81
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).
82
+
To show the high contrast values when user's specify based on their color system preferences, apply
83
+
the `high-contrast-overrides()` mixin from the generated file wrapped inside
84
+
`@media (prefers-contrast: more)` in your theme file. You can pass in `light`, `dark`, or
85
+
`color-scheme`. To see the high contrast values in your application locally, you can [use Chrome DevTools to emulate
86
+
the CSS media features](https://developer.chrome.com/docs/devtools/rendering/emulate-css).
87
+
88
+
```
89
+
@media (prefers-contrast: more) {
90
+
@include my-theme.high-contrast-overrides(light);
91
+
}
92
+
```
93
+
94
+
#### Adaptive high contrast colors for explicit light and dark themes
95
+
You can manually define the light theme and dark theme separately. This is recommended if you need
96
+
granular control over when to show each specific theme in your application. Prior to v19, this was
97
+
the only way to create light and dark themes.
45
98
46
-
Apply the `high-contrast-overrides(color-scheme)` mixin wrapped inside `@media (prefers-contrast: more)`.
99
+
In this example, the colors would automatically change between dark and dark high contrast based on
100
+
user's contrast preferences.
47
101
48
102
```scss
49
103
@use'@angular/material';
50
104
@use'./path/to/my-theme'; // location of generated file
51
105
52
106
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
107
+
// Apply the dark theme by default
57
108
@includematerial.theme((
58
109
color: (
59
110
primary: my-theme.$primary-palette,
60
111
tertiary: my-theme.$tertiary-palette,
112
+
theme-type: dark,
61
113
),
62
114
typography: Roboto,
63
115
density: 0,
64
116
));
65
117
66
-
// Use high contrast values when users prefer contrast
118
+
// Use high contrast dark theme colors when users prefer contrast
0 commit comments