All files / components/Header Header.svelte

100% Statements 70/70
83.33% Branches 5/6
100% Functions 4/4
100% Lines 70/70

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 711x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<script lang="ts">
  import "./Header.scss";
  import { url as closeIcon } from "$icons/close";
  import classNames from "$lib/util/classNames";
  import Icon from "$lib/components/Icon";
  import Link from "$lib/components/Link";
  import Logo from "$lib/components/Logo";
  import Search from "$lib/components/Search";
  import { page } from "$app/stores";
  import Title from "./Title";
  import Nav, { type NavItemType, type NavLinkType } from "./Nav";
  import User from "./User";
 
  export let primaryNavItems: NavItemType[] = [];
  export let secondaryNavItems: NavLinkType[] = [];
 
  // Need to export this as a prop so we can reset it on route change.
  export let navMenuExpanded = false;
  const toggleNavMenu = (show: boolean) => (navMenuExpanded = show);
 
  $: navClassNames = classNames("usa-nav", navMenuExpanded && "is-visible");
</script>
 
<!-- TODO: Continue replacing parts of this file with components and content from the CMS. -->
<!-- TODO: Possibly add support for other header variations, e.g. usa-header--basic -->
<header class="ldaf-header usa-header usa-header--extended">
  <div class="ldaf-nav usa-navbar">
    <Title />
    <!--TODO: Replace with content from CMS. -->
    <button type="button" class="usa-menu-btn" on:click={() => toggleNavMenu(true)}> Menu </button>
  </div>
  <!-- TODO: Replace aria-label with content from CMS. -->
  <nav aria-label="Primary navigation" class={navClassNames}>
    <div class="usa-nav__inner">
      <button type="button" class="usa-nav__close" on:click={() => toggleNavMenu(false)}>
        <!-- TODO: Replace alt text with content from CMS. -->
        <Icon src={closeIcon} alt="Close" size={3} />
      </button>
 
      <a class="ldaf-logo__compact" href="/">
        <span class="usa-sr-only">Go to home page.</span>
        <Logo placement="mobile-header-menu" />
      </a>
 
      <Nav items={primaryNavItems} />
 
      <!-- TODO: Extend <Nav/> to cover secondary nav or build out component with shared dependencies. -->
      <div
        class="ldaf-nav__secondary usa-nav__secondary"
        class:search-page={$page.url.pathname === "/search"}
      >
        <User />
        <ul class="usa-nav__secondary-links">
          {#each secondaryNavItems as item (item.id)}
            {@const { name, link } = item}
            <li class="usa-nav__secondary-item">
              <Link href={link}>{name}</Link>
            </li>
          {/each}
        </ul>
 
        {#if $page.url.pathname !== "/search"}
          <section aria-label="Search component">
            <Search size="small" id="ldaf-header-search" />
          </section>
        {/if}
      </div>
    </div>
  </nav>
</header>