2023-11-27 16:17:22 +00:00
|
|
|
<script lang="ts" setup>
|
2024-04-23 17:36:45 +00:00
|
|
|
import { computed, ComputedRef } from 'vue';
|
2023-11-27 16:17:22 +00:00
|
|
|
import { Link, usePage } from '@inertiajs/vue3';
|
2023-03-03 15:54:28 +00:00
|
|
|
// import { Link } from '@inertiajs/inertia-vue3';
|
|
|
|
|
2024-04-23 17:36:45 +00:00
|
|
|
import { StyleService } from '@/Stores/style.service';
|
2023-03-03 15:54:28 +00:00
|
|
|
import { mdiMinus, mdiPlus } from '@mdi/js';
|
2024-04-29 09:25:50 +00:00
|
|
|
import { getButtonColor } from '@/colors';
|
2023-03-03 15:54:28 +00:00
|
|
|
import BaseIcon from '@/Components/BaseIcon.vue';
|
2023-11-29 15:52:41 +00:00
|
|
|
// import AsideMenuList from '@/Components/AsideMenuList.vue';
|
2023-03-03 15:54:28 +00:00
|
|
|
import { stardust } from '@eidellev/adonis-stardust/client';
|
2023-11-27 16:17:22 +00:00
|
|
|
import type { User } from '@/Dataset';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const props = defineProps({
|
2023-10-31 14:38:43 +00:00
|
|
|
item: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2023-11-29 15:52:41 +00:00
|
|
|
parentItem: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
// isDropdownList: Boolean,
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
|
2023-11-27 16:17:22 +00:00
|
|
|
const user: ComputedRef<User> = computed(() => {
|
|
|
|
return usePage().props.authUser as User;
|
|
|
|
});
|
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const itemRoute = computed(() => (props.item && props.item.route ? stardust.route(props.item.route) : ''));
|
2023-03-03 15:54:28 +00:00
|
|
|
// const isCurrentRoute = computed(() => (props.item && props.item.route ? stardust.isCurrent(props.item.route): false));
|
2023-11-29 15:52:41 +00:00
|
|
|
// const itemHref = computed(() => (props.item && props.item.href ? props.item.href : ''));
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const emit = defineEmits(['menu-click']);
|
|
|
|
|
|
|
|
const styleService = StyleService();
|
|
|
|
|
|
|
|
const hasColor = computed(() => props.item && props.item.color);
|
|
|
|
|
2023-11-30 12:40:32 +00:00
|
|
|
// const isDropdownOpen = ref(false);
|
2023-11-29 15:52:41 +00:00
|
|
|
|
2023-11-30 12:40:32 +00:00
|
|
|
// const isChildSelected = computed(() => {
|
|
|
|
// if (props.item.children && props.item.children.length > 0) {
|
|
|
|
// return children.value.some(childItem => stardust.isCurrent(childItem.route));
|
|
|
|
// }
|
|
|
|
// return false;
|
2023-11-29 15:52:41 +00:00
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
const hasChildren = computed(() => {
|
|
|
|
// props.item.children?.length > 0
|
|
|
|
if (props.item.children && props.item.children.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
const children = computed(() => {
|
|
|
|
return props.item.children || [];
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const componentClass = computed(() => [
|
2023-11-29 15:52:41 +00:00
|
|
|
hasChildren ? 'py-3 px-6 text-sm font-semibold' : 'py-3 px-6',
|
2023-10-31 14:38:43 +00:00
|
|
|
hasColor.value ? getButtonColor(props.item.color, false, true) : styleService.asideMenuItemStyle,
|
2023-03-03 15:54:28 +00:00
|
|
|
]);
|
|
|
|
|
2023-11-29 15:52:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
// const toggleDropdown = () => {
|
|
|
|
// // emit('menu-click', event, props.item);
|
|
|
|
// // console.log(props.item);
|
|
|
|
// if (hasChildren.value) {
|
|
|
|
// isDropdownOpen.value = !isDropdownOpen.value;
|
|
|
|
// }
|
|
|
|
// // if (props.parentItem?.hasDropdown.value) {
|
|
|
|
// // props.parentItem.isDropdownActive.value = true;
|
|
|
|
// // }
|
|
|
|
// };
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const menuClick = (event) => {
|
2023-10-31 14:38:43 +00:00
|
|
|
emit('menu-click', event, props.item);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-11-29 15:52:41 +00:00
|
|
|
if (hasChildren.value) {
|
|
|
|
// if (isChildSelected.value == false) {
|
|
|
|
// isDropdownOpen.value = !isDropdownOpen.value;
|
|
|
|
props.item.isOpen = !props.item.isOpen;
|
|
|
|
// }
|
2023-10-31 14:38:43 +00:00
|
|
|
}
|
2023-11-29 15:52:41 +00:00
|
|
|
|
2023-03-03 15:54:28 +00:00
|
|
|
};
|
|
|
|
|
2023-11-29 15:52:41 +00:00
|
|
|
// const handleChildSelected = () => {
|
|
|
|
// isChildSelected.value = true;
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
2023-03-03 15:54:28 +00:00
|
|
|
const activeInactiveStyle = computed(() => {
|
2023-10-31 14:38:43 +00:00
|
|
|
if (props.item.route && stardust.isCurrent(props.item.route)) {
|
|
|
|
// console.log(props.item.route);
|
|
|
|
return styleService.asideMenuItemActiveStyle;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const is = computed(() => {
|
2023-10-31 14:38:43 +00:00
|
|
|
if (props.item.href) {
|
|
|
|
return 'a';
|
|
|
|
}
|
|
|
|
if (props.item.route) {
|
|
|
|
return Link;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'div';
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-11-27 16:17:22 +00:00
|
|
|
const hasRoles = computed(() => {
|
|
|
|
if (props.item.roles) {
|
|
|
|
return user.value.roles.some(role => props.item.roles.includes(role.name));
|
|
|
|
// return test;
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
});
|
|
|
|
|
2023-03-03 15:54:28 +00:00
|
|
|
// props.routeName && stardust.isCurrent(props.routeName) ? props.activeColor : null
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- :target="props.item.target ?? null" -->
|
|
|
|
<template>
|
2023-11-27 16:17:22 +00:00
|
|
|
<li v-if="hasRoles">
|
2023-10-31 14:38:43 +00:00
|
|
|
<!-- <component :is="itemHref ? 'div' : Link" :href="itemHref ? itemHref : itemRoute" -->
|
2023-11-29 15:52:41 +00:00
|
|
|
<component :is="is" :href="itemRoute ? stardust.route(props.item.route) : props.item.href"
|
|
|
|
class="flex cursor-pointer dark:text-slate-300 dark:hover:text-white menu-item-wrapper" :class="componentClass"
|
|
|
|
@click="menuClick" v-bind:target="props.item.target ?? null">
|
|
|
|
<BaseIcon v-if="item.icon" :path="item.icon" class="flex-none menu-item-icon" :class="activeInactiveStyle"
|
|
|
|
w="w-16" :size="18" />
|
|
|
|
<div class="menu-item-label">
|
|
|
|
<span class="grow text-ellipsis line-clamp-1" :class="activeInactiveStyle">
|
|
|
|
{{ item.label }}
|
|
|
|
</span>
|
|
|
|
</div>
|
2023-10-31 14:38:43 +00:00
|
|
|
<!-- plus icon for expanding sub menu -->
|
2023-11-29 15:52:41 +00:00
|
|
|
<BaseIcon v-if="hasChildren" :path="props.item.isOpen ? mdiMinus : mdiPlus" class="flex-none"
|
|
|
|
:class="[activeInactiveStyle]" w="w-12" />
|
2023-10-31 14:38:43 +00:00
|
|
|
</component>
|
2023-11-29 15:52:41 +00:00
|
|
|
<div class="menu-item-dropdown"
|
|
|
|
:class="[styleService.asideMenuDropdownStyle, props.item.isOpen ? 'block dark:bg-slate-800/50' : 'hidden']"
|
|
|
|
v-if="hasChildren">
|
|
|
|
<ul>
|
|
|
|
<!-- <li v-for="( child, index ) in children " :key="index">
|
|
|
|
<AsideMenuItem :item="child" :key="index"> </AsideMenuItem>
|
|
|
|
</li> -->
|
2023-11-30 12:40:32 +00:00
|
|
|
<AsideMenuItem v-for="(childItem, index) in children" :key="index" :item="childItem" />
|
2023-11-29 15:52:41 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<!-- <AsideMenuList v-if="hasChildren" :items="item.children"
|
|
|
|
:class="[styleService.asideMenuDropdownStyle, isDropdownOpen ? 'block dark:bg-slate-800/50' : 'hidden']" /> -->
|
|
|
|
|
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
</li>
|
2023-03-03 15:54:28 +00:00
|
|
|
</template>
|
2023-11-29 15:52:41 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.menu-item-wrapper {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2023-11-30 12:40:32 +00:00
|
|
|
.menu-item-icon {
|
|
|
|
font-size: 2.5rem;
|
|
|
|
/* margin-right: 10px; */
|
2023-11-29 15:52:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 12:40:32 +00:00
|
|
|
/* .menu-item-label {
|
2023-11-29 15:52:41 +00:00
|
|
|
font-size: 1.2rem;
|
|
|
|
font-weight: bold;
|
2023-11-30 12:40:32 +00:00
|
|
|
} */
|
2023-11-29 15:52:41 +00:00
|
|
|
|
|
|
|
.menu-item-dropdown {
|
2023-11-30 12:40:32 +00:00
|
|
|
/* margin-left: 10px; */
|
|
|
|
padding-left: 0.75rem;
|
|
|
|
}
|
2023-11-29 15:52:41 +00:00
|
|
|
</style>
|