Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate settings associated with compatibility mode #2844

Merged
merged 6 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ This will enable screen reader users to have a better, more coherent experience

This was added in [pull request #2677: Amend error summary markup to fix page load focus bug in JAWS 2022](https://github.com/alphagov/govuk-frontend/pull/2677).

### Deprecated features

#### Stop using settings associated with legacy codebases

In GOV.UK Frontend v5.0 we will stop supporting compatibility with legacy codebases. As part of this, we are deprecating settings controlled by compatibility mode variables. This includes the `govuk-compatibility` mixin and the following settings:

- `$govuk-use-legacy-palette`
- `$govuk-use-legacy-font`
- `$govuk-typography-use-rem`
- `$govuk-font-family-tabular`

This was introduced in [pull request #2844: Deprecate compatibility mode settings](https://github.com/alphagov/govuk-frontend/pull/2844).

### Fixes

We’ve made fixes to GOV.UK Frontend in the following pull requests:
Expand Down
6 changes: 3 additions & 3 deletions src/govuk/components/button/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ $govuk-button-text-colour: govuk-colour("white") !default;
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-button-text-colour;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ $govuk-button-text-colour: govuk-colour("white") !default;
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-secondary-button-text-colour;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ $govuk-button-text-colour: govuk-colour("white") !default;
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-warning-button-text-colour;
}
Expand Down
2 changes: 1 addition & 1 deletion src/govuk/components/footer/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// alphagov/govuk_template includes a specific a:link:focus selector
// designed to make unvisited links a slightly darker blue when focussed, so
// we need to override the text colour for that combination of selectors.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
@include govuk-text-colour;
}
Expand Down
2 changes: 1 addition & 1 deletion src/govuk/components/table/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
vertical-align: top;
// GOV.UK Elements sets the font-size and line-height for all headers and cells
// in tables.
@include govuk-compatibility(govuk_elements) {
@include _govuk-compatibility(govuk_elements) {
font-size: inherit;
line-height: inherit;
}
Expand Down
2 changes: 1 addition & 1 deletion src/govuk/core/_section-break.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// fix double-width section break and forced visible section break
// when combined with styles from alphagov/elements
@include govuk-compatibility(govuk_elements) {
@include _govuk-compatibility(govuk_elements) {
height: 0;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/govuk/helpers/_links.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-focus-text-colour;
}
Expand Down Expand Up @@ -150,7 +150,7 @@
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-focus-text-colour;
}
Expand Down Expand Up @@ -198,7 +198,7 @@
// we need to override the text colour for that combination of selectors so
// so that unvisited links styled as buttons do not end up with dark blue
// text when focussed.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-focus-text-colour;
}
Expand Down Expand Up @@ -241,7 +241,7 @@
// alphagov/govuk_template includes a specific a:link:focus selector designed
// to make unvisited links a slightly darker blue when focussed, so we need to
// override the text colour for that combination of selectors.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
@include govuk-text-colour;
}
Expand Down Expand Up @@ -286,7 +286,7 @@
// alphagov/govuk_template includes a specific a:link:focus selector designed
// to make unvisited links a slightly darker blue when focussed, so we need to
// override the text colour for that combination of selectors.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
@include govuk-text-colour;
}
Expand Down Expand Up @@ -329,7 +329,7 @@
// alphagov/govuk_template includes a specific a:link:focus selector designed
// to make unvisited links a slightly darker blue when focussed, so we need to
// override the text colour for that combination of selectors.
@include govuk-compatibility(govuk_template) {
@include _govuk-compatibility(govuk_template) {
&:link:focus {
color: $govuk-focus-text-colour;
}
Expand Down
25 changes: 24 additions & 1 deletion src/govuk/helpers/colour.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const sass = require('node-sass')
const { renderSass } = require('../../../lib/jest-helpers')

// Create a mock warn function that we can use to override the native @warn
// function, that we can make assertions about post-render.
const mockWarnFunction = jest.fn()
.mockReturnValue(sass.NULL)

const sassConfig = {
outputStyle: 'compact'
outputStyle: 'compact',
functions: {
'@warn': mockWarnFunction
}
}

describe('@function govuk-colour', () => {
Expand Down Expand Up @@ -120,6 +129,20 @@ describe('@function govuk-colour', () => {
'Unknown colour `hooloovoo`'
)
})

it('outputs a deprecation warning when set to true', async () => {
const sass = `${sassBootstrap}`

await renderSass({ data: sass, ...sassConfig }).then(() => {
// Expect our mocked @warn function to have been called once with a single
// argument, which should be the deprecation notice
return expect(mockWarnFunction.mock.calls[0][0].getValue())
.toEqual(
'$govuk-use-legacy-palette is deprecated. ' +
'Only the modern colour palette will be supported from v5.0'
)
})
})
})

describe('when $govuk-use-legacy-palette is false', () => {
Expand Down
48 changes: 46 additions & 2 deletions src/govuk/helpers/typography.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const outdent = require('outdent')

const sass = require('node-sass')
const outdent = require('outdent')
const { renderSass } = require('../../../lib/jest-helpers')

// Create a mock warn function that we can use to override the native @warn
// function, that we can make assertions about post-render.
const mockWarnFunction = jest.fn()
.mockReturnValue(sass.NULL)

const sassConfig = {
outputStyle: 'nested'
outputStyle: 'nested',
functions: {
'@warn': mockWarnFunction
}
}

const sassBootstrap = `
Expand Down Expand Up @@ -391,6 +400,22 @@ describe('@mixin govuk-typography-responsive', () => {
line-height: 1.42857 !important; } }`)
})
})

