AvatarMenu.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { storeToRefs } from 'pinia'
  4. import { computed } from 'vue'
  5. import CommonPopover from '#shared/components/CommonPopover/CommonPopover.vue'
  6. import { usePopover } from '#shared/components/CommonPopover/usePopover.ts'
  7. import CommonUserAvatar from '#shared/components/CommonUserAvatar/CommonUserAvatar.vue'
  8. import { useSessionStore } from '#shared/stores/session.ts'
  9. import CommonPopoverMenu from '#desktop/components/CommonPopoverMenu/CommonPopoverMenu.vue'
  10. import { avatarMenuItems } from '#desktop/components/layout/LayoutSidebar/LeftSidebar/AvatarMenu/plugins/index.ts'
  11. import { useCollapsedState } from '#desktop/components/layout/LayoutSidebar/LeftSidebar/useCollapsedState.ts'
  12. const { user } = storeToRefs(useSessionStore())
  13. const { collapsedState } = useCollapsedState()
  14. const avatarSize = computed(() => (collapsedState?.value ? 'small' : 'normal'))
  15. const { popover, popoverTarget, toggle, isOpen: popoverIsOpen } = usePopover()
  16. </script>
  17. <template>
  18. <CommonPopover
  19. id="user-menu-popover"
  20. ref="popover"
  21. :owner="popoverTarget"
  22. :hide-arrow="collapsedState"
  23. orientation="autoVertical"
  24. :placement="collapsedState ? 'start' : 'arrowStart'"
  25. >
  26. <CommonPopoverMenu
  27. :popover="popover"
  28. :header-label="user?.fullname!"
  29. :items="avatarMenuItems"
  30. />
  31. </CommonPopover>
  32. <button
  33. id="user-menu"
  34. ref="popoverTarget"
  35. v-tooltip="user?.fullname || user?.email || $t('User menu')"
  36. class="-:outline-transparent hover:-:outline-blue-900 rounded-full outline outline-2 focus-visible:outline-blue-800 hover:focus-visible:outline-blue-800"
  37. :class="{
  38. 'outline-blue-800 hover:outline-blue-800': popoverIsOpen,
  39. }"
  40. :aria-label="user?.fullname || user?.email || $t('User menu')"
  41. aria-controls="user-menu-popover"
  42. aria-expanded="false"
  43. @click="toggle(true)"
  44. >
  45. <CommonUserAvatar
  46. v-if="user"
  47. :entity="user"
  48. class="!flex"
  49. :size="avatarSize"
  50. personal
  51. />
  52. </button>
  53. </template>