blob: 4c93be5588b4e468a584f467fb61158ede80705b [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 -->
8 <b-nav-item
9 v-if="!navItem.children"
Ed Tanous7d6b44c2024-03-23 14:56:34 -070010 :key="navItem.index"
Yoshie Muranakad329ec82020-08-11 18:24:59 -070011 :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 -->
Ed Tanous7d6b44c2024-03-23 14:56:34 -070019 <li v-else :key="navItem.index" class="nav-item">
Yoshie Muranakad329ec82020-08-11 18:24:59 -070020 <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">
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053030 <li class="nav-item">
31 <router-link
Damian Celicoaeb19812022-11-24 02:00:53 +010032 v-for="(subNavItem, i) of filteredNavItem(navItem.children)"
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053033 :key="i"
34 :to="subNavItem.route"
35 :data-test-id="`nav-item-${subNavItem.id}`"
36 class="nav-link"
37 >
38 {{ subNavItem.label }}
39 </router-link>
40 </li>
Yoshie Muranakad329ec82020-08-11 18:24:59 -070041 </b-collapse>
42 </li>
43 </template>
Yoshie Muranaka74f86872020-02-10 12:28:37 -080044 </b-nav>
45 </nav>
46 </div>
47 <transition name="fade">
48 <div
49 v-if="isNavigationOpen"
Derick Montaguead2ceb62020-04-24 18:11:04 -050050 id="nav-overlay"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080051 class="nav-overlay"
52 @click="toggleIsOpen"
53 ></div>
54 </transition>
55 </div>
Derick Montaguea2988f42020-01-17 13:46:30 -060056</template>
57
58<script>
Yoshie Muranaka8263d852020-10-16 07:58:06 -070059//Do not change Mixin import.
60//Exact match alias set to support
61//dotenv customizations.
Yoshie Muranakad329ec82020-08-11 18:24:59 -070062import AppNavigationMixin from './AppNavigationMixin';
Derick Montaguea2988f42020-01-17 13:46:30 -060063
64export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -060065 name: 'AppNavigation',
Yoshie Muranakad329ec82020-08-11 18:24:59 -070066 mixins: [AppNavigationMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -080067 data() {
68 return {
Derick Montague602e98a2020-10-21 16:20:00 -050069 isNavigationOpen: false,
Damian Celicoaeb19812022-11-24 02:00:53 +010070 currentUserRole: null,
Yoshie Muranaka74f86872020-02-10 12:28:37 -080071 };
72 },
73 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050074 $route: function () {
Yoshie Muranaka74f86872020-02-10 12:28:37 -080075 this.isNavigationOpen = false;
76 },
Derick Montague602e98a2020-10-21 16:20:00 -050077 isNavigationOpen: function (isNavigationOpen) {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053078 this.$root.$emit('change-is-navigation-open', isNavigationOpen);
Derick Montague602e98a2020-10-21 16:20:00 -050079 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -080080 },
81 mounted() {
Damian Celicoaeb19812022-11-24 02:00:53 +010082 this.getPrivilege();
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053083 this.$root.$on('toggle-navigation', () => this.toggleIsOpen());
Yoshie Muranaka74f86872020-02-10 12:28:37 -080084 },
85 methods: {
86 toggleIsOpen() {
87 this.isNavigationOpen = !this.isNavigationOpen;
Derick Montague602e98a2020-10-21 16:20:00 -050088 },
Damian Celicoaeb19812022-11-24 02:00:53 +010089 getPrivilege() {
90 this.currentUserRole = this.$store?.getters['global/userPrivilege'];
91 },
92 filteredNavItem(navItem) {
93 if (this.currentUserRole) {
94 return navItem.filter(({ exclusiveToRoles }) => {
95 if (!exclusiveToRoles?.length) return true;
96 return exclusiveToRoles.includes(this.currentUserRole);
97 });
98 } else return navItem;
99 },
Derick Montague602e98a2020-10-21 16:20:00 -0500100 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600101};
102</script>
Derick Montague42c19892020-01-17 16:10:34 -0600103
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700104<style lang="scss" scoped>
105@import '@/assets/styles/bmc/helpers/_index.scss';
106@import '@/assets/styles/bootstrap/_helpers.scss';
107
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800108svg {
Derick Montague66f903f2020-02-28 11:22:31 -0600109 fill: currentColor;
110 height: 1.2rem;
111 width: 1.2rem;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800112 margin-left: 0 !important; //!important overriding button specificity
113 vertical-align: text-bottom;
114 &:not(.icon-expand) {
115 margin-right: $spacer;
116 }
117}
118
119.nav {
SurenNeware057232b2020-06-08 20:53:26 +0530120 padding-top: $spacer / 4;
121 @include media-breakpoint-up($responsive-layout-bp) {
122 padding-top: $spacer;
123 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800124}
125
126.nav-item__nav {
Derick Montague42c19892020-01-17 16:10:34 -0600127 list-style: none;
128 padding-left: 0;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800129 margin-left: 0;
130
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700131 .nav-item {
132 outline: none;
133 }
134
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800135 .nav-link {
136 padding-left: $spacer * 4;
Yoshie Muranaka85358ed2020-05-18 10:05:36 -0700137 outline: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800138
139 &:not(.nav-link--current) {
140 font-weight: normal;
141 }
142 }
143}
144
145.btn-link {
Dixsie Wolmers30f11f82020-11-10 16:07:56 -0600146 display: inline-block;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800147 width: 100%;
148 text-align: left;
149 text-decoration: none !important;
150 border-radius: 0;
151
152 &.collapsed {
153 .icon-expand {
154 transform: rotate(180deg);
155 }
156 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800157}
158
159.icon-expand {
160 float: right;
161 margin-top: $spacer / 4;
162}
163
164.btn-link,
165.nav-link {
166 position: relative;
167 font-weight: $headings-font-weight;
168 padding-left: $spacer; // defining consistent padding for links and buttons
169 padding-right: $spacer;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700170 color: theme-color('secondary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800171
172 &:hover {
SurenNeware1f8117f2020-09-22 19:28:56 +0530173 background-color: theme-color-level(dark, -10.5);
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700174 color: theme-color('dark');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800175 }
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800176
177 &:focus {
SurenNeware1f8117f2020-09-22 19:28:56 +0530178 background-color: theme-color-level(light, 0);
179 box-shadow: inset 0 0 0 2px theme-color('primary');
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700180 color: theme-color('dark');
Derick Montague59569d82020-10-26 15:17:31 -0500181 outline: 0;
Yoshie Muranaka9f5cea82020-02-04 09:30:00 -0800182 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530183
184 &:active {
Derick Montague59569d82020-10-26 15:17:31 -0500185 background-color: theme-color('secondary');
SurenNeware1f8117f2020-09-22 19:28:56 +0530186 color: $white;
187 }
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800188}
189
SurenNeware1f8117f2020-09-22 19:28:56 +0530190.nav-link--current {
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800191 font-weight: $headings-font-weight;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700192 background-color: theme-color('secondary');
193 color: theme-color('light');
Derick Montague66f903f2020-02-28 11:22:31 -0600194 cursor: default;
SurenNeware1f8117f2020-09-22 19:28:56 +0530195 box-shadow: none;
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800196
197 &::before {
198 content: '';
199 position: absolute;
200 top: 0;
201 bottom: 0;
202 left: 0;
203 width: 4px;
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700204 background-color: theme-color('primary');
Yoshie Muranaka71ac2302019-12-26 11:43:36 -0800205 }
Derick Montague59569d82020-10-26 15:17:31 -0500206
207 &:hover,
SurenNeware1f8117f2020-09-22 19:28:56 +0530208 &:focus {
Derick Montague59569d82020-10-26 15:17:31 -0500209 background-color: theme-color('secondary');
210 color: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530211 }
212}
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800213
214.nav-container {
215 position: fixed;
216 width: $navigation-width;
217 top: $header-height;
218 bottom: 0;
219 left: 0;
220 z-index: $zindex-fixed;
221 overflow-y: auto;
Derick Montague59569d82020-10-26 15:17:31 -0500222 background-color: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800223 transform: translateX(-$navigation-width);
224 transition: transform $exit-easing--productive $duration--moderate-02;
Derick Montague59569d82020-10-26 15:17:31 -0500225 border-right: 1px solid theme-color-level('light', 2.85);
226
SurenNeware057232b2020-06-08 20:53:26 +0530227 @include media-breakpoint-down(md) {
228 z-index: $zindex-fixed + 2;
229 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800230
Derick Montague74466b82020-06-28 10:17:32 -0500231 &.open,
232 &:focus-within {
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800233 transform: translateX(0);
234 transition-timing-function: $entrance-easing--productive;
235 }
236
237 @include media-breakpoint-up($responsive-layout-bp) {
238 transition-duration: $duration--fast-01;
239 transform: translateX(0);
240 }
241}
242
243.nav-overlay {
244 position: fixed;
245 top: $header-height;
246 bottom: 0;
247 left: 0;
248 right: 0;
SurenNeware057232b2020-06-08 20:53:26 +0530249 z-index: $zindex-fixed + 1;
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800250 background-color: $black;
251 opacity: 0.5;
252
253 &.fade-enter-active {
254 transition: opacity $duration--moderate-02 $entrance-easing--productive;
255 }
256
257 &.fade-leave-active {
258 transition: opacity $duration--fast-02 $exit-easing--productive;
259 }
260
SurenNeware151dd242020-11-10 20:15:05 +0530261 &.fade-enter, // Remove this vue2 based only class when switching to vue3
262 &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter'
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800263 &.fade-leave-to {
264 opacity: 0;
265 }
266
267 @include media-breakpoint-up($responsive-layout-bp) {
268 display: none;
269 }
270}
Derick Montague42c19892020-01-17 16:10:34 -0600271</style>