Skip to content

Instantly share code, notes, and snippets.

@regenrek
Last active September 8, 2021 07:58
Show Gist options
  • Save regenrek/e7e26ca662b896e95b4d3843cf1f56dd to your computer and use it in GitHub Desktop.
Save regenrek/e7e26ca662b896e95b4d3843cf1f56dd to your computer and use it in GitHub Desktop.
AppNav vue
<template>
<aside
class="w-full lg:w-1/5 lg:block fixed lg:relative inset-0 mt-16 lg:mt-0 z-30 bg-white dark:bg-gray-900 lg:bg-transparent lg:dark:bg-transparent"
>
<div class="lg:sticky lg:top-16 overflow-y-auto h-full lg:h-auto lg:max-h-(screen-16)">
<ul class="p-4 lg:py-8 lg:pl-0 lg:pr-8">
<li
v-for="(docs, category, index) in categories"
:key="category"
class="mb-4"
:class="{
'active': isCategoryActive(docs),
'lg:mb-0': index === Object.keys(categories).length - 1
}"
>
<p
v-if="category"
class="mb-2 text-gray-500 uppercase tracking-wider font-bold text-sm lg:text-xs"
>{{ category }}</p>
<ul>
<li v-for="doc of docs" :key="doc.slug" class="text-gray-700 dark:text-gray-300">
<NuxtLink
:to="doc.to"
class="px-2 rounded font-medium py-1 hover:text-primary-500 flex items-center justify-between"
exact-active-class="text-primary-500 bg-primary-100 hover:text-primary-500 dark:bg-primary-900"
>
{{ doc.menuTitle || doc.title }}
</NuxtLink>
</li>
</ul>
</li>
</ul>
</div>
</aside>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
computed: {
categories () {
return this.$store.state.categories['en']
}
},
methods: {
isCategoryActive (documents) {
return documents.some(document => document.to === this.$route.fullPath)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment