-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
_typography.scss
149 lines (129 loc) · 4.8 KB
/
_typography.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@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,
$font-family: null) {
@return (
font-size: $font-size,
line-height: $line-height,
font-weight: $font-weight,
font-family: $font-family
);
}
// Represents a collection of typography levels.
// Defaults come from https://material.io/guidelines/style/typography.html
@function mat-typography-config(
$font-family: 'Roboto, "Helvetica Neue", 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, 32px, 500),
$subheading-2: mat-typography-level(16px, 28px, 400),
$subheading-1: mat-typography-level(15px, 24px, 400),
$body-2: mat-typography-level(14px, 24px, 500),
$body-1: mat-typography-level(14px, 20px, 400),
$caption: mat-typography-level(12px, 20px, 400),
$button: mat-typography-level(14px, 14px, 500),
// Line-height must be unit-less fraction of the font-size.
$input: mat-typography-level(16px, 1.125, 400)
) {
// Declare an initial map with all of the levels.
$config: (
display-4: $display-4,
display-3: $display-3,
display-2: $display-2,
display-1: $display-1,
headline: $headline,
title: $title,
subheading-2: $subheading-2,
subheading-1: $subheading-1,
body-2: $body-2,
body-1: $body-1,
caption: $caption,
button: $button,
input: $input,
);
// Loop through the levels and set the `font-family` of the ones that don't have one to the base.
// Note that SASS can't modify maps in place, which means that we need to merge and re-assign.
@each $key, $level in $config {
@if map-get($level, font-family) == null {
$new-level: map-merge($level, (font-family: $font-family));
$config: map-merge($config, ($key: $new-level));
}
}
// Add the base font family to the config.
@return map-merge($config, (font-family: $font-family));
}
// Adds the base typography styles, based on a config.
@mixin mat-base-typography($config, $selector: '.mat-typography') {
.mat-h1, .mat-headline, #{$selector} h1 {
@include mat-typography-level-to-styles($config, headline);
margin: 0 0 16px;
}
.mat-h2, .mat-title, #{$selector} h2 {
@include mat-typography-level-to-styles($config, title);
margin: 0 0 16px;
}
.mat-h3, .mat-subheading-2, #{$selector} h3 {
@include mat-typography-level-to-styles($config, subheading-2);
margin: 0 0 16px;
}
.mat-h4, .mat-subheading-1, #{$selector} h4 {
@include mat-typography-level-to-styles($config, subheading-1);
margin: 0 0 16px;
}
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
// and h6 at 0.67em.
.mat-h5, #{$selector} h5 {
font-size: mat-font-size($config, body-1) * 0.83;
font-weight: mat-font-weight($config, body-1);
font-family: mat-font-family($config, body-1);
line-height: mat-line-height($config, body-1);
margin: 0 0 12px;
}
.mat-h6, #{$selector} h6 {
font-size: mat-font-size($config, body-1) * 0.67;
font-weight: mat-font-weight($config, body-1);
font-family: mat-font-family($config, body-1);
line-height: mat-line-height($config, body-1);
margin: 0 0 12px;
}
.mat-body-strong, .mat-body-2 {
@include mat-typography-level-to-styles($config, body-2);
}
.mat-body, .mat-body-1, #{$selector} {
@include mat-typography-level-to-styles($config, body-1);
p {
margin: 0 0 12px;
}
}
.mat-small, .mat-caption {
@include mat-typography-level-to-styles($config, caption);
}
// Note: The spec doesn't mention letter spacing. The value comes from
// eyeballing it until it looked exactly like the spec examples.
.mat-display-4, #{$selector} .mat-display-4 {
@include mat-typography-level-to-styles($config, display-4);
margin: 0 0 56px;
letter-spacing: -0.05em;
}
.mat-display-3, #{$selector} .mat-display-3 {
@include mat-typography-level-to-styles($config, display-3);
margin: 0 0 64px;
letter-spacing: -0.02em;
}
.mat-display-2, #{$selector} .mat-display-2 {
@include mat-typography-level-to-styles($config, display-2);
margin: 0 0 64px;
letter-spacing: -0.005em;
}
.mat-display-1, #{$selector} .mat-display-1 {
@include mat-typography-level-to-styles($config, display-1);
margin: 0 0 64px;
}
}