Skip to content

Commit 4aa3a7a

Browse files
committed
Add inverse styles to the navigation on homepage
1 parent ba93947 commit 4aa3a7a

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

lib/nunjucks/globals.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,20 @@ exports.getMacroOptions = getMacroOptions
167167
* @property {string} href - The URL of the ancestor page
168168
* @property {string} text - The title of the ancestor page
169169
*/
170+
171+
/**
172+
* Helper function that returns true if the current page is the homepage, useful
173+
* for outputting things conditionally.
174+
*
175+
* @returns {boolean} If this is the homepage or not
176+
*/
177+
178+
exports.isHomepage = function () {
179+
const permalink = this.lookup('permalink')
180+
181+
// The homepage always has an empty string as a permalink
182+
if (typeof permalink === 'string' && permalink === '') {
183+
return true
184+
}
185+
return false
186+
}

src/stylesheets/main.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ $app-code-color: #d13118;
8686
@include govuk-width-container(1100px);
8787
}
8888

89+
// Invert the colours of the navigation on the homepage
90+
.govuk-template--rebranded .govuk-service-navigation--inverse {
91+
border-bottom-color: govuk-colour("white");
92+
background-color: $govuk-brand-colour;
93+
94+
// Override the 'active' border colour
95+
.govuk-service-navigation__item,
96+
.govuk-service-navigation__service-name {
97+
border-color: govuk-colour("white");
98+
}
99+
100+
// Override mobile menu toggles colour
101+
.govuk-service-navigation__toggle,
102+
.app-mobile-navigation-section__toggle {
103+
color: govuk-colour("white");
104+
}
105+
106+
// Override link styles, but only the ones on the top level,
107+
// not those in sub menus
108+
.govuk-service-navigation__item > .govuk-service-navigation__link {
109+
@include govuk-link-style-inverse;
110+
}
111+
}
112+
89113
.app-main-wrapper {
90114
padding-top: govuk-spacing(3);
91115
padding-bottom: govuk-spacing(4);

views/layouts/layout.njk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{% extends "_generic.njk" %}
22

33
{% block body %}
4-
{# Only render breadcrumbs on pages that aren't the homepage. This is a bit
5-
hacky, but works as the homepage has an empty string for a permalink. #}
6-
{% if permalink %}
4+
{# Only render breadcrumbs on pages that aren't the homepage. #}
5+
{% if not isHomepage() %}
76
{{ govukBreadcrumbs({
87
classes: "app-width-container",
98
items: getAncestorPages(permalink)

views/partials/_navigation.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ service navigation component. #}
3333
{%- endfor %}
3434

3535
{{ govukServiceNavigation({
36+
classes: 'govuk-service-navigation--inverse' if isHomepage(),
3637
navigation: navLinks,
3738
navigationClasses: 'app-service-navigation__wrapper'
3839
}) }}

0 commit comments

Comments
 (0)