TicketSidebarContent.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { onBeforeUnmount, onMounted, useTemplateRef } from 'vue'
  4. import type { ObjectLike } from '#shared/types/utils.ts'
  5. import CommonActionMenu from '#desktop/components/CommonActionMenu/CommonActionMenu.vue'
  6. import type { MenuItem } from '#desktop/components/CommonPopoverMenu/types.ts'
  7. import { useScrollPosition } from '#desktop/composables/useScrollPosition.ts'
  8. interface Props {
  9. title: string
  10. icon: string
  11. entity?: ObjectLike
  12. actions?: MenuItem[]
  13. }
  14. defineProps<Props>()
  15. const scrollPosition = defineModel<number>({
  16. required: true,
  17. default: 0,
  18. })
  19. const scrollContainer = useTemplateRef('scroll-container')
  20. // Handle scroll position (re)storing of the active sidebar, when navigating between taskbar tabs.
  21. useScrollPosition(scrollContainer)
  22. // Handle scroll position (re)storing, when switching between different sidebars.
  23. onMounted(() => {
  24. if (!scrollContainer?.value) return
  25. scrollContainer.value.scrollTop = scrollPosition.value
  26. })
  27. onBeforeUnmount(() => {
  28. if (!scrollContainer?.value) return
  29. scrollPosition.value = scrollContainer.value.scrollTop
  30. })
  31. </script>
  32. <template>
  33. <div class="flex w-full gap-2 p-3">
  34. <CommonLabel
  35. tag="h2"
  36. class="min-h-7 grow gap-1.5"
  37. size="large"
  38. :prefix-icon="icon"
  39. icon-color="text-stone-200 dark:text-neutral-500"
  40. >
  41. {{ $t(title) }}
  42. </CommonLabel>
  43. <CommonActionMenu
  44. v-if="actions"
  45. class="text-gray-100 dark:text-neutral-400"
  46. no-single-action-mode
  47. placement="arrowEnd"
  48. :entity="entity"
  49. :actions="actions"
  50. />
  51. </div>
  52. <div
  53. ref="scroll-container"
  54. class="flex h-full flex-col gap-3 overflow-y-auto p-3"
  55. >
  56. <slot />
  57. </div>
  58. </template>