Skip to content

Commit

Permalink
refactor(material/theming): normalize config in all typography mixins
Browse files Browse the repository at this point in the history
for mdc components

This is split off of angular#21778 which covers non-MDC conmponents as well
  • Loading branch information
mmalerba committed Mar 3, 2021
1 parent 9cbfd91 commit 99b3dc8
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 113 deletions.
2 changes: 2 additions & 0 deletions src/dev-app/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ $candy-app-theme: theming.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: all-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,4 +1,5 @@
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';
@import '@material/menu-surface/mixins.import';
@import '@material/list/mixins.import';
Expand All @@ -12,7 +13,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
7 changes: 4 additions & 3 deletions src/material-experimental/mdc-button/_button-theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../../material/core/ripple/ripple';
@use '../../material/core/typography/typography';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/theming/theming';
@import '@material/button/mixins.import';
Expand Down Expand Up @@ -174,7 +175,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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 @@ -261,7 +262,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin fab-typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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 @@ -334,7 +335,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
}

@mixin icon-button-typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-card/_card-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'sass:color';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';
@import '@material/card/mixins.import';
@import '@material/theme/functions.import';
Expand Down Expand Up @@ -35,7 +36,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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';

Expand Down Expand Up @@ -110,7 +111,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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: 2 additions & 2 deletions src/material-experimental/mdc-chips/_chips-theme.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@use 'sass:color';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';
@import '@material/chips/mixins.import';

@import '@material/theme/functions.import';

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

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
@include mdc-chip-set-core-styles($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-chip-without-ripple($query: mdc-helpers.$mat-typography-styles-query);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@use '../../mdc-helpers/mdc-helpers';
@use '../../../material/core/theming/theming';
@use '../../../material/core/typography/typography';
@import '@material/list/mixins.import';
@import '@material/list/variables.import';
@import '@material/theme/functions.import';
@import '@material/theme/mixins.import';


@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);

Expand All @@ -20,7 +22,7 @@
}

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

@mixin density($config-or-theme) {
Expand Down
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-core/option/_option-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '../../mdc-helpers/mdc-helpers';
@use '../../../material/core/theming/theming';
@use '../../../material/core/typography/typography';
@import '@material/list/mixins.import';
@import '@material/list/variables.import';
@import '@material/theme/functions.import';
Expand Down Expand Up @@ -46,7 +47,7 @@
}

@mixin option-typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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: 2 additions & 2 deletions src/material-experimental/mdc-dialog/_dialog-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';

@import '@material/dialog/mixins.import';

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

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
@@ -1,6 +1,7 @@
@use '@material/ripple/mixins' as mdc-ripple;
@use '@material/textfield/variables' as mdc-text-field;
@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,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2018-config(theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-text-field-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.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
3 changes: 2 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,7 @@
}

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

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

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-menu/_menu-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';
@import '@material/menu-surface/mixins.import';
@import '@material/menu-surface/variables.import';
Expand Down Expand Up @@ -45,7 +46,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
@@ -1,6 +1,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 @@ -49,7 +50,7 @@
}

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

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

@import '@material/form-field/mixins.import';
@import '@material/radio/mixins';
@import '@material/radio/variables';
Expand Down Expand Up @@ -45,7 +45,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-select/_select-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';
@import '@material/menu-surface/mixins.import';
@import '@material/list/mixins.import';
Expand Down Expand Up @@ -82,7 +83,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.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
Loading

0 comments on commit 99b3dc8

Please sign in to comment.