Skip to content

Commit b312b94

Browse files
committed
feat(material/schematics): use M3 themes in schematics
Updates the schematics to refer to the M3 prebuilt themes and to generate an M3 theme when the user selects `custom` in `ng add`.
1 parent d1128dd commit b312b94

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('ng-add schematic', () => {
104104
const workspace = await getWorkspace(tree);
105105
const project = getProjectFromWorkspace(workspace, baseOptions.project);
106106

107-
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/indigo-pink.css');
107+
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/azure-blue.css');
108108
});
109109

110110
it('should support adding a custom theme', async () => {
@@ -124,7 +124,8 @@ describe('ng-add schematic', () => {
124124
const themeContent = buffer!.toString();
125125

126126
expect(themeContent).toContain(`@use '@angular/material' as mat;`);
127-
expect(themeContent).toContain(`$material-primary: mat.define-palette(`);
127+
expect(themeContent).toContain(`@use '@angular/material-experimental' as matx;`);
128+
expect(themeContent).toContain(`$material-theme: matx.define-theme((`);
128129
});
129130

130131
it('should create a custom theme file if no SCSS file could be found', async () => {
@@ -312,7 +313,7 @@ describe('ng-add schematic', () => {
312313

313314
describe('theme files', () => {
314315
/** Path to the default prebuilt theme file that will be added when running ng-add. */
315-
const defaultPrebuiltThemePath = '@angular/material/prebuilt-themes/indigo-pink.css';
316+
const defaultPrebuiltThemePath = '@angular/material/prebuilt-themes/azure-blue.css';
316317

317318
/** Writes a specific style file to the workspace in the given tree */
318319
function writeStyleFileToWorkspace(tree: Tree, stylePath: string) {
@@ -560,7 +561,7 @@ describe('ng-add schematic', () => {
560561
const workspace = await getWorkspace(tree);
561562
const project = getProjectFromWorkspace(workspace, baseOptions.project);
562563

563-
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/indigo-pink.css');
564+
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/azure-blue.css');
564565
});
565566

566567
it('should add material app styles', async () => {
@@ -630,7 +631,7 @@ describe('ng-add schematic', () => {
630631
const workspace = await getWorkspace(tree);
631632
const project = getProjectFromWorkspace(workspace, baseOptions.project);
632633

633-
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/indigo-pink.css');
634+
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/azure-blue.css');
634635
});
635636

636637
it('should add material app styles', async () => {

src/material/schematics/ng-add/schema.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
"theme": {
1515
"description": "The theme to apply",
1616
"type": "string",
17-
"default": "indigo-pink",
17+
"default": "azure-blue",
1818
"x-prompt": {
1919
"message": "Choose a prebuilt theme name, or \"custom\" for a custom theme:",
2020
"type": "list",
2121
"items": [
2222
{
23-
"value": "indigo-pink",
24-
"label": "Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ]"
23+
"value": "azure-blue",
24+
"label": "Azure/Blue [Preview: https://material.angular.io?theme=azure-blue]"
2525
},
2626
{
27-
"value": "deeppurple-amber",
28-
"label": "Deep Purple/Amber [ Preview: https://material.angular.io?theme=deeppurple-amber ]"
27+
"value": "rose-red",
28+
"label": "Rose/Red [Preview: https://material.angular.io?theme=rose-red]"
2929
},
3030
{
31-
"value": "pink-bluegrey",
32-
"label": "Pink/Blue Grey [ Preview: https://material.angular.io?theme=pink-bluegrey ]"
31+
"value": "magenta-violet",
32+
"label": "Magenta/Violet [Preview: https://material.angular.io?theme=magenta-violet]"
3333
},
3434
{
35-
"value": "purple-green",
36-
"label": "Purple/Green [ Preview: https://material.angular.io?theme=purple-green ]"
35+
"value": "cyan-orange",
36+
"label": "Cyan/Orange [Preview: https://material.angular.io?theme=cyan-orange]"
3737
},
3838
{"value": "custom", "label": "Custom"}
3939
]

src/material/schematics/ng-add/schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Schema {
1414
animations: 'enabled' | 'disabled' | 'excluded';
1515

1616
/** Name of pre-built theme to install. */
17-
theme: 'indigo-pink' | 'deeppurple-amber' | 'pink-bluegrey' | 'purple-green' | 'custom';
17+
theme: 'azure-blue' | 'rose-red' | 'magenta-violet' | 'cyan-orange' | 'custom';
1818

1919
/** Whether to set up global typography styles. */
2020
typography: boolean;

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ export function createCustomTheme(name: string = 'app') {
1212
// Custom Theming for Angular Material
1313
// For more information: https://material.angular.io/guide/theming
1414
@use '@angular/material' as mat;
15+
@use '@angular/material-experimental' as matx;
1516
// Plus imports for other components in your app.
1617
1718
// Include the common styles for Angular Material. We include this here so that you only
1819
// have to load a single css file for Angular Material in your app.
1920
// Be sure that you only ever include this mixin once!
2021
@include mat.core();
2122
22-
// Define the palettes for your theme using the Material Design palettes available in palette.scss
23-
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
24-
// hue. Available color palettes: https://material.io/design/color/
25-
$${name}-primary: mat.define-palette(mat.$indigo-palette);
26-
$${name}-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
27-
28-
// The warn palette is optional (defaults to red).
29-
$${name}-warn: mat.define-palette(mat.$red-palette);
30-
31-
// Create the theme object. A theme consists of configurations for individual
32-
// theming systems such as "color" or "typography".
33-
$${name}-theme: mat.define-light-theme((
23+
// Define the theme object.
24+
$${name}-theme: matx.define-theme((
3425
color: (
35-
primary: $${name}-primary,
36-
accent: $${name}-accent,
37-
warn: $${name}-warn,
26+
theme-type: light,
27+
primary: matx.$m3-azure-palette,
28+
tertiary: matx.$m3-blue-palette,
3829
),
39-
typography: mat.define-typography-config(),
40-
density: 0
30+
density: (
31+
scale: 0,
32+
)
4133
));
4234
4335
// Include theme styles for core and each component used in your app.
4436
// Alternatively, you can import and @include the theme mixins for each component
4537
// that you are using.
46-
@include mat.all-component-themes($${name}-theme);
38+
:root {
39+
@include mat.all-component-themes($${name}-theme);
40+
}
41+
42+
// Comment out the line below if you want to use the pre-defined typography utility classes.
43+
// For more information: https://material.angular.io/guide/typography#using-typography-styles-in-your-application.
44+
// @include mat.typography-hierarchy($theme);
4745
46+
// Comment out the line below if you want to use the deprecated \`color\` inputs.
47+
// @include matx.color-variants-back-compat($theme);
4848
`;
4949
}

src/material/schematics/ng-add/theming/theming.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const defaultCustomThemeFilename = 'custom-theme.scss';
3939
/** Add pre-built styles to the main project style file. */
4040
export function addThemeToAppStyles(options: Schema): Rule {
4141
return (host: Tree, context: SchematicContext) => {
42-
const themeName = options.theme || 'indigo-pink';
42+
const themeName = options.theme || 'azure-blue';
4343
return themeName === 'custom'
4444
? insertCustomTheme(options.project, host, context.logger)
4545
: insertPrebuiltTheme(options.project, themeName, context.logger);

0 commit comments

Comments
 (0)