uktrade/directory-components

View on GitHub
directory_components/export_elements/sass/components/header-footer/_header.scss

Summary

Maintainability
Test Coverage
@import '../../partials/typography';
@import '../../partials/colours';
@import '../../partials/mixins';
@import '../../partials/spacings';

$menu-max-width: 1200px;
$menu-item-vertical-spacing: 10px;
$menu-margin-l: 30px;
$menu-margin-s: 20px;

@mixin desktopOnly {
  @media (max-width: 768px) {
    display: none;
  }
}

@mixin mobileOnly {
  display: none;

  @media (max-width: 768px) {
    display: flex;
  }
}

@mixin headerContainer {
  max-width: $menu-max-width;
  margin: 0 auto;

  @media (max-width: 1260px) {
    margin: 0 $menu-margin-l;
  }

  @media (max-width: 420px) {
    margin: 0 $menu-margin-s;
  }
}

.great-header,
.great-sub-header {
  // need to make sure it's not underneath anything
  position: relative;
  z-index: 5;

  &:focus-within {
    // ensure that the focused outline will appear above any other headers/sub-headers.
    // focus-within won't work on all browsers, but its still usable without this.
    z-index: 6;
  }

  a:focus {
    @include focus;

    &:active {
      background-color: $focus-yellow;
      color: $great-blue;
    }
  }

  .menu {
    background-color: $great-blue;
    position: relative;

    .container {
      @include headerContainer;
      position: relative;
      display: flex;
      flex-wrap: wrap;
      align-content: center;
      padding: 0;
    }
  }

  .extra-links {
    font-size: 14px;
    color: $white;
    position: absolute;
    top: 25px;
    right: 0;
    display: flex;

    @media (max-width: 768px) {
      top: 10px;
    }

    li:last-child {
      margin-left: 10px;
    }
  }

  .main-nav-container {
    &.mobile {
      @include mobileOnly;
      margin: 0;
    }

    &.desktop {
      @include desktopOnly;
      background-color: transparent;
      display: flex;
      justify-content: flex-end;
      flex-grow: 1;
      align-self: flex-end;

      @media (max-width: 1260px) {
        margin-left: $menu-margin-l;
      }
    }
  }

  .main-nav {
    &.mobile {
      display: none;
      transition: all .2s ease;
      background-color: $lightened-great-blue;
      margin: 0;
      width: 100%;
      opacity: 0;
      overflow: hidden;

      &.expanded {
        opacity: 1;
        display: block;
      }

      .nav-list {
        margin: 4px 30px;
        flex-direction: column;
      }
    }

    &.desktop {
      max-width: $menu-max-width;
    }
  }

  .nav-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    position: relative;

    @media (max-width: 420px) {
      margin: 4px $menu-margin-s;
    }
  }

  .menu-item {
    width: auto;
    padding: 0;
    box-sizing: border-box;
    line-height: 1;
  }

  .link-heading {
    color: $white;
    font-family: inherit;
    display: block;
    font-size: 16px;
    line-height: $spacing-3;
    padding: 15px;
    text-decoration: none;
    position: relative;

    &:hover {
      text-decoration: underline;
    }

    @media (max-width: 768px) {
      text-decoration: underline;
      padding: 15px 0;
      margin: 0;
      line-height: 1;
    }
  }
}