In Angular with Material installed I'm trying to override Material Typography to include 2 different fonts.
- I want 'Roboto' for all body/button/caption text,
- and 'Roboto-Condensed' for all heading/title/display text.
What's the best way to do this?
Here's what I've done in my SCSS files so far:
($title-font = Roboto-Condensed, $primary-font = Roboto)
// https://material.angular.io/guide/typography
@import '~@angular/material/theming';
// Define a custom typography config that overrides the font-family as well as the other `headlines` and `body-1` levels.
$custom-heading-typography: mat-typography-config(
$font-family: $title-font,
$display-4: mat-typography-level($d4, $disp-line-ht, $light),
$display-3: mat-typography-level($d3, $disp-line-ht, $regular),
$display-2: mat-typography-level($d2, $title-line-ht, $regular),
$display-1: mat-typography-level($d1, $title-line-ht, $regular),
$headline: mat-typography-level($h1, $title-line-ht, $bold),
$title: mat-typography-level($h2, $title-line-ht, $regular),
$subheading-2: mat-typography-level($h3, $title-line-ht $regular),
$subheading-1: mat-typography-level($h4, $title-line-ht, $light),
);
$custom-body-typography: mat-typography-config(
$font-family: $primary-font,
$body-1: mat-typography-level($primary-fs, $primary-line-ht, $regular),
$body-2: mat-typography-level($primary-fs, $primary-line-ht, $medium),
$caption: mat-typography-level($font-sm, $caption-line-ht, $regular),
$button: mat-typography-level($primary-fs, $disp-line-ht, $medium),
$input: mat-typography-level(inherit, $input-line-ht, $regular),
);
I also want to change various font styles, like font-size, line-height, weight, etc..., so I didn't just focus on setting font-family per text class.
This doesn't work (passing 2 configs) :
// Override the typography in the core CSS.
@include mat-core($custom-heading-typography, $custom-body-typography);
I created 2 different typography configs, one for title text and one for body text. they both work on their own if I pass them to mat-core, but I'm trying to pass both to mat-core at the same time--is this typography override with 2 different font-families possible, or should I go about this another way?
Even with just 1 font, there are problems:
When I include only one of the configs in the mat-core mixin, it changes ALL text elements to be the font family (the heading config with result in paragraphs, buttons, and list-items being 'Roboto-Condensed').
I also tried to include one of the two configs in these directives per the Material.Angular typography docs, but the behavior is unpredictable, and may also result in all elements having the same font-family.
Tried this:
// Override typography CSS classes (e.g., mat-h1, mat-display-1, mat-typography, etc.).
@include mat-base-typography($custom-heading-typography);
Also tried this:
// Override typography for all Angular Material, including mat-base-typography and all components.
@include angular-material-typography($custom-heading-typography);