Skip to content

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

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 1 commit into from
Feb 24, 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
81 changes: 38 additions & 43 deletions src/dev-app/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,43 @@
@use '../material/core/core';
@use '../material/core/theming/palette';
@use '../material/core/theming/theming';
@use '../material/core/typography/typography';

// Plus imports for other components in your app.

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// **Be sure that you only ever include this mixin once!**
@include core.core();
@include all-typography.angular-material-mdc-typography(all-typography.config());
@include popover-edit.typography(typography.config());

// Include base styles for strong focus indicators.
.demo-strong-focus {
@include focus-indicators-focus-indicators.strong-focus-indicators();
@include focus-indicators.strong-focus-indicators();
}

// Define the default theme (same as the example above).
// Define the default (light) theme.
$candy-app-primary: theming.palette(palette.$indigo);
$candy-app-accent: theming.palette(palette.$pink, A200, A100, A400);
$candy-app-theme: theming.light-theme((
color: (
primary: $candy-app-primary,
accent: $candy-app-accent
)
// Define the default colors for our app.
color: (
primary: $candy-app-primary,
accent: $candy-app-accent
),
// Define the default typography for our app.
typography: all-typography.config(),
// Define the default density level for our app.
density: 0,
));

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// **Be sure that you only ever include this mixin once!**
@include core.core($candy-app-theme);

// Include the default theme styles.
@include theming-all-theme.angular-material-theme($candy-app-theme);
@include all-theme.angular-material-mdc-theme($candy-app-theme);
@include column-resize.theme($candy-app-theme);
@include popover-edit.theme($candy-app-theme);

// We add this in manually for now, because it isn't included in `angular-material-mdc-theme`.
@include slider-theme.theme($candy-app-theme);

// Define an alternate dark theme.
$dark-primary: theming.palette(palette.$blue-grey);
$dark-accent: theming.palette(palette.$amber, A200, A100, A400);
$dark-warn: theming.palette(palette.$deep-orange);
$dark-theme: theming.dark-theme((
color: (
primary: $dark-primary,
accent: $dark-accent,
warn: $dark-warn
)
));

