Skip to content

Commit 99b3dc8

Browse files
committed
refactor(material/theming): normalize config in all typography mixins
for mdc components This is split off of #21778 which covers non-MDC conmponents as well
1 parent 9cbfd91 commit 99b3dc8

File tree

25 files changed

+77
-113
lines changed

25 files changed

+77
-113
lines changed

src/dev-app/theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ $candy-app-theme: theming.light-theme((
2828
accent: $candy-app-accent
2929
),
3030
// Define the default typography for our app.
31+
// TODO(mmalerba): Update to `mat-mdc-typography-config()` once non-MDC components can handle
32+
// 2018 configs.
3133
typography: all-typography.config(),
3234
// Define the default density level for our app.
3335
density: 0,

src/material-experimental/mdc-autocomplete/_autocomplete-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
34
@import '@material/menu-surface/mixins.import';
45
@import '@material/list/mixins.import';
@@ -12,7 +13,7 @@
1213
}
1314

1415
@mixin typography($config-or-theme) {
15-
$config: theming.get-typography-config($config-or-theme);
16+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
1617
@include mdc-helpers.mat-using-mdc-typography($config) {
1718
@include mdc-menu-surface-core-styles(mdc-helpers.$mat-typography-styles-query);
1819

src/material-experimental/mdc-button/_button-theme.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '../../material/core/ripple/ripple';
2+
@use '../../material/core/typography/typography';
23
@use '../mdc-helpers/mdc-helpers';
34
@use '../../material/core/theming/theming';
45
@import '@material/button/mixins.import';
@@ -174,7 +175,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
174175
}
175176

176177
@mixin typography($config-or-theme) {
177-
$config: theming.get-typography-config($config-or-theme);
178+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
178179
@include mdc-helpers.mat-using-mdc-typography($config) {
179180
@include mdc-button-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
180181
}
@@ -261,7 +262,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
261262
}
262263

263264
@mixin fab-typography($config-or-theme) {
264-
$config: theming.get-typography-config($config-or-theme);
265+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
265266
@include mdc-helpers.mat-using-mdc-typography($config) {
266267
@include mdc-fab-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
267268
}
@@ -334,7 +335,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
334335
}
335336

336337
@mixin icon-button-typography($config-or-theme) {
337-
$config: theming.get-typography-config($config-or-theme);
338+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
338339
@include mdc-helpers.mat-using-mdc-typography($config) {
339340
@include mdc-icon-button-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
340341
}

src/material-experimental/mdc-card/_card-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'sass:color';
22
@use 'sass:map';
33
@use '../mdc-helpers/mdc-helpers';
4+
@use '../../material/core/typography/typography';
45
@use '../../material/core/theming/theming';
56
@import '@material/card/mixins.import';
67
@import '@material/theme/functions.import';
@@ -35,7 +36,7 @@
3536
}
3637

3738
@mixin typography($config-or-theme) {
38-
$config: theming.get-typography-config($config-or-theme);
39+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
3940
@include mdc-helpers.mat-using-mdc-typography($config) {
4041
@include mdc-card-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
4142

src/material-experimental/mdc-checkbox/_checkbox-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@use '@material/theme/theme';
44
@use 'sass:map';
55
@use '../mdc-helpers/mdc-helpers';
6+
@use '../../material/core/typography/typography';
67
@use '../../material/core/theming/theming';
78
@use '../../material/core/ripple/ripple';
89

@@ -110,7 +111,7 @@
110111
}
111112

112113
@mixin typography($config-or-theme) {
113-
$config: theming.get-typography-config($config-or-theme);
114+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
114115
@include mdc-helpers.mat-using-mdc-typography($config) {
115116
@include mdc-checkbox-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
116117
@include mdc-form-field-core-styles($query: mdc-helpers.$mat-typography-styles-query);

src/material-experimental/mdc-chips/_chips-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@use 'sass:color';
22
@use 'sass:map';
33
@use '../mdc-helpers/mdc-helpers';
4+
@use '../../material/core/typography/typography';
45
@use '../../material/core/theming/theming';
56
@import '@material/chips/mixins.import';
6-
77
@import '@material/theme/functions.import';
88

99
@mixin _selected-color($color) {
@@ -76,7 +76,7 @@
7676
}
7777

7878
@mixin typography($config-or-theme) {
79-
$config: theming.get-typography-config($config-or-theme);
79+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
8080
@include mdc-chip-set-core-styles($query: mdc-helpers.$mat-typography-styles-query);
8181
@include mdc-helpers.mat-using-mdc-typography($config) {
8282
@include mdc-chip-without-ripple($query: mdc-helpers.$mat-typography-styles-query);

src/material-experimental/mdc-core/option/_optgroup-theme.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
@use '../../mdc-helpers/mdc-helpers';
22
@use '../../../material/core/theming/theming';
3+
@use '../../../material/core/typography/typography';
34
@import '@material/list/mixins.import';
45
@import '@material/list/variables.import';
56
@import '@material/theme/functions.import';
67
@import '@material/theme/mixins.import';
78

9+
810
@mixin color($config-or-theme) {
911
$config: theming.get-color-config($config-or-theme);
1012

@@ -20,7 +22,7 @@
2022
}
2123

2224
@mixin typography($config-or-theme) {
23-
$config: theming.get-typography-config($config-or-theme);
25+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
2426
}
2527

2628
@mixin density($config-or-theme) {

src/material-experimental/mdc-core/option/_option-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use '../../mdc-helpers/mdc-helpers';
22
@use '../../../material/core/theming/theming';
3+
@use '../../../material/core/typography/typography';
34
@import '@material/list/mixins.import';
45
@import '@material/list/variables.import';
56
@import '@material/theme/functions.import';
@@ -46,7 +47,7 @@
4647
}
4748

4849
@mixin option-typography($config-or-theme) {
49-
$config: theming.get-typography-config($config-or-theme);
50+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
5051

5152
@include mdc-helpers.mat-using-mdc-typography($config) {
5253
// MDC uses the `subtitle1` level for list items, but the spec shows `body1` as the correct

src/material-experimental/mdc-dialog/_dialog-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
3-
44
@import '@material/dialog/mixins.import';
55

66
@mixin color($config-or-theme) {
@@ -11,7 +11,7 @@
1111
}
1212

1313
@mixin typography($config-or-theme) {
14-
$config: theming.get-typography-config($config-or-theme);
14+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
1515
@include mdc-helpers.mat-using-mdc-typography($config) {
1616
@include mdc-dialog-core-styles($query: mdc-helpers.$mat-typography-styles-query);
1717
}

src/material-experimental/mdc-form-field/_form-field-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use '@material/ripple/mixins' as mdc-ripple;
22
@use '@material/textfield/variables' as mdc-text-field;
33
@use '../mdc-helpers/mdc-helpers';
4+
@use '../../material/core/typography/typography';
45
@use 'form-field-density';
56
@use 'form-field-subscript';
67
@use 'form-field-focus-overlay';
@@ -63,7 +64,7 @@
6364
}
6465

6566
@mixin typography($config-or-theme) {
66-
$config: theming.get-typography-config($config-or-theme);
67+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
6768
@include mdc-helpers.mat-using-mdc-typography($config) {
6869
@include mdc-text-field-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
6970
@include mdc-floating-label-core-styles($query: mdc-helpers.$mat-typography-styles-query);

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

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,84 +19,26 @@ $mat-base-styles-without-animation-query:
1919
$mat-theme-styles-query: color;
2020
$mat-typography-styles-query: typography;
2121

22-
// Mappings between Angular Material and MDC's typography levels.
23-
// TODO: delete once all MDC components have migrated to using the 2018 mappings.
24-
$mat-typography-2014-level-mappings: (
25-
mdc-to-mat: (
26-
headline1: display-4,
27-
headline2: display-3,
28-
headline3: display-2,
29-
headline4: display-1,
30-
headline5: headline,
31-
headline6: title,
32-
subtitle1: subheading-2,
33-
subtitle2: subheading-1,
34-
body1: body-2,
35-
body2: body-1,
22+
// Mappings from Angular Material's typography levels to MDC's typography levels.
23+
$mat-typography-mdc-level-mappings: (
24+
headline-1: headline1,
25+
headline-2: headline2,
26+
headline-3: headline3,
27+
headline-4: headline4,
28+
headline-5: headline5,
29+
headline-6: headline6,
30+
subtitle-1: subtitle1,
31+
subtitle-2: subtitle2,
32+
body-1: body1,
33+
body-2: body2,
3634
caption: caption,
3735
button: button,
38-
overline: null
39-
),
40-
mat-to-mdc: (
41-
display-4: headline1,
42-
display-3: headline2,
43-
display-2: headline3,
44-
display-1: headline4,
45-
headline: headline5,
46-
title: headline6,
47-
subheading-2: subtitle1,
48-
subheading-1: subtitle2,
49-
body-2: body1,
50-
body-1: body2,
51-
caption: caption,
52-
button: button,
53-
input: null
54-
)
55-
);
56-
57-
// Mappings between Angular Material and MDC's typography levels.
58-
$mat-typography-2018-level-mappings: (
59-
// Maps from MDC typography levels (e.g. body1) to Angular Material typography levels
60-
// (e.g. body-1).
61-
mdc-to-mat: (
62-
headline1: headline-1,
63-
headline2: headline-2,
64-
headline3: headline-3,
65-
headline4: headline-4,
66-
headline5: headline-5,
67-
headline6: headline-6,
68-
subtitle1: subtitle-1,
69-
subtitle2: subtitle-2,
70-
body1: body-1,
71-
body2: body-2,
72-
caption: caption,
73-
button: button,
74-
overline: overline
75-
),
76-
// Maps from Angular Material typography levels (e.g. body-1) to MDC typography levels
77-
// (e.g. body1).
78-
mat-to-mdc: (
79-
headline-1: headline1,
80-
headline-2: headline2,
81-
headline-3: headline3,
82-
headline-4: headline4,
83-
headline-5: headline5,
84-
headline-6: headline6,
85-
subtitle-1: subtitle1,
86-
subtitle-2: subtitle2,
87-
body-1: body1,
88-
body-2: body2,
89-
caption: caption,
90-
button: button,
91-
overline: overline
92-
)
36+
overline: overline
9337
);
9438

9539
// Converts an Angular Material typography level config to an MDC one.
9640
@function mat-typography-level-config-to-mdc($mat-config, $mat-level) {
97-
$mappings: if(typography.private-typography-is-2018-config($mat-config),
98-
$mat-typography-2018-level-mappings, $mat-typography-2014-level-mappings);
99-
$mdc-level: map.get(map.get($mappings, mat-to-mdc), $mat-level);
41+
$mdc-level: map.get($mat-typography-mdc-level-mappings, $mat-level);
10042

10143
$result-with-nulls: map.merge(
10244
if($mdc-level,
@@ -130,13 +72,10 @@ $mat-typography-2018-level-mappings: (
13072
}
13173

13274
// Converts an Angular Material typography config to an MDC one.
133-
@function mat-typography-config-to-mdc($mat-config: typography.config()) {
75+
@function mat-typography-config-to-mdc($mat-config) {
13476
$mdc-config: ();
13577

136-
$mappings: if(typography.private-typography-is-2018-config($mat-config),
137-
$mat-typography-2018-level-mappings, $mat-typography-2014-level-mappings);
138-
139-
@each $mdc-level, $mat-level in map.get($mappings, mdc-to-mat) {
78+
@each $mat-level, $mdc-level in $mat-typography-mdc-level-mappings {
14079
$mdc-config: map.merge(
14180
$mdc-config,
14281
($mdc-level: mat-typography-level-config-to-mdc($mat-config, $mat-level)));

src/material-experimental/mdc-input/_input-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
34

45
@mixin color($config-or-theme) {
@@ -7,7 +8,7 @@
78
}
89

910
@mixin typography($config-or-theme) {
10-
$config: theming.get-typography-config($config-or-theme);
11+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
1112
@include mdc-helpers.mat-using-mdc-typography($config) {}
1213
}
1314

src/material-experimental/mdc-list/_list-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use './interactive-list-theme';
33
@use './list-option-theme';
44
@use '../mdc-helpers/mdc-helpers';
5+
@use '../../material/core/typography/typography';
56
@use '../../material/core/theming/theming';
67
@import '@material/list/variables.import';
78
@import '@material/list/mixins.import';
@@ -53,7 +54,7 @@
5354
}
5455

5556
@mixin typography($config-or-theme) {
56-
$config: theming.get-typography-config($config-or-theme);
57+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
5758
@include mdc-helpers.mat-using-mdc-typography($config) {
5859
@include mdc-list-deprecated-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
5960
@include list-option-theme.private-list-option-typography-styles();

src/material-experimental/mdc-menu/_menu-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
34
@import '@material/menu-surface/mixins.import';
45
@import '@material/menu-surface/variables.import';
@@ -45,7 +46,7 @@
4546
}
4647

4748
@mixin typography($config-or-theme) {
48-
$config: theming.get-typography-config($config-or-theme);
49+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
4950
@include mdc-helpers.mat-using-mdc-typography($config) {
5051
@include mdc-menu-surface-core-styles(mdc-helpers.$mat-typography-styles-query);
5152

src/material-experimental/mdc-paginator/_paginator-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'sass:map';
22
@use '../../material/core/theming/theming';
33
@use '../../material/core/density/private/compatibility';
4+
@use '../../material/core/typography/typography';
45
@use '../mdc-helpers/mdc-helpers';
56
@use './paginator-variables';
67
@use '../../material/core/typography/typography-utils';
@@ -49,7 +50,7 @@
4950
}
5051

5152
@mixin typography($config-or-theme) {
52-
$config: theming.get-typography-config($config-or-theme);
53+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
5354

5455
@include mdc-helpers.mat-using-mdc-typography($config) {
5556
.mat-mdc-paginator {

src/material-experimental/mdc-radio/_radio-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
3-
44
@import '@material/form-field/mixins.import';
55
@import '@material/radio/mixins';
66
@import '@material/radio/variables';
@@ -45,7 +45,7 @@
4545
}
4646

4747
@mixin typography($config-or-theme) {
48-
$config: theming.get-typography-config($config-or-theme);
48+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
4949
@include mdc-helpers.mat-using-mdc-typography($config) {
5050
@include mdc-radio-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
5151
@include mdc-form-field-core-styles($query: mdc-helpers.$mat-typography-styles-query);

src/material-experimental/mdc-select/_select-theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '../mdc-helpers/mdc-helpers';
2+
@use '../../material/core/typography/typography';
23
@use '../../material/core/theming/theming';
34
@import '@material/menu-surface/mixins.import';
45
@import '@material/list/mixins.import';
@@ -82,7 +83,7 @@
8283
}
8384

8485
@mixin typography($config-or-theme) {
85-
$config: theming.get-typography-config($config-or-theme);
86+
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
8687
@include mdc-helpers.mat-using-mdc-typography($config) {
8788
@include mdc-menu-surface-core-styles(mdc-helpers.$mat-typography-styles-query);
8889

0 commit comments

Comments
 (0)