jointrashposs/components/docs/AsideNav.vue

61 lines
1.5 KiB
Vue
Raw Normal View History

2023-07-16 13:18:07 +02:00
<template>
<ul class="toc-links mb-4 space-y-2">
<li
v-for="link in findDeepObject((links[0] as NavItem), (v) => realBasePath.replace(/\/$/, '') === v?._path.replace(/\/$/, ''))?.children ?? []"
2023-07-16 13:18:07 +02:00
:key="link.text"
:class="[`depth-${link.depth}`]"
>
<GNuxtLink
:to="link._path"
@click.passive="emit('child-click');"
:class="['hover:text-accent-600']"
2023-07-16 13:18:07 +02:00
>
{{ link.text }}
</GNuxtLink>
2023-07-16 13:18:07 +02:00
<AsideNav
class="mt-2"
v-if="link.children"
:links="link.children"
/>
</li>
</ul>
</template>
<script setup lang="ts">
import type { PropType } from 'vue'
import type { NavItem } from '@nuxt/content/dist/runtime/types'
import { findDeepObject } from 'assets/js/misc';
2023-07-16 13:18:07 +02:00
const props = defineProps({
links: {
type: Array as PropType<NavItem[]>,
2023-07-16 13:18:07 +02:00
default: () => []
},
basePath: {
type: String,
default: '',
2023-07-16 13:18:07 +02:00
}
});
const { locale } = useI18n();
const route = useRoute();
2023-07-16 13:18:07 +02:00
const realBasePath = computed<string>(() => {
if (props.basePath) {
return props.basePath;
2023-07-16 13:18:07 +02:00
}
return route.path.replace(/^.*\/docs/, `/${locale.value}/docs`);
});
const emit = defineEmits(['move', 'child-click']);
2023-07-16 13:18:07 +02:00
</script>
<style scoped>
.toc-links ::v-deep(.depth-3) {
@apply ml-2;
}
.toc-links ::v-deep(.depth-4) {
@apply ml-4;
}
</style>