Skip to content

Commit

Permalink
Merge pull request #748 from alphagov/document-sass
Browse files Browse the repository at this point in the history
Document (non-contentious parts of) Sass settings layer
  • Loading branch information
36degrees authored Jun 4, 2018
2 parents 205d7e1 + 6ef84cf commit a051ee9
Show file tree
Hide file tree
Showing 22 changed files with 405 additions and 167 deletions.
4 changes: 0 additions & 4 deletions app/assets/scss/app-ie8.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
// If you want to display the currently active breakpoint in the top
// right corner of your site during development, add the breakpoints
// to this list, ordered by width, e.g. (mobile, tablet, desktop).
$mq-show-breakpoints: (desktop);
@import "../../../src/all-ie8";
@import "partials/app";
6 changes: 2 additions & 4 deletions app/assets/scss/app.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// If you want to display the currently active breakpoint in the top
// right corner of your site during development, add the breakpoints
// to this list, ordered by width, e.g. (mobile, tablet, desktop).
$mq-show-breakpoints: (mobile, tablet, desktop);
$govuk-show-breakpoints: true;

@import "../../../src/all";
@import "partials/app";
5 changes: 5 additions & 0 deletions src/components/button/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

@include govuk-exports("govuk/component/button") {

$govuk-button-colour: #00823b;
$govuk-button-hover-colour: darken($govuk-button-colour, 5%);
$govuk-button-shadow-colour: darken($govuk-button-colour, 15%);
$govuk-button-text-colour: $govuk-white;

// Because the shadow (s0) is visually 'part of' the button, we need to reduce
// the height of the button to compensate by adjusting its padding (s1) and
// increase the bottom margin to include it (s2).
Expand Down
21 changes: 20 additions & 1 deletion src/helpers/_media-queries.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
// We use sass-mq module for media queries
// Import sass-mq as a helper for media queries

// Pass our breakpoints and static breakpoint definitions through to sass-mq.
$mq-breakpoints: if(variable-exists(govuk-breakpoints), $govuk-breakpoints, ());
$mq-static-breakpoint: if(variable-exists(govuk-ie8-breakpoint), $govuk-ie8-breakpoint, desktop);

$mq-show-breakpoints: ();

@if (variable-exists(govuk-show-breakpoints) and $govuk-show-breakpoints) {
$mq-show-breakpoints: map-keys($govuk-breakpoints);
}

// When building a stylesheet for IE8, set $mq-responsive to false in order to
// 'rasterize' any media queries.

@if (variable-exists(govuk-is-ie8) and $govuk-is-ie8) {
$mq-responsive: false;
} @else {
$mq-responsive: true;
}

// This is a horrible, horrible hack to prevent the 'dev mode' CSS to display
// the current breakpoint from being included multiple times.
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
// Sets the font family and associated properties, such as font smoothing. Also
// overrides the font for print.

@mixin govuk-typography-common($font-family: $govuk-font-stack) {
@mixin govuk-typography-common($font-family: $govuk-font-family) {
font-family: $font-family;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

// If using NTA, include the font-face definition
@if ($govuk-font-stack == $govuk-nta-light) {
@if ($govuk-font-family == $govuk-font-family-nta) {
@include govuk-font-face-nta;
}

@include mq($media-type: print) {
font-family: $govuk-font-stack-print;
font-family: $govuk-font-family-print;
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@
// Regular weights, tabular numbers

@mixin govuk-font-regular-tabular {
@include govuk-typography-common($font-family: $govuk-nta-light-tabular);
@include govuk-typography-common($font-family: $govuk-font-family-tabular);
@include govuk-typography-weight-regular;
}

Expand Down Expand Up @@ -262,7 +262,7 @@
// Bold weights, tabular numbers

@mixin govuk-font-bold-tabular {
@include govuk-typography-common($font-family: $govuk-nta-light-tabular);
@include govuk-typography-common($font-family: $govuk-font-family-tabular);
@include govuk-typography-weight-bold;
}

Expand Down
22 changes: 13 additions & 9 deletions src/helpers/grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ const sassConfig = {
}
describe('grid system', () => {
const sassImports = `
@import "tools/exports";
@import "settings/ie8";
@import "settings/media-queries";
@import "settings/spacing";
@import "settings/measurements";
@import "helpers/grid";
@import "helpers/media-queries";
@import "tools/exports";
`
describe('grid-width function', () => {
it('outputs the specified key value from the map of widths', async () => {
Expand Down Expand Up @@ -115,7 +119,7 @@ describe('grid system', () => {
box-sizing: border-box;
width: 100%;
padding: 0 15px; }
@media (min-width: 46.25em) {
@media (min-width: 40.0625em) {
.govuk-grid-column-full {
width: 100%;
float: left; } }`)
Expand All @@ -137,7 +141,7 @@ describe('grid system', () => {
box-sizing: border-box;
width: 100%;
padding: 0 15px; }
@media (min-width: 46.25em) {
@media (min-width: 40.0625em) {
.govuk-grid-column-two-thirds {
width: 66.6666%;
float: left; } }
Expand All @@ -148,20 +152,20 @@ describe('grid system', () => {
const sass = `
${sassImports}
@include govuk-grid-column(three-quarters, $class:'large-columnumn');
@include govuk-grid-column(three-quarters, $class:'large-column');
`
const results = await sassRender({ data: sass, ...sassConfig })

expect(results.css
.toString()
.trim())
.toBe(outdent`
.large-columnumn-three-quarters {
.large-column-three-quarters {
box-sizing: border-box;
width: 100%;
padding: 0 15px; }
@media (min-width: 46.25em) {
.large-columnumn-three-quarters {
@media (min-width: 40.0625em) {
.large-column-three-quarters {
width: 75%;
float: left; } }
`)
Expand All @@ -182,7 +186,7 @@ describe('grid system', () => {
.govuk-grid-column-one-quarter {
box-sizing: border-box;
padding: 0 15px; }
@media (min-width: 61.25em) {
@media (min-width: 48.0625em) {
.govuk-grid-column-one-quarter {
width: 25%;
float: left; } }
Expand Down Expand Up @@ -227,7 +231,7 @@ describe('grid system', () => {
box-sizing: border-box;
width: 100%;
padding: 0 15px; }
@media (min-width: 46.25em) {
@media (min-width: 40.0625em) {
.govuk-grid-column-one-half {
width: 50%;
float: right; } }
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/spacing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const sassConfig = {
}

const sassBootstrap = `
$mq-breakpoints: (
@import "settings/media-queries";
@import "settings/ie8";
$govuk-breakpoints: (
my_breakpoint: 30em
);
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/typography.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const sassConfig = {
}

const sassBootstrap = `
$mq-breakpoints: (
@import "settings/media-queries";
@import "settings/ie8";
$govuk-breakpoints: (
my_breakpoint: 30em
);
Expand Down
2 changes: 1 addition & 1 deletion src/settings/_all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
@import "spacing";
@import "measurements";

@import "typography-font-stacks";
@import "typography-font-families";
@import "typography-font";
@import "typography-responsive";
17 changes: 15 additions & 2 deletions src/settings/_assets.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
////
/// @group settings/assets
////

/// Path to the assets directory, with trailing slash.
///
/// This is the directory where the images and fonts subdirectories live. You
/// will need to make this directory available via your application – see the
/// README for details.
///
/// @type String
/// @access public

$govuk-assets-path: "/assets/" !default;

/// Path to the images folder, with trailing slash.
///
/// @type String
/// @access public

$govuk-images-path: "#{$govuk-assets-path}images/" !default;

/// Path to the fonts folder, with trailing slash.
///
/// @type String
/// @access public

$govuk-fonts-path: "#{$govuk-assets-path}fonts/" !default;

Expand All @@ -37,10 +44,13 @@ $govuk-fonts-path: "#{$govuk-assets-path}fonts/" !default;
/// @example scss - Custom asset handling
///
/// @function my-url-handler($filename) {
/// @return ''; // Some custom URL handling
/// // Some custom URL handling
/// @return url('example.jpg');
/// }
///
/// $govuk-image-url-function: 'my-url-handler';
///
/// @access public

$govuk-image-url-function: false !default;

Expand All @@ -61,9 +71,12 @@ $govuk-image-url-function: false !default;
/// @example scss - Custom asset handling
///
/// @function my-url-handler($filename) {
/// @return ''; // Some custom URL handling
/// // Some custom URL handling
/// @return url('example.woff');
/// }
///
/// $govuk-font-url-function: 'my-url-handler';
///
/// @access public

$govuk-font-url-function: false !default;
Loading

0 comments on commit a051ee9

Please sign in to comment.