PageNavigation.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!-- Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { nextTick } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import { useSessionStore } from '#shared/stores/session.ts'
  6. import emitter from '#shared/utils/emitter.ts'
  7. import CommonSectionCollapse from '#desktop/components/CommonSectionCollapse/CommonSectionCollapse.vue'
  8. import { sortedFirstLevelRoutes } from '#desktop/components/PageNavigation/firstLevelRoutes.ts'
  9. import CommonButton from '../CommonButton/CommonButton.vue'
  10. interface Props {
  11. collapsed?: boolean
  12. }
  13. //*
  14. // IMPORTANT: This is just a temporary implementations please replace and adapt it later
  15. // *//
  16. defineProps<Props>()
  17. const router = useRouter()
  18. const { userId } = useSessionStore()
  19. const openSearch = () => {
  20. emitter.emit('expand-collapsed-content', `${userId}-left`)
  21. nextTick(() => emitter.emit('focus-quick-search-field'))
  22. }
  23. </script>
  24. <template>
  25. <div class="py-2">
  26. <CommonSectionCollapse
  27. id="page-navigation"
  28. :title="__('Navigation')"
  29. :no-header="collapsed"
  30. >
  31. <template #default="{ headerId }">
  32. <nav :aria-labelledby="headerId">
  33. <ul class="m-0 flex basis-full flex-col gap-1 p-0">
  34. <li class="flex justify-center">
  35. <CommonButton
  36. v-if="collapsed"
  37. class="flex-shrink-0 text-neutral-400 hover:outline-blue-900"
  38. size="large"
  39. variant="neutral"
  40. :aria-label="$t('Open quick search')"
  41. icon="search"
  42. @click="openSearch"
  43. />
  44. </li>
  45. <li
  46. v-for="route in sortedFirstLevelRoutes"
  47. :key="route.path"
  48. class="flex justify-center"
  49. >
  50. <CommonButton
  51. v-if="collapsed"
  52. class="flex-shrink-0 text-neutral-400 hover:outline-blue-900"
  53. size="large"
  54. variant="neutral"
  55. :icon="route.meta.icon"
  56. @click="router.push(route.path.replace(/:\w+/, ''))"
  57. />
  58. <CommonLink
  59. v-else
  60. class="flex grow gap-2 rounded-md px-2 py-3 text-neutral-400 hover:bg-blue-900 hover:text-white! hover:no-underline!"
  61. :class="{
  62. 'bg-blue-800! text-white!':
  63. router.currentRoute.value.name === route.name, // $route.name is not detected by ts
  64. }"
  65. :link="route.path.replace(/\/:\w+/, '')"
  66. exact-active-class="bg-blue-800! w-full text-white!"
  67. internal
  68. >
  69. <CommonLabel
  70. class="gap-2 text-sm! text-current!"
  71. size="large"
  72. :prefix-icon="route.meta.icon"
  73. >
  74. {{ $t(route.meta.title) }}
  75. </CommonLabel>
  76. </CommonLink>
  77. </li>
  78. </ul>
  79. </nav>
  80. </template>
  81. </CommonSectionCollapse>
  82. </div>
  83. </template>