Skip to content

Commit 0cb27f9

Browse files
authored
fix(material/schematics): switch custom theme schematic to @use (#22436)
Reworks the custom theme schematic to go through the new theming API.
1 parent 10cc9cf commit 0cb27f9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/material/schematics/ng-add/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ describe('ng-add schematic', () => {
122122
const buffer = tree.read(expectedStylesPath);
123123
const themeContent = buffer!.toString();
124124

125-
expect(themeContent).toContain(`@import '~@angular/material/theming';`);
126-
expect(themeContent).toContain(`$app-primary: mat-palette(`);
125+
expect(themeContent).toContain(`@use '~@angular/material' as mat;`);
126+
expect(themeContent).toContain(`$app-primary: mat.define-palette(`);
127127
});
128128

129129
it('should create a custom theme file if no SCSS file could be found', async () => {

src/material/schematics/ng-add/theming/create-custom-theme.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ export function createCustomTheme(name: string = 'app') {
1111
return `
1212
// Custom Theming for Angular Material
1313
// For more information: https://material.angular.io/guide/theming
14-
@import '~@angular/material/theming';
14+
@use '~@angular/material' as mat;
1515
// Plus imports for other components in your app.
1616
1717
// Include the common styles for Angular Material. We include this here so that you only
1818
// have to load a single css file for Angular Material in your app.
1919
// Be sure that you only ever include this mixin once!
20-
@include mat-core();
20+
@include mat.core();
2121
2222
// Define the palettes for your theme using the Material Design palettes available in palette.scss
2323
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
2424
// hue. Available color palettes: https://material.io/design/color/
25-
$${name}-primary: mat-palette($mat-indigo);
26-
$${name}-accent: mat-palette($mat-pink, A200, A100, A400);
25+
$${name}-primary: mat.define-palette(mat.$indigo-palette);
26+
$${name}-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
2727
2828
// The warn palette is optional (defaults to red).
29-
$${name}-warn: mat-palette($mat-red);
29+
$${name}-warn: mat.define-palette(mat.$red-palette);
3030
3131
// Create the theme object. A theme consists of configurations for individual
3232
// theming systems such as "color" or "typography".
33-
$${name}-theme: mat-light-theme((
33+
$${name}-theme: mat.define-light-theme((
3434
color: (
3535
primary: $${name}-primary,
3636
accent: $${name}-accent,
@@ -41,7 +41,7 @@ $${name}-theme: mat-light-theme((
4141
// Include theme styles for core and each component used in your app.
4242
// Alternatively, you can import and @include the theme mixins for each component
4343
// that you are using.
44-
@include angular-material-theme($${name}-theme);
44+
@include mat.all-component-themes($${name}-theme);
4545
4646
`;
4747
}

0 commit comments

Comments
 (0)