// Include the default theme for focus indicators.
.demo-strong-focus {
// Include base styles for strong focus indicators.
@include focus-indicators-focus-indicators.strong-focus-indicators();
@include focus-indicators.strong-focus-indicators();

// Include the default theme for focus indicators.
@include focus-indicators-focus-indicators.strong-focus-indicators-theme($candy-app-theme);
@include focus-indicators.strong-focus-indicators-theme($candy-app-theme);
}
Expand All @@ -74,17 +61,25 @@ $dark-theme: theming.dark-theme((
// `.demo-unicorn-dark-theme` will be affected by this alternate dark theme instead of the
// default theme.
.demo-unicorn-dark-theme {
@include color-all-color.angular-material-color($dark-theme);
@include all-color.angular-material-mdc-color($dark-theme);
@include column-resize.color($dark-theme);
@include popover-edit.color($dark-theme);
@include slider-theme.color($dark-theme);
}
// Create the color palettes used in our dark theme.
$dark-primary: theming.palette(palette.$blue-grey);
$dark-accent: theming.palette(palette.$amber, A200, A100, A400);
$dark-warn: theming.palette(palette.$deep-orange);
$dark-colors: theming.dark-theme($dark-primary, $dark-accent, $dark-warn);

// Include the dark theme for focus indicators.
.demo-unicorn-dark-theme.demo-strong-focus {
@include focus-indicators-focus-indicators.strong-focus-indicators-color($dark-theme);
@include focus-indicators.strong-focus-indicators-color($dark-theme);
// Include the dark theme color styles.
@include color-all-color.angular-material-color($dark-colors);
@include all-color.angular-material-mdc-color($dark-colors);
@include column-resize.color($dark-colors);
@include popover-edit.color($dark-colors);
// We add this in manually for now, because it isn't included in `angular-material-mdc-theme`.
@include slider-theme.color($dark-colors);

// Include the dark theme colors for focus indicators.
.demo-strong-focus {
@include focus-indicators-focus-indicators.strong-focus-indicators-color($dark-colors);
@include focus-indicators.strong-focus-indicators-color($dark-colors);
}
}

// Create classes for all density scales which are supported by all MDC-based components.
Expand Down
3 changes: 2 additions & 1 deletion src/material-experimental/popover-edit/_popover-edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@use '../../material/core/style/private';
@use '../../material/core/theming/palette';
@use '../../material/core/theming/theming';
@use '../../material/core/typography/typography';
@use '../../material/core/typography/typography-utils';

@function mat-edit-hover-content-background($direction, $background-color) {
Expand Down Expand Up @@ -145,7 +146,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
[mat-edit-title] {
@include typography-utils.level-to-styles($config, title);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/badge/_badge-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@use 'sass:meta';
@use '../core/theming/palette';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';
@use '../../cdk/a11y/a11y';

Expand Down Expand Up @@ -191,7 +192,7 @@ $large-size: $default-size + 6;
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-badge-content {
font-weight: $font-weight;
font-size: $font-size;
Expand Down
3 changes: 2 additions & 1 deletion src/material/bottom-sheet/_bottom-sheet-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:map';
@use '../core/style/private';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';
@use '../core/theming/palette';
@use '../core/theming/theming';
Expand All @@ -17,7 +18,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-bottom-sheet-container {
@include typography-utils.level-to-styles($config, body-1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/button-toggle/_button-toggle-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use '../core/style/private';
@use '../core/theming/palette';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';
@use '../core/density/private/compatibility';
@use './button-toggle-variables';
Expand Down Expand Up @@ -86,7 +87,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-button-toggle {
font-family: typography-utils.font-family($config);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/button/_button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use 'sass:meta';
@use '../core/theming/theming';
@use '../core/style/private';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';

$_mat-button-ripple-opacity: 0.1;
Expand Down Expand Up @@ -163,7 +164,7 @@ $_mat-button-ripple-opacity: 0.1;
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-button, .mat-raised-button, .mat-icon-button, .mat-stroked-button,
.mat-flat-button, .mat-fab, .mat-mini-fab {
font: {
Expand Down
3 changes: 2 additions & 1 deletion src/material/card/_card-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use '../core/theming/palette';
@use '../core/theming/theming';
@use '../core/style/private';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';


Expand All @@ -27,7 +28,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-card {
font-family: typography-utils.font-family($config);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:map';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';


Expand Down Expand Up @@ -97,7 +98,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-checkbox {
font-family: typography-utils.font-family($config);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/chips/_chips-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use '../core/style/private';
@use '../core/theming/palette';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';

$chip-remove-font-size: 18px;
Expand Down Expand Up @@ -90,7 +91,7 @@ $chip-remove-font-size: 18px;
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-chip {
font-size: typography-utils.font-size($config, body-2);
font-weight: typography-utils.font-weight($config, body-2);
Expand Down
3 changes: 2 additions & 1 deletion src/material/core/option/_optgroup-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'sass:map';
@use '../theming/palette';
@use '../theming/theming';
@use '../typography/typography';
@use '../typography/typography-utils';

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

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-optgroup-label {
@include typography-utils.level-to-styles($config, body-2);
}
Expand Down
3 changes: 2 additions & 1 deletion src/material/core/option/_option-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'sass:map';
@use '../theming/palette';
@use '../theming/theming';
@use '../typography/typography';
@use '../typography/typography-utils';

@mixin color($config-or-theme) {
Expand Down Expand Up @@ -48,7 +49,7 @@
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-option {
font: {
family: typography-utils.font-family($config);
Expand Down
52 changes: 37 additions & 15 deletions src/material/core/typography/_typography.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:map';
@use 'typography-utils';
@use '../theming/theming';

// Represents a typography level from the Material design spec.
@function level(
Expand Down Expand Up @@ -84,22 +85,35 @@
// produces a normalized typography config for the 2014 Material Design typography system.
// 2014 - https://material.io/archive/guidelines/style/typography.html#typography-styles
// 2018 - https://material.io/design/typography/the-type-system.html#type-scale
//
// Components using this function should be migrated to normalize to the 2018 style config instead.
// New components should not use this function.
@function typography-to-2014-config($config) {
@if typography-is-2018-config($config) {
@return config(
$display-4: map.get($config, headline-1),
$display-3: map.get($config, headline-2),
$display-2: map.get($config, headline-3),
$display-1: map.get($config, headline-4),
$headline: map.get($config, headline-5),
$title: map.get($config, headline-6),
$subheading-2: map.get($config, subtitle-1),
$subheading-1: map.get($config, subtitle-2),
$body-2: map.get($config, body-1),
$body-1: map.get($config, body-2),
$button: map.get($config, button),
$caption: map.get($config, caption),
@if $config == null {
@return null;
}
@if not typography-is-2014-config($config) {
$args: (
display-4: map.get($config, headline-1),
display-3: map.get($config, headline-2),
display-2: map.get($config, headline-3),
display-1: map.get($config, headline-4),
headline: map.get($config, headline-5),
title: map.get($config, headline-6),
subheading-2: map.get($config, subtitle-1),
subheading-1: map.get($config, subtitle-2),
body-2: map.get($config, body-1),
body-1: map.get($config, body-2),
button: map.get($config, button),
caption: map.get($config, caption),
);
$non-null-args: ();
@each $key, $value in $args {
@if $value != null {
$non-null-args: map.merge($non-null-args, ($key: $value));
}
}
@return config($non-null-args...);
}
@return $config;
}
Expand All @@ -109,6 +123,9 @@
// 2014 - https://material.io/archive/guidelines/style/typography.html#typography-styles
// 2018 - https://material.io/design/typography/the-type-system.html#type-scale
@function typography-to-2018-config($config) {
@if $config == null {
@return null;
}
@if typography-is-2014-config($config) {
@return (
headline-1: map.get($config, display-4),
Expand All @@ -123,14 +140,19 @@
body-2: map.get($config, body-1),
button: map.get($config, button),
caption: map.get($config, caption),
overline: if(map.get($config, overline), map.get($config, overline),
level(12px, 32px, 500)
)
);
}
@return $config;
}

// Adds the base typography styles, based on a config.
/* stylelint-disable-next-line material/theme-mixin-api */
@mixin base-typography($config, $selector: '.mat-typography') {
@mixin base-typography($config-or-theme, $selector: '.mat-typography') {
$config: typography-to-2014-config(theming.get-typography-config($config-or-theme));

.mat-h1, .mat-headline, #{$selector} h1 {
@include typography-utils.level-to-styles($config, headline);
margin: 0 0 16px;
Expand Down
3 changes: 2 additions & 1 deletion src/material/datepicker/_datepicker-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@use '../core/style/private';
@use '../core/theming/palette';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';


Expand Down Expand Up @@ -183,7 +184,7 @@ $calendar-weekday-table-font-size: 11px !default;
}

@mixin typography($config-or-theme) {
$config: theming.get-typography-config($config-or-theme);
$config: typography.typography-to-2014-config(theming.get-typography-config($config-or-theme));
.mat-calendar {
font-family: typography-utils.font-family($config);
}
Expand Down
Loading