2023-03-03 15:54:28 +00:00
|
|
|
<script setup>
|
2024-04-23 17:36:45 +00:00
|
|
|
import { StyleService } from '@/Stores/style.service';
|
2023-10-31 14:38:43 +00:00
|
|
|
import { computed, ref, onMounted, onBeforeUnmount } from 'vue';
|
|
|
|
import { mdiChevronUp, mdiChevronDown } from '@mdi/js';
|
|
|
|
import NavBarItem from '@/Components/NavBarItem.vue';
|
|
|
|
import BaseIcon from '@/Components/BaseIcon.vue';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const styleStore = StyleService();
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const isDropdownActive = ref(false);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const toggleDropdownIcon = computed(() => (isDropdownActive.value ? mdiChevronUp : mdiChevronDown));
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const toggle = () => {
|
2023-10-31 14:38:43 +00:00
|
|
|
isDropdownActive.value = !isDropdownActive.value;
|
|
|
|
};
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const root = ref(null);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const forceClose = (event) => {
|
|
|
|
if (!root.value.$el.contains(event.target)) {
|
|
|
|
isDropdownActive.value = false;
|
|
|
|
}
|
|
|
|
};
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
2023-10-31 14:38:43 +00:00
|
|
|
window.addEventListener('click', forceClose);
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2023-10-31 14:38:43 +00:00
|
|
|
window.removeEventListener('click', forceClose);
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-10-31 14:38:43 +00:00
|
|
|
<NavBarItem ref="root" type="block" :active="isDropdownActive" dropdown @click="toggle">
|
|
|
|
<a
|
|
|
|
class="flex items-center py-2 px-3 dark:bg-slate-800 lg:bg-transparent lg:dark:bg-transparent"
|
|
|
|
:class="styleStore.navBarMenuListUpperLabelStyle"
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
<BaseIcon :path="toggleDropdownIcon" class="hidden lg:inline-flex transition-colors" />
|
|
|
|
</a>
|
|
|
|
<div
|
|
|
|
class="-mx-px text-sm border-b border-gray-100 lg:border lg:bg-white lg:absolute lg:top-full lg:left-0 lg:min-w-full lg:z-20 lg:rounded-b lg:dark:bg-slate-800 dark:border-slate-700"
|
|
|
|
:class="{ 'lg:hidden': !isDropdownActive }"
|
|
|
|
>
|
|
|
|
<slot name="dropdown" />
|
|
|
|
</div>
|
|
|
|
</NavBarItem>
|
2024-04-23 17:36:45 +00:00
|
|
|
</template>
|