-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy path_typography.scss
204 lines (176 loc) · 6.14 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
////
/// @group helpers
////
@import "../tools/px-to-rem";
/// 'Common typography' helper
///
/// Sets the font family and associated properties, such as font smoothing. Also
/// overrides the font for print.
///
/// @param {List} $font-family [$govuk-font-family] Font family to use
/// @access public
@mixin govuk-typography-common($font-family: $govuk-font-family) {
font-family: $font-family;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// If the user is using the default GDS Transport font we need to include
// the font-face declarations.
//
// We do not need to include the GDS Transport font-face declarations if
// alphagov/govuk_template is being used since nta will already be included by
// default.
@if ($govuk-include-default-font-face) {
@include _govuk-font-face-gds-transport;
}
@include govuk-media-query($media-type: print) {
font-family: $govuk-font-family-print;
}
}
/// Text colour helper
///
/// Sets the text colour, including a suitable override for print.
///
/// @access public
@mixin govuk-text-colour {
color: $govuk-text-colour;
@include govuk-media-query($media-type: print) {
color: $govuk-print-text-colour;
}
}
/// Regular font weight helper
///
/// @param {Boolean} $important [false] - Whether to mark declarations as
/// `!important`. Generally Used to create override classes.
/// @access public
@mixin govuk-typography-weight-regular($important: false) {
font-weight: $govuk-font-weight-regular iff($important, !important);
}
/// Bold font weight helper
///
/// @param {Boolean} $important [false] - Whether to mark declarations as
/// `!important`. Generally Used to create override classes.
/// @access public
@mixin govuk-typography-weight-bold($important: false) {
font-weight: $govuk-font-weight-bold iff($important, !important);
}
/// Convert line-heights specified in pixels into a relative value, unless
/// they are already unit-less (and thus already treated as relative values)
/// or the units do not match the units used for the font size.
///
/// @param {Number} $line-height Line height
/// @param {Number} $font-size Font size
/// @return {Number} The line height as either a relative value or unmodified
///
/// @access private
@function _govuk-line-height($line-height, $font-size) {
@if not unitless($line-height) and unit($line-height) == unit($font-size) {
$line-height: $line-height / $font-size;
}
@return $line-height;
}
/// Responsive typography helper
///
/// Takes a 'font map' as an argument and uses it to create font-size and
/// line-height declarations for different breakpoints, and for print.
///
/// Example font map:
///
/// $my-font-map: (
/// null: (
/// font-size: 16px,
/// line-height: 20px
/// ),
/// tablet: (
/// font-size: 19px,
/// line-height: 25px
/// ),
/// print: (
/// font-size: 14pt,
/// line-height: 1.15
/// )
/// );
///
/// @param {Map} $font-map - Font map
/// @param {Number} $override-line-height [false] - Non responsive custom line
/// height. Omit to use the line height from the font map.
/// @param {Boolean} $important [false] - Whether to mark declarations as
/// `!important`.
///
/// @access public
@mixin govuk-typography-responsive($size, $override-line-height: false, $important: false) {
@if not map-has-key($govuk-typography-scale, $size) {
@error "Unknown font size `#{$size}` - expected a point from the typography scale.";
}
$font-map: map-get($govuk-typography-scale, $size);
@each $breakpoint, $breakpoint-map in $font-map {
$font-size: map-get($breakpoint-map, "font-size");
$font-size-rem: govuk-px-to-rem($font-size);
$line-height: _govuk-line-height(
$line-height: if($override-line-height,
$override-line-height,
map-get($breakpoint-map, "line-height")
),
$font-size: $font-size
);
// Mark rules as !important if $important is true - this will result in
// these variables becoming strings, so this needs to happen *after* they
// are used in calculations
$font-size: $font-size iff($important, !important);
$font-size-rem: $font-size-rem iff($important, !important);
$line-height: $line-height iff($important, !important);
@if $breakpoint == null {
font-size: $font-size; // sass-lint:disable no-duplicate-properties
@if $govuk-typography-use-rem {
font-size: $font-size-rem; // sass-lint:disable no-duplicate-properties
}
line-height: $line-height;
} @else if $breakpoint == "print" {
@include govuk-media-query($media-type: print) {
font-size: $font-size;
line-height: $line-height;
}
} @else {
@include govuk-media-query($from: $breakpoint) {
font-size: $font-size; // sass-lint:disable no-duplicate-properties
@if $govuk-typography-use-rem {
font-size: $font-size-rem; // sass-lint:disable no-duplicate-properties
}
line-height: $line-height;
}
}
}
}
/// Font helper
///
/// @param {Number} $size - Size of the font as it would appear on desktop -
/// uses the responsive font size map
/// @param {String} $weight [regular] - Weight: `bold` or `regular`
/// @param {Boolean} $tabular [false] - Whether to use tabular numbers or not
/// @param {Number} $line-height [false] - Line-height, if overriding the default
///
/// @access public
@mixin govuk-font($size, $weight: regular, $tabular: false, $line-height: false) {
@if $tabular {
// if govuk-font-family-tabular is set use $govuk-font-family-tabular
@if $govuk-font-family-tabular {
@include govuk-typography-common($font-family: $govuk-font-family-tabular);
} @else {
@include govuk-typography-common;
font-feature-settings: "tnum" 1;
@supports(font-variant-numeric: tabular-nums) {
font-feature-settings: normal;
font-variant-numeric: tabular-nums;
}
}
} @else {
@include govuk-typography-common;
}
@if $weight == regular {
@include govuk-typography-weight-regular;
} @else if $weight == bold {
@include govuk-typography-weight-bold;
}
@if $size {
@include govuk-typography-responsive($size, $override-line-height: $line-height);
}
}