Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 7c28b98

Browse files
committed
feat: basic navigation dropdown
1 parent 000eb3c commit 7c28b98

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

components/ContentNavItem.vue

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script setup lang="ts">
2+
import type { NavItem } from '@nuxt/content/dist/runtime/types'
3+
4+
const props = defineProps<{
5+
item: NavItem
6+
}>()
7+
8+
const ui = useUiState()
9+
10+
const resolved = computed(() => {
11+
if (props.item.children?.length === 1)
12+
return props.item.children[0]
13+
return props.item
14+
})
15+
</script>
16+
17+
<template>
18+
<div px1 py0.5 class="content-nav-item">
19+
<template v-if="resolved.children?.length">
20+
<details>
21+
<summary>
22+
<div flex="~ gap-1 items-center" cursor-pointer select-none>
23+
<div class="caret" i-ph-caret-right-duotone text-sm op50 transition duration-400 />
24+
<div i-ph-folder-simple-duotone />
25+
<div ml1>
26+
{{ resolved.title }}
27+
</div>
28+
</div>
29+
</summary>
30+
<div v-if="resolved.children?.length" pl-2>
31+
<ContentNavItem v-for="child in resolved.children" :key="child.url" :item="child" />
32+
</div>
33+
</details>
34+
</template>
35+
<NuxtLink
36+
v-else :to="resolved._path"
37+
flex="~ gap-1 items-center"
38+
hover="text-primary"
39+
@click="ui.isContentDropdownShown = false"
40+
>
41+
<div i-ph-caret-right-duotone class="caret" text-sm op0 />
42+
<div i-ph-file-duotone />
43+
<div ml1>
44+
{{ resolved.title }}
45+
</div>
46+
</NuxtLink>
47+
</div>
48+
</template>
49+
50+
<style>
51+
.content-nav-item details summary {
52+
list-style-type: none;
53+
}
54+
55+
.content-nav-item details[open] .caret {
56+
transform: rotate(90deg);
57+
}
58+
</style>

components/PanelDocs.vue

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
<script setup lang="ts">
22
const { page } = useContent()
3+
const ui = useUiState()
34
45
const sourceUrl = computed(() => page.value?._file
56
? `https://github.com/nuxt/learn.nuxt.com/edit/main/content/${page.value._file}`
67
: undefined)
8+
9+
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation())
710
</script>
811

912
<template>
10-
<div h-full grid="~ rows-[min-content_1fr_min-content]">
11-
<div flex="~ gap-2 items-center" border="b base dashed" bg-faded px4 py2>
13+
<div grid="~ rows-[min-content_1fr_min-content]" relative h-full>
14+
<button
15+
flex="~ gap-2 items-center" border="b base dashed" bg-faded px4 py2
16+
@click="ui.isContentDropdownShown = !ui.isContentDropdownShown"
17+
>
1218
<div i-ph-book-duotone />
1319
<NuxtLink to="/" text-sm>
1420
Guide
1521
</NuxtLink>
22+
<div flex-auto />
23+
<div i-ph-caret-down-duotone text-sm op50 transition duration-400 :class="ui.isContentDropdownShown ? 'rotate-180' : ''" />
24+
</button>
25+
<div relative h-full of-hidden>
26+
<article class="max-w-none prose" h-full of-auto p6>
27+
<ContentDoc />
28+
</article>
29+
<!-- Navigration Dropdown -->
30+
<div
31+
v-if="ui.isContentDropdownShown"
32+
flex="~ col"
33+
border="b base"
34+
absolute left-0 right-0 top-0 max-h-60vh py2
35+
backdrop-blur-10 bg-base important-bg-opacity-80
36+
>
37+
<ContentNavItem v-for="item in navigation" :key="item.url" :item="item" />
38+
</div>
1639
</div>
17-
<article class="max-w-none prose" of-auto p6>
18-
<ContentDoc />
19-
</article>
2040
<div border="t base dashed" px6 py2>
2141
<NuxtLink
2242
v-if="sourceUrl"
File renamed without changes.

stores/ui.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const useUiState = defineStore('ui', () => {
22
const isPanelDragging = ref(false)
3+
const isContentDropdownShown = ref(false)
34

45
const persistState = reactive(getLayoutDefaults())
56

@@ -44,6 +45,7 @@ export const useUiState = defineStore('ui', () => {
4445

4546
return {
4647
isPanelDragging,
48+
isContentDropdownShown,
4749
toggleTerminal,
4850
resetLayout,
4951
...toRefs(persistState),

0 commit comments

Comments
 (0)