Skip to content

Commit

Permalink
Merge pull request #658 from alphagov/global-a-and-p-styles
Browse files Browse the repository at this point in the history
Opt-in global anchor and paragraph styles
  • Loading branch information
Jani Kraner authored May 3, 2018
2 parents 53d2ccc + 563d373 commit d1595d6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ New features:
- Focus Error Summary on window load
(PR [#671](https://github.com/alphagov/govuk-frontend/pull/671))

- Opt-in Global `<a>` and `<p>` styles
(PR [#658](https://github.com/alphagov/govuk-frontend/pull/658))

Global styles are not included by default.

This is to avoid the risk of these globals conflicting with any pre-existing globals, for example in GOV.UK Elements or GOV.UK Template.

Hovever, we do include them in the [GOV.UK Prototype Kit](https://github.com/alphagov/govuk-prototype-kit-private-beta) to speed up prototyping.

To include global styles, you can set `$govuk-global-styles` variable to `true`.

Internal:

- Update publishing docs (PR [#651](https://github.com/alphagov/govuk-frontend/pull/651))
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ After resolving the import paths you can import GOV.UK Frontend by using:
@import "@govuk-frontend/button/button";
```

#### Global Styles

[Global styles](src/globals/core/_global-styles.scss) are not included by default.

This is to avoid the risk of these globals conflicting with any pre-existing globals, for example in GOV.UK Elements or GOV.UK Template.

Hovever, we do include them in the [GOV.UK Prototype Kit](https://github.com/alphagov/govuk-prototype-kit-private-beta) to speed up prototyping.

To include global styles, you can set `$govuk-global-styles` variable to `true`.
```
// application.scss
$govuk-global-styles: true;
@import "govuk-frontend/all/all";
```

### Import JavaScript

You need to import the GOV.UK Frontend scripts into the main JavaScript file in your project.
Expand Down
34 changes: 34 additions & 0 deletions src/all/all.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-env jest */

const util = require('util')

const configPaths = require('../../config/paths.json')

const sass = require('node-sass')
const sassRender = util.promisify(sass.render)

const sassConfig = {
includePaths: [ configPaths.src ]
}

describe('GOV.UK Frontend', () => {
describe('global styles', async() => {
it('are disabled by default', async () => {
const sass = `
@import "all/all";
`
const results = await sassRender({ data: sass, ...sassConfig })
expect(results.css.toString()).not.toContain(', a {')
expect(results.css.toString()).not.toContain(', p {')
})
it('are enabled if $global-styles variable is set to true', async () => {
const sass = `
$govuk-global-styles: true;
@import "all/all";
`
const results = await sassRender({ data: sass, ...sassConfig })
expect(results.css.toString()).toContain(', a {')
expect(results.css.toString()).toContain(', p {')
})
})
})
2 changes: 2 additions & 0 deletions src/globals/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import "settings/paths";

@import "settings/compatibility";
@import "settings/global-styles";
@import "settings/ie8";

@import "settings/media-queries";
Expand Down Expand Up @@ -48,6 +49,7 @@
@import "core/typography";
@import "core/prose-scope";
@import "core/section-break";
@import "core/global-styles";

// Objects
@import "objects/form-group";
Expand Down
21 changes: 21 additions & 0 deletions src/globals/core/_global-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@import "../tools/exports";
@import "links";
@import "typography";
@import "../settings/global-styles";

@mixin govuk-global-styles {
a {
@extend %govuk-link;
}

p {
@extend %govuk-body-m;
}
}

@include govuk-exports("govuk-global-styles") {

@if $govuk-global-styles == true {
@include govuk-global-styles;
}
}
3 changes: 3 additions & 0 deletions src/globals/settings/_global-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// set to include optional globals styles

$govuk-global-styles: false !default;

0 comments on commit d1595d6

Please sign in to comment.