Skip to content

refactor(material/typography): Move define-typography-config under _typography.scss #27195

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 2 commits into from
May 31, 2023
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
8 changes: 4 additions & 4 deletions src/material/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
$amber-palette, $orange-palette, $deep-orange-palette, $brown-palette, $grey-palette,
$gray-palette, $blue-grey-palette, $blue-gray-palette, $light-theme-background-palette,
$dark-theme-background-palette, $light-theme-foreground-palette, $dark-theme-foreground-palette;
@forward './core/typography/typography' show define-typography-level,
define-legacy-typography-config, legacy-typography-hierarchy, typography-hierarchy;
@forward './core/typography/typography' show define-typography-level, define-rem-typography-config,
define-typography-config, typography-hierarchy, define-legacy-typography-config,
legacy-typography-hierarchy;
@forward './core/typography/typography-utils' show typography-level,
font-size, line-height, font-weight, letter-spacing, font-family, font-shorthand;

Expand Down Expand Up @@ -48,8 +49,7 @@
// Theme bundles
@forward './core/theming/all-theme' show all-component-themes;
@forward './core/color/all-color' show all-component-colors;
@forward './core/typography/all-typography' show all-component-typographies,
define-rem-typography-config, define-typography-config;
@forward './core/typography/all-typography' show all-component-typographies;
@forward './legacy-core/theming/all-theme' show all-legacy-component-themes;
@forward './legacy-core/color/all-color' show all-legacy-component-colors;
@forward './legacy-core/typography/all-typography' show all-legacy-component-typographies;
Expand Down
41 changes: 13 additions & 28 deletions src/material/core/mdc-helpers/_mdc-helpers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ $mat-typography-mdc-level-mappings: (
@return $mdc-config;
}

// Converts an MDC typography level config to an Angular Material one.
@function typography-config-level-from-mdc($mdc-level, $font-family: null) {
$mdc-level-config: map.get(mdc-typography.$styles, $mdc-level);

// Explicitly default the font family to null since we'll apply it globally
// through the `define-typgraphy-config`/`define-legacy-typography-config`.
@return typography.define-typography-level(
$font-family: $font-family,
$font-size: map.get($mdc-level-config, font-size),
$line-height: map.get($mdc-level-config, line-height),
$font-weight: map.get($mdc-level-config, font-weight),
$letter-spacing: map.get($mdc-level-config, letter-spacing)
);
}

// MDC logs a warning if the `contrast-tone` function is called with a CSS variable.
// This function falls back to determining the tone based on whether the theme is light or dark.
@function variable-safe-contrast-tone($value, $is-dark) {
Expand Down Expand Up @@ -238,19 +223,19 @@ $mat-typography-mdc-level-mappings: (
$font-family: mdc-typography.$font-family;
@return (
font-family: $font-family,
headline-1: typography-config-level-from-mdc(headline1, $font-family),
headline-2: typography-config-level-from-mdc(headline2, $font-family),
headline-3: typography-config-level-from-mdc(headline3, $font-family),
headline-4: typography-config-level-from-mdc(headline4, $font-family),
headline-5: typography-config-level-from-mdc(headline5, $font-family),
headline-6: typography-config-level-from-mdc(headline6, $font-family),
subtitle-1: typography-config-level-from-mdc(subtitle1, $font-family),
subtitle-2: typography-config-level-from-mdc(subtitle2, $font-family),
body-1: typography-config-level-from-mdc(body1, $font-family),
body-2: typography-config-level-from-mdc(body2, $font-family),
caption: typography-config-level-from-mdc(caption, $font-family),
button: typography-config-level-from-mdc(button, $font-family),
overline: typography-config-level-from-mdc(overline, $font-family),
headline-1: typography.typography-config-level-from-mdc(headline1, $font-family),
headline-2: typography.typography-config-level-from-mdc(headline2, $font-family),
headline-3: typography.typography-config-level-from-mdc(headline3, $font-family),
headline-4: typography.typography-config-level-from-mdc(headline4, $font-family),
headline-5: typography.typography-config-level-from-mdc(headline5, $font-family),
headline-6: typography.typography-config-level-from-mdc(headline6, $font-family),
subtitle-1: typography.typography-config-level-from-mdc(subtitle1, $font-family),
subtitle-2: typography.typography-config-level-from-mdc(subtitle2, $font-family),
body-1: typography.typography-config-level-from-mdc(body1, $font-family),
body-2: typography.typography-config-level-from-mdc(body2, $font-family),
caption: typography.typography-config-level-from-mdc(caption, $font-family),
button: typography.typography-config-level-from-mdc(button, $font-family),
overline: typography.typography-config-level-from-mdc(overline, $font-family),
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/material/core/theming/prebuilt/deeppurple-amber.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@use '../../core';
@use '../palette';
@use '../theming';
@use '../../typography/all-typography';
@use '../../typography/typography';

// Include non-theme styles for core.
Expand All @@ -17,7 +16,7 @@ $theme: theming.define-light-theme((
primary: $primary,
accent: $accent,
),
typography: all-typography.define-typography-config(),
typography: typography.define-typography-config(),
density: 0,
));

Expand Down
3 changes: 1 addition & 2 deletions src/material/core/theming/prebuilt/indigo-pink.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@use '../../core';
@use '../palette';
@use '../theming';
@use '../../typography/all-typography';
@use '../../typography/typography';


Expand All @@ -18,7 +17,7 @@ $theme: theming.define-light-theme((
primary: $primary,
accent: $accent
),
typography: all-typography.define-typography-config(),
typography: typography.define-typography-config(),
density: 0,
));

Expand Down
3 changes: 1 addition & 2 deletions src/material/core/theming/prebuilt/pink-bluegrey.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@use '../../core';
@use '../palette';
@use '../theming';
@use '../../typography/all-typography';
@use '../../typography/typography';


Expand All @@ -18,7 +17,7 @@ $theme: theming.define-dark-theme((
primary: $primary,
accent: $accent
),
typography: all-typography.define-typography-config(),
typography: typography.define-typography-config(),
density: 0,
));

