Skip to content

Commit 3b41c0c

Browse files
crisbetokara
authored andcommitted
feat(typography): allow font-family to be set per typography level (#5905)
Fixes #5563.
1 parent 1e0c1fc commit 3b41c0c

File tree

9 files changed

+42
-23
lines changed

9 files changed

+42
-23
lines changed

src/lib/button/_button-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
@mixin mat-button-typography($config) {
110110
.mat-button, .mat-raised-button, .mat-icon-button {
111111
font: {
112-
family: mat-font-family($config);
112+
family: mat-font-family($config, button);
113113
size: mat-font-size($config, button);
114114
weight: mat-font-weight($config, button);
115115
}

src/lib/core/option/_option-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@mixin mat-option-typography($config) {
4848
.mat-option {
4949
font: {
50-
family: mat-font-family($config);
50+
family: mat-font-family($config, subheading-2);
5151
size: mat-font-size($config, subheading-2);
5252
}
5353
}

src/lib/core/typography/_typography-utils.scss

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
}
2020

2121
// Gets the font-family from a typography config and removes the quotes around it.
22-
@function mat-font-family($config) {
23-
@return unquote(map-get($config, font-family));
22+
@function mat-font-family($config, $level: null) {
23+
$font-family: map-get($config, font-family);
24+
25+
@if $level != null {
26+
$font-family: _mat-get-type-value($config, $level, font-family);
27+
}
28+
29+
@return unquote($font-family);
2430
}
2531

2632
// Converts a typography level into CSS styles.
2733
@mixin mat-typography-level-to-styles($config, $level) {
2834
$font-size: mat-font-size($config, $level);
2935
$font-weight: mat-font-weight($config, $level);
3036
$line-height: mat-line-height($config, $level);
31-
$font-family: mat-font-family($config);
37+
$font-family: mat-font-family($config, $level);
3238

3339
// Use the shorthand `font` to represent a typography level, because it's the shortest. Notes that
3440
// we need to use interpolation for `font-size/line-height` in order to prevent SASS from dividing

src/lib/core/typography/_typography.scss

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
@import 'typography-utils';
22

33
// 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+
510
@return (
611
font-size: $font-size,
712
line-height: $line-height,
8-
font-weight: $font-weight
13+
font-weight: $font-weight,
14+
font-family: $font-family
915
);
1016
}
1117

@@ -28,8 +34,9 @@
2834
// Line-height must be unit-less fraction of the font-size.
2935
$input: mat-typography-level(inherit, 1.125, 400)
3036
) {
31-
@return (
32-
font-family: $font-family,
37+
38+
// Declare an initial map with all of the levels.
39+
$config: (
3340
display-4: $display-4,
3441
display-3: $display-3,
3542
display-2: $display-2,
@@ -44,6 +51,18 @@
4451
button: $button,
4552
input: $input,
4653
);
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));
4766
}
4867

4968
// Adds the base typography styles, based on a config.
@@ -74,15 +93,15 @@
7493
.mat-h5, #{$selector} h5 {
7594
font-size: mat-font-size($config, body-1) * 0.83;
7695
font-weight: mat-font-weight($config, body-1);
77-
font-family: mat-font-family($config);
96+
font-family: mat-font-family($config, body-1);
7897
line-height: mat-line-height($config, body-1);
7998
margin: 0 0 12px;
8099
}
81100

82101
.mat-h6, #{$selector} h6 {
83102
font-size: mat-font-size($config, body-1) * 0.67;
84103
font-weight: mat-font-weight($config, body-1);
85-
font-family: mat-font-family($config);
104+
font-family: mat-font-family($config, body-1);
86105
line-height: mat-line-height($config, body-1);
87106
margin: 0 0 12px;
88107
}

src/lib/expansion/_expansion-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
@mixin mat-expansion-panel-typography($config) {
3737
.mat-expansion-panel-header {
3838
font: {
39-
family: mat-font-family($config);
39+
family: mat-font-family($config, subheading-1);
4040
size: mat-font-size($config, subheading-1);
4141
weight: mat-font-weight($config, subheading-1);
4242
}

src/lib/menu/_menu-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@mixin mat-menu-typography($config) {
3939
.mat-menu-item {
4040
font: {
41-
family: mat-font-family($config);
41+
family: mat-font-family($config, subheading-2);
4242
size: mat-font-size($config, subheading-2);
4343
}
4444
}

src/lib/paginator/_paginator-theme.scss

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@
3131
}
3232

3333
@mixin mat-paginator-typography($config) {
34-
.mat-paginator {
35-
font: {
36-
family: mat-font-family($config);
37-
size: mat-font-size($config, caption);
38-
}
39-
}
40-
34+
.mat-paginator,
4135
.mat-paginator-page-size .mat-select-trigger {
4236
font: {
43-
family: mat-font-family($config);
37+
family: mat-font-family($config, caption);
4438
size: mat-font-size($config, caption);
4539
}
4640
}

src/lib/snack-bar/_simple-snack-bar-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@mixin mat-simple-snack-bar-typography($config) {
66
.mat-simple-snackbar {
77
font: {
8-
family: mat-font-family($config);
8+
family: mat-font-family($config, body-1);
99
size: mat-font-size($config, body-1);
1010
}
1111
}

src/lib/tabs/_tabs-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
.mat-tab-label, .mat-tab-link {
4949
font: {
50-
family: mat-font-family($config);
50+
family: mat-font-family($config, button);
5151
size: mat-font-size($config, button);
5252
weight: mat-font-weight($config, button);
5353
}

0 commit comments

Comments
 (0)