Skip to content

Commit

Permalink
INTR-204 Header redesign (#683)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico Picchio <nico.picchio@digital.trade.gov.uk>
  • Loading branch information
SamDudley and nicopicchio committed Jul 31, 2024
1 parent 95b8383 commit d5c82ce
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 65 deletions.
4 changes: 2 additions & 2 deletions assets/stylesheets/components/_search_field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $input-size: 40px;
position: relative;
display: flex;
flex: 0 $input-size;
margin: 7px 0;
margin: 0;

input {
// overly specific to prevent some overrides from outside
Expand Down Expand Up @@ -74,7 +74,7 @@ $input-size: 40px;
}

.site-search {
position: inherit;
position: inherit;
right: 0;
top: -4px;
align-items: center;
Expand Down
81 changes: 39 additions & 42 deletions src/core/templates/includes/header_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,52 @@
<div class="dwds-header-container">
<div class="dwds dwds-container">
<header class="dwds-header" role="banner" data-module="govuk-header">
<!-- logo -->
<div class="dwds-header-logo govuk-header__logo govuk-header__logo--ws">
<a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype govuk-header__logotype--ws">
<img aria-hidden="true"
src="{% webpack_static 'dbt-logo.png' %}"
srcset="{% webpack_static 'dbt-logo@2x.png' %} 2x"
alt="Department for Business & Trade logo" />
<span class="govuk-visually-hidden">Department for Business & Trade</span>
</span>
</a>
</div>

<!-- top row -->
<div class="dwds-header-top">
<!-- app name -->
<div class="dwds-header-app-name">
<a href="/" class="">
DBT Intranet
<div class="dwds-header-logo">
<div class="govuk-header__logo govuk-header__logo--ws">
<a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype govuk-header__logotype--ws">
<img aria-hidden="true"
src="{% webpack_static 'dbt-logo.png' %}"
srcset="{% webpack_static 'dbt-logo@2x.png' %} 2x"
alt="Department for Business & Trade logo" />
<span class="govuk-visually-hidden">Department for Business & Trade</span>
</span>
</a>
</div>
<!-- profile -->
{% include 'includes/profile_panel.html' %}
<!-- mobile menu -->

<button type="button"
class="govuk-header__menu-button govuk-header__menu-button--ws govuk-js-header-toggle"
id="header-menu-toggle"
class="dwds-header-menu-toggle"
aria-controls="navigation"
aria-label="Show or hide Top Level Navigation"
hidden>Menu</button>
aria-label="Show or hide Top Level Navigation">Menu</button>
</div>

<!-- bottom row -->
<div class="dwds-header-bottom">
{% if USER_IS_AUTHENTICATED %}
<!-- nav links -->
<nav aria-label="Top Level Navigation" class="dwds-header-nav-links">
{% main_menu max_levels=1 template="menus/main_menu.html" apply_active_classes=True %}
</nav>
<!-- search panel -->
<div class="dwds-header-search">
{% if not search_url %}
{% url 'search:all' as search_url %}
{% endif %}
{% include 'search/partials/search_form.html' with placeholder="Search pages and people" search_url=search_url %}
</div>
{% endif %}

<div id="header-menu" class="dwds-header-menu">
<a href="/" class="dwds-header-item dwds-header-app-name">DBT Intranet</a>

{% include 'includes/header_new_profile.html' %}

{% main_menu max_levels=1 template="menus/main_menu_new.html" apply_active_classes=True %}

<div class="dwds-header-item">
{% if not search_url %}
{% url 'search:all' as search_url %}
{% endif %}
{% include 'search/partials/search_form.html' with placeholder="Search pages and people" search_url=search_url %}
</div>
</div>
</header>
</div>
</div>

<!-- FIXME: removed site alert banner -->
<script>
document.addEventListener('DOMContentLoaded', () => {
const menuButton = document.querySelector("#header-menu-toggle");
const menu = document.querySelector("#header-menu");

menuButton.addEventListener("click", () => {
menuButton.classList.toggle("is-open");
menu.classList.toggle("is-active");
});
});
</script>
17 changes: 17 additions & 0 deletions src/core/templates/includes/header_new_profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% load webpack_static from webpack_loader %}
{% if peoplefinder_profile %}
<a href="{% url 'profile-view' peoplefinder_profile.slug %}"
class="dwds-header-item dwds-header-profile">
{% if peoplefinder_profile.profile_completion < 100 %}
<span>Your profile is {{ peoplefinder_profile.profile_completion|floatformat:0 }}% complete</span>
{% else %}
<span>Your profile</span>
{% endif %}
{% if peoplefinder_profile.photo %}
<img src="{{ peoplefinder_profile.photo_small.url }}"
alt="Profile image of {{ peoplefinder_profile.full_name }}">
{% else %}
<img src="{% webpack_static 'no-photo.png' %}" alt="No photo">
{% endif %}
</a>
{% endif %}
8 changes: 8 additions & 0 deletions src/core/templates/menus/main_menu_new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<nav class="dwds-header-nav" aria-label="Top Level Navigation">
{% for item in menu_items %}
<a class="dwds-header-item"
data-testid="main-menu-{{ item.text|lower }}"
href="{{ item.href }}"
{% if item.active_class %}data-active="true"{% endif %}>{{ item.text }}</a>
{% endfor %}
</nav>
136 changes: 115 additions & 21 deletions src/dw_design_system/dwds/styles/header.scss
Original file line number Diff line number Diff line change
@@ -1,44 +1,138 @@
// FIXME: Where should these styles live in the new design system?

.dwds-header-container {
border-bottom: 4px solid var(--dbt-red);
// Variables
--header-border-bottom: 4px solid var(--dbt-red);

background-color: var(--color-background);
border-bottom: var(--header-border-bottom);
}

.dwds-header, .dwds-header-menu {
display: flex;
flex-direction: column;

a {
color: black;
text-decoration: none;
}
}

.dwds-header {
display: grid;
grid-template-columns: min-content 1fr;
grid-template-rows: min-content min-content;
grid-template-areas:
"logo top"
"logo bottom";

padding: var(--space) 0;
}

.dwds-header-logo {
display: flex;
align-items: center;
gap: var(--s-4);
padding: var(--s-4) 0;
justify-content: space-between;
}

&-logo {
grid-area: logo;
margin-right: 1rem;
.dwds-header-menu-toggle {
all: unset;
cursor: pointer;

&:focus, &:active {
background-color: var(--color-button-background-active);
}

&-top {
grid-area: top;
&::after {
content: "";
}

&.is-open::after {
content: "";
}
}

.dwds-header-menu {
display: none;

&.is-active {
display: flex;
align-items: center;
}
}

&-bottom {
grid-area: bottom;
.dwds-header-item {
vertical-align: middle;

padding: var(--s-3) 0;
}

.dwds-header-app-name {
display: none;
align-items: center;
font-size: var(--s2);
font-weight: bold;
}

.dwds-header-profile {
display: flex;
gap: var(--space);
align-items: center;

img {
width: 40px;
border-radius: 50%;
// display the profile image first
order: -1;
}
}

.dwds-header-nav {
display: flex;
flex-direction: column;

a {
display: flex;
align-items: center;

padding: var(--s-3) 0;

font-weight: bold;
}

a[data-active] {
border-bottom: var(--header-border-bottom);
}
}

@media screen and (min-width: 770px) {
// hide the menu toggle
.dwds-header-menu-toggle {
display: none;
}

.dwds-header {
display: grid;
grid-template-columns: max-content 1fr;
padding: 0;
}

&-app-name {
flex-grow: 1;
.dwds-header-menu {
display: grid;
grid-template-columns: 1fr max-content;
grid-template-rows: min-content min-content;
}

&-nav-links {
flex-grow: 1;
.dwds-header-logo {
padding: var(--s-3);
}

.dwds-header-app-name {
display: flex;
}

.dwds-header-item {
padding: var(--s-3);
}

.dwds-header-nav {
flex-direction: row;

a {
padding: var(--s-3);
}
}
}

0 comments on commit d5c82ce

Please sign in to comment.