Expand Down
3 changes: 1 addition & 2 deletions src/material/core/theming/prebuilt/purple-green.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@use '../../core';
@use '../palette';
@use '../theming';
@use '../../typography/all-typography';
@use '../../typography/typography';


Expand All @@ -18,7 +17,7 @@ $theme: theming.define-dark-theme((
primary: $primary,
accent: $accent
),
typography: all-typography.define-typography-config(),
typography: typography.define-typography-config(),
density: 0,
));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use 'sass:map';
@use 'sass:meta';
@use '../all-theme';
@use '../../typography/all-typography';
@use '../../typography/typography';
@use '../palette';
@use '../theming';
@use '../../../legacy-core/theming/all-theme' as legacy-all-theme;
Expand Down Expand Up @@ -31,7 +31,7 @@
accent: $palette,
warn: $palette
),
typography: all-typography.define-typography-config(),
typography: typography.define-typography-config(),
));
$css-var-theme: _replace-all-values($theme, var(--test-var));
@include all-theme.all-component-themes($css-var-theme);
Expand Down
2 changes: 1 addition & 1 deletion src/material/core/theming/tests/test-theming-api.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $new-api-dark-theme-default-warn: theming.define-dark-theme((
$light-theme-only-density: theming.define-light-theme((density: -2));
$dark-theme-only-density: theming.define-dark-theme((density: -2));

$typography-config: all-typography.define-typography-config();
$typography-config: typography.define-typography-config();
$light-theme-only-typography: theming.define-light-theme((typography: $typography-config));
$dark-theme-only-typography: theming.define-dark-theme((typography: $typography-config));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use '@material/typography' as mdc-typography;
@use '../../typography/all-typography';
@use '../../typography/typography';
@use 'sass:map';
@use 'sass:meta';
Expand All @@ -16,17 +15,17 @@

$no-font-family: assert-font-family(
'should take default MDC font family if none is specified',
all-typography.define-typography-config(),
typography.define-typography-config(),
mdc-typography.$font-family);

$only-top-level-font-family: assert-font-family(
'should take custom font family if specified at top level',
all-typography.define-typography-config($font-family: 'custom-top'),
typography.define-typography-config($font-family: 'custom-top'),
'custom-top');

$individual-levels-without-font-families: assert-font-family(
'should set the default MDC font family if all keys are specified, but without a font-family',
all-typography.define-typography-config(
typography.define-typography-config(
$headline-1: typography.define-typography-level($font-size: 1px),
$headline-2: typography.define-typography-level($font-size: 1px),
$headline-3: typography.define-typography-level($font-size: 1px),
Expand All @@ -46,7 +45,7 @@ $individual-levels-without-font-families: assert-font-family(

$individual-levels-without-font-families-with-top-level-family: assert-font-family(
'should set a custom top-level font family if all keys are specified, but without a font-family',
all-typography.define-typography-config(
typography.define-typography-config(
$font-family: 'custom-top',
$headline-1: typography.define-typography-level($font-size: 1px),
$headline-2: typography.define-typography-level($font-size: 1px),
Expand All @@ -67,7 +66,7 @@ $individual-levels-without-font-families-with-top-level-family: assert-font-fami

$individual-levels-with-font-families: assert-font-family(
'should use the level font family if one is specified, but there is none at the top level',
all-typography.define-typography-config(
typography.define-typography-config(
$headline-1: typography.define-typography-level($font-size: 1px, $font-family: 'custom-level'),
$headline-2: typography.define-typography-level($font-size: 1px, $font-family: 'custom-level'),
$headline-3: typography.define-typography-level($font-size: 1px, $font-family: 'custom-level'),
Expand All @@ -87,7 +86,7 @@ $individual-levels-with-font-families: assert-font-family(

$individual-levels-with-font-families-and-top-level-family: assert-font-family(
'should use the level font family if a top-level one is specified together with it',
all-typography.define-typography-config(
typography.define-typography-config(
$font-family: 'custom-top',
$headline-1: typography.define-typography-level($font-size: 1px, $font-family: 'custom-level'),
$headline-2: typography.define-typography-level($font-size: 1px, $font-family: 'custom-level'),
Expand Down
4 changes: 2 additions & 2 deletions src/material/core/tokens/_token-utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
@use '@material/theme/custom-properties' as mdc-custom-properties;
@use '@material/theme/theme' as mdc-theme;
@use '@material/theme/keys' as mdc-keys;
@use '../mdc-helpers/mdc-helpers';
@use '../theming/palette';
@use '../theming/theming';
@use '../typography/typography';

$_placeholder-color-palette: theming.define-palette(palette.$red-palette);

Expand All @@ -20,7 +20,7 @@ $placeholder-color-config: (
background: palette.$light-theme-background-palette,
);

$_placeholder-typography-level-config: mdc-helpers.typography-config-level-from-mdc(body1);
$_placeholder-typography-level-config: typography.typography-config-level-from-mdc(body1);

// Placeholder typography config that can be passed to token getter functions when generating token
// slots.
Expand Down
Loading