Skip to content

refactor(material/theming): normalize config in all typography mixins for mdc components #21935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dev-app/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ $candy-app-theme: mat.define-light-theme((
accent: $candy-app-accent
),
// Define the default typography for our app.
// TODO(mmalerba): Update to `mat-mdc-typography-config()` once non-MDC components can handle
// 2018 configs.
typography: mat.define-typography-config(),
// Define the default density level for our app.
density: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use '@material/menu-surface/mixins' as mdc-menu-surface;
@use '@material/list/mixins' as mdc-list;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin color($config-or-theme) {
Expand All @@ -12,7 +13,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-menu-surface.core-styles(mdc-helpers.$mat-typography-styles-query);

Expand Down
10 changes: 7 additions & 3 deletions src/material-experimental/mdc-button/_button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@use '@material/theme/theme' as mdc-theme;
@use '@material/elevation/elevation-theme' as mdc-elevation-theme;
@use '../../material/core/ripple/ripple-theme';
@use '../../material/core/typography/typography';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/theming/theming';

Expand Down Expand Up @@ -189,7 +190,8 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-button.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
}
Expand Down Expand Up @@ -281,7 +283,8 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin fab-typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-fab.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
}
Expand Down Expand Up @@ -350,7 +353,8 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin icon-button-typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-icon-button.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
}
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-card/_card-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@use 'sass:color';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin color($config-or-theme) {
Expand Down Expand Up @@ -34,7 +35,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-card.without-ripple($query: mdc-helpers.$mat-typography-styles-query);

Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@use '@material/theme/theme';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';
@use '../../material/core/ripple/ripple-theme';

Expand Down Expand Up @@ -108,7 +109,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-checkbox.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-typography-styles-query);
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-chips/_chips-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use 'sass:color';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin _selected-color($color) {
Expand Down Expand Up @@ -75,7 +76,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-chips.set-core-styles($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-chips.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use '@material/theme/theme' as mdc-theme;
@use '../../mdc-helpers/mdc-helpers';
@use '../../../material/core/theming/theming';
@use '../../../material/core/typography/typography';

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
Expand All @@ -18,7 +19,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
}

@mixin density($config-or-theme) {
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-core/option/_option-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@use '@material/ripple' as mdc-ripple;
@use '../../mdc-helpers/mdc-helpers';
@use '../../../material/core/theming/theming';
@use '../../../material/core/typography/typography';

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
Expand Down Expand Up @@ -54,7 +55,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));

