@@ -12,14 +12,14 @@ You want to style your angular material dynamically with all the colors in the r
12122. If @angular/material is already configured remove ` @import ' @angular/material/theming' ; ` from your main stylesheet file if present.
13133. Add this to your main stylesheet instead:
1414 ` ` ` scss
15- @import ' angular-material-css-vars/main' ;
15+ @use ' angular-material-css-vars/main' as mat-css ;
1616
1717 // optional
1818 $mat -css-dark-theme-selector: ' .isDarkTheme' ;
1919 $mat -css-light-theme-selector: ' .isLightTheme' ;
2020
2121 // init theme
22- @include init-material-css-vars () {
22+ @include mat-css. init-material-css-vars () using( $mat -css-theme ) {
2323 // If your app has any theme mixins, call them here.
2424 // $mat -css-theme gets set to an appropriate value before this content is called.
2525 // @include your-custom-component-theme($mat -css-theme);
@@ -69,18 +69,18 @@ export class AppModule {
6969# # Utility
7070There are also several [utility functions and mixins](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_public-util.scss).
7171` ` ` scss
72- @import ' angular-material-css-vars/public-util' ;
72+ @use ' angular-material-css-vars/public-util' as mat-css-utilities ;
7373
7474.with-color {
75- border-color: mat-css-color-primary(300);
75+ border-color: mat-css-utilities.mat-css- color-primary(300);
7676}
7777
7878.color-and-contrast {
79- @include mat-css-color-and-contrast(300);
79+ @include mat-css-utilities.mat-css- color-and-contrast(300);
8080}
8181
8282.with-bg {
83- @include mat-css-bg(300);
83+ @include mat-css-utilities.mat-css- bg(300);
8484}
8585` ` `
8686
@@ -89,23 +89,27 @@ There are also [some additional hacks](additional-hacks.md) (e.g. adding a color
8989# # Initialization Options
9090You can provide different options before initialization to change the body class used for the dark theme and to provide different default styles:
9191` ` ` scss
92+ ...
93+ @use ' angular-material-css-vars/main' as mat-css;
94+ ...
95+
9296// $mat -css-default-light-theme: ... ;
9397// $mat -css-text: ... ;
9498$mat -css-dark-theme-selector: ' .isDarkTheme' ;
9599$mat -css-light-theme-selector: ' .isLightTheme' ;
96100
97- @include init-material-css-vars ();
101+ @include mat-css. init-material-css-vars ();
98102
99103` ` `
100104To make those variables take effect with your mixins, you need to make sure that they are also defined before using them. E.g.:
101105` ` ` scss
106+ @use ' angular-material-css-vars/public-util' as mat-css-utilities;
107+
102108// probably best put in a common variables file and imported before the mixins
103109$mat -css-dark-theme-selector: ' .isDarkThemeCUSTOM' ;
104110
105- @import ' angular-material-css-vars/public-util' ;
106-
107111.my-component {
108- @include mat-css-dark-theme {
112+ @include mat-css-utilities.mat-css- dark-theme {
109113 // dark theme styles ...
110114 }
111115}
@@ -118,34 +122,37 @@ A full list of the theme map [can be found here](https://github.com/johannesjo/a
118122# ## Set default (fallback palettes)
119123There are two ways to set the default fallback theme. One is using the ` mat-css-palette-defaults` mixin.
120124` ` ` scss
121- @import ' angular-material-css-vars/public-util' ;
122- @import ' angular-material-css-vars/main' ;
125+ @use ' angular-material-css-vars/public-util' as mat-css-utilities;
126+ @use ' angular-material-css-vars/main' as mat-css-main;
127+ @use ' @angular/material/theming' as mat-theming;
123128
124- @include init-material-css-vars ();
129+ @include mat-css-main. init-material-css-vars ();
125130
126- @include mat-css-set-palette-defaults($mat -light-blue, ' primary' );
127- @include mat-css-set-palette-defaults($mat -pink, ' accent' );
128- @include mat-css-set-palette-defaults($mat -red, ' warn' );
131+ @include mat-css-utilities.mat-css- set-palette-defaults(mat-theming. $mat -light-blue, ' primary' );
132+ @include mat-css-utilities.mat-css- set-palette-defaults(mat-theming. $mat -pink, ' accent' );
133+ @include mat-css-utilities.mat-css- set-palette-defaults(mat-theming. $mat -red, ' warn' );
129134` ` `
130135The other is to include your own variables for [$mat -css-default-light-theme](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_variables.scss).
131136` ` ` scss
132- @import ' angular-material-css-vars/main' ;
137+ @use ' angular-material-css-vars/main' as mat-css-main;
138+ @use ' angular-material-css-vars/variables' as mat-css-vars;
139+ @use ' angular-material-css-vars/public-util' as mat-css-utilities;
133140
134141$mat -css-default-light-theme: map-merge(
135142 // if you don' t want to enter ALL the properties
136- $ mat-css-default-light-theme,
143+ mat-css-vars.$ default-light-theme,
137144 (
138- --palette-primary-50: _mat -css-hex-to-rgb(#e1f5fe),
139- --palette-primary-100: _mat -css-hex-to-rgb(#b3e5fc),
140- --palette-primary-200: _mat -css-hex-to-rgb(#81d4fa),
141- --palette-primary-300: _mat -css-hex-to-rgb(#4fc3f7),
142- --palette-primary-400: _mat -css-hex-to-rgb(#29b6f6),
143- --palette-primary-500: _mat -css-hex-to-rgb(#03a9f4),
145+ --palette-primary-50: mat -css-utilities. hex-to-rgb(#e1f5fe),
146+ --palette-primary-100: mat -css-utilities. hex-to-rgb(#b3e5fc),
147+ --palette-primary-200: mat -css-utilities. hex-to-rgb(#81d4fa),
148+ --palette-primary-300: mat -css-utilities. hex-to-rgb(#4fc3f7),
149+ --palette-primary-400: mat -css-utilities. hex-to-rgb(#29b6f6),
150+ --palette-primary-500: mat -css-utilities. hex-to-rgb(#03a9f4),
144151 // ...
145152 )
146153);
147154
148- @include init-material-css-vars();
155+ @include mat-css-main. init-material-css-vars();
149156
150157```
151158
@@ -160,14 +167,18 @@ See the Material guide on [Theming your custom component](https://material.angul
160167# # Font config
161168If needed the typography can be adjusted as well.
162169` ` ` scss
170+ @use ' angular-material-css-vars/main' as mat-css-main;
171+ @use ' @angular/material' as mat;
172+ @use ' @angular/material/theming' as mat-theming;
173+
163174// example
164- $custom -typography: mat-typography-config(
175+ $custom -typography: mat.mat -typography-config(
165176 $font -family: ' Roboto, monospace' ,
166- $headline : mat-typography-level(32px, 48px, 700),
167- $body -1: mat-typography-level(16px, 24px, 500)
177+ $headline : mat-theming.mat- typography-level(32px, 48px, 700),
178+ $body -1: mat-theming.mat- typography-level(16px, 24px, 500)
168179);
169180
170- @include init-material-css-vars($typography -config: $custom -typography) {
181+ @include mat-css-main. init-material-css-vars($typography -config: $custom -typography) using( $mat -css-theme ) {
171182 @include app-theme($mat -css-theme);
172183};
173184` ` `
@@ -182,19 +193,19 @@ With Angular v15, you can decide whether to keep using the legacy components, or
182193No further action is required, just import the ` init-material-css-vars` mixin like before:
183194
184195` ` ` scss
185- @import " angular-material-css-vars/main" ;
196+ @use ' angular-material-css-vars/main' as mat-css-main ;
186197
187- @include init-material-css-vars;
198+ @include mat-css-main. init-material-css-vars;
188199` ` `
189200
190201# ## Keep using the legacy components
191202
192203Please pass the following configuration to the mixin:
193204
194205` ` ` scss
195- @import " angular-material-css-vars/main" ;
206+ @use ' angular-material-css-vars/main' as mat-css-main ;
196207
197- @include init-material-css-vars($load -legacy-components: true, $load -mdc-components: false);
208+ @include mat-css-main. init-material-css-vars($load -legacy-components: true, $load -mdc-components: false);
198209` ` `
199210
200211# ## Use legacy and MDC based components in parallel
@@ -204,9 +215,9 @@ Please pass the following configuration to the mixin:
204215Please pass the following configuration to the mixin:
205216
206217` ` ` scss
207- @import " angular-material-css-vars/main" ;
218+ @use ' angular-material-css-vars/main' as mat-css-main ;
208219
209- @include init-material-css-vars($load -legacy-components: true, $load -mdc-components: true);
220+ @include mat-css-main. init-material-css-vars($load -legacy-components: true, $load -mdc-components: true);
210221` ` `
211222
212223# # upgrading to angular v12
0 commit comments