-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationButton.vue
More file actions
68 lines (63 loc) · 1.97 KB
/
Copy pathNavigationButton.vue
File metadata and controls
68 lines (63 loc) · 1.97 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
<template>
<button
class="flex flex-col items-center justify-center gap-1 px-4 cursor-pointer tg-text-subtitle"
@click="(isMainPage && canScrollToTop && isThisRoute) ? handleScrollToTop() : handleRedirect(route.path)"
>
<div
class="relative py-1 w-full rounded-2xl flex flex-row items-center justify-center"
:class="[
(isThisRoute || isThisName) && 'tg-bg-button tg-text-button motion-translate-y-in',
]"
>
<UIcon
v-if="isMainPage && canScrollToTop && isThisRoute"
name="i-lucide-arrow-up"
class="size-6 motion-preset-shake"
/>
<UIcon
v-else-if="router.currentRoute.value.meta.canReturn && isThisName"
name="i-lucide-undo-2"
class="size-6 motion-preset-shake"
/>
<UChip
v-else
size="3xl"
color="error"
:show="!!route.badge && route.badge !== '0'"
:text="route.badge"
:ui="{
base: '-right-1 px-1.5 py-2 ring-2 tg-text-button font-bold motion-translate-y-loop-25 motion-duration-3500',
}"
>
<UIcon
:name="route.icon"
class="size-6 motion-preset-shake"
/>
</UChip>
</div>
<p
class="text-xs font-medium"
:class="[
(isThisRoute || isThisName) && 'tg-text',
]"
>
{{ route.title }}
</p>
</button>
</template>
<script setup lang="ts">
const { route } = defineProps<{ route: NavigationRoute }>()
const { vibrate } = useFeedback()
const { canScrollToTop, isMainPage } = useNavigation()
const router = useRouter()
const isThisRoute = computed(() => route.exact ? router.currentRoute.value.path === route.path : router.currentRoute.value.path.startsWith(route.path))
const isThisName = computed(() => route.names.includes(router.currentRoute.value.name))
function handleScrollToTop() {
vibrate()
window.scrollTo({ top: 0, behavior: 'smooth' })
}
function handleRedirect(path: string) {
vibrate()
router.push(path)
}
</script>