-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathSidebarNav.vue
More file actions
122 lines (110 loc) 路 4.09 KB
/
Copy pathSidebarNav.vue
File metadata and controls
122 lines (110 loc) 路 4.09 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
<template>
<div
id="web-nav-sidebar"
class="bg-role-surface-container z-40 flex flex-col rounded-l-xl overflow-hidden transition-all duration-350 ease-[cubic-bezier(0.34,0.11,0,1.12)] max-w-[230px] min-w-[230px]"
>
<div class="flex flex-col grow">
<nav class="oc-sidebar-nav mt-3 px-1" :aria-label="$gettext('Sidebar navigation menu')">
<div v-if="floatingActionButton && !isMobile" class="pb-6 px-2">
<oc-button
:id="getButtonId(floatingActionButton.id)"
:disabled="isFloatingActionButtonDisabled"
appearance="filled"
color-role="primary"
class="oc-app-floating-action-button h-[48px] min-w-[100px] rounded-xl shadow-md"
@click="floatingActionButton.handler?.()"
>
<oc-icon :name="floatingActionButton.icon" />
<span v-text="floatingActionButton.label()" />
</oc-button>
<template
v-if="floatingActionButton.dropComponent && floatingActionButton.mode() === 'drop'"
>
<component
:is="floatingActionButton.dropComponent"
:toggle="`#${getButtonId(floatingActionButton.id)}`"
/>
</template>
</div>
<oc-list class="relative">
<sidebar-nav-item
v-for="(link, index) in navItems"
:key="index"
:target="link.route"
:active="link.active"
:icon="link.icon"
:fill-type="link.active ? 'fill' : 'line'"
:name="link.name"
:handler="link.handler"
/>
</oc-list>
</nav>
<custom-component-target :extension-point="dynamicExtensionPointMain" />
</div>
<div class="flex flex-col gap-2">
<custom-component-target :extension-point="dynamicExtensionPointBottom" />
<div class="flex flex-col pb-4 px-4 text-xs text-role-on-surface-variant">
<span v-text="backendVersion" />
<version-check />
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, unref, watchEffect } from 'vue'
import SidebarNavItem from './SidebarNavItem.vue'
import {
useCapabilityStore,
VersionCheck,
NavItem,
getBackendVersion,
CustomComponentTarget,
ExtensionPoint,
CustomComponentExtension,
useActiveApp,
useExtensionRegistry,
FloatingActionButtonExtension
} from '@opencloud-eu/web-pkg'
import { useIsMobile } from '@opencloud-eu/design-system/composables'
const { navItems } = defineProps<{ navItems: NavItem[] }>()
const capabilityStore = useCapabilityStore()
const backendVersion = computed(() => getBackendVersion({ capabilityStore }))
const activeApp = useActiveApp()
const { requestExtensions } = useExtensionRegistry()
const { isMobile } = useIsMobile()
const dynamicExtensionPointMain = computed<ExtensionPoint<CustomComponentExtension>>(() => ({
id: `app.${unref(activeApp)}.sidebar-nav.main`,
extensionType: 'customComponent'
}))
const dynamicExtensionPointBottom = computed<ExtensionPoint<CustomComponentExtension>>(() => ({
id: `app.${unref(activeApp)}.sidebar-nav.bottom`,
extensionType: 'customComponent'
}))
const isFloatingActionButtonDisabled = ref(true)
const floatingActionButton = computed(() => {
return requestExtensions<FloatingActionButtonExtension>({
id: `app.${unref(activeApp)}.floating-action-button`,
extensionType: 'floatingActionButton'
}).find(({ isVisible }) => !isVisible || isVisible())
})
function getButtonId(extensionId: string): string {
return `app-floating-action-button-${extensionId.replace(/\./g, '-')}`
}
let timeoutId: ReturnType<typeof setTimeout> | null = null
// use a timeout to avoid flickering of the floating action button in case the isFloatingActionButtonDisabled state changes rapidly
watchEffect(() => {
const disabled = unref(floatingActionButton)?.isDisabled?.() ?? false
if (timeoutId) {
clearTimeout(timeoutId)
}
timeoutId = setTimeout(() => {
isFloatingActionButtonDisabled.value = disabled
timeoutId = null
}, 50)
})
onBeforeUnmount(() => {
if (timeoutId) {
clearTimeout(timeoutId)
}
})
</script>