All files / components/organisms/TheHeader TheHeader.vue

80.55% Statements 58/72
0% Branches 0/2
0% Functions 0/1
80.55% Lines 58/72

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 1471x 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 setup lang="ts">
import DarkModeToggleButton from "@/components/atoms/DarkModeToggleButton/DarkModeToggleButton.vue";
import HeaderItem from "@/components/atoms/HeaderItem/HeaderItem.vue";
import { useBreakpoints, breakpointsElement, useDark } from "@vueuse/core";
import { ref, watch } from "vue";
import MenuButton from "@/components/atoms/MenuButton/MenuButton.vue";
import type { HeaderItemData } from "@/types/api";
 
const isDark = ref(useDark().value);
watch(useDark(), () => {
  isDark.value = useDark().value;
});
 
const breakpoints = useBreakpoints(breakpointsElement);
const isMobileMode = breakpoints.smallerOrEqual("md");
const isMenuOpenWhenMobile = ref(false);
const toggleIsMenuVisible = () => {
  isMenuOpenWhenMobile.value = !isMenuOpenWhenMobile.value;
};
 
const headerItems: Array<HeaderItemData> = [
  {
    id: 1,
    title: "index",
    link: "/index",
  },
  {
    id: 2,
    title: "sample",
    link: "/sample",
  },
  {
    id: 3,
    title: "sample2",
    link: "/sample",
  },
  {
    id: 4,
    title: "sample3",
    link: "/sample",
  },
];
</script>
 
<template>
  <div :class="[$style.headerWrapper, { [$style.dark]: isDark }]">
    <div v-if="isMobileMode" :class="$style.headerContainer">
      <div>
        <MenuButton @click="toggleIsMenuVisible" :class="$style.menuButton" />
      </div>
      <div>
        <span :class="[$style.headerTitle, { [$style.dark]: isDark }]"
          >Vue3 Template</span
        >
      </div>
      <div :class="$style.dark_mode_button_container">
      </div>
    </div>
    <div v-else :class="$style.headerContainer">
      <div>
        <span :class="[$style.headerTitle, { [$style.dark]: isDark }]"
          >Vue3 Template</span
        >
      </div>
      <div :class="$style.header_right">
        <nav v-for="headerItem in headerItems" :key="headerItem.id" :class="$style.headerNav">
          <HeaderItem :link="headerItem.link" :title="headerItem.title" />
        </nav>
        <div :class="$style.dark_mode_button_container">
          <DarkModeToggleButton />
        </div>
      </div>
    </div>
  </div>
  <div v-if="isMobileMode&&isMenuOpenWhenMobile">
    <nav v-for="headerItem in headerItems" :key="headerItem.id" :class="$style.menuList">
      <HeaderItem :link="headerItem.link" :title="headerItem.title" :class="$style.menu" />
    </nav>
  </div>
</template>
 
<style module>
.headerWrapper {
  width: 100%;
  height: 100px;
  background-color: #fff;
}
.headerWrapper.dark {
  width: 100%;
  height: 100px;
  background-color: #555;
}
 
.headerContainer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
}
 
.headerTitle {
  color: #000;
  font-size: 32px;
}
.headerTitle.dark {
  color: #eee;
  font-size: 32px;
}
 
.menuButton {
  padding: 8px;
}
 
.header_right {
  display: flex;
  flex-direction: row;
  height: 100%;
  gap: 8px;
}
 
.menuList {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.menu {
  width: 100%;
  border: 1px solid #222;
  border-radius: 4px;
  background-color: #fff;
}
 
.headerNav {
  height: 100%;
  display: flex;
  flex-direction: row;
  border: 2px solid #222;
  border-radius: 4px;
}
 
.dark_mode_button_container {
  margin-top: auto;
  margin-bottom: auto;
}
</style>