Skip to content

fix(material/core): change ng-add to use mat.theme #29990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/material/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('ng-add schematic', () => {
const themeContent = buffer!.toString();

expect(themeContent).toContain(`@use '@angular/material' as mat;`);
expect(themeContent).toContain(`$material-theme: mat.define-theme((`);
expect(themeContent).toContain(`@include mat.theme((`);
});

it('should create a custom theme file if no SCSS file could be found', async () => {
Expand Down
38 changes: 11 additions & 27 deletions src/material/schematics/ng-add/theming/create-custom-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,16 @@ export function createCustomTheme(name: string = 'app') {
// Custom Theming for Angular Material
// For more information: https://material.angular.io/guide/theming
@use '@angular/material' as mat;
// Plus imports for other components in your app.

// Define the theme object.
$${name}-theme: mat.define-theme((
color: (
theme-type: light,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
density: (
scale: 0,
)
));

// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
:root {
@include mat.all-component-themes($${name}-theme);
}

// Comment out the line below if you want to use the pre-defined typography utility classes.
// For more information: https://material.angular.io/guide/typography#using-typography-styles-in-your-application.
// @include mat.typography-hierarchy($${name}-theme);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an equivalent for these optional bits with the new system? Or are we changing to a more opinionated stance of either automatically including these as part of the new mixin or just recommending not to use them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer recommending that clients just depend on the system variables where they want them. For example they can make their own custom setup like:

h1 {
  font: var(--mat-sys-headline-large);
}

h2 {
  font: var(--mat-sys-headline-medium);
}

h3 {
  font: var(--mat-sys-headline-small);
}

My hope is that we can get folks to generally just need to know about mat.theme and the available variables. This also seems to match with Material's departure from their previous opinionated typography names: https://m2.material.io/develop/web/guides/typography


// Comment out the line below if you want to use the deprecated \`color\` inputs.
// @include mat.color-variants-backwards-compatibility($${name}-theme);
`;
html {
@include mat.theme((
color: (
theme-type: light,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
typography: Roboto,
density: 0,
));
}`;
}
Loading