blob: aa8598be2865ff1aeab991fe151ef8434649ee6a [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">
Ed Tanous7d6b44c2024-03-23 14:56:34 -07006 <template v-for="navItem in navigationItems">
Yoshie Muranakad329ec82020-08-11 18:24:59 -07007 <!-- Navigation items with no children -->
jason westoverd36ac8a2025-11-03 20:58:59 -06008 <li
Yoshie Muranakad329ec82020-08-11 18:24:59 -07009 v-if="!navItem.children"
jason westoverd36ac8a2025-11-03 20:58:59 -060010 :key="`nav-${navItem.index}`"
11 class="nav-item"
Derick Montague2d589a72020-07-23 17:43:12 -050012 >
jason westoverd36ac8a2025-11-03 20:58:59 -060013 <router-link
14 :to="navItem.route"
15 :data-test-id="`nav-item-${navItem.id}`"
16 class="nav-link"
17 >
18 <component :is="navItem.icon" />
19 {{ navItem.label }}
20 </router-link>
21 </li>
Derick Montague42c19892020-01-17 16:10:34 -060022
Yoshie Muranakad329ec82020-08-11 18:24:59 -070023 <!-- Navigation items with children -->
jason westoverd36ac8a2025-11-03 20:58:59 -060024 <li v-else :key="`nav-group-${navItem.index}`" class="nav-item">
Yoshie Muranakad329ec82020-08-11 18:24:59 -070025 <b-button
jason westoverd36ac8a2025-11-03 20:58:59 -060026 :class="{ collapsed: !isItemOpen(navItem.id) }"
Yoshie Muranakad329ec82020-08-11 18:24:59 -070027 variant="link"
28 :data-test-id="`nav-button-${navItem.id}`"
jason westoverd36ac8a2025-11-03 20:58:59 -060029 :aria-controls="navItem.id"
30 :aria-expanded="isItemOpen(navItem.id) ? 'true' : 'false'"
31 @click="toggleCollapse(navItem.id)"
Derick Montague2d589a72020-07-23 17:43:12 -050032 >
Yoshie Muranakad329ec82020-08-11 18:24:59 -070033 <component :is="navItem.icon" />
34 {{ navItem.label }}
35 <icon-expand class="icon-expand" />
36 </b-button>
jason westoverd36ac8a2025-11-03 20:58:59 -060037 <b-collapse
38 :id="navItem.id"
39 v-model="openSections[navItem.id]"
40 tag="ul"
41 class="nav-item__nav"
42 >
43 <li
44 v-for="(subNavItem, i) in filteredNavItem(navItem.children)"
45 :key="i"
46 class="nav-item"
47 >
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053048 <router-link
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053049 :to="subNavItem.route"
50 :data-test-id="`nav-item-${subNavItem.id}`"
51 class="nav-link"
52 >
53 {{ subNavItem.label }}
54 </router-link>
55 </li>
Yoshie Muranakad329ec82020-08-11 18:24:59 -070056 </b-collapse>
57 </li>
58 </template>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080059 </b-nav>
60 </nav>
61 </div>
62 <transition name="fade">
63 <div
64 v-if="isNavigationOpen"
Derick Montaguead2ceb62020-04-24 18:11:04 -050065 id="nav-overlay"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080066 class="nav-overlay"
67 @click="toggleIsOpen"
68 ></div>
69 </transition>
70 </div>
Derick Montaguea2988f42020-01-17 13:46:30 -060071</template>
72
73<script>
Yoshie Muranaka8263d852020-10-16 07:58:06 -070074//Do not change Mixin import.
75//Exact match alias set to support
76//dotenv customizations.
Yoshie Muranakad329ec82020-08-11 18:24:59 -070077import AppNavigationMixin from './AppNavigationMixin';
Ed Tanous883a0d52024-03-23 14:56:34 -070078import { useI18n } from 'vue-i18n';
Derick Montaguea2988f42020-01-17 13:46:30 -060079
80export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -060081 name: 'AppNavigation',
Yoshie Muranakad329ec82020-08-11 18:24:59 -070082 mixins: [AppNavigationMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -080083 data() {
84 return {
Ed Tanous883a0d52024-03-23 14:56:34 -070085 $t: useI18n().t,
Derick Montague602e98a2020-10-21 16:20:00 -050086 isNavigationOpen: false,
Damian Celicoaeb19812022-11-24 02:00:53 +010087 currentUserRole: null,
jason westoverd36ac8a2025-11-03 20:58:59 -060088 openSections: {},
Yoshie Muranaka74f86872020-02-10 12:28:37 -080089 };
90 },
91 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050092 $route: function () {
Yoshie Muranaka74f86872020-02-10 12:28:37 -080093 this.isNavigationOpen = false;
jason westoverd36ac8a2025-11-03 20:58:59 -060094 // Ensure the parent section of the current route is expanded
95 this.initializeOpenSectionsFromRoute();
Yoshie Muranaka74f86872020-02-10 12:28:37 -080096 },
Derick Montague602e98a2020-10-21 16:20:00 -050097 isNavigationOpen: function (isNavigationOpen) {
jason westoverd36ac8a2025-11-03 20:58:59 -060098 require('@/eventBus').default.$emit(
99 'change-is-navigation-open',
100 isNavigationOpen,
101 );
Derick Montague602e98a2020-10-21 16:20:00 -0500102 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800103 },
104 mounted() {
Damian Celicoaeb19812022-11-24 02:00:53 +0100105 this.getPrivilege();
jason westoverd36ac8a2025-11-03 20:58:59 -0600106 require('@/eventBus').default.$on('toggle-navigation', () =>
107 this.toggleIsOpen(),
108 );
109 // Expand the parent section for the current route on initial load/refresh
110 this.initializeOpenSectionsFromRoute();
111 },
112 beforeUnmount() {
113 require('@/eventBus').default.$off(
114 'toggle-navigation',
115 this.handleToggleNavigation,
116 );
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800117 },
118 methods: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600119 isItemOpen(id) {
120 return !!this.openSections[id];
121 },
122 toggleCollapse(id) {
123 if (this.$set) {
124 this.$set(this.openSections, id, !this.openSections[id]);
125 } else {
126 this.openSections = {
127 ...this.openSections,
128 [id]: !this.openSections[id],
129 };
130 }
131 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800132 toggleIsOpen() {
133 this.isNavigationOpen = !this.isNavigationOpen;
Derick Montague602e98a2020-10-21 16:20:00 -0500134 },
Damian Celicoaeb19812022-11-24 02:00:53 +0100135 getPrivilege() {
136 this.currentUserRole = this.$store?.getters['global/userPrivilege'];
137 },
138 filteredNavItem(navItem) {
139 if (this.currentUserRole) {
140 return navItem.filter(({ exclusiveToRoles }) => {
141 if (!exclusiveToRoles?.length) return true;
142 return exclusiveToRoles.includes(this.currentUserRole);
143 });
144 } else return navItem;
145 },
jason westoverd36ac8a2025-11-03 20:58:59 -0600146 initializeOpenSectionsFromRoute() {
147 const currentPath = this.$route?.path;
148 if (!currentPath) return;
149 const sectionsToOpen = {};
150 for (const item of this.navigationItems) {
151 if (
152 item.children &&
153 item.children.some((child) => child.route === currentPath)
154 ) {
155 sectionsToOpen[item.id] = true;
156 }
157 }
158 this.openSections = { ...this.openSections, ...sectionsToOpen };
159 },
Derick Montague602e98a2020-10-21 16:20:00 -0500160 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600161};
162</script>
Derick Montague42c19892020-01-17 16:10:34 -0600163
suryav972424b377d2025-01-24 15:06:35 +0530164<style scoped lang="scss">
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800165svg {
Derick Montague66f903f2020-02-28 11:22:31 -0600166 fill: currentColor;
167 height: 1.2rem;
168 width: 1.2rem;
jason westoverd36ac8a2025-11-03 20:58:59 -0600169 margin-inline-start: 0 !important; //!important overriding button specificity
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800170 vertical-align: text-bottom;
171 &:not(.icon-expand) {
jason westoverd36ac8a2025-11-03 20:58:59 -0600172 margin-inline-end: $spacer;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800173 }
174}
175
176.nav {
jason westoverd36ac8a2025-11-03 20:58:59 -0600177 padding-top: calc(#{$spacer} / 4);
SurenNeware057232b2020-06-08 20:53:26 +0530178 @include media-breakpoint-up($responsive-layout-bp) {
179 padding-top: $spacer;
180 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800181}
182
183.nav-item__nav {
Derick Montague42c19892020-01-17 16:10:34 -0600184 list-style: none;
jason westoverd36ac8a2025-11-03 20:58:59 -0600185 padding-inline-start: 0;
186 margin-inline-start: 0;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800187
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700188 .nav-item {
189 outline: none;
jason westoverd36ac8a2025-11-03 20:58:59 -0600190 list-style: none;
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700191 }
192
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800193 .nav-link {
jason westoverd36ac8a2025-11-03 20:58:59 -0600194 padding-inline-start: $spacer * 4;
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700195 outline: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800196
197 &:not(.nav-link--current) {
198 font-weight: normal;
199 }
200 }
201}
202
203.btn-link {
Dixsie Wolmers30f11f82020-11-10 16:07:56 -0600204 display: inline-block;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800205 width: 100%;
jason westoverd36ac8a2025-11-03 20:58:59 -0600206 text-align: start;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800207 text-decoration: none !important;
208 border-radius: 0;
209
210 &.collapsed {
211 .icon-expand {
212 transform: rotate(180deg);
213 }
214 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800215}
216
217.icon-expand {
jason westoverd36ac8a2025-11-03 20:58:59 -0600218 float: inline-end;
219 margin-top: calc(#{$spacer} / 4);
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800220}
221
222.btn-link,
223.nav-link {
224 position: relative;
225 font-weight: $headings-font-weight;
jason westoverd36ac8a2025-11-03 20:58:59 -0600226 padding-inline-start: $spacer; // defining consistent padding for links and buttons
227 padding-inline-end: $spacer;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700228 color: theme-color('secondary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800229
230 &:hover {
SurenNeware1f8117f2020-09-22 19:28:56 +0530231 background-color: theme-color-level(dark, -10.5);
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700232 color: theme-color('dark');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800233 }
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800234
235 &:focus {
SurenNeware1f8117f2020-09-22 19:28:56 +0530236 background-color: theme-color-level(light, 0);
237 box-shadow: inset 0 0 0 2px theme-color('primary');
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700238 color: theme-color('dark');
Derick Montague59569d82020-10-26 15:17:31 -0500239 outline: 0;
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800240 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530241
242 &:active {
Derick Montague59569d82020-10-26 15:17:31 -0500243 background-color: theme-color('secondary');
SurenNeware1f8117f2020-09-22 19:28:56 +0530244 color: $white;
245 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800246}
247
SurenNeware1f8117f2020-09-22 19:28:56 +0530248.nav-link--current {
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800249 font-weight: $headings-font-weight;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700250 background-color: theme-color('secondary');
251 color: theme-color('light');
Derick Montague66f903f2020-02-28 11:22:31 -0600252 cursor: default;
SurenNeware1f8117f2020-09-22 19:28:56 +0530253 box-shadow: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800254
255 &::before {
256 content: '';
257 position: absolute;
258 top: 0;
259 bottom: 0;
jason westoverd36ac8a2025-11-03 20:58:59 -0600260 inset-inline-start: 0;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800261 width: 4px;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700262 background-color: theme-color('primary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800263 }
Derick Montague59569d82020-10-26 15:17:31 -0500264
265 &:hover,
SurenNeware1f8117f2020-09-22 19:28:56 +0530266 &:focus {
Derick Montague59569d82020-10-26 15:17:31 -0500267 background-color: theme-color('secondary');
268 color: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530269 }
270}
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800271
272.nav-container {
273 position: fixed;
274 width: $navigation-width;
275 top: $header-height;
276 bottom: 0;
277 left: 0;
278 z-index: $zindex-fixed;
279 overflow-y: auto;
Derick Montague59569d82020-10-26 15:17:31 -0500280 background-color: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800281 transform: translateX(-$navigation-width);
282 transition: transform $exit-easing--productive $duration--moderate-02;
jason westoverd36ac8a2025-11-03 20:58:59 -0600283 border-inline-end: 1px solid theme-color-level('light', 2.85);
Derick Montague59569d82020-10-26 15:17:31 -0500284
SurenNeware057232b2020-06-08 20:53:26 +0530285 @include media-breakpoint-down(md) {
286 z-index: $zindex-fixed + 2;
287 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800288
Derick Montague74466b82020-06-28 10:17:32 -0500289 &.open,
290 &:focus-within {
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800291 transform: translateX(0);
292 transition-timing-function: $entrance-easing--productive;
293 }
294
295 @include media-breakpoint-up($responsive-layout-bp) {
296 transition-duration: $duration--fast-01;
297 transform: translateX(0);
298 }
299}
300
301.nav-overlay {
302 position: fixed;
303 top: $header-height;
304 bottom: 0;
305 left: 0;
306 right: 0;
SurenNeware057232b2020-06-08 20:53:26 +0530307 z-index: $zindex-fixed + 1;
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800308 background-color: $black;
309 opacity: 0.5;
310
311 &.fade-enter-active {
312 transition: opacity $duration--moderate-02 $entrance-easing--productive;
313 }
314
315 &.fade-leave-active {
316 transition: opacity $duration--fast-02 $exit-easing--productive;
317 }
318
SurenNeware151dd242020-11-10 20:15:05 +0530319 &.fade-enter, // Remove this vue2 based only class when switching to vue3
320 &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter'
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800321 &.fade-leave-to {
322 opacity: 0;
323 }
324
325 @include media-breakpoint-up($responsive-layout-bp) {
326 display: none;
327 }
328}
Derick Montague42c19892020-01-17 16:10:34 -0600329</style>