Skip to content

Commit

Permalink
feat: migrate updateMarker to the child component
Browse files Browse the repository at this point in the history
  • Loading branch information
WRXinYue committed Jul 24, 2024
1 parent db1769d commit d94b1ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/valaxy-addon-live2d
20 changes: 1 addition & 19 deletions theme/components/SakuraSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts" setup>
import { nextTick, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
import { useSakuraAppStore } from '../stores'
import { useThemeConfig } from '../composables'
Expand All @@ -9,26 +8,9 @@ const props = withDefaults(defineProps<{
}>(), {})
const sakuraAppStore = useSakuraAppStore()
const route = useRoute()
const themeConfig = useThemeConfig()
const marker = ref()
const position = ref(props.position ?? themeConfig.value.sidebarOptions.position)
watch(() => route.path, () => nextTick(() => updateMarker()))
function updateMarker() {
const routeActive = document.querySelector('.sakura-sidebar .site-link .router-link-active') as HTMLElement
// const sidebarTop = document.querySelector('.sakura-sidebar .site-link') as HTMLElement
marker.value.style.top = `${routeActive?.offsetTop || 0}px`
marker.value.style.height = `${routeActive?.offsetHeight || 0}px`
}
onMounted(() => {
nextTick(() => updateMarker())
marker.value = document.querySelector('.sakura-sidebar #marker')
})
</script>

<template>
Expand Down
23 changes: 20 additions & 3 deletions theme/components/themes/SidebarThemeOverview.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { useCategories, useSiteStore, useTags } from 'valaxy'
import type { NavItem } from '../../types'
import { useThemeConfig } from '../../composables'
Expand All @@ -10,14 +11,30 @@ const props = defineProps<{
}>()
const { t } = useI18n()
const site = useSiteStore()
const categories = useCategories()
const tags = useTags()
const themeConfig = useThemeConfig()
const route = useRoute()
const marker = ref()
const sidebar = computed(() => props.sidebar || themeConfig.value.sidebar) as unknown as NavItem[]
watch(() => route.path, () => nextTick(() => updateMarker()))
function updateMarker() {
const routeActive = document.querySelector('.sakura-sidebar .site-link .router-link-active') as HTMLElement
// const sidebarTop = document.querySelector('.sakura-sidebar .site-link') as HTMLElement
marker.value.style.top = `${routeActive?.offsetTop || 0}px`
marker.value.style.height = `${routeActive?.offsetHeight || 0}px`
}
onMounted(() => {
nextTick(() => updateMarker())
marker.value = document.querySelector('.sakura-sidebar #marker')
})
</script>

<template>
Expand Down

0 comments on commit d94b1ae

Please sign in to comment.