Skip to content

Commit 2a8bc66

Browse files
committed
fix(material/core): switch typography hierarchy to new terminology
Switches the `typography-hierarchy` mixin to use the 2018 spec terminology and introduces a `legacy-typography-hierarchy` mixin.
1 parent bdec140 commit 2a8bc66

File tree

8 files changed

+137
-7
lines changed

8 files changed

+137
-7
lines changed

src/material/_index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$gray-palette, $blue-grey-palette, $blue-gray-palette, $light-theme-background-palette,
1111
$dark-theme-background-palette, $light-theme-foreground-palette, $dark-theme-foreground-palette;
1212
@forward './core/typography/typography' show define-typography-level,
13-
define-legacy-typography-config, typography-hierarchy;
13+
define-legacy-typography-config, legacy-typography-hierarchy, typography-hierarchy;
1414
@forward './core/typography/typography-utils' show typography-level,
1515
font-size, line-height, font-weight, letter-spacing, font-family, font-shorthand;
1616

src/material/core/typography/_typography-deprecated.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// @deprecated Use `typography-hierarchy`.
1515
@mixin base-typography($config-or-theme, $selector: '.mat-typography') {
16-
@include typography.typography-hierarchy($config-or-theme, $selector);
16+
@include typography.legacy-typography-hierarchy($config-or-theme, $selector);
1717
}
1818

1919
// @deprecated Use `define-typography-config`.

src/material/core/typography/_typography.scss

