Skip to content

Commit c770d18

Browse files
Merge pull request #1294 from nhsuk/nhsuk-type-scale
Deprecate 24px from typography scale
2 parents e61e890 + d9e9f16 commit c770d18

37 files changed

+155
-27
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ This was added in [pull request #1291: Add Sass warning suppression functionalit
9494

9595
:wastebasket: **Deprecated features**
9696

97+
#### Stop using `nhsuk-u-font-size-24` and '24' on the typography scale
98+
99+
We have deprecated point 24 (24px large screens, 20px small screens) on the typography scale, including the font utility class `nhsuk-u-font-size-24` that uses point 24.
100+
101+
We will be removing this class and point 24 on the typography scale in a future release. You will no longer be able to call the Sass mixins `nhsuk-font()` or `nhsuk-font-size()` with `$size` set to '24'.
102+
103+
This change was introduced in [#1294: Deprecate 24 on the typography scale](https://github.com/nhsuk/nhsuk-frontend/pull/1294)
104+
97105
#### Replace Sass mixins for media queries
98106

99107
If you're using the `mq()` Sass mixin to output CSS media queries, you must replace it with the `nhsuk-media-query()` mixin.
@@ -208,6 +216,17 @@ After:
208216

209217
:recycle: **Changes**
210218

219+
We've completed changes to fully replace 24px with 26px from the typography scale in [pull request #1294](https://github.com/nhsuk/nhsuk-frontend/issues/1294) for the following:
220+
221+
- Do and Don't list title
222+
- Pagination "Previous" and "Next" titles
223+
- Panel text content
224+
- Table and warning callout headings
225+
- Lead paragraph `.nhsuk-body-l` class
226+
- Lede text `.nhsuk-lede-text` class
227+
228+
We've made changes to NHS.UK frontend in the following pull requests:
229+
211230
- [#1077: Secondary button has been restyled to improve its visual hierarchy and prevent users from interpreting it as a disabled button](https://github.com/nhsuk/nhsuk-frontend/pull/1077)
212231
- [#1198: Reverse button has been restyled to better match other buttons](https://github.com/nhsuk/nhsuk-frontend/pull/1198)
213232

packages/components/pagination/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
.nhsuk-pagination__title {
120120
display: block;
121121

122-
@include nhsuk-font-size(24);
122+
@include nhsuk-font-size(26);
123123

124124
@include nhsuk-media-query($media-type: print) {
125125
&::after {

packages/components/panel/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $nhsuk-border-width-panel: nhsuk-spacing(1);
3030
color: $color_nhsuk-white;
3131
padding: nhsuk-spacing(5) - $nhsuk-border-width-panel; /* [2] */
3232

33-
@include nhsuk-font-size(24);
33+
@include nhsuk-font-size(26);
3434
@include nhsuk-responsive-margin(4, "bottom");
3535

3636
@include nhsuk-media-query($until: tablet) {

packages/core/settings/_typography.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ $nhsuk-typography-scale: (
8686
)
8787
),
8888
24: (
89+
null: (
90+
font-size: 20px,
91+
line-height: 28px
92+
),
93+
tablet: (
94+
font-size: 24px,
95+
line-height: 31px
96+
),
97+
print: (
98+
font-size: 16pt,
99+
line-height: 1.25
100+
),
101+
deprecation: (
102+
key: "nhsuk-typography-scale-24",
103+
message: "24 on the typography scale is deprecated and will be removed in the next major version."
104+
)
105+
),
106+
_24: (
89107
null: (
90108
font-size: 20px,
91109
line-height: 28px

packages/core/settings/_warnings.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ $nhsuk-suppressed-warnings: () !default;
6363
/// Check whether a key is present in the suppressed warnings list.
6464
///
6565
/// @param {String} $key - The key to be checked against `$nhsuk-suppressed-warnings`.
66-
/// @access private
66+
///
67+
/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service)
6768

6869
@function _should-warn($key) {
6970
@return list.index($nhsuk-suppressed-warnings, $key) == null;
@@ -73,7 +74,8 @@ $nhsuk-suppressed-warnings: () !default;
7374
///
7475
/// @param {String} $key - The key needed to suppress the warning.
7576
/// @param {String} $message - The warning text.
76-
/// @access private
77+
///
78+
/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service)
7779

7880
@function _warning-text($key, $message) {
7981
@return $message + " To silence this warning, update $nhsuk-suppressed-warnings " + 'with key: "#{$key}"';

packages/core/styles/_typography.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ h6,
139139
display: block;
140140
margin-top: 0;
141141

142-
@include nhsuk-font-size(24);
142+
@include nhsuk-font-size(26);
143143
@include nhsuk-responsive-margin(5, "bottom");
144144
}
145145

@@ -185,13 +185,13 @@ address {
185185
/// 2. Reduces the spacing between the page heading and the lede text
186186

187187
.nhsuk-lede-text {
188-
@include nhsuk-font(24);
188+
@include nhsuk-font(26);
189189
@include nhsuk-responsive-margin(7, "bottom");
190190

191191
// [1]
192192
p,
193193
ul {
194-
@include nhsuk-font(24);
194+
@include nhsuk-font(26);
195195
}
196196
}
197197

packages/core/tools/_mixins.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
position: relative;
236236
top: -16px; // [5]
237237

238-
@include nhsuk-font-size(24);
238+
@include nhsuk-font-size(26);
239239

240240
@include nhsuk-media-query($until: tablet) {
241241
margin-left: -25px;

packages/core/tools/_typography.scss

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use "sass:map";
22
@use "sass:math";
3+
@use "sass:string";
34
@use "../settings" as *;
45
@use "functions" as *;
56
@use "ifff" as *;
@@ -93,6 +94,7 @@
9394
///
9495
/// Example font map:
9596
///
97+
/// ```scss
9698
/// 19: (
9799
/// null: (
98100
/// font-size: 16px,
@@ -107,34 +109,59 @@
107109
/// line-height: 1.15
108110
/// )
109111
/// );
112+
/// ```
110113
///
111-
/// @example scss
112-
/// .foo {
113-
/// @include nhsuk-font-size(19);
114-
/// }
115-
///
116-
/// .foo {
117-
/// @include nhsuk-font-size(36, $important: true);
118-
/// }
119-
///
120-
/// @param {Number} $size - Point from the spacing scale (the size as it would
121-
/// appear on tablet and above)
114+
/// @param {Number | String} $size - Point from the typography scale (the size
115+
/// as it would appear on tablet and above)
122116
/// @param {Number} $line-height [false] - Non responsive custom line
123117
/// height. Omit to use the line height from the font map.
124118
/// @param {Boolean} $important [false] - Whether to mark declarations as
125119
/// `!important`.
126120
///
127-
/// @throw if `$size` is not a valid point from the spacing scale
121+
/// @throw if `$size` is not a valid point from the typography scale
128122
///
129123
/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service)
130124

131125
@mixin nhsuk-font-size($size, $line-height: false, $important: false) {
132-
@if not map.has-key($nhsuk-typography-scale, $size) {
133-
@error "Unknown font size `#{$size}` - expected a point from the typography scale.";
126+
// Flag font sizes that start with underscores so we can suppress warnings on
127+
// deprecated sizes used internally, for example `nhsuk-font($size: "_24")`
128+
$size-internal-use-only: string.slice(#{$size}, 1, 1) == "_";
129+
130+
// Remove underscore from font sizes flagged for internal use
131+
@if $size-internal-use-only {
132+
$size: string.slice(#{$size}, 2);
134133
}
135134

135+
// Check for a font map exactly matching the given size
136136
$font-map: map.get($nhsuk-typography-scale, $size);
137137

138+
// No match? Try with string type (e.g. $size: "16" not 16)
139+
@if not $font-map {
140+
@each $font-size in map.keys($nhsuk-typography-scale) {
141+
@if not $font-map and "#{$font-size}" == "#{$size}" {
142+
$font-map: map.get($nhsuk-typography-scale, $font-size);
143+
}
144+
}
145+
}
146+
147+
// Still no match? Throw error
148+
@if not $font-map {
149+
@error "Unknown font size `#{$size}` - expected a point from the typography scale.";
150+
}
151+
152+
// Check for a deprecation within the typography scale
153+
$deprecation: map.get($font-map, "deprecation");
154+
155+
@if $deprecation {
156+
// Warn on deprecated font sizes unless flagged for internal use
157+
@if not $size-internal-use-only {
158+
@include nhsuk-warning(map.get($deprecation, "key"), map.get($deprecation, "message"));
159+
}
160+
161+
// remove the deprecation map keys so they do not break the breakpoint loop
162+
$font-map: map.remove($font-map, "deprecation");
163+
}
164+
138165
@each $breakpoint, $breakpoint-map in $font-map {
139166
$font-size: map.get($breakpoint-map, "font-size");
140167
$font-size-rem: nhsuk-px-to-rem($font-size);
@@ -180,14 +207,15 @@
180207

181208
/// Font size and line height helper (deprecated)
182209
///
183-
/// @param {Number} $size - Point from the spacing scale (the size as it would
184-
/// appear on tablet and above)
210+
/// @param {Number | Boolean | String} $size - Point from the typography scale
211+
/// (the size as it would appear on tablet and above). Use `false` to avoid
212+
/// setting a size.
185213
/// @param {Number} $override-line-height [false] - Non responsive custom line
186214
/// height. Omit to use the line height from the font map.
187215
/// @param {Boolean} $important [false] - Whether to mark declarations as
188216
/// `!important`.
189217
///
190-
/// @throw if `$size` is not a valid point from the spacing scale
218+
/// @throw if `$size` is not a valid point from the typography scale (or false)
191219
///
192220
/// @alias nhsuk-font-size
193221
/// @deprecated Use `nhsuk-font-size` instead
@@ -200,7 +228,7 @@
200228
@include nhsuk-font-size($size, $override-line-height, $important);
201229
}
202230

203-
/// Font
231+
/// Font helper
204232
///
205233
/// @example scss
206234
/// .foo {

packages/core/tools/typography.unit.test.mjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,37 @@ describe('Typography tools', () => {
243243
})
244244
})
245245

246+
it('outputs CSS when passing size as a string', async () => {
247+
const sass = `
248+
${sassBootstrap}
249+
250+
.foo {
251+
@include nhsuk-font-size($size: "14")
252+
}
253+
`
254+
255+
const results = compileStringAsync(sass, {
256+
loadPaths: ['packages']
257+
})
258+
259+
await expect(results).resolves.toMatchObject({
260+
css: outdent`
261+
.foo {
262+
font-size: 12px;
263+
font-size: 0.75rem;
264+
line-height: 1.25;
265+
}
266+
@media (min-width: 30em) {
267+
.foo {
268+
font-size: 14px;
269+
font-size: 0.875rem;
270+
line-height: 1.42857;
271+
}
272+
}
273+
`
274+
})
275+
})
276+
246277
it('outputs CSS using points as strings', async () => {
247278
const sass = `
248279
@use "core/settings/breakpoints" as * with (
@@ -312,6 +343,28 @@ describe('Typography tools', () => {
312343
)
313344
})
314345

346+
it('throws a deprecation warning if a point on the scale is deprecated', async () => {
347+
const sass = `
348+
${sassBootstrap}
349+
350+
.foo {
351+
@include nhsuk-font-size($size: 16)
352+
}
353+
`
354+
355+
await compileStringAsync(sass, {
356+
loadPaths: ['packages'],
357+
logger
358+
})
359+
360+
// Expect our mocked @warn function to have been called once with a single
361+
// argument, which should be the deprecation notice
362+
expect(logger.warn).toHaveBeenCalledWith(
363+
'This point on the scale is deprecated. To silence this warning, update $nhsuk-suppressed-warnings with key: "test-key"',
364+
expect.anything()
365+
)
366+
})
367+
315368
describe('when $important is set to true', () => {
316369
it('marks font size and line height as important', async () => {
317370
const sass = `

packages/core/utilities/_typography.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
///
1919
/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service)
2020

21-
@each $size in map.keys($nhsuk-typography-scale) {
21+
// nhsuk-u-font-size-24 is deprecated
22+
@each $size, $font-map in $nhsuk-typography-scale {
2223
.nhsuk-u-font-size-#{$size} {
24+
$font-map: map.get($nhsuk-typography-scale, $size);
25+
26+
// Add underscore to deprecated typography scale keys
27+
@if map.has-key($font-map, "deprecation") {
28+
$size: _#{$size};
29+
}
30+
2331
@include nhsuk-font-size($size, $important: true);
2432
}
2533
}
Loading
Loading
Loading
-2.49 KB
Loading
Loading
966 Bytes
Loading
-2.3 KB
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
861 Bytes
Loading
463 Bytes
Loading
594 Bytes
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)