1<template> 2 <div> 3 <div class="nav-container" :class="{ open: isNavigationOpen }"> 4 <nav ref="nav" :aria-label="$t('appNavigation.primaryNavigation')"> 5 <b-nav vertical class="mb-4"> 6 <template v-for="(navItem, index) in navigationItems"> 7 <!-- Navigation items with no children --> 8 <b-nav-item 9 v-if="!navItem.children" 10 :key="index" 11 :to="navItem.route" 12 :data-test-id="`nav-item-${navItem.id}`" 13 > 14 <component :is="navItem.icon" /> 15 {{ navItem.label }} 16 </b-nav-item> 17 18 <!-- Navigation items with children --> 19 <li v-else :key="index" class="nav-item"> 20 <b-button 21 v-b-toggle="`${navItem.id}`" 22 variant="link" 23 :data-test-id="`nav-button-${navItem.id}`" 24 > 25 <component :is="navItem.icon" /> 26 {{ navItem.label }} 27 <icon-expand class="icon-expand" /> 28 </b-button> 29 <b-collapse :id="navItem.id" tag="ul" class="nav-item__nav"> 30 <b-nav-item 31 v-for="(subNavItem, i) of navItem.children" 32 :key="i" 33 :to="subNavItem.route" 34 :data-test-id="`nav-item-${subNavItem.id}`" 35 > 36 {{ subNavItem.label }} 37 </b-nav-item> 38 </b-collapse> 39 </li> 40 </template> 41 </b-nav> 42 </nav> 43 </div> 44 <transition name="fade"> 45 <div 46 v-if="isNavigationOpen" 47 id="nav-overlay" 48 class="nav-overlay" 49 @click="toggleIsOpen" 50 ></div> 51 </transition> 52 </div> 53</template> 54 55<script> 56//Do not change Mixin import. 57//Exact match alias set to support 58//dotenv customizations. 59import AppNavigationMixin from './AppNavigationMixin'; 60 61export default { 62 name: 'AppNavigation', 63 mixins: [AppNavigationMixin], 64 data() { 65 return { 66 isNavigationOpen: false 67 }; 68 }, 69 watch: { 70 $route: function() { 71 this.isNavigationOpen = false; 72 }, 73 isNavigationOpen: function(isNavigationOpen) { 74 this.$root.$emit('change:isNavigationOpen', isNavigationOpen); 75 } 76 }, 77 mounted() { 78 this.$root.$on('toggle:navigation', () => this.toggleIsOpen()); 79 }, 80 methods: { 81 toggleIsOpen() { 82 this.isNavigationOpen = !this.isNavigationOpen; 83 } 84 } 85}; 86</script> 87 88<style scoped lang="scss"> 89svg { 90 fill: currentColor; 91 height: 1.2rem; 92 width: 1.2rem; 93 margin-left: 0 !important; //!important overriding button specificity 94 vertical-align: text-bottom; 95 &:not(.icon-expand) { 96 margin-right: $spacer; 97 } 98} 99 100.nav { 101 padding-top: $spacer / 4; 102 @include media-breakpoint-up($responsive-layout-bp) { 103 padding-top: $spacer; 104 } 105} 106 107.nav-item__nav { 108 list-style: none; 109 padding-left: 0; 110 margin-left: 0; 111 112 .nav-item { 113 outline: none; 114 } 115 116 .nav-link { 117 padding-left: $spacer * 4; 118 outline: none; 119 120 &:not(.nav-link--current) { 121 font-weight: normal; 122 } 123 } 124} 125 126.btn-link { 127 width: 100%; 128 text-align: left; 129 text-decoration: none !important; 130 border-radius: 0; 131 132 &.collapsed { 133 .icon-expand { 134 transform: rotate(180deg); 135 } 136 } 137} 138 139.icon-expand { 140 float: right; 141 margin-top: $spacer / 4; 142} 143 144.btn-link, 145.nav-link { 146 position: relative; 147 font-weight: $headings-font-weight; 148 padding-left: $spacer; // defining consistent padding for links and buttons 149 padding-right: $spacer; 150 color: theme-color('secondary'); 151 152 &:hover { 153 background-color: theme-color-level(dark, -10.5); 154 color: theme-color('dark'); 155 } 156 157 &:focus { 158 background-color: theme-color-level(light, 0); 159 box-shadow: inset 0 0 0 2px theme-color('primary'); 160 color: theme-color('dark'); 161 outline: 0; 162 } 163 164 &:active { 165 background-color: theme-color('secondary'); 166 color: $white; 167 } 168} 169 170.nav-link--current { 171 font-weight: $headings-font-weight; 172 background-color: theme-color('secondary'); 173 color: theme-color('light'); 174 cursor: default; 175 box-shadow: none; 176 177 &::before { 178 content: ''; 179 position: absolute; 180 top: 0; 181 bottom: 0; 182 left: 0; 183 width: 4px; 184 background-color: theme-color('primary'); 185 } 186 187 &:hover, 188 &:focus { 189 background-color: theme-color('secondary'); 190 color: theme-color('light'); 191 } 192} 193 194.nav-container { 195 position: fixed; 196 width: $navigation-width; 197 top: $header-height; 198 bottom: 0; 199 left: 0; 200 z-index: $zindex-fixed; 201 overflow-y: auto; 202 background-color: theme-color('light'); 203 transform: translateX(-$navigation-width); 204 transition: transform $exit-easing--productive $duration--moderate-02; 205 border-right: 1px solid theme-color-level('light', 2.85); 206 207 @include media-breakpoint-down(md) { 208 z-index: $zindex-fixed + 2; 209 } 210 211 &.open, 212 &:focus-within { 213 transform: translateX(0); 214 transition-timing-function: $entrance-easing--productive; 215 } 216 217 @include media-breakpoint-up($responsive-layout-bp) { 218 transition-duration: $duration--fast-01; 219 transform: translateX(0); 220 } 221} 222 223.nav-overlay { 224 position: fixed; 225 top: $header-height; 226 bottom: 0; 227 left: 0; 228 right: 0; 229 z-index: $zindex-fixed + 1; 230 background-color: $black; 231 opacity: 0.5; 232 233 &.fade-enter-active { 234 transition: opacity $duration--moderate-02 $entrance-easing--productive; 235 } 236 237 &.fade-leave-active { 238 transition: opacity $duration--fast-02 $exit-easing--productive; 239 } 240 241 &.fade-enter, 242 &.fade-leave-to { 243 opacity: 0; 244 } 245 246 @include media-breakpoint-up($responsive-layout-bp) { 247 display: none; 248 } 249} 250</style> 251