|
| 1 | +@import '@material/typography/variables.import'; |
1 | 2 | @import '../mdc-theming/all-theme';
|
2 | 3 |
|
| 4 | +/// Generates an Angular Material typography config based on values from the official Material |
| 5 | +/// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override |
| 6 | +/// the default values. The `mat-typography-level` function can be used to generate a custom |
| 7 | +/// typography level map which can be passed to this function to override one of the default levels. |
| 8 | +/// |
| 9 | +/// @param {String} $font-family The font family to use for levels where it is not explicitly |
| 10 | +/// specified. |
| 11 | +/// @param {Map} $headline-1 The font settings for the headline-1 font level. |
| 12 | +/// @param {Map} $headline-2 The font settings for the headline-2 font level. |
| 13 | +/// @param {Map} $headline-3 The font settings for the headline-3 font level. |
| 14 | +/// @param {Map} $headline-4 The font settings for the headline-4 font level. |
| 15 | +/// @param {Map} $headline-5 The font settings for the headline-5 font level. |
| 16 | +/// @param {Map} $headline-6 The font settings for the headline-6 font level. |
| 17 | +/// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level. |
| 18 | +/// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level. |
| 19 | +/// @param {Map} $body-1 The font settings for the body-1 font level. |
| 20 | +/// @param {Map} $body-2 The font settings for the body-2 font level. |
| 21 | +/// @param {Map} $caption The font settings for the caption font level. |
| 22 | +/// @param {Map} $button The font settings for the button font level. |
| 23 | +/// @param {Map} $overline The font settings for the overline font level. |
| 24 | +/// @return {Map} A map containing font settings for each of the levels in the Material Design spec. |
| 25 | +@function mat-mdc-typography-config( |
| 26 | + $font-family: $mdc-typography-font-family, |
| 27 | + $headline-1: mat-typography-config-level-from-mdc(headline1), |
| 28 | + $headline-2: mat-typography-config-level-from-mdc(headline2), |
| 29 | + $headline-3: mat-typography-config-level-from-mdc(headline3), |
| 30 | + $headline-4: mat-typography-config-level-from-mdc(headline4), |
| 31 | + $headline-5: mat-typography-config-level-from-mdc(headline5), |
| 32 | + $headline-6: mat-typography-config-level-from-mdc(headline6), |
| 33 | + $subtitle-1: mat-typography-config-level-from-mdc(subtitle1), |
| 34 | + $subtitle-2: mat-typography-config-level-from-mdc(subtitle2), |
| 35 | + $body-1: mat-typography-config-level-from-mdc(body1), |
| 36 | + $body-2: mat-typography-config-level-from-mdc(body2), |
| 37 | + $caption: mat-typography-config-level-from-mdc(caption), |
| 38 | + $button: mat-typography-config-level-from-mdc(button), |
| 39 | + $overline: mat-typography-config-level-from-mdc(overline), |
| 40 | +) { |
| 41 | + // Declare an initial map with all of the levels. |
| 42 | + $config: ( |
| 43 | + headline-1: $headline-1, |
| 44 | + headline-2: $headline-2, |
| 45 | + headline-3: $headline-3, |
| 46 | + headline-4: $headline-4, |
| 47 | + headline-5: $headline-5, |
| 48 | + headline-6: $headline-6, |
| 49 | + subtitle-1: $subtitle-1, |
| 50 | + subtitle-2: $subtitle-2, |
| 51 | + body-1: $body-1, |
| 52 | + body-2: $body-2, |
| 53 | + caption: $caption, |
| 54 | + button: $button, |
| 55 | + overline: $overline, |
| 56 | + ); |
| 57 | + |
| 58 | + // Loop through the levels and set the `font-family` of the ones that don't have one to the base. |
| 59 | + // Note that Sass can't modify maps in place, which means that we need to merge and re-assign. |
| 60 | + @each $key, $level in $config { |
| 61 | + @if map-get($level, font-family) == null { |
| 62 | + $new-level: map-merge($level, (font-family: $font-family)); |
| 63 | + $config: map-merge($config, ($key: $new-level)); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // Add the base font family to the config. |
| 68 | + @return map-merge($config, (font-family: $font-family)); |
| 69 | +} |
| 70 | + |
3 | 71 | @mixin angular-material-mdc-typography($config-or-theme: null) {
|
4 | 72 | $config: if(mat-private-is-theme-object($config-or-theme),
|
5 | 73 | mat-get-typography-config($config-or-theme), $config-or-theme);
|
|
0 commit comments