-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Nunjucks macros for colorBlock, colorCard
colorBlock shows a block of color for display in playbook colorCard shows a shows a block of color alongside various color properties such as Hex, RGB, CMYK Uses colorConvert dependency Fixes minor SonarQube issues
- Loading branch information
1 parent
ef67ddc
commit bc4a67c
Showing
14 changed files
with
5,738 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.colorblock { | ||
display: inline-block; | ||
border: 1px solid black; | ||
} | ||
|
||
// mixin used here for creating size variations | ||
@mixin colorblock-size($size) { | ||
width: $size; | ||
height: $size; | ||
max-width: $size; | ||
max-height: $size; | ||
} | ||
|
||
$sizes: ( | ||
'xs': 10px, | ||
's': 20px, | ||
'm': 50px, | ||
'l': 100px, | ||
'xl': 200px | ||
); | ||
|
||
@each $key, $size in $sizes { | ||
.colorblock_#{$key} { | ||
@extend .colorblock; | ||
@include colorblock-size($size); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro colorBlock(params) %} | ||
{%- include "./template.njk" -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span style="background-color: {{params.color}}" class="colorblock colorblock_{{params.blockSize if params.blockSize else 'm'}}"></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.colorCard > dl { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
.colorCard > dl > dd { | ||
padding: 0; | ||
margin-left: 100px; | ||
} | ||
@media (max-width: 640px) { | ||
.colorCard > dl > dd { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} | ||
@media (min-width: 641px) { | ||
.colorCard > dl > dt { | ||
padding: 0; | ||
margin: 0 10px 0 0; | ||
width: 100px; | ||
} | ||
} | ||
@media (max-width: 640px) { | ||
.colorCard > dl > dt { | ||
padding: 0; | ||
margin: 0 10px 0 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro colorCard(params) %} | ||
{%- include "./template.njk" -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% from "colorBlock/macro.njk" import colorBlock %} | ||
{% set headingLevel %} | ||
{{ params.headingLevel if params.headingLevel else 'h2' }} | ||
{% endset %} | ||
<div class="card colorCard"> | ||
{% if params.heading %} | ||
<{{headingLevel}} class="nhsuk-card__heading nhsuk-heading-m"> | ||
{{ params.heading }} | ||
</{{headingLevel}}> | ||
{% endif %} | ||
<div>{{ colorBlock(params) }}</div> | ||
<dl> | ||
<dt>Hex</dt> | ||
<dd>{{params.color}}</dd> | ||
<dt>RGB</dt> | ||
<dd>{{params.color | convertColor('RGB') }}</dd> | ||
<dt>CMYK</dt> | ||
<dd>{{params.color | convertColor('CMYK') }}</dd> | ||
{% if params.pantone %} | ||
<dt>Pantone</dt> | ||
<dd>{{params.pantone}}</dd> | ||
{% endif %} | ||
{% if params.ral %} | ||
<dt>RAL</dt> | ||
<dd>{{params.ral}}</dd> | ||
{% endif %} | ||
</dl> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let convert = require('color-convert'); | ||
|
||
function hexToRgb(hex) { | ||
return convert.hex.rgb(hex); | ||
} | ||
function hexToCmyk(hex) { | ||
return convert.hex.cmyk(hex); | ||
} | ||
function stringify(values) { | ||
return values ? values.join(',') : values; | ||
} | ||
let convertColor = (value, format) => { | ||
if (value) { | ||
if ('CMYK' === format) { | ||
return stringify(hexToCmyk(value)); | ||
} | ||
if ('RGB' === format) { | ||
return stringify(hexToRgb(value)); | ||
} | ||
} | ||
return value; | ||
}; | ||
|
||
module.exports = convertColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const convertColor = require('../../_filters/convertColor'); | ||
|
||
describe('blank', () => { | ||
test('should export module as a function', () => { | ||
expect(typeof convertColor).toBe('function'); | ||
}); | ||
|
||
test.each([ | ||
{ value: '#000000', format: 'RGB', expected: '0,0,0' }, | ||
{ value: '#FFFFFF', format: 'RGB', expected: '255,255,255' }, | ||
{ value: '#FF0000', format: 'RGB', expected: '255,0,0' }, | ||
{ value: '#00FF00', format: 'RGB', expected: '0,255,0' }, | ||
{ value: '#0000FF', format: 'RGB', expected: '0,0,255' }, | ||
])('should return RGB when input is: %s', ({ value, format, expected }) => { | ||
expect(convertColor(value, format)).toBe(expected); | ||
}); | ||
|
||
test.each([ | ||
{ value: '#000000', format: 'CMYK', expected: '0,0,0,100' }, | ||
{ value: '#FFFFFF', format: 'CMYK', expected: '0,0,0,0' }, | ||
{ value: '#FF0000', format: 'CMYK', expected: '0,100,100,0' }, | ||
{ value: '#00FF00', format: 'CMYK', expected: '100,0,100,0' }, | ||
{ value: '#0000FF', format: 'CMYK', expected: '100,100,0,0' }, | ||
{ value: '#00FFFF', format: 'CMYK', expected: '100,0,0,0' }, | ||
{ value: '#FF00FF', format: 'CMYK', expected: '0,100,0,0' }, | ||
{ value: '#FFFF00', format: 'CMYK', expected: '0,0,100,0' }, | ||
])('should return CMYK when input is: %s', ({ value, format, expected }) => { | ||
expect(convertColor(value, format)).toBe(expected); | ||
}); | ||
}); |
Oops, something went wrong.