ui icon indicating copy to clipboard operation
ui copied to clipboard

Add children to VerticalNavigation

Open jeydi243 opened this issue 10 months ago • 2 comments

Description

Hi, I really like the way VerticalNavigation is. If it could be possible to have a children component for every link in case of a link have children route. this dribbble explain it well shot image So to add the possibility to have a children key that will also have VerticalNavigation for nested routes. I didn't see like issue. Thank you.

Additional context

Will be also better to have the possibility to set the icon indicator either left or right. The link with children could be rendered as an accordion but with content as a VerticalNavigation component.

jeydi243 avatar Apr 08 '24 14:04 jeydi243

We have the DashboardSidebarLinks component that does exactly that: https://ui.nuxt.com/pro/components/dashboard-sidebar-links but it's part of @nuxt/ui-pro.

benjamincanac avatar Apr 08 '24 14:04 benjamincanac

a very simple menu-component supports nested menu based on nuxt-ui vertical-navigation for those waiting for v3...

<!-- p-menu.vue -->
<template>
  <UVerticalNavigation
    :class="[ns.b(), ns.is(String(props.indent))]"
    :links="props.menus"
    v-bind="$attrs"
  >
    <template #default="{ link }">
      <span class="relative" :class="ns.e('label')">{{ link.name }}</span>
      <p-menu
        v-if="getSubMenus(link).length"
        :menus="getSubMenus(link)"
        :indent="props.indent + 1"
      />
    </template>
  </UVerticalNavigation>
</template>

<script setup lang="ts">
const ns = useBEM("menu");
const props = withDefaults(
  defineProps<{
    indent: number
    menus: any[]
  }>(),
  {
    indent: 0,
    menus: () => []
  }
);

const getSubMenus = (link: any) => {
  return link.childs || []
}
</script>

<style lang="scss">
@import 'assets/styles/index.scss';

@include b("menu") {
  @include e("label") {
    @apply text-base;
  }

  button:has(> .p-menu) {
    flex-wrap: wrap;
    row-gap: 0;

    > .p-menu {
      @apply mt-[0.7rem] -ml-[0.2rem] pl-5;

      @include e("label") {
        @apply font-normal text-sm;
      }
    }
  }
}
</style>

Lionad-Morotar avatar Jul 16 '24 11:07 Lionad-Morotar

Closing in favor of #2136.

benjamincanac avatar Sep 20 '24 12:09 benjamincanac