Skip to content

Commit

Permalink
Remove ability to pass ‘font maps’ directly
Browse files Browse the repository at this point in the history
  • Loading branch information
36degrees committed Jun 7, 2018
1 parent f35ccff commit 93a0f33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
17 changes: 3 additions & 14 deletions src/helpers/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,11 @@

@mixin govuk-typography-responsive($size, $override-line-height: false, $important: false) {

$font-map: null;

@if (type-of($size) == "map") {
$font-map: $size;
} @else {
@if (map-has-key($govuk-typography-scale, $size)) {
$font-map: map-get($govuk-typography-scale, $size);
}
@if not map-has-key($govuk-typography-scale, $size) {
@error "Unknown font size `#{$size}` - expected a point from the typography scale.";
}

// Ensure that $font-map is actually a map
$actual-input-type: type-of($font-map);
@if $actual-input-type != "map" {
@error "Expected a map of breakpoints and font sizes, but got a "
+ "#{$actual-input-type}. Make sure you are passing a font map.";
}
$font-map: map-get($govuk-typography-scale, $size);

@each $breakpoint, $breakpoint-map in $font-map {
$font-size: map-get($breakpoint-map, "font-size") iff($important, !important);
Expand Down
17 changes: 8 additions & 9 deletions src/helpers/typography.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('@mixin govuk-typography-responsive', () => {
${sassBootstrap}
.foo {
@include govuk-typography-responsive(map-get($govuk-typography-scale, 14))
@include govuk-typography-responsive($size: 14)
}`

const results = await sassRender({ data: sass, ...sassConfig })
Expand All @@ -74,7 +74,7 @@ describe('@mixin govuk-typography-responsive', () => {
${sassBootstrap}
.foo {
@include govuk-typography-responsive(12)
@include govuk-typography-responsive($size: 12)
}`

const results = await sassRender({ data: sass, ...sassConfig })
Expand All @@ -89,19 +89,18 @@ describe('@mixin govuk-typography-responsive', () => {
line-height: 20pt; } }`)
})

it('throws an exception when passed anything other than a font map', async () => {
it('throws an exception when passed a size that is not in the scale', async () => {
const sass = `
${sassBootstrap}
.foo {
@include govuk-typography-responsive(14px)
@include govuk-typography-responsive(3.14159265359)
}`

await expect(sassRender({ data: sass, ...sassConfig }))
.rejects
.toThrow(
'Expected a map of breakpoints and font sizes, but got a null. ' +
'Make sure you are passing a font map.'
'Unknown font size `3.14159` - expected a point from the typography scale.'
)
})

Expand All @@ -111,7 +110,7 @@ describe('@mixin govuk-typography-responsive', () => {
${sassBootstrap}
.foo {
@include govuk-typography-responsive(14, $important: true);
@include govuk-typography-responsive($size: 14, $important: true);
}`

const results = await sassRender({ data: sass, ...sassConfig })
Expand All @@ -131,7 +130,7 @@ describe('@mixin govuk-typography-responsive', () => {
${sassBootstrap}
.foo {
@include govuk-typography-responsive(12, $important: true);
@include govuk-typography-responsive($size: 12, $important: true);
}`

const results = await sassRender({ data: sass, ...sassConfig })
Expand All @@ -153,7 +152,7 @@ describe('@mixin govuk-typography-responsive', () => {
${sassBootstrap}
.foo {
@include govuk-typography-responsive(14, $override-line-height: 30px);
@include govuk-typography-responsive($size: 14, $override-line-height: 30px);
}`

const results = await sassRender({ data: sass, ...sassConfig })
Expand Down
4 changes: 2 additions & 2 deletions src/overrides/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// Generate typography override classes for each responsive font map in the
// typography scale eg .govuk-\!-f-80
@each $size, $font-map in $govuk-typography-scale {
@each $size in map-keys($govuk-typography-scale) {
.govuk-\!-f-#{$size} {
@include govuk-typography-responsive($font-map, $important: true);
@include govuk-typography-responsive($size, $important: true);
}
}

Expand Down

0 comments on commit 93a0f33

Please sign in to comment.