-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial sass typography API (#4162)
- 20.0.0-next.0
- 19.2.2
- 19.2.1
- 19.2.0
- 19.2.0-rc.0
- 19.2.0-next.4
- 19.2.0-next.3
- 19.2.0-next.2
- 19.2.0-next.1
- 19.2.0-next.0
- 19.1.5
- 19.1.4
- 19.1.3
- 19.1.2
- 19.1.1
- 19.1.0
- 19.1.0-rc.0
- 19.1.0-next.3
- 19.1.0-next.2
- 19.1.0-next.1
- 19.1.0-next.0
- 19.0.5
- 19.0.4
- 19.0.3
- 19.0.2
- 19.0.1
- 19.0.0
- 19.0.0-rc.3
- 19.0.0-rc.2
- 19.0.0-rc.1
- 19.0.0-rc.0
- 19.0.0-next.10
- 19.0.0-next.9
- 19.0.0-next.8
- 19.0.0-next.7
- 19.0.0-next.6
- 19.0.0-next.5
- 19.0.0-next.4
- 19.0.0-next.3
- 19.0.0-next.2
- 19.0.0-next.1
- 19.0.0-next.0
- 18.2.14
- 18.2.13
- 18.2.12
- 18.2.11
- 18.2.10
- 18.2.9
- 18.2.8
- 18.2.7
- 18.2.6
- 18.2.5
- 18.2.4
- 18.2.3
- 18.2.2
- 18.2.1
- 18.2.0
- 18.2.0-rc.0
- 18.2.0-next.3
- 18.2.0-next.2
- 18.2.0-next.1
- 18.2.0-next.0
- 18.1.5
- 18.1.4
- 18.1.3
- 18.1.2
- 18.1.1
- 18.1.0
- 18.1.0-rc.0
- 18.1.0-next.4
- 18.1.0-next.3
- 18.1.0-next.2
- 18.1.0-next.1
- 18.1.0-next.0
- 18.0.6
- 18.0.5
- 18.0.4
- 18.0.3
- 18.0.2
- 18.0.1
- 18.0.0
- 18.0.0-rc.3
- 18.0.0-rc.2
- 18.0.0-rc.1
- 18.0.0-rc.0
- 18.0.0-next.6
- 18.0.0-next.5
- 18.0.0-next.4
- 18.0.0-next.3
- 18.0.0-next.2
- 18.0.0-next.1
- 18.0.0-next.0
- 17.3.10
- 17.3.9
- 17.3.8
- 17.3.7
- 17.3.6
- 17.3.5
- 17.3.4
- 17.3.3
- 17.3.2
- 17.3.1
- 17.3.0
- 17.3.0-rc.0
- 17.3.0-next.0
- 17.2.2
- 17.2.1
- 17.2.0
- 17.2.0-rc.0
- 17.2.0-next.1
- 17.2.0-next.0
- 17.1.2
- 17.1.1
- 17.1.0
- 17.1.0-rc.0
- 17.1.0-next.3
- 17.1.0-next.2
- 17.1.0-next.1
- 17.1.0-next.0
- 17.0.6
- 17.0.5
- 17.0.4
- 17.0.3
- 17.0.2
- 17.0.1
- 17.0.0
- 17.0.0-rc.3
- 17.0.0-rc.2
- 17.0.0-rc.1
- 17.0.0-rc.0
- 17.0.0-next.7
- 17.0.0-next.6
- 17.0.0-next.5
- 17.0.0-next.4
- 17.0.0-next.3
- 17.0.0-next.2
- 17.0.0-next.1
- 17.0.0-next.0
- 16.2.14
- 16.2.13
- 16.2.12
- 16.2.11
- 16.2.10
- 16.2.9
- 16.2.8
- 16.2.7
- 16.2.6
- 16.2.5
- 16.2.4
- 16.2.3
- 16.2.2
- 16.2.1
- 16.2.0
- 16.2.0-rc.0
- 16.2.0-next.5
- 16.2.0-next.4
- 16.2.0-next.3
- 16.2.0-next.2
- 16.2.0-next.1
- 16.2.0-next.0
- 16.1.8
- 16.1.7
- 16.1.6
- 16.1.5
- 16.1.4
- 16.1.3
- 16.1.2
- 16.1.1
- 16.1.0
- 16.1.0-rc.0
- 16.1.0-next.2
- 16.1.0-next.1
- 16.1.0-next.0
- 16.0.4
- 16.0.3
- 16.0.2
- 16.0.1
- 16.0.0
- 16.0.0-rc.2
- 16.0.0-rc.1
- 16.0.0-rc.0
- 16.0.0-next.5
- 16.0.0-next.4
- 16.0.0-next.3
- 16.0.0-next.2
- 16.0.0-next.1
- 16.0.0-next.0
- 15.2.9
- 15.2.8
- 15.2.7
- 15.2.6
- 15.2.5
- 15.2.4
- 15.2.3
- 15.2.2
- 15.2.1
- 15.2.0
- 15.2.0-rc.0
- 15.2.0-next.4
- 15.2.0-next.3
- 15.2.0-next.2
- 15.2.0-next.1
- 15.2.0-next.0
- 15.1.6
- 15.1.5
- 15.1.4
- 15.1.3
- 15.1.2
- 15.1.1
- 15.1.0
- 15.1.0-rc.0
- 15.1.0-next.2
- 15.1.0-next.1
- 15.1.0-next.0
- 15.0.4
- 15.0.3
- 15.0.2
- 15.0.1
- 15.0.0
- 15.0.0-rc.3
- 15.0.0-rc.2
- 15.0.0-rc.1
- 15.0.0-rc.0
- 15.0.0-next.5
- 15.0.0-next.4
- 15.0.0-next.3
- 15.0.0-next.2
- 15.0.0-next.1
- 15.0.0-next.0
- 14.2.7
- 14.2.6
- 14.2.5
- 14.2.4
- 14.2.3
- 14.2.2
- 14.2.1
- 14.2.0
- 14.2.0-rc.0
- 14.2.0-next.2
- 14.2.0-next.1
- 14.2.0-next.0
- 14.1.3
- 14.1.2
- 14.1.1
- 14.1.0
- 14.1.0-rc.0
- 14.1.0-next.3
- 14.1.0-next.2
- 14.1.0-next.1
- 14.1.0-next.0
- 14.0.6
- 14.0.5
- 14.0.4
- 14.0.3
- 14.0.2
- 14.0.1
- 14.0.0
- 14.0.0-rc.2
- 14.0.0-rc.1
- 14.0.0-rc.0
- 14.0.0-next.13
- 14.0.0-next.12
- 14.0.0-next.11
- 14.0.0-next.10
- 14.0.0-next.9
- 14.0.0-next.8
- 14.0.0-next.7
- 14.0.0-next.6
- 14.0.0-next.5
- 14.0.0-next.4
- 14.0.0-next.3
- 14.0.0-next.2
- 14.0.0-next.1
- 14.0.0-next.0
- 13.3.9
- 13.3.8
- 13.3.7
- 13.3.6
- 13.3.5
- 13.3.4
- 13.3.3
- 13.3.2
- 13.3.1
- 13.3.0
- 13.2.6
- 13.2.5
- 13.2.4
- 13.2.3
- 13.2.2
- 13.2.1
- 13.2.0
- 13.2.0-rc.0
- 13.2.0-next.1
- 13.2.0-next.0
- 13.1.3
- 13.1.2
- 13.1.1
- 13.1.0
- 13.1.0-rc.0
- 13.1.0-next.3
- 13.1.0-next.2
- 13.1.0-next.1
- 13.1.0-next.0
- 13.0.4
- 13.0.3
- 13.0.2
- 13.0.1
- 13.0.0
- 13.0.0-rc.3
- 13.0.0-rc.2
- 13.0.0-rc.1
- 13.0.0-rc.0
- 13.0.0-next.8
- 13.0.0-next.7
- 13.0.0-next.6
- 13.0.0-next.5
- 13.0.0-next.4
- 13.0.0-next.3
- 13.0.0-next.2
- 13.0.0-next.1
- 13.0.0-next.0
- 12.2.13
- 12.2.12
- 12.2.11
- 12.2.10
- 12.2.9
- 12.2.8
- 12.2.7
- 12.2.6
- 12.2.5
- 12.2.4
- 12.2.3
- 12.2.2
- 12.2.1
- 12.2.0
- 12.2.0-rc.0
- 12.1.4
- 12.1.3
- 12.1.2
- 12.1.1
- 12.1.0
- 12.1.0-rc.0
- 12.1.0-next.1
- 12.1.0-next.0
- 12.0.6
- 12.0.5
- 12.0.4
- 12.0.3
- 12.0.2
- 12.0.1
- 12.0.0
- 12.0.0-rc.3
- 12.0.0-rc.2
- 12.0.0-rc.1
- 12.0.0-rc.0
- 12.0.0-next.7
- 12.0.0-next.6
- 12.0.0-next.5
- 12.0.0-next.4
- 12.0.0-next.3
- 12.0.0-next.2
- 12.0.0-next.1
- 11.2.13
- 11.2.12
- 11.2.11
- 11.2.10
- 11.2.9
- 11.2.8
- 11.2.7
- 11.2.6
- 11.2.5
- 11.2.4
- 11.2.3
- 11.2.2
- 11.2.1
- 11.2.0
- 11.2.0-rc.0
- 11.1.2
- 11.1.1
- 11.1.0
- 11.1.0-rc.0
- 11.0.4
- 11.0.3
- 11.0.2
- 11.0.1
- 11.0.0
- 11.0.0-rc.4
- 11.0.0-rc.3
- 11.0.0-rc.2
- 11.0.0-rc.1
- 11.0.0-rc.0
- 11.0.0-next.2
- 11.0.0-next.1
- 10.2.7
- 10.2.6
- 10.2.5
- 10.2.4
- 10.2.3
- 10.2.2
- 10.2.1
- 10.2.0
- 10.2.0-rc.0
- 10.1.3
- 10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6.0.0-rc.0
- 6.0.0-beta-5
- 6.0.0-beta-4
- 6.0.0-beta-2
- 6.0.0-beta-0
- 5.2.5
- 5.2.4
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 5.0.0-rc.3
- 5.0.0-rc.2
- 5.0.0-rc.1
- 5.0.0-rc0
- 2.0.0-beta.12
- 2.0.0-beta.11
- 2.0.0-beta.10
- 2.0.0-beta.8
- 2.0.0-beta.7
- 2.0.0-beta.6
- 2.0.0-beta.5
- 2.0.0-beta.4
Showing
3 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Utility for fetching a nested value from a typography config. | ||
@function _mat-get-type-value($config, $level, $name) { | ||
@return map-get(map-get($config, $level), $name); | ||
} | ||
|
||
// Gets the font size for a level inside a typography config. | ||
@function mat-font-size($config, $level) { | ||
@return _mat-get-type-value($config, $level, font-size); | ||
} | ||
|
||
// Gets the line height for a level inside a typography config. | ||
@function mat-line-height($config, $level) { | ||
@return _mat-get-type-value($config, $level, line-height); | ||
} | ||
|
||
// Gets the font weight for a level inside a typography config. | ||
@function mat-font-weight($config, $level) { | ||
@return _mat-get-type-value($config, $level, font-weight); | ||
} | ||
|
||
// Gets the font-family from a typography config and removes the quotes around it. | ||
@function mat-font-family($config) { | ||
@return unquote(map-get($config, font-family)); | ||
} | ||
|
||
// Converts a typography level into CSS styles. | ||
@mixin mat-typography-level-to-styles($config, $level) { | ||
$font-size: mat-font-size($config, $level); | ||
$font-weight: mat-font-weight($config, $level); | ||
$line-height: mat-line-height($config, $level); | ||
$font-family: mat-font-family($config); | ||
|
||
// Use the shorthand `font` to represent a typography level, because it's the shortest. Notes that | ||
// we need to use interpolation for `font-size/line-height` in order to prevent SASS from dividing | ||
// the two values. | ||
font: $font-weight #{$font-size}/#{$line-height} $font-family; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,85 @@ | ||
// Implement the rem unit with SCSS so we don't have to actually set a font-size on | ||
// the user's body element. | ||
@function rem($multiplier) { | ||
$font-size: 10px; | ||
@return $multiplier * $font-size; | ||
@import 'typography-utils'; | ||
|
||
// Represents a typography level from the Material design spec. | ||
@function mat-typography-level($font-size, $line-height: $font-size, $font-weight: 400) { | ||
@return ( | ||
font-size: $font-size, | ||
line-height: $line-height, | ||
font-weight: $font-weight | ||
); | ||
} | ||
|
||
// Represents a collection of typography levels. | ||
// Defaults come from https://material.io/guidelines/style/typography.html | ||
@function mat-typography-config( | ||
$font-family: 'Roboto, sans-serif', | ||
$display-4: mat-typography-level(112px, 112px, 300), | ||
$display-3: mat-typography-level(56px, 56px, 400), | ||
$display-2: mat-typography-level(45px, 48px, 400), | ||
$display-1: mat-typography-level(34px, 40px, 400), | ||
$headline: mat-typography-level(24px, 32px, 400), | ||
$title: mat-typography-level(20px, 20px, 500), | ||
$subheading: mat-typography-level(16px, 28px, 400), | ||
$body-2: mat-typography-level(14px, 24px, 500), | ||
$body-1: mat-typography-level(14px, 20px, 400), | ||
$caption: mat-typography-level(12px, 12px, 400), | ||
$button: mat-typography-level(14px, 14px, 500) | ||
) { | ||
@return ( | ||
font-family: $font-family, | ||
display-4: $display-4, | ||
display-3: $display-3, | ||
display-2: $display-2, | ||
display-1: $display-1, | ||
headline: $headline, | ||
title: $title, | ||
subheading: $subheading, | ||
body-2: $body-2, | ||
body-1: $body-1, | ||
caption: $caption, | ||
button: $button | ||
); | ||
} | ||
|
||
// Adds the base typography styles, based on a config. | ||
@mixin mat-typography($config: mat-typography-config(), $selector: '.mat-typography') { | ||
.mat-h0, .mat-hero-header { | ||
@include mat-typography-level-to-styles($config, display-4); | ||
} | ||
|
||
.mat-h1, #{$selector} h1 { | ||
@include mat-typography-level-to-styles($config, display-3); | ||
} | ||
|
||
.mat-h2, #{$selector} h2 { | ||
@include mat-typography-level-to-styles($config, display-2); | ||
} | ||
|
||
.mat-h3, #{$selector} h3 { | ||
@include mat-typography-level-to-styles($config, display-1); | ||
} | ||
|
||
.mat-h4, #{$selector} h4 { | ||
@include mat-typography-level-to-styles($config, headline); | ||
} | ||
|
||
.mat-h5, #{$selector} h5 { | ||
@include mat-typography-level-to-styles($config, title); | ||
} | ||
|
||
.mat-h6, #{$selector} h6 { | ||
@include mat-typography-level-to-styles($config, subheading); | ||
} | ||
|
||
.mat-body-strong { | ||
@include mat-typography-level-to-styles($config, body-2); | ||
} | ||
|
||
.mat-body, #{$selector} { | ||
@include mat-typography-level-to-styles($config, body-1); | ||
} | ||
|
||
.mat-small { | ||
@include mat-typography-level-to-styles($config, caption); | ||
} | ||
} |