Skip to content

Commit 6830350

Browse files
committed
feat(material/core): add typography config normalization function (#21059)
* fix(material/core): add typography config normalization function Future PRs will adopt this function in the typography mixins for our components * fixup! fix(material/core): add typography config normalization function (cherry picked from commit 1a6f9f4)
1 parent 868915e commit 6830350

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/material/core/typography/_typography.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@
6969
@return map-merge($config, (font-family: $font-family));
7070
}
7171

72+
// Whether a config is for the Material Design 2018 typography system.
73+
@function mat-private-typography-is-2018-config($config) {
74+
@return map-get($config, headline-1) != null;
75+
}
76+
77+
// Given a config for either the 2014 or 2018 Material Design typography system,
78+
// produces a normalized typography config for the 2014 Material Design typography system.
79+
// 2014 - https://material.io/archive/guidelines/style/typography.html#typography-styles
80+
// 2018 - https://material.io/design/typography/the-type-system.html#type-scale
81+
@function mat-typography-normalized-config($config) {
82+
@if mat-private-typography-is-2018-config($config) {
83+
@return mat-typography-config(
84+
$display-3: map-get($config, display-1),
85+
$display-2: map-get($config, display-2),
86+
$display-1: map-get($config, display-3),
87+
$headline: map-get($config, headline-4),
88+
$title: map-get($config, subtitle-1),
89+
$subheading-2: map-get($config, subhead-1),
90+
$subheading-1: map-get($config, subhead-2),
91+
$body-2: map-get($config, body-1),
92+
$body-1: map-get($config, body-2),
93+
$caption: map-get($config, caption),
94+
$button: map-get($config, button),
95+
);
96+
}
97+
@return $config;
98+
}
99+
72100
// Adds the base typography styles, based on a config.
73101
/* stylelint-disable-next-line material/theme-mixin-api */
74102
@mixin mat-base-typography($config, $selector: '.mat-typography') {

0 commit comments

Comments
 (0)