-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathMenuLink.vue
More file actions
137 lines (119 loc) · 5.72 KB
/
Copy pathMenuLink.vue
File metadata and controls
137 lines (119 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
<component
:is="isExternalUrl(item.url) ? 'a' : RouterLink"
v-bind="isExternalUrl(item.url)
? { href: item.url }
: { to: item.url || { name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {} } }"
:target="item.isOpenInNewTab ? '_blank' : '_self'"
class="af-menu-link flex group relative items-center w-full py-2 text-lightSidebarText dark:text-darkSidebarText rounded-default transition-all duration-200 ease-in-out"
:class="{
'hover:bg-lightSidebarItemHover hover:text-lightSidebarTextHover dark:hover:bg-darkSidebarItemHover dark:hover:text-darkSidebarTextHover active:bg-lightSidebarActive dark:active:bg-darkSidebarHover': !['divider', 'gap', 'heading'].includes(item.type),
'pl-6 pr-3.5': (isChild && !isSidebarIconOnly && !isSidebarHovering) || (isChild && isSidebarIconOnly && isSidebarHovering),
'px-3.5 ': !isChild || (isSidebarIconOnly && !isSidebarHovering),
'max-w-12': isSidebarIconOnly && !isSidebarHovering,
'bg-lightSidebarItemActive dark:bg-darkSidebarItemActive': isItemActive(item)
}"
>
<component v-if="item.icon" :is="getIcon(item.icon)"
class="min-w-5 min-h-5 text-lightSidebarIcons dark:text-darkSidebarIcons group-hover:text-lightSidebarIconsHover dark:group-hover:text-darkSidebarIconsHover transition-all duration-200 ease-in-out"
>
</component>
<IconFileImageOutline v-else
class="min-w-5 min-h-5 text-lightSidebarIcons dark:text-darkSidebarIcons group-hover:text-lightSidebarIconsHover dark:group-hover:text-darkSidebarIconsHover transition-all duration-200 ease-in-out"
/>
<div
class="overflow-hidden block ms-3 pr-4 text-left rtl:text-right transition-all duration-200 ease-in-out"
:class="{
'opacity-0 ms-0 translate-x-4 flex-none': isSidebarIconOnly && !isSidebarHovering,
'opacity-100 ms-3 translate-x-0 flex-1': !isSidebarIconOnly || (isSidebarIconOnly && isSidebarHovering),
}"
:style="isSidebarIconOnly ? {
minWidth: isChild
? `calc(${expandedWidth} - 0.75rem*2 - 1.5rem*2 - 1.25rem - 0.75rem)`
: `calc(${expandedWidth} - 0.75rem*2 - 0.875rem*2 - 1.25rem - 0.75rem)`,
width: isChild
? `calc(${expandedWidth} - 0.75rem*2 - 1.5rem*2 - 1.25rem - 0.75rem)`
: `calc(${expandedWidth} - 0.75rem*2 - 0.875rem*2 - 1.25rem - 0.75rem)`
} : {}"
>
{{ item.label }}
</div>
<span class="absolute flex items-center justify-center right-1 top-1/2 -translate-y-1/2" v-if="(item.badge || item.badge === 0) && showExpandedBadge ">
<Tooltip v-if="item.badgeTooltip">
<div class="af-badge inline-flex items-center justify-center h-3 py-2.5 px-1 ms-3 text-xs font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
<template #tooltip>
{{ item.badgeTooltip }}
</template>
</Tooltip>
<template v-else>
<div class="af-badge inline-flex items-center justify-center h-3 py-2.5 px-1 ms-3 text-xs font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
</template>
</span>
<div v-if="(item.badge || item.badge === 0) && isSidebarIconOnly && !isSidebarHovering" class="af-badge absolute right-0.5 bottom-1 -translate-y-1/2 inline-flex items-center justify-center h-2 w-2 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent">
</div>
</component>
</template>
<script setup lang="ts">
import { getIcon } from '@/utils';
import { Tooltip } from '@/afcl';
import { ref, watch, computed } from 'vue';
import { useCoreStore } from '@/stores/core';
import { IconFileImageOutline } from '@iconify-prerendered/vue-flowbite';
import { useRoute, RouterLink } from 'vue-router';
const isExternalUrl = (url: string ) => /^https?:\/\//.test(url || '');
const route = useRoute();
const isItemActive = (item: any) => {
if (item.url) {
return !isExternalUrl(item.url) && route.fullPath === item.url;
}
if (item.resourceId) {
return route.params.resourceId === item.resourceId && route.name === 'resource-list';
}
return route.name === item.path;
};
const props = defineProps(['item', 'isChild', 'isSidebarIconOnly', 'isSidebarHovering']);
const coreStore = useCoreStore();
const expandedWidth = computed(() => coreStore.config?.iconOnlySidebar?.expandedSidebarWidth || '16.5rem');
const BADGE_SHOW_DELAY_MS = 200;
const showExpandedBadge = ref(false);
let showBadgeTimer: ReturnType<typeof setTimeout> | null = null;
function cancelShowBadgeTimer() {
if (showBadgeTimer) {
clearTimeout(showBadgeTimer);
showBadgeTimer = null;
}
}
function showBadgeImmediately() {
cancelShowBadgeTimer();
showExpandedBadge.value = true;
}
function hideBadgeImmediately() {
cancelShowBadgeTimer();
showExpandedBadge.value = false;
}
function showBadgeAfterDelay() {
cancelShowBadgeTimer();
showBadgeTimer = setTimeout(() => {
showExpandedBadge.value = true;
showBadgeTimer = null;
}, BADGE_SHOW_DELAY_MS);
}
watch(
[() => props.isSidebarIconOnly, () => props.isSidebarHovering],
([isIconOnly, isHovering]) => {
if (!isIconOnly) {
showBadgeImmediately();
return;
}
if (isHovering) {
showBadgeAfterDelay();
return;
}
hideBadgeImmediately();
},
{ immediate: true }
);
</script>