Skip to content

Commit 093709a

Browse files
committed
Rework header component architecture to consume generic header
1 parent 19ed433 commit 093709a

2 files changed

Lines changed: 26 additions & 82 deletions

File tree

packages/govuk-frontend/src/govuk/components/header/_mixin.scss

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,33 @@
11
@use "../../base";
2+
@use "../generic-header/mixin" as genericHeader;
23

34
/// @access private
45
@mixin styles {
56
$logo-bottom-margin: 2px;
67

78
.govuk-header {
8-
@include base.govuk-font($size: 16, $line-height: 1);
9-
10-
// Add a transparent bottom border for forced-colour modes
11-
border-bottom: 1px solid transparent;
12-
color: base.govuk-colour("white");
13-
background: base.govuk-functional-colour(brand);
9+
@include genericHeader.header-styles($background: base.govuk-functional-colour("brand"));
1410
}
1511

1612
.govuk-header__container--full-width {
1713
padding: 0 base.govuk-spacing(3);
1814
}
1915

2016
.govuk-header__logo {
21-
box-sizing: border-box;
22-
2317
// Magic numbers, set padding to vertically centre align the logo
24-
padding-top: 16px;
25-
padding-bottom: 14px - $logo-bottom-margin;
18+
@include genericHeader.header-logo-styles($padding-top: 16px, $padding-bottom: 14px - $logo-bottom-margin);
2619
}
2720

2821
.govuk-header__homepage-link {
29-
// Avoid using the `base.govuk-link-common` mixin because the links in the
30-
// header get a special treatment, because:
31-
//
32-
// - underlines are only visible on hover
33-
// - all links get a 3px underline regardless of text size, as there are
34-
// multiple grouped elements close to one another and having slightly
35-
// different underline widths looks unbalanced
36-
//
37-
// Font size needs to be set on the link so that the box sizing is correct
38-
// in Firefox
39-
display: inline;
40-
margin-right: base.govuk-spacing(2);
41-
font-size: 30px; // We don't have a mixin that produces 30px font size
42-
text-decoration: none;
22+
@include genericHeader.header-link-styles;
23+
4324
// Remove word-spacing from within the logo so we can ignore
4425
// whitespace characters in the HTML
4526
word-spacing: base.govuk-px-to-rem(-6px);
4627
// Reset word-spacing for child elements
4728
> * {
4829
word-spacing: 0;
4930
}
50-
@include base.govuk-link-style-inverse;
51-
52-
&:link,
53-
&:visited {
54-
text-decoration: none;
55-
}
56-
57-
&:hover,
58-
&:active {
59-
// Negate the added border
60-
$link-underline-thickness: 3px;
61-
margin-bottom: $link-underline-thickness * -1;
62-
border-bottom: $link-underline-thickness solid;
63-
}
64-
65-
&:focus {
66-
// Remove any borders that show when focused and hovered.
67-
margin-bottom: 0;
68-
border-bottom: 0;
69-
70-
@include base.govuk-focused-text;
71-
}
7231
}
7332

7433
.govuk-header__logotype {
@@ -146,24 +105,6 @@
146105
}
147106

148107
@media print {
149-
.govuk-header {
150-
border-bottom-width: 0;
151-
color: base.govuk-colour("black");
152-
background: transparent;
153-
}
154-
155-
.govuk-header__homepage-link {
156-
&:link,
157-
&:visited {
158-
color: base.govuk-colour("black");
159-
}
160-
161-
// Do not append link href to GOV.UK link when printing (e.g. '(/)')
162-
&::after {
163-
display: none;
164-
}
165-
}
166-
167108
.govuk-header__product-name {
168109
// Fix product name alignment in Firefox when printing
169110
@-moz-document url-prefix() {
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
{% from "../../macros/attributes.njk" import govukAttributes -%}
1+
{% from "../generic-header/macro.njk" import govukGenericHeader -%}
22
{% from "../../macros/logo.njk" import govukLogo -%}
33

4-
<div class="govuk-header {%- if params.classes %} {{ params.classes }}{% endif %}" {{- govukAttributes(params.attributes) }}>
5-
<div class="govuk-header__container {{ params.containerClasses | default("govuk-width-container", true) }}">
6-
<div class="govuk-header__logo">
7-
<a href="{{ params.homepageUrl | default("//gov.uk", true) }}" class="govuk-header__homepage-link">
8-
{{ govukLogo({
9-
classes: "govuk-header__logotype",
10-
ariaLabelText: "GOV.UK"
11-
}) | trim | indent(8) }}
12-
{% if (params.productName) %}
13-
<span class="govuk-header__product-name">
14-
{{- params.productName -}}
15-
</span>
16-
{% endif %}
17-
</a>
18-
</div>
19-
</div>
20-
</div>
4+
{% set logoContent %}
5+
{{ govukLogo({
6+
classes: "govuk-header__logotype",
7+
ariaLabelText: "GOV.UK"
8+
}) | trim | indent(8) }}
9+
{%- if (params.productName) %}
10+
<span class="govuk-header__product-name">
11+
{{- params.productName -}}
12+
</span>
13+
{% endif -%}
14+
{% endset %}
15+
16+
{{ govukGenericHeader({
17+
_rootClass: 'govuk-header',
18+
logo: logoContent,
19+
url: params.homepageUrl | default("//gov.uk", true),
20+
containerClasses: params.containerClasses,
21+
classes: params.classes,
22+
attributes: params.attributes
23+
}) }}

0 commit comments

Comments
 (0)