AppSubSidebar.vue 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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="[
  25. {
  26. 'layout-menuitem-category': root,
  27. 'active-menuitem': activeIndex === i && !item.to,
  28. },
  29. ]"
  30. >
  31. <template v-if="root">
  32. <div class="layout-menuitem-root-text" :aria-label="item.label">
  33. {{ item.label }}
  34. </div>
  35. <AppSubSidebar :items="item.items" />
  36. </template>
  37. <template v-else>
  38. <Link
  39. v-if="item.to"
  40. :href="item.to"
  41. class="p-ripple"
  42. :class="{
  43. 'router-link-active': activeIndex,
  44. 'router-link-exact-active': activeIndex,
  45. }"
  46. @click="onMenuItemClick($event, item, i)"
  47. :aria-label="item.label"
  48. v-ripple
  49. >
  50. <i :class="item.icon"></i>
  51. <span>{{ item.label }}</span>
  52. <i
  53. v-if="item.items"
  54. class="pi pi-angle-down menuitem-toggle-icon"
  55. ></i>
  56. </Link>
  57. <a
  58. v-if="!item.to"
  59. :href="item.url || '#'"
  60. class="p-ripple"
  61. @click="onMenuItemClick($event, item, i)"
  62. :aria-label="item.label"
  63. v-ripple
  64. >
  65. <i :class="item.icon"></i>
  66. <span>{{ item.label }}</span>
  67. <i
  68. v-if="item.items"
  69. class="pi pi-angle-down menuitem-toggle-icon"
  70. ></i>
  71. </a>
  72. <Transition name="layout-submenu-wrapper">
  73. <AppSubSidebar v-show="activeIndex === i" :items="item.items" />
  74. </Transition>
  75. </template>
  76. </li>
  77. </ul>
  78. </template>