Skip to content

Commit 7da5e8e

Browse files
Stuart Robsonkhawkins98
Stuart Robson
andauthored
the one that refactors the masthead (#1195)
* sneaks in hiding vscode workspaces * removes masthead search CSS * removes vf-masthead support as it's no longer needed * updates to masthead and variants * updates yaml/nunjuck relationship with variables * updates masthead variants * takes this back to normal * Refactore: vf-masthead-js Optimastions for #1195, this: - lints the JS - allows use of `style=" --vf-masthead__bg-image: url(../../assets/vf-masthead/assets/group-bg_2d4155.png);` - fixes the JS to remove escaped syntax * Update vf-masthead.js * updates masthead JS, image, njk variables * cupdates theming variable for title-block--primary * makes words break on smaller devices * more updates to masthead, cleaner code, improved docs * cha-cha-cha-changelog Co-authored-by: Ken Hawkins <[email protected]>
1 parent 390cf9d commit 7da5e8e

9 files changed

+148
-194
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ backstop_data/html_report/
1111
bitmaps_test/
1212
temp
1313
package.variables.scss
14-
*.precompiled.js
14+
*.precompiled.js
15+
*.code-workspace

components/vf-componenet-rollup/index.scss

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ button {
8686
@import 'vf-lede/vf-lede.scss';
8787

8888
@import 'vf-masthead/vf-masthead.scss';
89-
@import 'vf-masthead/vf-masthead--supports.scss';
9089

9190
@import 'vf-navigation/vf-navigation.scss';
9291
@import 'vf-navigation/vf-navigation--global.scss';

components/vf-masthead/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 2.0.0
2+
3+
* updates how `njk` and `yml` variables are named and work.
4+
* tidied up how JavaScript decides on text colour from image.
5+
* renamed `h2` classnames so they're not so specific to its content.
6+
* removes redundant form search CSS
7+
* updated documentation
8+
19
### 1.2.0
210

311
* updates spacing design tokens

components/vf-masthead/README.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44

55
## About
66

7+
The `vf-masthead` (masthead) is a full-width container that can take a text, theme colour, an image, and create a 'block' for the text to lay atop.
8+
79
## Usage
810

11+
The `vf-masthead` component can be used on the home page of group sites to help inform the visitor of the groups name, location, and additional information.
12+
13+
| ✅ Do's | 🚫 Do Not's |
14+
| --------------------------------------- | ------------------------------------------ |
15+
| Use this on the homepage of group sites | On every subsquent page |
16+
| Use the title block with a theme colour | Use a title block, theme colour, and image |
17+
18+
919
### Background Colours
1020

11-
By Default, the `vf-masthead` is white text on a black background except if it is the title block variant where the text will be black on a white background with an overall black background.
21+
By Default, the `vf-masthead` is black text on a light grey background except if it is the title block variant where the text will be white on a black background with an overall light grey background.
1222

13-
This can be effected by either having a global theme class applied to a parent (usually on `body`) where the colours determined by the theme name will cascade into this component. The other way is to apply a component specific class that effects the colours.
23+
This can be effected by either having a component specific class that effects the colours.
1424

1525
Theme Variants available are:
1626

@@ -41,22 +51,24 @@ When using a background image we have to determine the best text colour to meet
4151

4252
We do this using JavaScript and the background image filename.
4353

44-
In creating the background images for mastheads each image filename needs to have it's most dominate colour added as a hexadecimal code.
54+
In choosing the image for masthead the image filename needs to have it's most dominate colour added as a hexadecimal code.
4555

4656
```bash
4757
masthead-background-image--00EF00.png
4858
```
4959
<br>
5060

51-
The JavaScript looks for this hexidecimal colour code and mathematically works out the correct text colour to use. The CSS custom property `--local-theme-fg-color` is then applied in the style tag of the component.
61+
To find the dominant colour in the background image you can use a colour picker in graphics software to find the hex code.
62+
63+
This then allows the code to look for this hexidecimal colour code and mathematically works out the correct text colour to use. The CSS custom property `--local-theme-fg-color` is then applied in the style tag of the component.
5264

5365
```html
5466
<style>
5567
<div
5668
class="vf-masthead vf-masthead--has-image"
5769
style="background-image: var(--vf-masthead__bg-image);
5870
--local-theme-fg-color:#FFFFFF;"
59-
data-vf-js-masthead=""
71+
data-vf-js-masthead
6072
>
6173
</style>
6274
```

components/vf-masthead/vf-masthead--supports.scss

-13
This file was deleted.

components/vf-masthead/vf-masthead.config.yml

+23-12
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,39 @@ context:
77
component-type: block
88

99
masthead_href: 'JavaScript:Void(0);'
10+
masthead_heading: Strategy & Communications
11+
masthead_heading_additional: Chromosome structure and dynamics
12+
masthead_subheading:
13+
- masthead_subheading_text: <a href="JavaScript:Void(0);">VF Hamburg</a>
14+
- masthead_subheading_text: Structural Biology
1015

1116
variants:
1217
- name: default
1318
- name: primary
1419
context:
15-
mastheadThemeVariant: vf-masthead-theme--primary
20+
mastheadTheme: primary
1621
- name: secondary
1722
context:
18-
mastheadThemeVariant: vf-masthead-theme--secondary
23+
mastheadTheme: secondary
1924
- name: tertiary
2025
context:
21-
mastheadThemeVariant: vf-masthead-theme--tertiary
22-
- name: with background image
26+
mastheadTheme: tertiary
27+
28+
- name: title block
2329
context:
24-
mastheadImageClass: vf-masthead--has-image
25-
mastheadImage: "../../assets/vf-masthead/assets/group-bg_2d4155.png"
26-
- name: with title block
30+
hasTitleBlock: true
31+
32+
- name: title block (primary)
2733
context:
28-
hasTitleBlock: vf-masthead--with-title-block
34+
hasTitleBlock: true
35+
mastheadTheme: primary
2936

30-
- name: kitchen sink
37+
- name: image
3138
context:
32-
mastheadImageClass: vf-masthead--has-image
33-
mastheadImage: "../../assets/vf-masthead/assets/group-bg_2d4155.png"
34-
hasTitleBlock: vf-masthead--with-title-block
39+
mastheadImage: "https://acxngcvroo.cloudimg.io/v7/https://www.embl.org/files/wp-content/uploads/VF_Masthead_Example_52ACEA.jpg"
40+
41+
- name: title block and image
42+
context:
43+
mastheadImage: "https://acxngcvroo.cloudimg.io/v7/https://www.embl.org/files/wp-content/uploads/VF_Masthead_Example_52ACEA.jpg"
44+
hasTitleBlock: true
45+

components/vf-masthead/vf-masthead.js

+26-27
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
// vf-masthead
22

3-
4-
// The background image for the banner element are taken from the database.
5-
// The filename includes the hex code for the background colour of the image.
6-
// Then test if the 6 characters are a hex code and declare the background-color
7-
83
/**
94
* Function for making background color of banner from image file name
5+
* The background image for the banner element are taken from the CSS custom property.
6+
* The filename includes the hex code for the background colour of the image.
7+
* Then test if the 6 characters are a hex code and declare the background-color
108
* @example vfMastheadSetStyle()
119
*/
1210

1311
function vfMastheadSetStyle() {
1412
const vfMastheads = document.querySelectorAll("[data-vf-js-masthead]");
1513

14+
// utility colour functions
15+
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h;}
16+
function hexToR(h) {return parseInt((cutHex(h)).substring(0,2),16);}
17+
function hexToG(h) {return parseInt((cutHex(h)).substring(2,4),16);}
18+
function hexToB(h) {return parseInt((cutHex(h)).substring(4,6),16);}
19+
20+
function getCorrectTextColor(hex){
21+
let hRed = hexToR(hex);
22+
let hGreen = hexToG(hex);
23+
let hBlue = hexToB(hex);
24+
return ((hRed * 299) + (hGreen * 587) + (hBlue * 114)) / 1000;
25+
}
26+
1627
if (vfMastheads[0]) {
1728
let el = vfMastheads[0];
1829
let bannerBG = getComputedStyle(el).getPropertyValue("--vf-masthead__bg-image");
30+
let regex = /\\/gi; // avoid escaped syntax like "bg_2d4155\.png"
31+
bannerBG = bannerBG.replaceAll(regex,"");
1932
let filename = bannerBG.substr(0, bannerBG.lastIndexOf(".")) || bannerBG;
2033
let hexcode = filename.substr(filename.length - 6);
2134
let bannerBGC = "#" + hexcode;
@@ -26,39 +39,25 @@ function vfMastheadSetStyle() {
2639
var modalAlertClasses = ["vf-masthead--with-title-block"];
2740
var modal = document.querySelector(".vf-masthead");
2841

29-
30-
if( modal.classList.contains(modalAlertClasses)){
31-
}
32-
else {
33-
42+
if (modal.classList.contains(modalAlertClasses)) {
43+
// if using title block no action neccessary
44+
} else {
3445
if (regHex.test(hexcode)) {
3546

36-
if (!bannerBGC) return;
47+
if (!bannerBGC) return; // if no background colour specified, nothing to do
3748

3849
bannerBGC = bannerBGC.trim();
39-
40-
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h;}
41-
function hexToR(h) {return parseInt((cutHex(h)).substring(0,2),16);}
42-
function hexToG(h) {return parseInt((cutHex(h)).substring(2,4),16);}
43-
function hexToB(h) {return parseInt((cutHex(h)).substring(4,6),16);}
44-
45-
function getCorrectTextColor(hex){
46-
let hRed = hexToR(hex);
47-
let hGreen = hexToG(hex);
48-
let hBlue = hexToB(hex);
49-
return ((hRed * 299) + (hGreen * 587) + (hBlue * 114)) / 1000;
50-
}
51-
5250
cBrightness = getCorrectTextColor(bannerBGC);
5351

5452
if (cBrightness > threshold){
5553
el.style.setProperty("--vf-masthead__color--foreground-default", "#000000");
54+
el.style.setProperty("--vf-masthead__color--background-default", "#FFFFFF");
5655
} else if (cBrightness < threshold) {
5756
el.style.setProperty("--vf-masthead__color--foreground-default", "#FFFFFF");
57+
el.style.setProperty("--vf-masthead__color--background-default", "#000000");
5858
}
59-
}
60-
else {
61-
el.style.setProperty("--vf-masthead__bg-image", "none");
59+
} else {
60+
el.style.setProperty("--vf-masthead__bg-image", "unset");
6261
}
6362
}
6463
}
+21-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
<style>
2-
.vf-masthead {
3-
--vf-masthead__bg-image: url({{ mastheadImage }});
4-
}
5-
</style>
1+
{% spaceless %}
62
<div
73
class="vf-masthead
8-
{%- if mastheadThemeVariant %}
9-
{{mastheadThemeVariant}}
4+
{%- if mastheadTheme %} vf-masthead-theme--{{mastheadTheme}}{%- endif -%}
5+
6+
{% if hasTitleBlock %} vf-masthead--with-title-block{% endif %}
7+
8+
{%- if mastheadImage %} vf-masthead--has-image{% endif %}
9+
| vf-u-fullbleed"
10+
{% if mastheadImage -%}
11+
style="
12+
--vf-masthead__bg-image: url({{ mastheadImage }});
13+
background-image: var(--vf-masthead__bg-image)" data-vf-js-masthead
1014
{%- endif -%}
11-
{% if hasTitleBlock %}
12-
{{hasTitleBlock}}
13-
{% endif -%}
14-
{% if mastheadImageClass %}
15-
{{mastheadImageClass}}
16-
{% endif -%}"
17-
{% if mastheadImage %}
18-
style="background-image: var(--vf-masthead__bg-image)"
19-
data-vf-js-masthead
20-
{% endif %}
2115
>
22-
<div class="vf-masthead__inner">
2316
<div class="vf-masthead__title">
2417
<h1 class="vf-masthead__heading">
25-
<a href="{{ masthead_href }}" class="vf-masthead__heading__link">Strategy &amp; Communications</a>
26-
<span class="vf-masthead__heading--additional">Chromosome structure and dynamics</span>
18+
<a href="{{ masthead_href }}" class="vf-masthead__heading__link">{{ masthead_heading }}</a>
19+
{%- if masthead_heading_additional -%}
20+
<span class="vf-masthead__heading--additional">{{ masthead_heading_additional }}</span>
21+
{%- endif -%}
2722
</h1>
23+
{%- if masthead_subheading -%}
2824
<h2 class="vf-masthead__subheading">
29-
<span class="vf-masthead__location">VF Hamburg</span>
30-
<span class="vf-masthead__group">Structural Biology</span>
25+
{% for item in masthead_subheading %}
26+
<span class="vf-masthead__subheading__text">{{ item.masthead_subheading_text }}</span>
27+
{% endfor %}
3128
</h2>
29+
{%- endif -%}
3230
</div>
33-
</div>
3431
</div>
32+
{% endspaceless %}

0 commit comments

Comments
 (0)