Skip to content

Commit c6bdf7f

Browse files
committed
feat(material-experimental/mdc-typography): add a function to create
config from MDC
1 parent 9cd2c46 commit c6bdf7f

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

src/dev-app/theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// have to load a single css file for Angular Material in your app.
2020
// **Be sure that you only ever include this mixin once!**
2121
@include mat-core();
22-
@include angular-material-mdc-typography();
22+
@include angular-material-mdc-typography(mat-mdc-typography-config());
2323
@include mat-popover-edit-typography(mat-typography-config());
2424

2525
// Include base styles for strong focus indicators.

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ $mat-typography-2018-level-mappings: (
132132

133133
// Converts an MDC typography level config to an Angular Material one.
134134
@function mat-typography-config-level-from-mdc($mdc-level) {
135+
$mdc-level-config: map-get($mdc-typography-styles, $mdc-level);
136+
135137
@return mat-typography-level(
136-
map-get($mdc-typography-styles, font-size),
137-
map-get($mdc-typography-styles, line-height),
138-
map-get($mdc-typography-styles, font-weight),
139-
map-get($mdc-typography-styles, font-family),
140-
map-get($mdc-typography-styles, letter-spacing));
138+
map-get($mdc-level-config, font-size),
139+
map-get($mdc-level-config, line-height),
140+
map-get($mdc-level-config, font-weight),
141+
map-get($mdc-level-config, font-family),
142+
map-get($mdc-level-config, letter-spacing));
141143
}
142144

143145
// Configures MDC's global variables to reflect the given theme, applies the given styles,

src/material-experimental/mdc-typography/_all-typography.scss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
1+
@import '@material/typography/variables.import';
12
@import '../mdc-theming/all-theme';
23

4+
@function mat-mdc-typography-config(
5+
$font-family: $mdc-typography-font-family,
6+
$headline-1: mat-typography-config-level-from-mdc(headline1),
7+
$headline-2: mat-typography-config-level-from-mdc(headline2),
8+
$headline-3: mat-typography-config-level-from-mdc(headline3),
9+
$headline-4: mat-typography-config-level-from-mdc(headline4),
10+
$headline-5: mat-typography-config-level-from-mdc(headline5),
11+
$headline-6: mat-typography-config-level-from-mdc(headline6),
12+
$subtitle-1: mat-typography-config-level-from-mdc(subtitle1),
13+
$subtitle-2: mat-typography-config-level-from-mdc(subtitle2),
14+
$body-1: mat-typography-config-level-from-mdc(body1),
15+
$body-2: mat-typography-config-level-from-mdc(body2),
16+
$caption: mat-typography-config-level-from-mdc(caption),
17+
$button: mat-typography-config-level-from-mdc(button),
18+
$overline: mat-typography-config-level-from-mdc(overline),
19+
) {
20+
// Declare an initial map with all of the levels.
21+
$config: (
22+
headline-1: $headline-1,
23+
headline-2: $headline-2,
24+
headline-3: $headline-3,
25+
headline-4: $headline-4,
26+
headline-5: $headline-5,
27+
headline-6: $headline-6,
28+
subtitle-1: $subtitle-1,
29+
subtitle-2: $subtitle-2,
30+
body-1: $body-1,
31+
body-2: $body-2,
32+
caption: $caption,
33+
button: $button,
34+
overline: $overline,
35+
);
36+
37+
// Loop through the levels and set the `font-family` of the ones that don't have one to the base.
38+
// Note that Sass can't modify maps in place, which means that we need to merge and re-assign.
39+
@each $key, $level in $config {
40+
@if map-get($level, font-family) == null {
41+
$new-level: map-merge($level, (font-family: $font-family));
42+
$config: map-merge($config, ($key: $new-level));
43+
}
44+
}
45+
46+
// Add the base font family to the config.
47+
@return map-merge($config, (font-family: $font-family));
48+
}
49+
350
@mixin angular-material-mdc-typography($config-or-theme: null) {
451
$config: if(mat-private-is-theme-object($config-or-theme),
552
mat-get-typography-config($config-or-theme), $config-or-theme);

0 commit comments

Comments
 (0)