Skip to content

Commit 4e8aa52

Browse files
crisbetojelbourn
authored andcommitted
refactor(typography): add mixin for shorthand declaration and use shorthand for h5 and h6 (#9346)
* Moves our `font` declaration shorthand logic into the `mat-typography-font-shorthand` mixin to make it easier to use without passing in a typography config. * Switches the `h5` and `h6` to use the shorthands.
1 parent 8de5e83 commit 4e8aa52

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
@return if($font-family == null, $font-family, unquote($font-family));
3030
}
3131

32-
// Converts a typography level into CSS styles.
33-
@mixin mat-typography-level-to-styles($config, $level) {
34-
$font-size: mat-font-size($config, $level);
35-
$font-weight: mat-font-weight($config, $level);
36-
$line-height: mat-line-height($config, $level);
37-
$font-family: mat-font-family($config, $level);
38-
32+
// Outputs the shorthand `font` CSS property, based on a set of typography values. Falls back to
33+
// the individual properties if a value that isn't allowed in the shorthand is passed in.
34+
@mixin mat-typography-font-shorthand($font-size, $font-weight, $line-height, $font-family) {
3935
// If any of the values are set to `inherit`, we can't use the shorthand
4036
// so we fall back to passing in the individual properties.
4137
@if ($font-size == inherit or
@@ -53,9 +49,19 @@
5349
font-family: $font-family;
5450
}
5551
@else {
56-
// Otherwise use the shorthand `font` to represent a typography level, because it's the the
57-
// least amount of bytes. Note that we need to use interpolation for `font-size/line-height`
58-
// in order to prevent Sass from dividing the two values.
52+
// Otherwise use the shorthand `font`, because it's the least amount of bytes. Note
53+
// that we need to use interpolation for `font-size/line-height` in order to prevent
54+
// Sass from dividing the two values.
5955
font: $font-weight #{$font-size}/#{$line-height} $font-family;
6056
}
6157
}
58+
59+
// Converts a typography level into CSS styles.
60+
@mixin mat-typography-level-to-styles($config, $level) {
61+
$font-size: mat-font-size($config, $level);
62+
$font-weight: mat-font-weight($config, $level);
63+
$line-height: mat-line-height($config, $level);
64+
$font-family: mat-font-family($config, $level);
65+
66+
@include mat-typography-font-shorthand($font-size, $font-weight, $line-height, $font-family);
67+
}

src/lib/core/typography/_typography.scss

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,24 @@
9191
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
9292
// and h6 at 0.67em.
9393
.mat-h5, #{$selector} h5 {
94-
font-size: mat-font-size($config, body-1) * 0.83;
95-
font-weight: mat-font-weight($config, body-1);
96-
font-family: mat-font-family($config, body-1);
97-
line-height: mat-line-height($config, body-1);
94+
@include mat-typography-font-shorthand(
95+
mat-font-size($config, body-1) * 0.83,
96+
mat-font-weight($config, body-1),
97+
mat-line-height($config, body-1),
98+
mat-font-family($config, body-1)
99+
);
100+
98101
margin: 0 0 12px;
99102
}
100103

101104
.mat-h6, #{$selector} h6 {
102-
font-size: mat-font-size($config, body-1) * 0.67;
103-
font-weight: mat-font-weight($config, body-1);
104-
font-family: mat-font-family($config, body-1);
105-
line-height: mat-line-height($config, body-1);
105+
@include mat-typography-font-shorthand(
106+
mat-font-size($config, body-1) * 0.67,
107+
mat-font-weight($config, body-1),
108+
mat-line-height($config, body-1),
109+
mat-font-family($config, body-1)
110+
);
111+
106112
margin: 0 0 12px;
107113
}
108114

0 commit comments

Comments
 (0)