|
1 | | -// Implement the rem unit with SCSS so we don't have to actually set a font-size on |
2 | | -// the user's body element. |
3 | | -@function rem($multiplier) { |
4 | | - $font-size: 10px; |
5 | | - @return $multiplier * $font-size; |
| 1 | +@import 'typography-utils'; |
| 2 | + |
| 3 | +// Represents a typography level from the Material design spec. |
| 4 | +@function mat-typography-level($font-size, $line-height: $font-size, $font-weight: 400) { |
| 5 | + @return ( |
| 6 | + font-size: $font-size, |
| 7 | + line-height: $line-height, |
| 8 | + font-weight: $font-weight |
| 9 | + ); |
| 10 | +} |
| 11 | + |
| 12 | +// Represents a collection of typography levels. |
| 13 | +// Defaults come from https://material.io/guidelines/style/typography.html |
| 14 | +@function mat-typography-config( |
| 15 | + $font-family: 'Roboto, sans-serif', |
| 16 | + $display-4: mat-typography-level(112px, 112px, 300), |
| 17 | + $display-3: mat-typography-level(56px, 56px, 400), |
| 18 | + $display-2: mat-typography-level(45px, 48px, 400), |
| 19 | + $display-1: mat-typography-level(34px, 40px, 400), |
| 20 | + $headline: mat-typography-level(24px, 32px, 400), |
| 21 | + $title: mat-typography-level(20px, 20px, 500), |
| 22 | + $subheading: mat-typography-level(16px, 28px, 400), |
| 23 | + $body-2: mat-typography-level(14px, 24px, 500), |
| 24 | + $body-1: mat-typography-level(14px, 20px, 400), |
| 25 | + $caption: mat-typography-level(12px, 12px, 400), |
| 26 | + $button: mat-typography-level(14px, 14px, 500) |
| 27 | +) { |
| 28 | + @return ( |
| 29 | + font-family: $font-family, |
| 30 | + display-4: $display-4, |
| 31 | + display-3: $display-3, |
| 32 | + display-2: $display-2, |
| 33 | + display-1: $display-1, |
| 34 | + headline: $headline, |
| 35 | + title: $title, |
| 36 | + subheading: $subheading, |
| 37 | + body-2: $body-2, |
| 38 | + body-1: $body-1, |
| 39 | + caption: $caption, |
| 40 | + button: $button |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +// Adds the base typography styles, based on a config. |
| 45 | +@mixin mat-typography($config: mat-typography-config(), $selector: '.mat-typography') { |
| 46 | + .mat-h0, .mat-hero-header { |
| 47 | + @include mat-typography-level-to-styles($config, display-4); |
| 48 | + } |
| 49 | + |
| 50 | + .mat-h1, #{$selector} h1 { |
| 51 | + @include mat-typography-level-to-styles($config, display-3); |
| 52 | + } |
| 53 | + |
| 54 | + .mat-h2, #{$selector} h2 { |
| 55 | + @include mat-typography-level-to-styles($config, display-2); |
| 56 | + } |
| 57 | + |
| 58 | + .mat-h3, #{$selector} h3 { |
| 59 | + @include mat-typography-level-to-styles($config, display-1); |
| 60 | + } |
| 61 | + |
| 62 | + .mat-h4, #{$selector} h4 { |
| 63 | + @include mat-typography-level-to-styles($config, headline); |
| 64 | + } |
| 65 | + |
| 66 | + .mat-h5, #{$selector} h5 { |
| 67 | + @include mat-typography-level-to-styles($config, title); |
| 68 | + } |
| 69 | + |
| 70 | + .mat-h6, #{$selector} h6 { |
| 71 | + @include mat-typography-level-to-styles($config, subheading); |
| 72 | + } |
| 73 | + |
| 74 | + .mat-body-strong { |
| 75 | + @include mat-typography-level-to-styles($config, body-2); |
| 76 | + } |
| 77 | + |
| 78 | + .mat-body, #{$selector} { |
| 79 | + @include mat-typography-level-to-styles($config, body-1); |
| 80 | + } |
| 81 | + |
| 82 | + .mat-small { |
| 83 | + @include mat-typography-level-to-styles($config, caption); |
| 84 | + } |
6 | 85 | } |
0 commit comments