-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add primary navigation component. Fixes #34
- Loading branch information
1 parent
a9e4173
commit c64d1cb
Showing
5 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Primary navigation | ||
|
||
Implements the primary navigation component used on the GOV.UK Design System website. | ||
|
||
## Example usage | ||
|
||
```njk | ||
{{ xGovukPrimaryNavigation({ | ||
visuallyHiddenTitle: 'Navigation', | ||
items: [{ | ||
text: "About this project", | ||
href: "/about" | ||
}, { | ||
text: "Contact us", | ||
href: "/contact" | ||
}] | ||
}) }} | ||
``` | ||
|
||
## Component options | ||
|
||
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text. | ||
|
||
Some options are required for the macro to work; these are marked as “Required” in the option description. | ||
|
||
If you’re using Nunjucks macros in production with `html` options, or ones ending with `html`, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). | ||
|
||
| Name | Type | Description | | ||
| :--- | :--- | :---------- | | ||
| **items** | array | **Required**. An array of navigation links within the side navigation. See [items](#options-for-items). | | ||
| **classes** | string | Classes to add to the primary navigation container. | | ||
| **attributes** | object | HTML attributes (for example data attributes) to add to the primary navigation container. | | ||
| **visuallyHiddenTitle** | string | A hidden title for the side navigation. | | ||
|
||
### Options for items | ||
|
||
| Name | Type | Description | | ||
| :--- | :--- | :---------- | | ||
| **text** | string | **Required**. Text of the navigation link. | | ||
| **href** | array | **Required**. The value of the navigation link’s `href` attribute. | | ||
| **current** | boolean | Indicate that the item is the current page. | | ||
| **classes** | string | Classes to add to the navigation item. | |
65 changes: 65 additions & 0 deletions
65
x-govuk/components/primary-navigation/_primary-navigation.scss
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,65 @@ | ||
.x-govuk-primary-navigation { | ||
@include govuk-font(19, $weight: bold); | ||
background-color: govuk-colour("light-grey"); | ||
border-bottom: 1px solid $govuk-border-colour; | ||
} | ||
|
||
.govuk-phase-banner + .x-govuk-primary-navigation { | ||
margin-top: -1px; | ||
} | ||
|
||
.x-govuk-primary-navigation__list { | ||
@include govuk-clearfix; | ||
left: govuk-spacing(-3); | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
position: relative; | ||
right: govuk-spacing(-3); | ||
width: calc(100% + #{govuk-spacing(6)}); | ||
} | ||
|
||
.x-govuk-primary-navigation__item { | ||
box-sizing: border-box; | ||
display: block; | ||
float: left; | ||
line-height: 50px; | ||
height: 50px; | ||
padding: 0 govuk-spacing(3); | ||
position: relative; | ||
} | ||
|
||
.x-govuk-primary-navigation__item--current { | ||
border-bottom: $govuk-border-width-narrow solid $govuk-link-colour; | ||
|
||
&:hover { | ||
border-bottom-color: $govuk-link-hover-colour; | ||
} | ||
|
||
&:active { | ||
border-bottom-color: $govuk-link-active-colour; | ||
} | ||
} | ||
|
||
.x-govuk-primary-navigation__item--align-right { | ||
@include govuk-media-query($from: tablet) { | ||
float: right; | ||
} | ||
} | ||
|
||
.x-govuk-primary-navigation__link { | ||
@include govuk-link-common; | ||
@include govuk-link-style-no-visited-state; | ||
@include govuk-link-style-no-underline; | ||
@include govuk-typography-weight-bold; | ||
|
||
// Extend the touch area of the link to the list | ||
&:after { | ||
bottom: 0; | ||
content: ""; | ||
left: 0; | ||
position: absolute; | ||
right: 0; | ||
top: 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 xGovukPrimaryNavigation(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,17 @@ | ||
<nav class="x-govuk-primary-navigation {%- if params.classes %} {{ params.classes }}{% endif -%}" aria-labelledby="x-govuk-primary-navigation-heading" | ||
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}> | ||
<div class="govuk-width-container"> | ||
<h2 class="govuk-visually-hidden" id="x-govuk-primary-navigation-heading">{{ params.visuallyHiddenTitle or "Menu" }}</h2> | ||
<ul class="x-govuk-primary-navigation__list"> | ||
{%- for item in params.items %} | ||
{% if item.href %} | ||
<li class="x-govuk-primary-navigation__item {{ "x-govuk-primary-navigation__item--current" if item.current }}{% if item.classes %} {{ item.classes }}{% endif -%}"> | ||
<a class="x-govuk-primary-navigation__link" {{ "aria-current=page" if item.current }} href="{{ item.href }}"> | ||
{{- item.text -}} | ||
</a> | ||
</li> | ||
{% endif %} | ||
{% endfor -%} | ||
</ul> | ||
</div> | ||
</nav> |