Skip to content

Commit

Permalink
Simplify font family settings
Browse files Browse the repository at this point in the history
Before we removed compatibility mode, the font-families file included multiple ‘settings’ (realistically, more like constants) that defined the font to be used depending on whether compatibility mode was enabled or not.

Now that we only have one possible default font stack, we can remove the unnecessary abstraction.

We also need to update the default value for the `$govuk-include-default-font-face` setting. Previously it checked whether the chosen font family was the default stack based on GDS Transport, but we can instead just check whether “GDS Transport” is in the font list. This also makes it more robust if somebody for example wants to update the setting to change the fallback fonts.
  • Loading branch information
36degrees committed Jul 11, 2023
1 parent 78a0111 commit 638a7b1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.

This file was deleted.

12 changes: 4 additions & 8 deletions packages/govuk-frontend/src/govuk/settings/_typography-font.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "typography-font-families";

////
/// @group settings/typography
////
Expand All @@ -13,7 +11,7 @@
/// @type List
/// @access public

$govuk-font-family: $govuk-font-family-gds-transport !default;
$govuk-font-family: "GDS Transport", arial, sans-serif !default;

/// Font families to use for print media
///
Expand All @@ -27,15 +25,13 @@ $govuk-font-family-print: sans-serif !default;

/// Include the default @font-face declarations
///
/// If you have set $govuk-font-family to something other than
/// `$govuk-font-family-gds-transport` this option is disabled by default.
/// Defaults to true if "GDS Transport" appears in the $govuk-font-family
/// setting.
///
/// @type Boolean
/// @access public

$govuk-include-default-font-face: (
$govuk-font-family == $govuk-font-family-gds-transport
) !default;
$govuk-include-default-font-face: if(index($govuk-font-family, "GDS Transport"), true, false) !default;

// =========================================================
// Font weights
Expand Down
44 changes: 44 additions & 0 deletions packages/govuk-frontend/src/govuk/settings/typography.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { compileSassString } = require('govuk-frontend-helpers/tests')

describe('$govuk-include-default-font-face', () => {
it('is true if $govuk-font-family is default', async () => {
const sass = `
@import "settings/typography-font";
:root {
--result: #{$govuk-include-default-font-face}
}
`

await expect(compileSassString(sass)).resolves.toMatchObject({
css: expect.stringContaining('--result: true')
})
})

it('is true if $govuk-font-family includes GDS Transport', async () => {
const sass = `
$govuk-font-family: "GDS Transport", "Comic Sans MS", "Comic Sans", cursive;
@import "settings/typography-font";
:root {
--result: #{$govuk-include-default-font-face}
}
`

await expect(compileSassString(sass)).resolves.toMatchObject({
css: expect.stringContaining('--result: true')
})
})

it('is false if $govuk-font-family does not include GDS Transport', async () => {
const sass = `
$govuk-font-family: "Comic Sans MS", "Comic Sans", cursive;
@import "settings/typography-font";
:root {
--result: #{$govuk-include-default-font-face}
}
`

await expect(compileSassString(sass)).resolves.toMatchObject({
css: expect.stringContaining('--result: false')
})
})
})

0 comments on commit 638a7b1

Please sign in to comment.