|
1 | 1 | @import 'typography-utils'; |
2 | 2 |
|
3 | 3 | // Represents a typography level from the Material design spec. |
4 | | -@function mat-typography-level($font-size, $line-height: $font-size, $font-weight: 400) { |
| 4 | +@function mat-typography-level( |
| 5 | + $font-size, |
| 6 | + $line-height: $font-size, |
| 7 | + $font-weight: 400, |
| 8 | + $font-family: null) { |
| 9 | + |
5 | 10 | @return ( |
6 | 11 | font-size: $font-size, |
7 | 12 | line-height: $line-height, |
8 | | - font-weight: $font-weight |
| 13 | + font-weight: $font-weight, |
| 14 | + font-family: $font-family |
9 | 15 | ); |
10 | 16 | } |
11 | 17 |
|
|
28 | 34 | // Line-height must be unit-less fraction of the font-size. |
29 | 35 | $input: mat-typography-level(inherit, 1.125, 400) |
30 | 36 | ) { |
31 | | - @return ( |
32 | | - font-family: $font-family, |
| 37 | + |
| 38 | + // Declare an initial map with all of the levels. |
| 39 | + $config: ( |
33 | 40 | display-4: $display-4, |
34 | 41 | display-3: $display-3, |
35 | 42 | display-2: $display-2, |
|
44 | 51 | button: $button, |
45 | 52 | input: $input, |
46 | 53 | ); |
| 54 | + |
| 55 | + // Loop through the levels and set the `font-family` of the ones that don't have one to the base. |
| 56 | + // Note that SASS can't modify maps in place, which means that we need to merge and re-assign. |
| 57 | + @each $key, $level in $config { |
| 58 | + @if map-get($level, font-family) == null { |
| 59 | + $new-level: map-merge($level, (font-family: $font-family)); |
| 60 | + $config: map-merge($config, ($key: $new-level)); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + // Add the base font family to the config. |
| 65 | + @return map-merge($config, (font-family: $font-family)); |
47 | 66 | } |
48 | 67 |
|
49 | 68 | // Adds the base typography styles, based on a config. |
|
74 | 93 | .mat-h5, #{$selector} h5 { |
75 | 94 | font-size: mat-font-size($config, body-1) * 0.83; |
76 | 95 | font-weight: mat-font-weight($config, body-1); |
77 | | - font-family: mat-font-family($config); |
| 96 | + font-family: mat-font-family($config, body-1); |
78 | 97 | line-height: mat-line-height($config, body-1); |
79 | 98 | margin: 0 0 12px; |
80 | 99 | } |
81 | 100 |
|
82 | 101 | .mat-h6, #{$selector} h6 { |
83 | 102 | font-size: mat-font-size($config, body-1) * 0.67; |
84 | 103 | font-weight: mat-font-weight($config, body-1); |
85 | | - font-family: mat-font-family($config); |
| 104 | + font-family: mat-font-family($config, body-1); |
86 | 105 | line-height: mat-line-height($config, body-1); |
87 | 106 | margin: 0 0 12px; |
88 | 107 | } |
|
0 commit comments