AppSubMenu.vue 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Link } from '@inertiajs/inertia-vue3'
  4. defineProps({
  5. items: Array,
  6. root: {
  7. type: Boolean,
  8. default: false,
  9. },
  10. })
  11. const activeIndex = ref(null)
  12. const onMenuItemClick = (event, item, index) => {
  13. if (!item.to) {
  14. event.preventDefault()
  15. }
  16. activeIndex.value = index === activeIndex.value ? null : index
  17. }
  18. </script>
  19. <template>
  20. <ul v-if="items">
  21. <li
  22. v-for="(item, i) of items"
  23. :key="item.label || i"
  24. :class="[{ 'layout-menuitem-category': root, 'active-menuitem': activeIndex === i && !item.to }]"
  25. >
  26. <template v-if="root">
  27. <div class="layout-menuitem-root-text" :aria-label="item.label">{{ item.label }}</div>
  28. <AppSubMenu :items="item.items"></AppSubMenu>
  29. </template>
  30. <template v-else>
  31. <Link
  32. v-if="item.to"
  33. :href="item.to"
  34. class="p-ripple"
  35. :class="{ 'router-link-active': activeIndex, 'router-link-exact-active': activeIndex }"
  36. @click="onMenuItemClick($event, item, i)"
  37. :aria-label="item.label"
  38. v-ripple
  39. >
  40. <i :class="item.icon"></i>
  41. <span>{{ item.label }}</span>
  42. <i v-if="item.items" class="pi pi-angle-down menuitem-toggle-icon"></i>
  43. </Link>
  44. <a
  45. v-if="!item.to"
  46. :href="item.url || '#'"
  47. class="p-ripple"
  48. @click="onMenuItemClick($event, item, i)"
  49. :aria-label="item.label"
  50. v-ripple
  51. >
  52. <i :class="item.icon"></i>
  53. <span>{{ item.label }}</span>
  54. <i v-if="item.items" class="pi pi-angle-down menuitem-toggle-icon"></i>
  55. </a>
  56. <Transition name="layout-submenu-wrapper">
  57. <AppSubMenu v-show="activeIndex === i" :items="item.items"></AppSubMenu>
  58. </Transition>
  59. </template>
  60. </li>
  61. </ul>
  62. </template>