+130
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,136 @@
184184
/// @param {String} $selector Ancestor selector under which native elements, such as h1, will
185185
/// be styled.
186186
@mixin typography-hierarchy($config-or-theme, $selector: '.mat-typography') {
187+
$config: private-typography-to-2018-config(theming.get-typography-config($config-or-theme));
188+
189+
// Note that it seems redundant to prefix the class rules with the `$selector`, however it's
190+
// necessary if we want to allow people to overwrite the tag selectors. This is due to
191+
// selectors like `#{$selector} h1` being more specific than ones like `.mat-title`.
192+
.mat-h1,
193+
.mat-headline-5,
194+
#{$selector} .mat-h1,
195+
#{$selector} .mat-headline-5,
196+
#{$selector} h1 {
197+
@include typography-utils.typography-level($config, headline-5);
198+
margin: 0 0 16px;
199+
}
200+
201+
.mat-h2,
202+
.mat-headline-6,
203+
#{$selector} .mat-h2,
204+
#{$selector} .mat-headline-6,
205+
#{$selector} h2 {
206+
@include typography-utils.typography-level($config, headline-6);
207+
margin: 0 0 16px;
208+
}
209+
210+
.mat-h3,
211+
.mat-subtitle-1,
212+
#{$selector} .mat-h3,
213+
#{$selector} .mat-subtitle-1,
214+
#{$selector} h3 {
215+
@include typography-utils.typography-level($config, subtitle-1);
216+
margin: 0 0 16px;
217+
}
218+
219+
.mat-h4,
220+
.mat-body-1,
221+
#{$selector} .mat-h4,
222+
#{$selector} .mat-body-1,
223+
#{$selector} h4 {
224+
@include typography-utils.typography-level($config, body-1);
225+
margin: 0 0 16px;
226+
}
227+
228+
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
229+
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
230+
// and h6 at 0.67em.
231+
.mat-h5,
232+
#{$selector} .mat-h5,
233+
#{$selector} h5 {
234+
@include typography-utils.font-shorthand(
235+
// calc is used here to support css variables
236+
calc(#{typography-utils.font-size($config, body-2)} * 0.83),
237+
typography-utils.font-weight($config, body-2),
238+
typography-utils.line-height($config, body-2),
239+
typography-utils.font-family($config, body-2)
240+
);
241+
242+
margin: 0 0 12px;
243+
}
244+
245+
.mat-h6,
246+
#{$selector} .mat-h6,
247+
#{$selector} h6 {
248+
@include typography-utils.font-shorthand(
249+
// calc is used here to support css variables
250+
calc(#{typography-utils.font-size($config, body-2)} * 0.67),
251+
typography-utils.font-weight($config, body-2),
252+
typography-utils.line-height($config, body-2),
253+
typography-utils.font-family($config, body-2)
254+
);
255+
256+
margin: 0 0 12px;
257+
}
258+
259+
.mat-body-strong,
260+
.mat-subtitle-2,
261+
#{$selector} .mat-body-strong,
262+
#{$selector} .mat-subtitle-2 {
263+
@include typography-utils.typography-level($config, subtitle-2);
264+
}
265+
266+
.mat-body,
267+
.mat-body-2,
268+
#{$selector} .mat-body,
269+
#{$selector} .mat-body-2,
270+
#{$selector} {
271+
@include typography-utils.typography-level($config, body-2);
272+
273+
p {
274+
margin: 0 0 12px;
275+
}
276+
}
277+
278+
.mat-small,
279+
.mat-caption,
280+
#{$selector} .mat-small,
281+
#{$selector} .mat-caption {
282+
@include typography-utils.typography-level($config, caption);
283+
}
284+
285+
.mat-headline-1,
286+
#{$selector} .mat-headline-1 {
287+
@include typography-utils.typography-level($config, headline-1);
288+
margin: 0 0 56px;
289+
}
290+
291+
.mat-headline-2,
292+
#{$selector} .mat-headline-2 {
293+
@include typography-utils.typography-level($config, headline-2);
294+
margin: 0 0 64px;
295+
}
296+
297+
.mat-headline-3,
298+
#{$selector} .mat-headline-3 {
299+
@include typography-utils.typography-level($config, headline-3);
300+
margin: 0 0 64px;
301+
}
302+
303+
.mat-headline-4,
304+
#{$selector} .mat-headline-4 {
305+
@include typography-utils.typography-level($config, headline-4);
306+
margin: 0 0 64px;
307+
}
308+
}
309+
310+
/// Emits baseline typographic styles based on a given config.
311+
/// @param {Map} $config-or-theme A typography config for an entire theme.
312+
/// @param {String} $selector Ancestor selector under which native elements, such as h1, will
313+
/// be styled.
314+
/// @deprecated Use `mat.typography-hierarchy` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
315+
/// @breaking-change 17.0.0
316+
@mixin legacy-typography-hierarchy($config-or-theme, $selector: '.mat-typography') {
187317
$config: private-typography-to-2014-config(theming.get-typography-config($config-or-theme));
188318

189319
// Note that it seems redundant to prefix the class rules with the `$selector`, however it's

src/material/legacy-core/theming/prebuilt/deeppurple-amber.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ $theme: theming.define-light-theme((
2525
// Include all theme styles for the components.
2626
@include all-theme.all-legacy-component-themes($theme);
2727

28-
@include typography.typography-hierarchy($theme);
28+
@include typography.legacy-typography-hierarchy($theme);

src/material/legacy-core/theming/prebuilt/indigo-pink.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ $theme: theming.define-light-theme((
2525
// Include all theme styles for the components.
2626
@include all-theme.all-legacy-component-themes($theme);
2727

28-
@include typography.typography-hierarchy($theme);
28+
@include typography.legacy-typography-hierarchy($theme);

src/material/legacy-core/theming/prebuilt/pink-bluegrey.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ $theme: theming.define-dark-theme((
2525
// Include all theme styles for the components.
2626
@include all-theme.all-legacy-component-themes($theme);
2727

28-
@include typography.typography-hierarchy($theme);
28+
@include typography.legacy-typography-hierarchy($theme);

src/material/legacy-core/theming/prebuilt/purple-green.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ $theme: theming.define-dark-theme((
2525
// Include all theme styles for the components.
2626
@include all-theme.all-legacy-component-themes($theme);
2727

28-
@include typography.typography-hierarchy($theme);
28+
@include typography.legacy-typography-hierarchy($theme);

src/material/legacy-core/typography/_all-typography.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858

5959
// Components without MDC versions.
60-
@include typography.typography-hierarchy($config);
60+
@include typography.legacy-typography-hierarchy($config);
6161
@include badge-theme.typography($config);
6262
@include bottom-sheet-theme.typography($config);
6363
@include button-toggle-theme.typography($config);

0 commit comments

Comments
 (0)