it('outputs a deprecation warning when set to false', async () => {
const sass = `
$govuk-typography-use-rem: false;
${sassBootstrap}`

await renderSass({ data: sass, ...sassConfig }).then(() => {
// Get the argument of the last @warn call, which we expect to be the
// deprecation notice
return expect(mockWarnFunction.mock.calls.at(-1)[0].getValue())
.toEqual(
'$govuk-typography-use-rem is deprecated. ' +
'From version 5.0, GOV.UK Frontend will not support disabling rem font sizes'
)
})
})
})

describe('when compatibility mode is set', () => {
Expand Down Expand Up @@ -572,3 +597,22 @@ describe('@mixin govuk-typography-responsive', () => {
})
})
})

describe('$govuk-font-family-tabular value is specified', () => {
it('outputs a deprecation warning when set', async () => {
const sass = `
$govuk-font-family-tabular: monospace;
${sassBootstrap}`

await renderSass({ data: sass, ...sassConfig }).then(() => {
// Get the argument of the last @warn call, which we expect to be the
// deprecation notice
return expect(mockWarnFunction.mock.calls.at(-1)[0].getValue())
.toEqual(
'$govuk-font-family-tabular is deprecated. ' +
'From version 5.0, GOV.UK Frontend will not support using a separate ' +
'font-face for tabular numbers'
)
})
})
})
12 changes: 12 additions & 0 deletions src/govuk/settings/_colours-palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
///
/// @type Boolean
/// @access public
/// @deprecated Will be removed in v5.0 with the rest of the compatibility mode
/// suite of tools and settings

