Skip to content

Commit

Permalink
Add navigation option
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 12, 2023
1 parent e76fc72 commit 8ec30a8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components/header/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// See: https://github.com/alphagov/govuk-design-system/blob/master/src/stylesheets/components/_header.scss

@include govuk-exports("app-header") {
.app-header--with-navigation {
border-bottom: $govuk-border-width-wide solid $govuk-brand-colour;
}

// Override the default 33% width on the logo in GOV.UK Frontend (prevents
// unnecessary wrapping of product name on smaller tablet / desktop
// viewports)
Expand Down
7 changes: 6 additions & 1 deletion components/header/template.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% from "x-govuk/components/primary-navigation/macro.njk" import xGovukPrimaryNavigation %}
{%- from "../site-search/macro.njk" import appSiteSearch -%}
<header class="govuk-header app-header" role="banner" data-module="govuk-header">
<header class="govuk-header app-header{% if params.navigation %} app-header--with-navigation{% endif %}" role="banner" data-module="govuk-header">
<div class="govuk-header__container govuk-width-container app-header__container">
<div class="govuk-header__logo app-header__logo">
<a href="{{ params.homepageUrl | default("/") | url }}" class="govuk-header__link govuk-header__link--homepage">
Expand All @@ -22,3 +23,7 @@
{{ appSiteSearch(params.search) if params.search.indexPath | indent(4) }}
</div>
</header>
{{ xGovukPrimaryNavigation({
visuallyHiddenTitle: params.navigation.visuallyHiddenTitle,
items: params.navigation.items | currentPage(page.url)
}) if params.navigation }}
13 changes: 13 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ module.exports = function (eleventyConfig) {
search: {
indexPath: '/search.json',
sitemapPath: '/sitemap'
},
// FOR PR REVIEW ONLY
navigation: {
items: [{
text: 'Layouts',
href: '/layouts',
}, {
text: 'Options',
href: '/options',
}, {
text: 'Hosting',
href: '/hosting',
}]
}
},
headingPermalinks: true,
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function (eleventyConfig, pluginOptions = {}) {

// Filters
eleventyConfig.addFilter('date', require('./lib/filters/date.js'))
eleventyConfig.addFilter('currentPage', require('./lib/filters/current-page.js'))
eleventyConfig.addFilter('includes', require('./lib/filters/includes.js'))
eleventyConfig.addFilter('itemsFromCollection', require('./lib/filters/items-from-collection.js'))
eleventyConfig.addFilter('itemsFromPagination', require('./lib/filters/items-from-pagination.js'))
Expand Down
2 changes: 1 addition & 1 deletion layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% from "components/document-header/macro.njk" import appDocumentHeader %}
{% from "components/document-list/macro.njk" import appDocumentList %}
{% from "components/footer/macro.njk" import appFooter %}
{% from "components/header/macro.njk" import appHeader %}
{% from "components/header/macro.njk" import appHeader with context %}
{% from "components/prose-scope/macro.njk" import appProseScope %}

{% block headIcons %}
Expand Down
13 changes: 13 additions & 0 deletions lib/filters/current-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Indicate which is the current item in navigation items
* @param {Array} array - Navigation items
* @param {string} pageUrl - URL of current page
* @returns {Array} Navigation items
*/
module.exports = (array, pageUrl) => {
return array.map(item => {
item.current = pageUrl.startsWith(item.href)

return item
})
}

0 comments on commit 8ec30a8

Please sign in to comment.