Skip to content

Commit

Permalink
feat(theme-yun): add active class for categories/tags/archives nav
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Nov 9, 2024
1 parent ec7bcb7 commit 47229ca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
15 changes: 12 additions & 3 deletions packages/valaxy-theme-yun/components/YunPostsInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ const tags = useTags()
<template>
<nav class="site-nav" text-xl mt-2>
<YunPostClassifyNavItem
to="/archives/" icon="i-ri-archive-line" :title="t('menu.archives')"
to="/archives/"
icon="i-ri-archive-line"
active-icon="i-ri-archive-fill"
:title="t('menu.archives')"
:total="site.postList.length"
/>
<YunPostClassifyNavItem
to="/categories/" icon="i-ri-folder-2-line" :title="t('menu.categories')"
to="/categories/"
icon="i-ri-folder-2-line"
active-icon="i-ri-folder-2-fill"
:title="t('menu.categories')"
:total="Array.from(categories.children).length"
/>
<YunPostClassifyNavItem
to="/tags/" icon="i-ri-price-tag-3-line" :title="t('menu.tags')"
to="/tags/"
icon="i-ri-price-tag-3-line"
active-icon="i-ri-price-tag-3-fill"
:title="t('menu.tags')"
:total="Array.from(tags).length"
/>
</nav>
Expand Down
1 change: 1 addition & 0 deletions packages/valaxy-theme-yun/components/YunSidebarCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<template>
<YunCard class="p-4 min-h-sm" flex="~ col gap-1">
<YunSiteInfo class="text-center" />
<YunGradientDivider class="my-2 op-20" />
<YunPostsInfo />
<YunGradientDivider class="my-2 op-20" />
<YunSocialLinks />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script lang="ts" setup>
defineProps<{
import { computed } from 'vue'
import { useRoute } from 'vue-router'
const props = defineProps<{
activeIcon?: string
icon: string
title: string
/**
Expand All @@ -8,23 +13,46 @@ defineProps<{
total: number
to: string
}>()
const route = useRoute()
const active = computed(() => route.path === props.to)
const icon = computed(() => {
if (active.value && props.activeIcon)
return props.activeIcon
return props.icon
})
</script>

<template>
<RouterLink
flex="~ col center"
class="gap-1 w-20 p-2 rounded transition op-80"
:to="to" :title="title"
class="post-classify-nav-item gap-1 w-20 p-2 rounded transition op-80"
:to="to"
:title="title"
hover="bg-$va-c-bg-soft op-100"
>
<div flex="~ col" class="text-$va-c-text inline-flex-center gap-1">
<div class="text-2xl" :class="icon" />
<div
class="text-2xl"
:class="icon"
/>
<span class="text-xs">
{{ title }}
</span>
</div>
<span
class="count text-base dark:text-white/80"
>{{ total }}</span>
class="count text-base text-black/80 dark:text-white/80"
>
{{ total }}
</span>
</RouterLink>
</template>

<style lang="scss">
.post-classify-nav-item {
&.router-link-active {
background-color: rgba(var(--va-c-primary-rgb), 0.08);
}
}
</style>

1 comment on commit 47229ca

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://672f9dd460aa1a83e2f45812--valaxy.netlify.app

Please sign in to comment.