useHeader.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue'
  3. import useMetaTitle from '#shared/composables/useMetaTitle.ts'
  4. import type { ComputedRef, Ref, UnwrapRef } from 'vue'
  5. import type { RouteLocationRaw } from 'vue-router'
  6. export interface HeaderOptions {
  7. title?: string | ComputedRef<string>
  8. titleClass?: string | ComputedRef<string>
  9. backTitle?: string | ComputedRef<string>
  10. backUrl?: RouteLocationRaw | ComputedRef<RouteLocationRaw>
  11. backAvoidHomeButton?: boolean
  12. backIgnore?: string[]
  13. refetch?: ComputedRef<boolean>
  14. actionTitle?: string | ComputedRef<string>
  15. actionHidden?: boolean | ComputedRef<boolean> | Ref<boolean>
  16. onAction?(): unknown
  17. }
  18. export const headerOptions = ref<HeaderOptions>({})
  19. const { setViewTitle } = useMetaTitle()
  20. watch(
  21. () => headerOptions.value.title,
  22. (title) => title && setViewTitle(title),
  23. )
  24. export const useHeader = (options: HeaderOptions) => {
  25. onBeforeMount(() => {
  26. headerOptions.value = options as UnwrapRef<HeaderOptions>
  27. })
  28. onBeforeUnmount(() => {
  29. headerOptions.value = {}
  30. })
  31. }