@include mdc-helpers.mat-using-mdc-typography($config) {
// MDC uses the `subtitle1` level for list items, but the spec shows `body1` as the correct
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-dialog/_dialog-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '@material/dialog' as mdc-dialog;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin color($config-or-theme) {
Expand All @@ -10,7 +11,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-dialog.core-styles($query: mdc-helpers.$mat-typography-styles-query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@use '@material/theme/theme-color' as mdc-theme-color;
@use '@material/typography' as mdc-typography;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use 'form-field-density';
@use 'form-field-subscript';
@use 'form-field-focus-overlay';
Expand Down Expand Up @@ -63,7 +64,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-textfield.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-floating-label.core-styles($query: mdc-helpers.$mat-typography-styles-query);
Expand Down
93 changes: 16 additions & 77 deletions src/material-experimental/mdc-helpers/_mdc-helpers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,26 @@ $mat-base-styles-without-animation-query:
$mat-theme-styles-query: color;
$mat-typography-styles-query: typography;

// Mappings between Angular Material and MDC's typography levels.
// TODO: delete once all MDC components have migrated to using the 2018 mappings.
$mat-typography-2014-level-mappings: (
mdc-to-mat: (
headline1: display-4,
headline2: display-3,
headline3: display-2,
headline4: display-1,
headline5: headline,
headline6: title,
subtitle1: subheading-2,
subtitle2: subheading-1,
body1: body-2,
body2: body-1,
// Mappings from Angular Material's typography levels to MDC's typography levels.
$mat-typography-mdc-level-mappings: (
headline-1: headline1,
headline-2: headline2,
headline-3: headline3,
headline-4: headline4,
headline-5: headline5,
headline-6: headline6,
subtitle-1: subtitle1,
subtitle-2: subtitle2,
body-1: body1,
body-2: body2,
caption: caption,
button: button,
overline: null
),
mat-to-mdc: (
display-4: headline1,
display-3: headline2,
display-2: headline3,
display-1: headline4,
headline: headline5,
title: headline6,
subheading-2: subtitle1,
subheading-1: subtitle2,
body-2: body1,
body-1: body2,
caption: caption,
button: button,
input: null
)
);

// Mappings between Angular Material and MDC's typography levels.
$mat-typography-2018-level-mappings: (
// Maps from MDC typography levels (e.g. body1) to Angular Material typography levels
// (e.g. body-1).
mdc-to-mat: (
headline1: headline-1,
headline2: headline-2,
headline3: headline-3,
headline4: headline-4,
headline5: headline-5,
headline6: headline-6,
subtitle1: subtitle-1,
subtitle2: subtitle-2,
body1: body-1,
body2: body-2,
caption: caption,
button: button,
overline: overline
),
// Maps from Angular Material typography levels (e.g. body-1) to MDC typography levels
// (e.g. body1).
mat-to-mdc: (
headline-1: headline1,
headline-2: headline2,
headline-3: headline3,
headline-4: headline4,
headline-5: headline5,
headline-6: headline6,
subtitle-1: subtitle1,
subtitle-2: subtitle2,
body-1: body1,
body-2: body2,
caption: caption,
button: button,
overline: overline
)
overline: overline
);

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

$result-with-nulls: map.merge(
if($mdc-level,
Expand Down Expand Up @@ -130,13 +72,10 @@ $mat-typography-2018-level-mappings: (
}

// Converts an Angular Material typography config to an MDC one.
@function mat-typography-config-to-mdc($mat-config: typography.define-mdc-typography-config()) {
@function mat-typography-config-to-mdc($mat-config) {
$mdc-config: ();

$mappings: if(typography.private-typography-is-2018-config($mat-config),
$mat-typography-2018-level-mappings, $mat-typography-2014-level-mappings);

@each $mdc-level, $mat-level in map.get($mappings, mdc-to-mat) {
@each $mat-level, $mdc-level in $mat-typography-mdc-level-mappings {
$mdc-config: map.merge(
$mdc-config,
($mdc-level: mat-typography-level-config-to-mdc($mat-config, $mat-level)));
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-input/_input-theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin color($config-or-theme) {
Expand All @@ -7,7 +8,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {}
}

Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-list/_list-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use './interactive-list-theme';
@use './list-option-theme';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';


Expand Down Expand Up @@ -52,7 +53,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-list.deprecated-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include list-option-theme.private-list-option-typography-styles();
Expand Down
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-menu/_menu-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@use '@material/typography' as mdc-typography;
@use '@material/ripple' as mdc-ripple;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@mixin color($config-or-theme) {
Expand Down Expand Up @@ -44,7 +45,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-menu-surface.core-styles(mdc-helpers.$mat-typography-styles-query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use 'sass:map';
@use '../../material/core/theming/theming';
@use '../../material/core/density/private/compatibility';
@use '../../material/core/typography/typography';
@use '../mdc-helpers/mdc-helpers';
@use './paginator-variables';
@use '../../material/core/typography/typography-utils';
Expand Down Expand Up @@ -48,7 +49,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));

@include mdc-helpers.mat-using-mdc-typography($config) {
.mat-mdc-paginator {
Expand Down
5 changes: 3 additions & 2 deletions src/material-experimental/mdc-radio/_radio-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
@use '@material/radio/radio' as mdc-radio;
@use '@material/form-field' as mdc-form-field;
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';


@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
// Save original values of MDC global variables. We need to save these so we can restore the
Expand Down Expand Up @@ -45,7 +45,8 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-radio.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-typography-styles-query);
Expand Down
Loading