Skip to content

Commit

Permalink
check menu item emptyness
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Dec 19, 2023
1 parent 3d73c84 commit b656949
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/components/SLocalNav.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<script setup lang="ts">
import { computed } from 'vue'
import SLocalNavMenu, { type MenuItem } from './SLocalNavMenu.vue'
import SLocalNavTitle, { type Title } from './SLocalNavTitle.vue'
export type { Title, MenuItem }
defineProps<{
const props = defineProps<{
title: Title[]
menu?: MenuItem[][]
}>()
const normalizedMenu = computed(() => {
return props.menu?.reduce<MenuItem[][]>((carry, group) => {
group.length && carry.push(group)
return carry
}, []) ?? null
})
</script>

<template>
<div class="SLocalNav" :class="{ 'has-menu': menu }">
<div class="SLocalNav" :class="{ 'has-menu': normalizedMenu }">
<SLocalNavTitle :title="title" />
<SLocalNavMenu v-if="menu" :menu="menu" />
<SLocalNavMenu v-if="normalizedMenu" :menu="normalizedMenu" />
</div>
</template>

Expand Down

0 comments on commit b656949

Please sign in to comment.