components icon indicating copy to clipboard operation
components copied to clipboard

Angular material typography supports for multiple fonts

Open nikhil4326 opened this issue 8 years ago • 7 comments

I read complete documentation for typography support provided by angular material2. The approah provided is quiet easy and clean. But i dont see documentation or approach to have support for multiple custom fonts. My application have 3 diferent fonts.

  1. my own custon font
  2. google font,(Roboto)
  3. other google font

Is it possible to configure 3 fonts in through custom typography and use it anywhere in application. If Yes, Then what is best and flexible way to implement it.

Thanks in advance.

nikhil4326 avatar Mar 14 '18 05:03 nikhil4326

Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.

donroyco avatar Mar 14 '18 08:03 donroyco

My question is related to feature that is "is multiple fonts support provided by angular material or not?". Because i dont see documentation for this.

nikhil4326 avatar Mar 14 '18 08:03 nikhil4326

You can pass in fallback fonts to mat-typography-config (e.g. Roboto, "Helvetica Neue", sans-serif), but we don't support multiple fonts, because there's no way of knowing which one to pick. You can still create multiple instances of mat-typography-config that each have their own font and you can use them to override particular sections of the app:

$roboto: mat-typography-config($font-family: 'Roboto');
$helvetica: mat-typography-config($font-family: 'Helvetica');

// Default to Roboto
@include angular-material-typography($roboto);

// Set the select to use Helvetica
@include mat-select-typography($helvetica);

crisbeto avatar Mar 14 '18 11:03 crisbeto

I have the same question as well. Can't we just simply have something like

@function mat-font-family($config, $level: null, $font-family: null) { ... }

so it allow us to pass in the font-family we defined in config?

maxisam avatar Aug 02 '18 15:08 maxisam

@import '~@angular/material/theming';

$custom-typography: mat-typography-config(
  $font-family: 'sans-serif',
  $display-1: mat-typography-level(36px, 50.4px, 200),
  $subheading-1: mat-typography-level(24px, 33.6px, 400),
  $body-1: mat-typography-level(14px, 20px, 400),
);
@include mat-core($custom-typography);

.mat-display-1 .mat-subheading-1 {
  font-family: Roboto;
}

tisak avatar Jan 31 '19 11:01 tisak

If someone is still interested, it is possible to configure font per typography level like this:

$custom-typography: mat-typography-config(
    $font-family: 'default font',
    $display-4: mat-typography-level(112px, 112px, 300, 'another font'),
    $display-3: mat-typography-level(56px, 56px, 400, 'and another font'),
);

Semyon13 avatar Mar 05 '19 12:03 Semyon13

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.