Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: click on heading and toc #671

Merged
merged 6 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/router.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig> {
scrollBehavior (to, from, savedPosition) {
if (to.hash) {
const { marginTop } = getComputedStyle((document.querySelector(to.hash) as any))
const marginTopValue = parseInt(marginTop)
const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
return {
top: offset,
behavior: 'smooth'
}
}
}
}
7 changes: 0 additions & 7 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
box-shadow: none !important;
}

html,
body {
height: 100%;
width: 100%;
overflow: auto;
}

body {
overflow-y: scroll;
-webkit-font-smoothing: antialiased;
Expand Down
11 changes: 1 addition & 10 deletions components/docs/DocsPageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ onBeforeUnmount(() => {
<DocsPrevNext />
</template>
</article>

<!-- TOC -->
<div
v-if="hasToc"
:class="{
'closed': !isOpen,
}"
class="toc"
>
<div class="toc-wrapper">
Expand Down Expand Up @@ -217,13 +215,6 @@ css({
alignSelf: 'flex-start',
py: '{space.8}',
},
'&.closed': {
display: 'flex',
alignItems: 'center',
'@mq.lg': {
display: 'block'
}
},
'.toc-wrapper': {
width: '100%',
backdropFilter: '{backdrop.filter}',
Expand Down
34 changes: 13 additions & 21 deletions components/docs/DocsTocLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,18 @@ const router = useRouter()

const { activeHeadings, updateHeadings } = useScrollspy()

watch(
() => route.path,
() => {
if (process.client) {
setTimeout(() => {
updateHeadings([
...document.querySelectorAll('.document-driven-page h1, .docus-content h1'),
...document.querySelectorAll('.document-driven-page h2, .docus-content h2'),
...document.querySelectorAll('.document-driven-page h3, .docus-content h3'),
...document.querySelectorAll('.document-driven-page h4, .docus-content h4')
])
}, 300)
}
},
{
immediate: true
}
)
if (process.client) {
setTimeout(() => {
updateHeadings([
...document.querySelectorAll('.document-driven-page h1, .docus-content h1'),
...document.querySelectorAll('.document-driven-page h2, .docus-content h2'),
...document.querySelectorAll('.document-driven-page h3, .docus-content h3'),
...document.querySelectorAll('.document-driven-page h4, .docus-content h4')
])
}, 300)
}

const scrollToHeading = (id: string) => {
function scrollToHeading (id: string) {
router.push(`#${id}`)
emit('move', id)
}
Expand Down Expand Up @@ -78,11 +70,11 @@ css({
'@mq.lg': {
paddingRight: '{space.3}'
},
'&:hover': {
'&:not(.active):hover': {
color: '{colors.gray.900}',
},
'@dark': {
'&:hover': {
'&:not(.active):hover': {
color: '{colors.gray.400}',
},
},
Expand Down