Skip to content

Commit

Permalink
Add alternative header layout
Browse files Browse the repository at this point in the history
    This adds a new layout alternative that allows for search on the
    left of the header and navigation items on the right to support
    some layouts seen in whitehall pages.

    It also corrects a stray div that was breaking the with-nav option
    without a searchbox.
  • Loading branch information
maxgds committed Feb 5, 2020
1 parent db0dbd8 commit 8d12349
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,66 @@
}
}

.gem-c-layout-header--search-left {

.gem-c-header__menu-button {
position: absolute;
margin-top: - govuk-spacing(7);
left: 0;
}

.gem-c-header__nav-wrapper {
position: relative;
padding-left: 0;
}

.govuk-header__navigation--open {
margin-top: govuk-spacing(2);
}

.govuk-header__navigation--end {
padding-top: 0;
text-align: left;
}

.gem-c-layout-header__search {
margin-bottom: govuk-spacing(2);
}

.gem-c-layout-header__search {
padding-bottom: govuk-spacing(5);
}

.gem-c-header__content {
position: relative;
}

@include govuk-media-query($from: desktop) {
.gem-c-layout-header__search {
padding-bottom: govuk-spacing(1);
}

.govuk-header__navigation-item {
padding: 0 0 govuk-spacing(1) 0;
}

.gem-c-header__logo {
margin-top: 0;
}

.gem-c-header__content {
@include govuk-grid-column(two-thirds, $at: desktop);
padding-left: govuk-spacing(6);
padding-right: govuk-spacing(1);
}

}

}

