Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): page outline for mobile
- Loading branch information
Showing
8 changed files
with
229 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/client/theme-default/components/VPDocOutlineDropdown.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { useData } from '../composables/data.js' | ||
import { getHeaders, resolveTitle } from '../composables/outline.js' | ||
import VPDocOutlineItem from './VPDocOutlineItem.vue' | ||
import { onContentUpdated } from 'vitepress' | ||
import VPIconChevronRight from './icons/VPIconChevronRight.vue' | ||
const { frontmatter, theme } = useData() | ||
const open = ref(false) | ||
onContentUpdated(() => { | ||
open.value = false | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="VPDocOutlineDropdown"> | ||
<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)" /> | ||
</div> | ||
</div> | ||
</template> | ||
<style scoped> | ||
.VPDocOutlineDropdown { | ||
margin-bottom: 42px; | ||
} | ||
.VPDocOutlineDropdown button { | ||
display: block; | ||
font-size: 14px; | ||
font-weight: 500; | ||
line-height: 24px; | ||
color: var(--vp-c-text-2); | ||
transition: color 0.5s; | ||
border: 1px solid var(--vp-c-border); | ||
padding: 4px 12px; | ||
border-radius: 8px; | ||
} | ||
.VPDocOutlineDropdown button:hover { | ||
color: var(--vp-c-text-1); | ||
transition: color 0.25s; | ||
} | ||
.VPDocOutlineDropdown button.open { | ||
color: var(--vp-c-text-1); | ||
} | ||
.icon { | ||
display: inline-block; | ||
vertical-align: middle; | ||
margin-left: 2px; | ||
width: 14px; | ||
height: 14px; | ||
fill: currentColor; | ||
} | ||
:deep(.outline-link) { | ||
font-size: 13px; | ||
} | ||
.open > .icon { | ||
transform: rotate(90deg); | ||
} | ||
.items { | ||
margin-top: 10px; | ||
border-left: 1px solid var(--vp-c-divider); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/client/theme-default/components/VPLocalNavOutlineDropdown.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { useData } from '../composables/data.js' | ||
import { getHeaders, resolveTitle } from '../composables/outline.js' | ||
import VPDocOutlineItem from './VPDocOutlineItem.vue' | ||
import { onContentUpdated } from 'vitepress' | ||
import VPIconChevronRight from './icons/VPIconChevronRight.vue' | ||
const { frontmatter, theme } = useData() | ||
const open = ref(false) | ||
const vh = ref(0) | ||
onContentUpdated(() => { | ||
open.value = false | ||
}) | ||
function toggle() { | ||
open.value = !open.value | ||
vh.value = window.innerHeight + Math.min(window.scrollY - 64, 0) | ||
} | ||
function onItemClick(e: Event) { | ||
if ((e.target as HTMLElement).classList.contains('outline-link')) { | ||
open.value = false | ||
} | ||
} | ||
function scrollToTop() { | ||
open.value = false | ||
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="VPLocalNavOutlineDropdown" :style="{ '--vp-vh': vh + 'px' }"> | ||
<button @click="toggle" :class="{ open }"> | ||
{{ resolveTitle(theme) }} | ||
<VPIconChevronRight class="icon" /> | ||
</button> | ||
<div class="items" v-if="open" @click="onItemClick"> | ||
<a class="top-link" href="#" @click="scrollToTop"> | ||
{{ theme.returnToTopLabel || 'Return to top' }} | ||
</a> | ||
<VPDocOutlineItem :headers="getHeaders(frontmatter.outline ?? theme.outline)" /> | ||
</div> | ||
</div> | ||
</template> | ||
<style scoped> | ||
.VPLocalNavOutlineDropdown { | ||
padding: 12px 20px 11px; | ||
} | ||
.VPLocalNavOutlineDropdown button { | ||
display: block; | ||
font-size: 12px; | ||
font-weight: 500; | ||
line-height: 24px; | ||
color: var(--vp-c-text-2); | ||
transition: color 0.5s; | ||
position: relative; | ||
} | ||
.VPLocalNavOutlineDropdown button:hover { | ||
color: var(--vp-c-text-1); | ||
transition: color 0.25s; | ||
} | ||
.VPLocalNavOutlineDropdown button.open { | ||
color: var(--vp-c-text-1); | ||
} | ||
.icon { | ||
display: inline-block; | ||
vertical-align: middle; | ||
margin-left: 2px; | ||
width: 14px; | ||
height: 14px; | ||
fill: currentColor; | ||
} | ||
:deep(.outline-link) { | ||
font-size: 14px; | ||
padding: 2px 0; | ||
} | ||
.open > .icon { | ||
transform: rotate(90deg); | ||
} | ||
.items { | ||
position: absolute; | ||
left: 20px; | ||
right: 20px; | ||
top: 64px; | ||
background-color: var(--vp-local-nav-bg-color); | ||
padding: 4px 10px 16px; | ||
border: 1px solid var(--vp-c-divider); | ||
border-radius: 8px; | ||
max-height: calc(var(--vp-vh, 100vh) - 86px); | ||
overflow: scroll; | ||
box-shadow: var(--vp-shadow-3); | ||
} | ||
.top-link { | ||
display: block; | ||
color: var(--vp-c-brand); | ||
font-size: 13px; | ||
font-weight: 500; | ||
padding: 6px 0; | ||
margin: 0 13px 10px; | ||
border-bottom: 1px solid var(--vp-c-divider); | ||
} | ||
</style> |
Oops, something went wrong.