blob: fb50f5ecffa04bf48c87b7d5edd9234e2a5fdc08 [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
Yoshie Muranaka74f86872020-02-10 12:28:37 -08002 <div>
3 <div class="nav-container" :class="{ open: isNavigationOpen }">
Derick Montague68592032020-04-04 14:02:34 -05004 <nav ref="nav" :aria-label="$t('appNavigation.primaryNavigation')">
Yoshie Muranaka7d044352020-07-24 10:45:14 -07005 <b-nav vertical class="mb-4">
Yoshie Muranakad329ec82020-08-11 18:24:59 -07006 <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}`"
Derick Montague2d589a72020-07-23 17:43:12 -050013 >
Yoshie Muranakad329ec82020-08-11 18:24:59 -070014 <component :is="navItem.icon" />
15 {{ navItem.label }}
16 </b-nav-item>
Derick Montague42c19892020-01-17 16:10:34 -060017
Yoshie Muranakad329ec82020-08-11 18:24:59 -070018 <!-- 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}`"
Derick Montague2d589a72020-07-23 17:43:12 -050024 >
Yoshie Muranakad329ec82020-08-11 18:24:59 -070025 <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>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080041 </b-nav>
42 </nav>
43 </div>
44 <transition name="fade">
45 <div
46 v-if="isNavigationOpen"
Derick Montaguead2ceb62020-04-24 18:11:04 -050047 id="nav-overlay"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080048 class="nav-overlay"
49 @click="toggleIsOpen"
50 ></div>
51 </transition>
52 </div>
Derick Montaguea2988f42020-01-17 13:46:30 -060053</template>
54
55<script>
Yoshie Muranaka8263d852020-10-16 07:58:06 -070056//Do not change Mixin import.
57//Exact match alias set to support
58//dotenv customizations.
Yoshie Muranakad329ec82020-08-11 18:24:59 -070059import AppNavigationMixin from './AppNavigationMixin';
Derick Montaguea2988f42020-01-17 13:46:30 -060060
61export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -060062 name: 'AppNavigation',
Yoshie Muranakad329ec82020-08-11 18:24:59 -070063 mixins: [AppNavigationMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -080064 data() {
65 return {
Derick Montague602e98a2020-10-21 16:20:00 -050066 isNavigationOpen: false,
Yoshie Muranaka74f86872020-02-10 12:28:37 -080067 };
68 },
69 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050070 $route: function () {
Yoshie Muranaka74f86872020-02-10 12:28:37 -080071 this.isNavigationOpen = false;
72 },
Derick Montague602e98a2020-10-21 16:20:00 -050073 isNavigationOpen: function (isNavigationOpen) {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053074 this.$root.$emit('change-is-navigation-open', isNavigationOpen);
Derick Montague602e98a2020-10-21 16:20:00 -050075 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -080076 },
77 mounted() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053078 this.$root.$on('toggle-navigation', () => this.toggleIsOpen());
Yoshie Muranaka74f86872020-02-10 12:28:37 -080079 },
80 methods: {
81 toggleIsOpen() {
82 this.isNavigationOpen = !this.isNavigationOpen;
Derick Montague602e98a2020-10-21 16:20:00 -050083 },
84 },
Derick Montaguea2988f42020-01-17 13:46:30 -060085};
86</script>
Derick Montague42c19892020-01-17 16:10:34 -060087
Yoshie Muranaka71ac2302019-12-26 11:43:36 -080088<style scoped lang="scss">
89svg {
Derick Montague66f903f2020-02-28 11:22:31 -060090 fill: currentColor;
91 height: 1.2rem;
92 width: 1.2rem;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -080093 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 {
SurenNeware057232b2020-06-08 20:53:26 +0530101 padding-top: $spacer / 4;
102 @include media-breakpoint-up($responsive-layout-bp) {
103 padding-top: $spacer;
104 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800105}
106
107.nav-item__nav {
Derick Montague42c19892020-01-17 16:10:34 -0600108 list-style: none;
109 padding-left: 0;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800110 margin-left: 0;
111
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700112 .nav-item {
113 outline: none;
114 }
115
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800116 .nav-link {
117 padding-left: $spacer * 4;
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700118 outline: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800119
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 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800137}
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;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700150 color: theme-color('secondary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800151
152 &:hover {
SurenNeware1f8117f2020-09-22 19:28:56 +0530153 background-color: theme-color-level(dark, -10.5);
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700154 color: theme-color('dark');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800155 }
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800156
157 &:focus {
SurenNeware1f8117f2020-09-22 19:28:56 +0530158 background-color: theme-color-level(light, 0);
159 box-shadow: inset 0 0 0 2px theme-color('primary');
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700160 color: theme-color('dark');
Derick Montague59569d82020-10-26 15:17:31 -0500161 outline: 0;
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800162 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530163
164 &:active {
Derick Montague59569d82020-10-26 15:17:31 -0500165 background-color: theme-color('secondary');
SurenNeware1f8117f2020-09-22 19:28:56 +0530166 color: $white;
167 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800168}
169
SurenNeware1f8117f2020-09-22 19:28:56 +0530170.nav-link--current {
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800171 font-weight: $headings-font-weight;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700172 background-color: theme-color('secondary');
173 color: theme-color('light');
Derick Montague66f903f2020-02-28 11:22:31 -0600174 cursor: default;
SurenNeware1f8117f2020-09-22 19:28:56 +0530175 box-shadow: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800176
177 &::before {
178 content: '';
179 position: absolute;
180 top: 0;
181 bottom: 0;
182 left: 0;
183 width: 4px;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700184 background-color: theme-color('primary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800185 }
Derick Montague59569d82020-10-26 15:17:31 -0500186
187 &:hover,
SurenNeware1f8117f2020-09-22 19:28:56 +0530188 &:focus {
Derick Montague59569d82020-10-26 15:17:31 -0500189 background-color: theme-color('secondary');
190 color: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530191 }
192}
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800193
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;
Derick Montague59569d82020-10-26 15:17:31 -0500202 background-color: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800203 transform: translateX(-$navigation-width);
204 transition: transform $exit-easing--productive $duration--moderate-02;
Derick Montague59569d82020-10-26 15:17:31 -0500205 border-right: 1px solid theme-color-level('light', 2.85);
206
SurenNeware057232b2020-06-08 20:53:26 +0530207 @include media-breakpoint-down(md) {
208 z-index: $zindex-fixed + 2;
209 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800210
Derick Montague74466b82020-06-28 10:17:32 -0500211 &.open,
212 &:focus-within {
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800213 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;
SurenNeware057232b2020-06-08 20:53:26 +0530229 z-index: $zindex-fixed + 1;
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800230 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
SurenNeware151dd242020-11-10 20:15:05 +0530241 &.fade-enter, // Remove this vue2 based only class when switching to vue3
242 &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter'
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800243 &.fade-leave-to {
244 opacity: 0;
245 }
246
247 @include media-breakpoint-up($responsive-layout-bp) {
248 display: none;
249 }
250}
Derick Montague42c19892020-01-17 16:10:34 -0600251</style>