.gem-c-layout-header__logo,
.gem-c-layout-header__search {
padding: 0;
margin-bottom: govuk-spacing(2);

@include govuk-media-query($until: "tablet") {
margin-bottom: 0;
Expand All @@ -40,6 +96,7 @@

.gem-c-header__logo {
white-space: nowrap;
margin-top: govuk-spacing(1);
}

.gem-c-header__content {
Expand All @@ -50,6 +107,10 @@
}
}

.govuk-header__navigation--end {
text-align: right;
}

.gem-c-header__product-name {
display: none;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<%= render "govuk_publishing_components/components/layout_header", {
environment: "public",
search: !without_search,
remove_bottom_border: full_width
remove_bottom_border: full_width,
} %>

<main class="<%= "govuk-width-container govuk-main-wrapper" unless full_width %> <%= main_classes %>" id="content">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<%
full_width ||= false
product_name ||= "Publishing"
search ||= false
public_environment = environment.eql?("public")
navigation_items ||= []
remove_bottom_border ||= false
search_left ||= false

if full_width
width_class = "govuk-header__container--full-width"
Expand All @@ -13,63 +15,49 @@
end
%>
<header class="gem-c-layout-header govuk-header gem-c-layout-header--<%= environment %> <%= "gem-c-layout-header--no-bottom-border" if remove_bottom_border %>" role="banner" data-module="govuk-header">
<div class="govuk-header__container <%= width_class %>">
<div class="gem-c-layout-header__logo govuk-grid-column-two-thirds">
<div class="govuk-header__logo gem-c-header__logo">
<a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype">
<svg role="presentation" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 132 97" height="32" width="36">
<path fill="currentColor" fill-rule="evenodd"
d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6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.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"
></path>
<image src="<%= asset_path('govuk-logotype-crown.png') %>" class="govuk-header__logotype-crown-fallback-image"></image>
</svg>
<span class="govuk-header__logotype-text">
GOV.UK
</span>
</span>
<% unless public_environment %>
<span class="govuk-header__product-name gem-c-header__product-name">
<%= product_name %>
</span>
<span class="gem-c-environment-tag govuk-tag gem-c-environment-tag--<%= environment %>">
<%= environment %>
</span>
<% end %>
</a>
</div><div class="govuk-header__content gem-c-header__content">
<% if navigation_items.any? %>
<button role="button" class="govuk-header__menu-button gem-c-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide Top Level Navigation">Menu</button>
<nav class="gem-c-header__nav">
<ul id="navigation" class="govuk-header__navigation govuk-header__navigation--end" aria-label="Top Level Navigation">
<% navigation_items.each_with_index do |item, index| %>
<li class="govuk-header__navigation-item <%= "govuk-header__navigation-item--active" if item[:active] %>
<%= "govuk-header__navigation-item--collapsed-menu-only" if item[:show_only_in_collapsed_menu] %>">
<%= link_to(
item[:text],
item[:href],
class: 'govuk-header__link',
) %>
</li>
<% end %>
</ul>
</nav>
<% end %>

</div>
</div>

<% if search %>
<div class="govuk-grid-column-one-third gem-c-layout-header__search">
<% if search_left %>
<header class="gem-c-layout-header gem-c-layout-header--search-left govuk-header gem-c-layout-header--<%= environment %> <%= "gem-c-layout-header--no-bottom-border" if remove_bottom_border %>" role="banner" data-module="govuk-header">
<div class="govuk-header__container <%= width_class %>">
<div class="govuk-grid-row govuk-!-margin-left-0 govuk-!-margin-right-0">
<div class="gem-c-layout-header__logo govuk-grid-column-one-third-from-desktop">
<%= render "govuk_publishing_components/components/layout_header/header_logo", public_environment: public_environment, environment: environment, product_name: product_name %>
</div>
</div>
<div class="govuk-grid-row govuk-!-margin-left-0 govuk-!-margin-right-0">
<div class="govuk-grid-column-full govuk-grid-column-one-third-from-desktop gem-c-layout-header__search">
<%= render "govuk_publishing_components/components/search", {
id: "site-search-text",
label_text: "Search",
no_border: true,
no_margin: true
} %>
</div>
<% end %>
<div class="govuk-header__content gem-c-header__content govuk-grid-column-full govuk-grid-column-two-thirds-from-desktop">
<%= render "govuk_publishing_components/components/layout_header/navigation_items", navigation_items: navigation_items %>
</div>
</div>
</div>
</header>

</div>
</header>
<% else %>
<header class="gem-c-layout-header govuk-header gem-c-layout-header--<%= environment %> <%= "gem-c-layout-header--no-bottom-border" if remove_bottom_border %>" role="banner" data-module="govuk-header">
<div class="govuk-header__container <%= width_class %>">
<div class="gem-c-layout-header__logo govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/layout_header/header_logo", public_environment: public_environment, environment: environment, product_name: product_name %>
</div>
<div class="govuk-header__content gem-c-header__content">
<%= render "govuk_publishing_components/components/layout_header/navigation_items", navigation_items: navigation_items %>
</div>
<% if search %>
<div class="govuk-grid-column-one-third gem-c-layout-header__search">
<%= render "govuk_publishing_components/components/search", {
id: "site-search-text",
label_text: "Search",
no_border: true,
no_margin: true
} %>
</div>
<% end %>
</div>
</header>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ examples:
- text: Hidden on desktop
href: "item-3"
show_only_in_collapsed_menu: true

with_left_search_and_navigation:
data:
search_left: true
environment: public
navigation_items:
- text: Departments
href: "item-1"
- text: Worldwide
href: "item-2"
- text: How government works
href: "item-3"
- text: Get involved
href: "item-4"
- text: Consultations
href: "item-4"
- text: Statistics
href: "item-5"
- text: News and communications
href: "item-6"
active: true


full_width:
description: |
This is difficult to preview because the preview windows are constrained, but the header will stretch to the size of its container.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<div class="govuk-header__logo gem-c-header__logo">
<a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype">
<svg role="presentation" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 132 97" height="32" width="36">
<path fill="currentColor" fill-rule="evenodd"
d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 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 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"
></path>
<image src="<%= asset_path('govuk-logotype-crown.png') %>" class="govuk-header__logotype-crown-fallback-image"></image>
</svg>
<span class="govuk-header__logotype-text">
GOV.UK
</span>
</span>
<% unless public_environment %>
<span class="govuk-header__product-name gem-c-header__product-name">
<%= product_name %>
</span>
<span class="gem-c-environment-tag govuk-tag gem-c-environment-tag--<%= environment %>">
<%= environment %>
</span>
<% end %>
</a>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if navigation_items.any? %>
<button role="button" class="govuk-header__menu-button gem-c-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide Top Level Navigation">Menu</button>
<nav class="gem-c-header__nav">
<ul id="navigation" class="govuk-header__navigation govuk-header__navigation--end" aria-label="Top Level Navigation">
<% navigation_items.each_with_index do |item, index| %>
<li class="govuk-header__navigation-item <%= "govuk-header__navigation-item--active" if item[:active] %>
<%= "govuk-header__navigation-item--collapsed-menu-only" if item[:show_only_in_collapsed_menu] %>">
<%= link_to(
item[:text],
item[:href],
class: 'govuk-header__link',
) %>
</li>
<% end %>
</ul>
</nav>
<% end %>
6 changes: 6 additions & 0 deletions spec/components/layout_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ def component_name

assert_select ".gem-c-layout-header .gem-c-search"
end

it "renders the search bar on the left when requested" do
render_component(environment: 'public', search: true, search_left: true)

assert_select ".gem-c-layout-header--search-left"
end
end

0 comments on commit 8d12349

Please sign in to comment.