Skip to content

Commit 64ab823

Browse files
committed
fix(material-experimental/mdc-typography): change mdc components to prefer
2018 typography mappings if the config is compatible (cherry picked from commit b8cdb83)
1 parent c87506e commit 64ab823

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

src/material-experimental/mdc-helpers/_mdc-helpers.scss

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ $mat-theme-styles-query: color;
1818
$mat-typography-styles-query: typography;
1919

2020
// Mappings between Angular Material and MDC's typography levels.
21-
$mat-typography-level-mappings: (
21+
// TODO: delete once all MDC components have migrated to using the 2018 mappings.
22+
$mat-typography-2014-level-mappings: (
2223
mdc-to-mat: (
2324
headline1: display-4,
2425
headline2: display-3,
@@ -51,9 +52,49 @@ $mat-typography-level-mappings: (
5152
)
5253
);
5354

55+
// Mappings between Angular Material and MDC's typography levels.
56+
$mat-typography-2018-level-mappings: (
57+
// Maps from MDC typography levels (e.g. body1) to Angular Material typography levels
58+
// (e.g. body-1).
59+
mdc-to-mat: (
60+
headline1: headline-1,
61+
headline2: headline-2,
62+
headline3: headline-3,
63+
headline4: headline-4,
64+
headline5: headline-5,
65+
headline6: headline-6,
66+
subtitle1: subtitle-1,
67+
subtitle2: subtitle-2,
68+
body1: body-1,
69+
body2: body-2,
70+
caption: caption,
71+
button: button,
72+
overline: overline
73+
),
74+
// Maps from Angular Material typography levels (e.g. body-1) to MDC typography levels
75+
// (e.g. body1).
76+
mat-to-mdc: (
77+
headline-1: headline1,
78+
headline-2: headline2,
79+
headline-3: headline3,
80+
headline-4: headline4,
81+
headline-5: headline5,
82+
headline-6: headline6,
83+
subtitle-1: subtitle1,
84+
subtitle-2: subtitle2,
85+
body-1: body1,
86+
body-2: body2,
87+
caption: caption,
88+
button: button,
89+
overline: overline
90+
)
91+
);
92+
5493
// Converts an Angular Material typography level config to an MDC one.
5594
@function mat-typography-level-config-to-mdc($mat-config, $mat-level) {
56-
$mdc-level: map-get(map-get($mat-typography-level-mappings, mat-to-mdc), $mat-level);
95+
$mappings: if(mat-private-typography-is-2018-config($mat-config),
96+
$mat-typography-2018-level-mappings, $mat-typography-2014-level-mappings);
97+
$mdc-level: map-get(map-get($mappings, mat-to-mdc), $mat-level);
5798

5899
@return map-merge(
59100
if($mdc-level,
@@ -81,7 +122,10 @@ $mat-typography-level-mappings: (
81122
@function mat-typography-config-to-mdc($mat-config: mat-typography-config()) {
82123
$mdc-config: ();
83124

84-
@each $mdc-level, $mat-level in map-get($mat-typography-level-mappings, mdc-to-mat) {
125+
$mappings: if(mat-private-typography-is-2018-config($mat-config),
126+
$mat-typography-2018-level-mappings, $mat-typography-2014-level-mappings);
127+
128+
@each $mdc-level, $mat-level in map-get($mappings, mdc-to-mat) {
85129
$mdc-config: map-merge(
86130
$mdc-config,
87131
($mdc-level: mat-typography-level-config-to-mdc($mat-config, $mat-level)));
@@ -100,17 +144,6 @@ $mat-typography-level-mappings: (
100144
map-get($mdc-typography-styles, letter-spacing));
101145
}
102146

103-
// Converts an MDC typography config to an Angular Material one.
104-
@function mat-typography-config-from-mdc() {
105-
$mat-config: ();
106-
107-
@each $mat-level, $mdc-level in map-get($mat-typography-level-mappings, mat-to-mdc) {
108-
$mat-config: map-merge($mat-config, mat-typography-config-from-mdc($mdc-level));
109-
}
110-
111-
@return $mat-config;
112-
}
113-
114147
// Configures MDC's global variables to reflect the given theme, applies the given styles,
115148
// then resets the global variables to prevent unintended side effects.
116149
/* stylelint-disable-next-line material/theme-mixin-api */

0 commit comments

Comments
 (0)