Skip to content

Commit

Permalink
feat: add custom menu active
Browse files Browse the repository at this point in the history
  • Loading branch information
Noval Oktavio committed Nov 29, 2021
1 parent 40696a0 commit 8547932
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/VMenu/VMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Disclosure, DisclosureButton, DisclosurePanel} from '@headlessui/vue';
import {ChevronRightIcon} from '@heroicons/vue/outline';
import VMenuTooltip from './VMenuTooltip.vue';
import VMenuItem from './VMenuItem.vue';
import { useRouter } from 'vue-router';
const props = defineProps({
menu: {
Expand Down Expand Up @@ -46,6 +47,7 @@ const props = defineProps({
}
});
const router = useRouter();
const emit = defineEmits([]);
const {menu, mini, dark, classMenuParent} = toRefs(props);
Expand Down Expand Up @@ -73,6 +75,14 @@ const openClass = (isOpen: boolean) => {
};
const scrollHeight = computed(() => (panel as any).value?.el?.scrollHeight);
const isActive = (path: any) => {
const currentPath = router.currentRoute.value.path;
const currentRoute = currentPath.split('/');
const route = path.to.split('/');
return route[2] === currentRoute[2];
}
</script>

<template>
Expand Down Expand Up @@ -133,7 +143,7 @@ const scrollHeight = computed(() => (panel as any).value?.el?.scrollHeight);
:key="j"
:item="child"
:mini="mini"
:text-color="textColor"
:text-color="isActive(child) ? 'text-primary-600' : textColor"
/>
</DisclosurePanel>
</Disclosure>
Expand All @@ -157,7 +167,7 @@ const scrollHeight = computed(() => (panel as any).value?.el?.scrollHeight);
mb-1
relative
"
:class="[textColor, mini ? 'justify-start sm:justify-center' : '']"
:class="[isActive(menu) ? 'text-primary-600' : textColor, mini ? 'justify-start sm:justify-center' : '']"
>
<img v-if="menu.img" :src="menu.img" alt="img icon" class="w-5 h-5" />
<component :is="menu.icon" v-else-if="menu.icon" class="w-5 h-5" />
Expand Down

0 comments on commit 8547932

Please sign in to comment.