2023-03-03 15:54:28 +00:00
|
|
|
<script setup>
|
|
|
|
import { ref, computed } from 'vue';
|
|
|
|
import { Link } from '@inertiajs/vue3';
|
|
|
|
// import { Link } from '@inertiajs/inertia-vue3';
|
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
import { StyleService } from '@/Stores/style';
|
2023-03-03 15:54:28 +00:00
|
|
|
import { mdiMinus, mdiPlus } from '@mdi/js';
|
|
|
|
import { getButtonColor } from '@/colors.js';
|
|
|
|
import BaseIcon from '@/Components/BaseIcon.vue';
|
|
|
|
import AsideMenuList from '@/Components/AsideMenuList.vue';
|
|
|
|
import { stardust } from '@eidellev/adonis-stardust/client';
|
|
|
|
|
|
|
|
const props = defineProps({
|
2023-10-31 14:38:43 +00:00
|
|
|
item: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isDropdownList: Boolean,
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
|
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));
|
|
|
|
const itemHref = computed(() => (props.item && props.item.href ? props.item.href : ''));
|
|
|
|
|
|
|
|
const emit = defineEmits(['menu-click']);
|
|
|
|
|
|
|
|
const styleService = StyleService();
|
|
|
|
|
|
|
|
const hasColor = computed(() => props.item && props.item.color);
|
|
|
|
|
|
|
|
const isDropdownActive = ref(false);
|
|
|
|
|
|
|
|
const componentClass = computed(() => [
|
2023-10-31 14:38:43 +00:00
|
|
|
props.isDropdownList ? 'py-3 px-6 text-sm font-semibold' : 'py-3 px-6',
|
|
|
|
hasColor.value ? getButtonColor(props.item.color, false, true) : styleService.asideMenuItemStyle,
|
2023-03-03 15:54:28 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
const hasDropdown = computed(() => props.item.children);
|
|
|
|
|
|
|
|
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-10-31 14:38:43 +00:00
|
|
|
if (hasDropdown.value) {
|
|
|
|
isDropdownActive.value = !isDropdownActive.value;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// props.routeName && stardust.isCurrent(props.routeName) ? props.activeColor : null
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- :target="props.item.target ?? null" -->
|
|
|
|
<template>
|
2023-10-31 14:38:43 +00:00
|
|
|
<li>
|
|
|
|
<!-- <component :is="itemHref ? 'div' : Link" :href="itemHref ? itemHref : itemRoute" -->
|
|
|
|
<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"
|
|
|
|
:class="componentClass"
|
|
|
|
@click="menuClick"
|
|
|
|
v-bind:target="props.item.target ?? null"
|
|
|
|
>
|
|
|
|
<BaseIcon v-if="item.icon" :path="item.icon" class="flex-none" :class="activeInactiveStyle" w="w-16" :size="18" />
|
|
|
|
<span class="grow text-ellipsis line-clamp-1" :class="activeInactiveStyle">
|
|
|
|
{{ item.label }}
|
|
|
|
</span>
|
|
|
|
<!-- plus icon for expanding sub menu -->
|
|
|
|
<BaseIcon
|
|
|
|
v-if="hasDropdown"
|
|
|
|
:path="isDropdownActive ? mdiMinus : mdiPlus"
|
|
|
|
class="flex-none"
|
|
|
|
:class="activeInactiveStyle"
|
|
|
|
w="w-12"
|
|
|
|
@click.prevent="menuClick"
|
|
|
|
/>
|
|
|
|
</component>
|
|
|
|
<AsideMenuList
|
|
|
|
v-if="hasDropdown"
|
|
|
|
:menu="item.children"
|
|
|
|
:class="[styleService.asideMenuDropdownStyle, isDropdownActive ? 'block dark:bg-slate-800/50' : 'hidden']"
|
|
|
|
is-dropdown-list
|
|
|
|
/>
|
|
|
|
</li>
|
2023-03-03 15:54:28 +00:00
|
|
|
</template>
|