Skip to content

Commit

Permalink
fix(theme): don't show outline when no header is there (#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd authored Mar 21, 2023
1 parent 83ce1b8 commit 42a0ef2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/client/theme-default/components/VPDocOutlineDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref } from 'vue'
import { ref, shallowRef } from 'vue'
import { useData } from '../composables/data'
import { getHeaders, resolveTitle } from '../composables/outline'
import { getHeaders, resolveTitle, type MenuItem } from '../composables/outline'
import VPDocOutlineItem from './VPDocOutlineItem.vue'
import { onContentUpdated } from 'vitepress'
import VPIconChevronRight from './icons/VPIconChevronRight.vue'
Expand All @@ -12,16 +12,24 @@ const open = ref(false)
onContentUpdated(() => {
open.value = false
})
const headers = shallowRef<MenuItem[]>([])
onContentUpdated(() => {
headers.value = getHeaders(
frontmatter.value.outline ?? theme.value.outline
)
})
</script>

<template>
<div class="VPDocOutlineDropdown">
<div class="VPDocOutlineDropdown" v-if="headers.length > 0">
<button @click="open = !open" :class="{ open }">
{{ resolveTitle(theme) }}
<VPIconChevronRight class="icon" />
</button>
<div class="items" v-if="open">
<VPDocOutlineItem :headers="getHeaders(frontmatter.outline ?? theme.outline)" />
<VPDocOutlineItem :headers="headers" />
</div>
</div>
</template>
Expand Down
19 changes: 15 additions & 4 deletions src/client/theme-default/components/VPLocalNavOutlineDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, nextTick } from 'vue'
import { ref, nextTick, shallowRef } from 'vue'
import { useData } from '../composables/data'
import { getHeaders, resolveTitle } from '../composables/outline'
import { getHeaders, resolveTitle, type MenuItem } from '../composables/outline'
import VPDocOutlineItem from './VPDocOutlineItem.vue'
import { onContentUpdated } from 'vitepress'
import VPIconChevronRight from './icons/VPIconChevronRight.vue'
Expand Down Expand Up @@ -36,14 +36,25 @@ function scrollToTop() {
open.value = false
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
}
const headers = shallowRef<MenuItem[]>([])
onContentUpdated(() => {
headers.value = getHeaders(
frontmatter.value.outline ?? theme.value.outline
)
})
</script>

<template>
<div class="VPLocalNavOutlineDropdown" :style="{ '--vp-vh': vh + 'px' }">
<button @click="toggle" :class="{ open }">
<button @click="toggle" :class="{ open }" v-if="headers.length > 0">
{{ resolveTitle(theme) }}
<VPIconChevronRight class="icon" />
</button>
<button @click="scrollToTop" v-else>
{{ theme.returnToTopLabel || 'Return to top' }}
</button>
<Transition name="flyout">
<div v-if="open"
ref="items"
Expand All @@ -53,7 +64,7 @@ function scrollToTop() {
<a class="top-link" href="#" @click="scrollToTop">
{{ theme.returnToTopLabel || 'Return to top' }}
</a>
<VPDocOutlineItem :headers="getHeaders(frontmatter.outline ?? theme.outline)" />
<VPDocOutlineItem :headers="headers" />
</div>
</Transition>
</div>
Expand Down

0 comments on commit 42a0ef2

Please sign in to comment.