-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_macro.njk
218 lines (213 loc) · 13.1 KB
/
_macro.njk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
{% macro onsHeaderNew(params) %}
{#
This is an override of ONS "components/header/_macro.njk"
It is customised for the following reasons:
- Addition of custom classes to create a flex layout using 'gap' - see static_src/sass/components/design_system_overrides/_grid.scss
- Overrides to the button classes to accommodate a text button that is visible at desktop (for the new navigation menu button) - see static_src/sass/components/design_system_overrides/_button.scss
- Addition of custom styles for the new navigation menu button - see static_src/sass/components/_button-nav.scss
- Replace the serviceLinks option with a new navLinks option that creates the drop down menu - it may be possible in the design system to accommodate both
- See base.html for the structure needed for navLinks
- See static_src/sass/compnents/design_system_overrides/_header.scss for styling customisations
#}
{% from "components/button/_macro.njk" import onsButton %}
{% from "components/icon/_macro.njk" import onsIcon %}
{% from "components/navigation/_macro.njk" import onsNavigation %}
{% from "components/browser-banner/_macro.njk" import onsBrowserBanner %}
{% set titleTag = "h1" if params.titleAsH1 else "div" %}
{% set openingTag = "<" + titleTag %}
{% set closingTag = "</" + titleTag + ">" %}
{% set currentLanguageIsoCode = "en" %}
{% if params.language and params.language.languages %}
{% set currentLanguage = params.language.languages | selectattr("current") | first %}
{% set currentLanguageIsoCode = currentLanguage.isoCode %}
{% endif %}
<header
class="ons-header{{ ' '+ params.classes if params.classes }}{% if params.variants is not string %}{% for variant in params.variants %}{{ ' ' }}ons-header--{{ variant }}{% endfor %}{% else %}{{ ' ' }}ons-header--{{ params.variants }}{% endif %}"
role="banner"
>
{{
onsBrowserBanner({
"lang": currentLanguageIsoCode,
"wide": params.wide,
"fullWidth": params.fullWidth
})
}}
{% if params.phase %}
{% from "components/phase-banner/_macro.njk" import onsPhaseBanner %}
{{
onsPhaseBanner({
"fullWidth": params.fullWidth,
"wide": params.wide,
"hideBadge": params.phase.hideBadge,
"badge": params.phase.badge,
"html": params.phase.html
})
}}
{% endif %}
<div class="ons-header__top">
<div class="ons-container{{ ' ons-container--full-width' if params.fullWidth }}{{ ' ons-container--wide' if params.wide }}">
<div
class="ons-header__grid-top ons-grid ons-grid-flex ons-grid-flex--between{{ ' '+ params.mastheadLogo.classes if params.mastheadLogo.classes }}{{ ' ons-grid-flex--no-wrap ons-grid--gutterless' if not params.mastheadLogo.multipleLogos }}"
>
<div class="ons-grid__col ons-col-auto">
{%- if not params.mastheadLogo.multipleLogos -%}
{% set mastheadLogo %}
<div class="ons-header__org-logo ons-header__org-logo--large">
{% if params.mastheadLogo.large %}
{{ params.mastheadLogo.large | safe }}
{% else %}
{{-
onsIcon({
"iconType": 'ons-logo-' + currentLanguageIsoCode,
"altText": 'Office for National Statistics homepage'
})
-}}
{% endif %}
</div>
<div class="ons-header__org-logo ons-header__org-logo--small">
{% if params.mastheadLogo.small %}
{{ params.mastheadLogo.small | safe }}
{% elif params.mastheadLogo.large %}
{{ params.mastheadLogo.large | safe }}
{% else %}
{{-
onsIcon({
"iconType": 'ons-logo-stacked-' + currentLanguageIsoCode,
"altText": 'Office for National Statistics logo'
})
-}}
{% endif %}
</div>
{% endset %}
{%- if params.mastheadLogoUrl -%}
<a class="ons-header__org-logo-link" href="{{ params.mastheadLogoUrl }}">{{ mastheadLogo | safe }}</a>
{% else %}
{{ mastheadLogo | safe }}
{% endif %}
{% else %}
<div class="ons-header__org-logo ons-header__org-logo--multi">
{% set logos = [params.mastheadLogo.multipleLogos.logo1, params.mastheadLogo.multipleLogos.logo2, params.mastheadLogo.multipleLogos.logo3] %}
{% for logo in logos %}
{% set mastheadLogo %}
{% if logo.image != "ONS Logo" %}
{{ logo.image | safe }}
{% else %}
{{-
onsIcon({
"iconType": 'ons-logo-stacked-' + currentLanguageIsoCode,
"altText": 'Office for National Statistics logo'
})
-}}
{% endif %}
{% endset %}
{% if logo.url %}
<a class="ons-header__org-logo-link" href="{{ logo.url }}">{{ mastheadLogo | safe }}</a>
{% else %}
{{ mastheadLogo | safe }}
{% endif %}
{% endfor %}
</div>
{%- endif -%}
</div>
{# Note that navLinks replaces the previous serviceLinks #}
{% if params.navLinks %}
<div class="ons-header__links ons-grid__col ons-u-ml-auto">
{% if params.navLinks %}
{# May need to be replaced with a custom button - for now use the design system one with some modifications #}
{% set buttonVariant = ["text-link"] %}
<div class="ons-grid__col ons-col-auto">
{{
onsButton({
"text": params.navLinks.toggleNavButton.text | default("Menu"),
"classes": "ons-u-fs-s--b ons-js-toggle-services button-nav",
"type": "button",
"variants": "text-link",
"iconType": "chevron",
"iconPosition": "before",
"attributes": {
"aria-label": params.navLinks.toggleNavButton.ariaLabel | default("Toggle menu"),
"aria-controls": params.navLinks.id,
"aria-expanded": "false"
}
})
}}
</div>
{% endif %}
</div>
{% endif %}
</div>
</div>
{% if params.navLinks %}
<nav
class="ons-u-d-no ons-js-services-mobile-nav navigation"
id="{{ params.navLinks.id }}"
aria-label="{{ params.navLinks.ariaLabel | default("Main navigation") }}"
>
{% if params.navLinks.keyLinksList %}
<div class="ons-container">
<ul class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--40 navigation__key-links ons-list ons-list--bare">
{% for item in params.navLinks.keyLinksList %}
{% if item.text and item.url %}
<li class="ons-grid__col ons-col-4@m ons-u-mb-no">
<h2 class="ons-u-fs-s--b ons-u-mb-no navigation__heading avigation__heading--key-link">
<a href="{{ item.url }}" class="navigation__link">
{{ item.text }}
</a>
</h2>
{% if item.description %}
<p class="ons-u-fs-s ons-u-mb-no navigation__paragraph navigation__paragraph--key-link">{{ item.description }}</p>
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
{% if params.navLinks.itemsList %}
<div class="ons-container">
<ul class="ons-grid ons-grid-flex-gap ons-grid-flex-gap--40 ons-list ons-list--bare">
{% for item in params.navLinks.itemsList %}
<li class="ons-grid__col ons-col-4@m ons-u-mb-no">
{% for link in item.linksList %}
{% if link.text and link.url %}
<h2 class="ons-u-fs-s--b navigation__heading">
<a
href="{{ link.url }}"
class="ons-header-service-nav__link navigation__link"
>
{{ link.text }}
</a>
</h2>
{% endif %}
{% if link.children %}
<ul class="ons-list ons-list--bare navigation__child-list">
{% for child in link.children %}
{% if child.text and child.url %}
<li class="ons-u-mb-no">
<a
href="{{ child.url }}"
class="ons-header-service-nav__link navigation__link"
>
<p class="ons-u-fs-s navigation__paragraph">
{{ child.text }}
</p>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</nav>
{% endif %}
</div>
{% if params.navigation %}
{{ onsNavigation(params) }}
{% endif %}
</header>
{% endmacro %}