/
AppHeaderNavigation.vue
97 lines (85 loc) · 2.18 KB
/
AppHeaderNavigation.vue
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
<script setup lang="ts">
const route = useRoute()
const { navBottomLink } = useContentHelpers()
const { navigation } = useContent()
const docus = useDocus()
const hasNavigation = computed(() => !!docus.value.aside?.level)
const filtered = computed(() => docus.value.header?.exclude || [])
const tree = computed(() => {
return (navigation.value || []).filter((item: any) => {
if (filtered.value.includes(item._path)) { return false }
return true
})
})
const isActive = (link: any) => (link.exact ? route.fullPath === link._path : route.fullPath.startsWith(link._path))
</script>
<template>
<nav v-if="hasNavigation">
<ul>
<li
v-for="link in tree"
:key="link._path"
>
<NuxtLink
class="link"
:to="link.redirect? link.redirect : navBottomLink(link)"
:class="{ active: isActive(link) }"
>
<Icon v-if="link.icon && docus.header.showLinkIcon" :name="link.icon" />
{{ link.title }}
</NuxtLink>
</li>
</ul>
</nav>
</template>
<style scoped lang="ts">
css({
nav: {
display: 'none',
'@lg': {
display: 'block'
},
ul: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flex: '1',
maxWidth: '100%',
// TODO: truncate
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
'& > * + *': {
marginLeft: '{space.2}'
},
li: {
display: 'inline-flex',
gap: '{space.1}',
},
'.link': {
display: 'flex',
alignItems: 'center',
gap: '{space.2}',
padding: '{space.2} {space.4}',
fontSize: '{fontSize.sm}',
borderRadius: '{radii.md}',
outline: 'none',
transition: 'background 200ms ease',
svg: {
display: 'inline-block'
},
'&:active,&.active,&:hover': {
backgroundColor: '{color.gray.100}',
'@dark': {
backgroundColor: '{color.gray.900}',
},
},
'&.active': {
boxShadow: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
fontWeight: '{fontWeight.semibold}'
}
}
}
}
})
</style>