$govuk-use-legacy-palette: if(
(
Expand All @@ -26,6 +28,16 @@ $govuk-use-legacy-palette: if(
false
) !default;

// Only show the deprecation warning if user is setting $govuk-use-legacy-palette
// manually instead of automatically via compatibility variables
@if $govuk-use-legacy-palette == true and
$govuk-compatibility-govukfrontendtoolkit == false and
$govuk-compatibility-govuktemplate == false and
$govuk-compatibility-govukelements == false {
36degrees marked this conversation as resolved.
Show resolved Hide resolved
@warn "$govuk-use-legacy-palette is deprecated. " +
"Only the modern colour palette will be supported from v5.0";
}

/// Modern colour palette
///
/// This exists only because you cannot easily set a !default variable
Expand Down
23 changes: 23 additions & 0 deletions src/govuk/settings/_typography-font.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
///
/// @type Boolean
/// @access public
/// @deprecated Will be removed in v5.0 with the rest of the compatibility mode
/// suite of tools and settings

$govuk-use-legacy-font: if(
(
Expand All @@ -24,6 +26,17 @@ $govuk-use-legacy-font: if(
false
) !default;

// Only show the deprecation warning if user is setting $govuk-use-legacy-font
// manually instead of automatically via compatibility variables
@if $govuk-use-legacy-font == true and
$govuk-compatibility-govukfrontendtoolkit == false and
$govuk-compatibility-govuktemplate == false and
$govuk-compatibility-govukelements == false {
@warn "$govuk-use-legacy-font is deprecated. " +
"From version 5.0, GOV.UK Frontend will only support the included version " +
"of GDS Transport";
}

// =========================================================
// Font families
// =========================================================
Expand All @@ -43,13 +56,23 @@ $govuk-font-family: if(
///
/// @type List
/// @access public
/// @deprecated Will be removed in v5.0 with the rest of the compatibility mode
/// suite of tools and settings

$govuk-font-family-tabular: if(
$govuk-use-legacy-font,
$govuk-font-family-nta-tabular,
false
) !default;

// Only show the deprecation warning if user is setting $govuk-font-family-tabular
// manually instead of automatically via $govuk-use-legacy-font
@if $govuk-font-family-tabular != false and $govuk-use-legacy-font == false {
@warn "$govuk-font-family-tabular is deprecated. " +
"From version 5.0, GOV.UK Frontend will not support using a separate " +
"font-face for tabular numbers";
}

/// Font families to use for print media
///
/// We recommend that you use system fonts when printing. This will avoid issues
Expand Down
12 changes: 12 additions & 0 deletions src/govuk/settings/_typography-responsive.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
///
/// @type Boolean
/// @access public
/// @deprecated Will be removed in v5.0 with the rest of the compatibility mode
/// suite of tools and settings

$govuk-typography-use-rem: if(
(
Expand All @@ -24,6 +26,16 @@ $govuk-typography-use-rem: if(
true
) !default;

// Only show the deprecation warning if user is setting $govuk-typography-use-rem
// manually instead of automatically via compatibility variables
@if $govuk-typography-use-rem == false and
$govuk-compatibility-govukfrontendtoolkit == false and
$govuk-compatibility-govuktemplate == false and
$govuk-compatibility-govukelements == false {
@warn "$govuk-typography-use-rem is deprecated. " +
"From version 5.0, GOV.UK Frontend will not support disabling rem font sizes";
}

/// Root font size
///
/// This is used to calculate rem sizes for the typography, and should match the
Expand Down
26 changes: 20 additions & 6 deletions src/govuk/tools/_compatibility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
/// @group tools/compatibility-mode
////

/// Temporary private version of govuk-compatibility to avoid deprecation warnings
///
/// @access private

@mixin _govuk-compatibility($product) {
@if map-has-key($_govuk-compatibility, $product) {
@if map-get($_govuk-compatibility, $product) == true {
@content;
}
} @else {
@error "Non existent product '#{$product}'";
}
}

/// Conditional Compatibility Mixin
///
/// Selectively output a block (available to the mixin as @content) if a given
Expand All @@ -24,13 +38,13 @@
/// this product
/// @throw Errors if product name is not recognised
/// @access public
/// @deprecated Will be removed in v5.0 with the rest of the compatibility mode
/// suite of tools and settings

@mixin govuk-compatibility($product) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this approach.

@if map-has-key($_govuk-compatibility, $product) {
@if map-get($_govuk-compatibility, $product) == true {
@content;
}
} @else {
@error "Non existent product '#{$product}'";
@warn "govuk-compatibility is deprecated. " +
"From version 5.0, GOV.UK Frontend will not support compatibility mode";
@include _govuk-compatibility($product) {
@content;
}
}
Loading